A Javascript/Typescript package for converting between MusicXML and the new MNX format. Works in Browser and Node.js.
This converter is initially ported from Python Package https://github.com/w3c/mnxconverter and very limited in scope at the moment. So far, it only reliably converts the types of notations described in Comparing MNX and MusicXML.
First, make sure you have package installed:
npm install mnxconverter
or
yarn add mnxconverter
To convert a MusicXML file, outputting the MNX score object:
import { getScoreFromMusicXml, getMNXScore } from 'mnxconverter';
const score = getScoreFromMusicXml('<?xml your music xml goes here....>'); // get internal model
const mnxScore = getMNXScore(score); // encode model as mnx score object
// {
// "global": {...},
// "mnx": {...},
// "parts": {...}
// }
Install jsdom or any browser compatible DomParser
npm install jsdom
Set global variables
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const { DOMParser, XPathResult } = new JSDOM().window;
global.DOMParser = DOMParser;
global.XPathResult = XPathResult;
// conversion code like above...
Highly inspired by converter developed by Adrian Holovaty