/** * This file is part of Satie music engraver . * Copyright (C) Joshua Netterfield 2015 - present. * * Satie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * Satie is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Satie. If not, see . */ import {serializeScoreHeader} from "musicxml-interfaces"; import {forEach, map} from "lodash"; import {Document} from "./document"; export function exportXML(score: Document): string { let out = ""; out += serializeScoreHeader(score.header) + "\n"; let recordedSongMeta = false; forEach(score.measures, measure => { // TODO: dehack out += `\n`; forEach(measure.parts, (part, id) => { out += ` \n`; out += ` \n`; if (!recordedSongMeta) { out += ` ` + `SATIE_SONG_META = ${JSON.stringify({})};` + `\n`; recordedSongMeta = true; } out += ` ` + `SATIE_MEASURE_META = ${JSON.stringify({uuid: measure.uuid})};` + `\n`; out += ` \n`; forEach(part.staves, (staff, staffIdx) => { if (staff) { out += ` \n`; out += (map(staff, model => (model).toXML()) .join("\n") .split("\n") .map(t => " " + t) .join("\n")) + "\n"; let divCount = staff.reduce((sum, item) => sum + item.divCount, 0); out += ` ${divCount}\n`; out += ` \n`; } }); forEach(part.voices, (voice, voiceIdx) => { if (voice) { out += ` \n`; out += (map(voice, model => (model).toXML()) .join("\n") .split("\n") .map(t => " " + t) .join("\n")) + "\n"; let divCount = voice.reduce((sum, item) => sum + item.divCount, 0); out += ` ${divCount}\n`; out += ` \n`; } }); out += ` \n`; }); out += `\n`; }); return "\n" + "\n" + "\n" + out.split("\n").map(t => " " + t).join("\n") + ""; }