Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion scripts/extract-w3c-mnx-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import cheerio from 'cheerio';
const examplesUrl = 'https://w3c.github.io/mnx/docs/comparisons/musicxml/';

const cwd = process.cwd();
const targetPath = path.join(cwd, 'tests', 'integration', '__data__', 'w3c-mnx');
const targetPath = path.join(cwd, 'tests', '__data__', 'w3c-mnx');

if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath);
Expand Down
21 changes: 13 additions & 8 deletions src/parsing/musicxml/musicxmlparser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as data from '@/data';
import * as musicxml from '@/musicxml';
import * as errors from '@/errors';
import { Score } from './score';
import { Config, DEFAULT_CONFIG } from '@/config';
import { Logger, NoopLogger } from '@/debug';
Expand All @@ -9,7 +10,6 @@ export type MusicXMLParserOptions = {
logger?: Logger;
};

/** Parses a MusicXML document string. */
export class MusicXMLParser {
private config: Config;
private log: Logger;
Expand All @@ -19,15 +19,20 @@ export class MusicXMLParser {
this.log = opts?.logger ?? new NoopLogger();
}

parse(musicXMLString: string): data.Document {
const musicXML = this.parseMusicXMLString(musicXMLString);
/** Parses a MusicXML source into a vexml data document. */
parse(musicXMLSrc: string | Document): data.Document {
let musicXML: musicxml.MusicXML;
if (musicXMLSrc instanceof Document) {
musicXML = new musicxml.MusicXML(musicXMLSrc);
} else if (typeof musicXMLSrc === 'string') {
musicXML = new musicxml.MusicXML(new DOMParser().parseFromString(musicXMLSrc, 'application/xml'));
} else {
throw new errors.VexmlError(`Invalid source type: ${musicXMLSrc}`);
}

const scorePartwise = musicXML.getScorePartwise();
const score = Score.create(this.config, this.log, { scorePartwise }).parse();
return new data.Document(score);
}

private parseMusicXMLString(musicXML: string): musicxml.MusicXML {
const xml = new DOMParser().parseFromString(musicXML, 'application/xml');
return new musicxml.MusicXML(xml);
return new data.Document(score);
}
}
2 changes: 1 addition & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type RenderMusicXMLOptions = {
logger?: Logger;
};

export function renderMusicXML(musicXML: string, div: HTMLDivElement, opts?: RenderMusicXMLOptions): Score {
export function renderMusicXML(musicXML: string | Document, div: HTMLDivElement, opts?: RenderMusicXMLOptions): Score {
const config = { ...DEFAULT_CONFIG, ...opts?.config };
const logger = opts?.logger ?? new NoopLogger();

Expand Down
Loading