-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from stringsync/fermata
Render lilypond32a (fermatas)
- Loading branch information
Showing
14 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NamedElement } from '@/util'; | ||
import { FERMATA_SHAPES, FERMATA_TYPES, FermataShape, FermataType } from './enums'; | ||
|
||
/** | ||
* The `<fermata>` element content represents the shape of the fermata sign. | ||
* | ||
* See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/fermata/ | ||
*/ | ||
export class Fermata { | ||
constructor(private element: NamedElement<'fermata'>) {} | ||
|
||
/** Returns the shape of the fermata. Defaults to normal. */ | ||
getShape(): FermataShape { | ||
return this.element.content().enum(FERMATA_SHAPES) ?? 'normal'; | ||
} | ||
|
||
/** Returns the type of fermata. Defaults to upright. */ | ||
getType(): FermataType { | ||
return this.element.attr('type').withDefault<FermataType>('upright').enum(FERMATA_TYPES); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as vexflow from 'vexflow'; | ||
import * as musicxml from '@/musicxml'; | ||
|
||
/** The result of rendering an Articulation. */ | ||
export type FermataRendering = { | ||
type: 'fermata'; | ||
vexflow: { | ||
articulation: vexflow.Articulation; | ||
}; | ||
}; | ||
|
||
/** Represents a Fermata. */ | ||
export class Fermata { | ||
private musicXML: { fermata: musicxml.Fermata }; | ||
|
||
constructor(opts: { musicXML: { fermata: musicxml.Fermata } }) { | ||
this.musicXML = opts.musicXML; | ||
} | ||
|
||
render(): FermataRendering { | ||
return { | ||
type: 'fermata', | ||
vexflow: { | ||
articulation: this.getVfArticulation(), | ||
}, | ||
}; | ||
} | ||
|
||
private getVfArticulation(): vexflow.Articulation { | ||
const type = this.musicXML.fermata.getType(); | ||
|
||
switch (type) { | ||
case 'upright': | ||
return new vexflow.Articulation('a@a'); | ||
case 'inverted': | ||
return new vexflow.Articulation('a@u').setPosition(vexflow.ModifierPosition.BELOW); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73.2 KB
tests/integration/__image_snapshots__/multi_system_spanners_400px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { FERMATA_SHAPES, FERMATA_TYPES, Fermata } from '@/musicxml'; | ||
import { xml } from '@/util'; | ||
|
||
describe(Fermata, () => { | ||
describe('getShape', () => { | ||
it.each(FERMATA_SHAPES.values)('returns the shape of the fermata', (shape) => { | ||
const node = xml.fermata({ shape }); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getShape()).toBe(shape); | ||
}); | ||
|
||
it('defaults to normal when missing', () => { | ||
const node = xml.fermata(); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getShape()).toBe('normal'); | ||
}); | ||
|
||
it('defaults to normal when invalid', () => { | ||
const node = xml.fermata({ shape: 'foo' }); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getShape()).toBe('normal'); | ||
}); | ||
}); | ||
|
||
describe('getType', () => { | ||
it.each(FERMATA_TYPES.values)('returns the type of the fermata', (type) => { | ||
const node = xml.fermata({ type }); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getType()).toBe(type); | ||
}); | ||
|
||
it('defaults to upright when missing', () => { | ||
const node = xml.fermata(); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getType()).toBe('upright'); | ||
}); | ||
|
||
it('defaults to upright when invalid', () => { | ||
const node = xml.fermata({ type: 'foo' }); | ||
const fermata = new Fermata(node); | ||
expect(fermata.getType()).toBe('upright'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters