Skip to content

Commit

Permalink
Initial commit for MuseScore converter/renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Oct 7, 2024
1 parent ebb506b commit e6fbffc
Show file tree
Hide file tree
Showing 43 changed files with 2,260 additions and 267 deletions.
1 change: 0 additions & 1 deletion demo/data/brazilian.txt

This file was deleted.

1 change: 0 additions & 1 deletion demo/data/stevie-wonder.txt

This file was deleted.

74 changes: 74 additions & 0 deletions demo/data/tutorial-apres-un-reve.mscore.json

Large diffs are not rendered by default.

1,574 changes: 1,574 additions & 0 deletions demo/data/tutorial-apres-un-reve.musicxml

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions demo/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ async function createPlayer() {
// Create new player.
if (g_state.musicXml) {
try {
const rendererObject = await createRenderer(renderer, sheet, options);
const player = await MusicXMLPlayer.Player.create({
musicXml: g_state.musicXml,
container: 'sheet-container',
renderer: createRenderer(renderer, options),
renderer: rendererObject,
output: createOutput(output),
converter: await createConverter(converter, sheet, groove),
converter: await createConverter(rendererObject, converter, sheet, groove),
unroll: options.unroll,
mute: options.mute,
repeat: Number(repeat),
Expand Down Expand Up @@ -107,7 +108,7 @@ async function createPlayer() {
}
}

function createRenderer(renderer, options) {
async function createRenderer(renderer, sheet, options) {
switch (renderer) {
case 'osmd':
return new MusicXMLPlayer.OpenSheetMusicDisplayRenderer({
Expand All @@ -124,8 +125,19 @@ function createRenderer(renderer, options) {
}, {
scrollOffset: 100,
});
case 'mscore':
const base = sheet.startsWith('http') || sheet.startsWith('data/') ? sheet : `data/${sheet}`;
const mscore = base.replace(/\.musicxml$|\.mxl$/, '.mscore.json');
try {
await MusicXMLPlayer.fetish(mscore, { method: 'HEAD' });
return new MusicXMLPlayer.MuseScoreRendererConverter(mscore);
}
catch {
console.warn(`MuseScore rendering not available for ${sheet}. Falling back to default.`);
return createRenderer(DEFAULT_RENDERER);
}
default:
console.warn(`Unknown renderer ${renderer}`);
console.warn(`Unknown renderer ${renderer}. Falling back to default.`);
return createRenderer(DEFAULT_RENDERER);
}
}
Expand All @@ -134,7 +146,7 @@ function getMmaEndpoint() {
return window.location.href + 'mma';
}

async function createConverter(converter, sheet, groove) {
async function createConverter(rendererObject, converter, sheet, groove) {
const candidates = [{
converter: new MusicXMLPlayer.VerovioConverter(),
id: 'converter-vrv',
Expand Down Expand Up @@ -183,6 +195,15 @@ async function createConverter(converter, sheet, groove) {
document.querySelector('input[name="converter"][id="converter-mma"]').disabled = true;
}

console.log(rendererObject);
if (rendererObject instanceof MusicXMLPlayer.MuseScoreRendererConverter) {
candidates.push({
converter: rendererObject,
id: 'converter-mscore',
priority: 20
});
}

const chosen = candidates.reduce((chosen, candidate) => {
document.querySelector(`input[name="converter"][id="${candidate.id}"]`).disabled = false;
if (candidate.id === `converter-${converter}`) {
Expand Down
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ <h1>MusicXML Player Demo</h1>
<option value="">-- Choose --</option>
<option value="data/salma-ya-salama.mxl">Salma ya Salama (Compressed MusicXML)</option>
<option value="data/asa-branca.musicxml">Asa Branca (Uncompressed MusicXML)</option>
<option value="data/tutorial-apres-un-reve.musicxml">Après un rêve (MuseScore Rendering)</option>
<option value="data/rast-tetrachord.musicxml">Rast Tetrachords (Microtonal MusicXML)</option>
<option value="data/baiao-miranda.musicxml">Baião Groove (Rhythm MusicXML)</option>
<option value="data/jazz.txt">Playlist: Jazz 1400 (iReal Pro)</option>
<option value="data/brazilian.txt">Playlist: Brazilian 150 (iReal Pro)</option>
<option value="data/stevie-wonder.txt">Playlist: Stevie Wonder 30 (iReal Pro)</option>
</select>
</div>

Expand Down Expand Up @@ -90,6 +89,8 @@ <h1>MusicXML Player Demo</h1>
<label for="renderer-osmd">OpenSheetMusicDisplay</label>
<input type="radio" id="renderer-vrv" name="renderer" value="vrv"/>
<label for="renderer-vrv">Verovio</label>
<input type="radio" id="renderer-mscore" name="renderer" value="mscore"/>
<label for="renderer-mscore">MuseScore</label>
<div class="player-options">
<input type="checkbox" class="player-option" id="option-unroll" value="unroll"/>
<label for="option-unroll">Unroll score</label>
Expand All @@ -106,6 +107,8 @@ <h1>MusicXML Player Demo</h1>
<label for="converter-mma">MusicXML MMA</label>
<input type="radio" id="converter-vrv" name="converter" value="vrv"/>
<label for="converter-vrv">Verovio</label>
<input type="radio" id="converter-mscore" name="converter" value="mscore"/>
<label for="converter-mscore">MuseScore</label>
</div>

<div>
Expand Down
Loading

0 comments on commit e6fbffc

Please sign in to comment.