Skip to content

Commit 93e3818

Browse files
authored
fix: android musicxml compatibility (#2650)
1 parent 71af261 commit 93e3818

9 files changed

Lines changed: 111 additions & 16 deletions

File tree

packages/alphatab/src/platform/worker/AlphaTabWorkerScoreRenderer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ export class AlphaTabWorkerScoreRenderer<T> implements IScoreRenderer {
105105
(this.renderFinished as EventEmitterOfT<RenderFinishedEventArgs>).trigger(data.result);
106106
break;
107107
case 'alphaTab.postRenderFinished':
108-
this.boundsLookup = BoundsLookup.fromJson(data.boundsLookup, this._api.score!);
109-
this.boundsLookup?.finish();
108+
const score = this._api.score;
109+
if (score && data.boundsLookup) {
110+
this.boundsLookup = BoundsLookup.fromJson(data.boundsLookup, this._api.score!);
111+
this.boundsLookup?.finish();
112+
}
110113
(this.postRenderFinished as EventEmitter).trigger();
111114
break;
112115
case 'alphaTab.error':

packages/alphatab/src/rendering/LineBarRenderer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,19 @@ export abstract class LineBarRenderer extends BarRendererBase {
261261
s = [];
262262
const zero = MusicFontSymbol.Tuplet0 as number;
263263
if (num > 10) {
264-
s.push((zero + Math.floor(num / 10)) as MusicFontSymbol);
265-
s.push((zero + (num - 10)) as MusicFontSymbol);
264+
const tens = Math.floor(num / 10);
265+
s.push((zero + tens) as MusicFontSymbol);
266+
s.push((zero + (num - 10 * tens)) as MusicFontSymbol);
266267
} else {
267268
s.push((zero + num) as MusicFontSymbol);
268269
}
269270

270271
s.push(MusicFontSymbol.TupletColon);
271272

272273
if (den > 10) {
273-
s.push((zero + Math.floor(den / 10)) as MusicFontSymbol);
274-
s.push((zero + (den - 10)) as MusicFontSymbol);
274+
const tens = Math.floor(den / 10);
275+
s.push((zero + tens) as MusicFontSymbol);
276+
s.push((zero + (den - 10 * tens)) as MusicFontSymbol);
275277
} else {
276278
s.push((zero + den) as MusicFontSymbol);
277279
}

packages/alphatab/src/rendering/glyphs/ScoreBeatGlyph.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ export class ScoreBeatGlyph extends BeatOnNoteGlyphBase {
264264
const group: GlyphGroup = new GlyphGroup(0, 0);
265265
group.renderer = this.renderer;
266266
for (const note of this.container.beat.notes) {
267-
const g = this._createBeatDot(sr.getNoteSteps(note), group);
268-
g.colorOverride = ElementStyleHelper.noteColor(
269-
sr.resources,
270-
NoteSubElement.StandardNotationEffects,
271-
note
272-
);
267+
if (note.isVisible) {
268+
const g = this._createBeatDot(sr.getNoteSteps(note), group);
269+
g.colorOverride = ElementStyleHelper.noteColor(
270+
sr.resources,
271+
NoteSubElement.StandardNotationEffects,
272+
note
273+
);
274+
}
273275
}
274276
this.addEffect(group);
275277
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
3+
<score-partwise version="3.1">
4+
<part-list>
5+
<score-part id="P1">
6+
<part-name>Piano</part-name>
7+
<score-instrument id="P1-I1">
8+
<instrument-name>Piano</instrument-name>
9+
</score-instrument>
10+
<midi-device id="P1-I1" port="1"></midi-device>
11+
<midi-instrument id="P1-I1">
12+
<midi-channel>1</midi-channel>
13+
<midi-program>1</midi-program>
14+
<volume>78.7402</volume>
15+
<pan>0</pan>
16+
</midi-instrument>
17+
</score-part>
18+
</part-list>
19+
<part id="P1">
20+
<measure number="1" width="412.51">
21+
<attributes>
22+
<divisions>480</divisions>
23+
<key>
24+
<fifths>-5</fifths>
25+
</key>
26+
<time>
27+
<beats>9</beats>
28+
<beat-type>8</beat-type>
29+
</time>
30+
<staves>2</staves>
31+
<clef number="1">
32+
<sign>G</sign>
33+
<line>2</line>
34+
</clef>
35+
<clef number="2">
36+
<sign>G</sign>
37+
<line>2</line>
38+
</clef>
39+
</attributes>
40+
<note default-x="176.69" default-y="-142.96" print-object="no">
41+
<pitch>
42+
<step>F</step>
43+
<octave>4</octave>
44+
</pitch>
45+
<duration>480</duration>
46+
<tie type="start"/>
47+
<voice>5</voice>
48+
<type>quarter</type>
49+
<dot/>
50+
<stem>none</stem>
51+
<staff>2</staff>
52+
<notations>
53+
<tied type="start"/>
54+
</notations>
55+
</note>
56+
<note default-x="255.99" default-y="-142.96">
57+
<pitch>
58+
<step>F</step>
59+
<octave>4</octave>
60+
</pitch>
61+
<duration>1440</duration>
62+
<tie type="stop"/>
63+
<voice>5</voice>
64+
<type>half</type>
65+
<dot/>
66+
<stem>up</stem>
67+
<staff>2</staff>
68+
<notations>
69+
<tied type="stop"/>
70+
</notations>
71+
</note>
72+
</measure>
73+
</part>
74+
</score-partwise>
15.1 KB
Loading
10 KB
Loading

packages/alphatab/test/exporter/AlphaTexExporter.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ describe('AlphaTexExporterTest', () => {
5656
}
5757
}
5858

59-
async function testRoundTripFolderEqual(name: string): Promise<void> {
59+
async function testRoundTripFolderEqual(name: string, ignoredFiles?: string[]): Promise<void> {
6060
const files: string[] = await TestPlatform.listDirectory(`test-data/${name}`);
61+
const ignoredFilesLookup = new Set<string>(ignoredFiles);
6162
for (const file of files.filter(f => !f.endsWith('.png'))) {
62-
await testRoundTripEqual(`${name}/${file}`, null);
63+
if (!ignoredFilesLookup.has(file) && !file.endsWith('.png')) {
64+
await testRoundTripEqual(`${name}/${file}`, null);
65+
}
6366
}
6467
}
6568

@@ -133,7 +136,7 @@ describe('AlphaTexExporterTest', () => {
133136
});
134137

135138
it('visual-effects-and-annotations', async () => {
136-
await testRoundTripFolderEqual('visual-tests/effects-and-annotations');
139+
await testRoundTripFolderEqual('visual-tests/effects-and-annotations', ['hidden-dots.mxml']);
137140
});
138141

139142
it('visual-general', async () => {

packages/alphatab/test/exporter/Gp7Exporter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Gp7ExporterTest', () => {
7777
});
7878

7979
it('visual-effects-and-annotations', async () => {
80-
await testRoundTripFolderEqual('visual-tests/effects-and-annotations');
80+
await testRoundTripFolderEqual('visual-tests/effects-and-annotations', ['hidden-dots.mxml']);
8181
});
8282

8383
it('visual-general', async () => {

packages/alphatab/test/visualTests/features/EffectsAndAnnotations.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ describe('EffectsAndAnnotationsTests', () => {
119119
await VisualTestHelper.runVisualTest('effects-and-annotations/tuplets.gp');
120120
});
121121

122+
it('tuplets-huge', async () => {
123+
await VisualTestHelper.runVisualTestTex(
124+
'C4 {tu 12 27} * 12',
125+
'test-data/visual-tests/effects-and-annotations/tuplets-huge.png'
126+
);
127+
});
128+
129+
it('hidden-dots', async () => {
130+
await VisualTestHelper.runVisualTest('effects-and-annotations/hidden-dots.mxml');
131+
});
132+
122133
it('tuplets-advanced', async () => {
123134
await VisualTestHelper.runVisualTest('effects-and-annotations/tuplets-advanced.gp', undefined, o => {
124135
o.tracks = [0, 1, 2];

0 commit comments

Comments
 (0)