UNPKG

satie

Version:

A sheet music renderer for the web

112 lines (111 loc) 9.1 kB
/** * This file is part of Satie music engraver <https://github.com/jnetterf/satie>. * Copyright (C) Joshua Netterfield <joshua.ca> 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 <http://www.gnu.org/licenses/>. */ "use strict"; /** * @file part of Satie test suite */ var engine_scoreHeader_1 = require("../engine_scoreHeader"); var chai_1 = require("chai"); var musicxml_interfaces_1 = require("musicxml-interfaces"); var headerTest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 3.0 Partwise//EN\"\n \"http://www.musicxml.org/dtds/partwise.dtd\">\n<score-partwise version=\"3.0\">\n <movement-title>Song Title</movement-title>\n <identification>\n <creator type=\"composer\">Song Composer</creator>\n <creator type=\"lyricist\">Song Lyricist</creator>\n <creator type=\"arranger\">Song Arranger</creator>\n <rights>Song Copyright</rights>\n <encoding>\n <software>Song Software 1</software>\n <software>Song Software 2</software>\n <encoding-date>2015-03-10</encoding-date>\n <supports attribute=\"new-page\" element=\"print\" type=\"yes\" value=\"yes\"/>\n <supports element=\"accidental\" type=\"yes\"/>\n </encoding>\n </identification>\n <credit page=\"1\">\n <credit-type>title</credit-type>\n <credit-words default-x=\"597\" default-y=\"1440\" font-size=\"24\" justify=\"center\" valign=\"top\">\n Song Title\n </credit-words>\n </credit>\n <credit page=\"1\">\n <credit-type>composer</credit-type>\n <credit-words default-x=\"1124\" default-y=\"1362\" font-size=\"12\" justify=\"right\" valign=\"top\">\n Song Composer\n </credit-words>\n </credit>\n <credit page=\"1\">\n <credit-type>rights</credit-type>\n <credit-words default-x=\"597\" default-y=\"70\" font-size=\"10\" justify=\"center\" valign=\"bottom\">\n Song Copyright\n </credit-words>\n </credit>\n <credit page=\"1\">\n <credit-words default-x=\"70\" default-y=\"1453\" font-size=\"12\" valign=\"top\">Score</credit-words>\n </credit>\n <credit page=\"2\">\n <credit-type>rights</credit-type>\n <credit-words default-x=\"597\" default-y=\"70\" font-size=\"10\" justify=\"center\" valign=\"bottom\">\n Song Copyright\n </credit-words>\n </credit>\n <part-list>\n <score-part id=\"P1\">\n <part-name print-object=\"no\">MusicXML Part</part-name>\n <score-instrument id=\"P1-I1\">\n <instrument-name>SmartMusic SoftSynth 1</instrument-name>\n </score-instrument>\n <midi-instrument id=\"P1-I1\">\n <midi-channel>1</midi-channel>\n <midi-bank>15489</midi-bank>\n <midi-program>1</midi-program>\n <volume>80</volume>\n <pan>0</pan>\n </midi-instrument>\n </score-part>\n </part-list>\n <part id=\"P1\">\n <measure number=\"1\" width=\"983\">\n <print>\n <system-layout>\n <system-margins>\n <left-margin>70</left-margin>\n <right-margin>0</right-margin>\n </system-margins>\n <top-system-distance>211</top-system-distance>\n </system-layout>\n <measure-numbering>system</measure-numbering>\n </print>\n <attributes>\n <divisions>2</divisions>\n <key>\n <fifths>0</fifths>\n <mode>major</mode>\n </key>\n <time>\n <beats>4</beats>\n <beat-type>4</beat-type>\n </time>\n <clef>\n <sign>G</sign>\n <line>2</line>\n </clef>\n </attributes>\n <sound tempo=\"120\"/>\n <note>\n <rest measure=\"yes\"/>\n <duration>8</duration>\n <voice>1</voice>\n </note>\n <barline location=\"right\">\n <bar-style>light-heavy</bar-style>\n </barline>\n </measure>\n </part>\n</score-partwise>\n"; var minimalTest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 3.0 Partwise//EN\"\n \"http://www.musicxml.org/dtds/partwise.dtd\">\n<score-partwise version=\"3.0\">\n <part-list>\n <score-part id=\"P1\">\n <part-name print-object=\"no\">MusicXML Part</part-name>\n </score-part>\n </part-list>\n <part id=\"P1\">\n <measure number=\"1\">\n </measure>\n </part>\n</score-partwise>\n"; describe("[engine/scoreHeader.ts]", function () { // NOTE: Some of the tests in mxmljson_test indirectly test ScoreHeader! it("can correctly modify metadata", function () { var mxmljson = musicxml_interfaces_1.parseScore(headerTest); var scoreHeader = new engine_scoreHeader_1.default(mxmljson); chai_1.expect(scoreHeader.credits.length).eq(5); chai_1.expect(scoreHeader.identification.creators.length).eq(3); // Changing the composer should change the credit words and identification scoreHeader.composer = "New Composer"; chai_1.expect(scoreHeader.credits.length).eq(5); chai_1.expect(scoreHeader.identification.creators.length).eq(3); chai_1.expect(scoreHeader.composer).to.eq("New Composer"); // Since get is not directly tied to set chai_1.expect(scoreHeader.identification.creators[0].creator).to.eq("New Composer"); chai_1.expect(scoreHeader.identification.creators[1].creator).to.not.eq("New Composer"); chai_1.expect(scoreHeader.identification.creators[2].creator).to.not.eq("New Composer"); chai_1.expect(scoreHeader.credits[1].creditWords[0].words).to.eq("New Composer"); // Changing the title should change credit words and movementTitle scoreHeader.title = "New Title"; chai_1.expect(scoreHeader.credits.length).eq(5); chai_1.expect(scoreHeader.identification.creators.length).eq(3); chai_1.expect(scoreHeader.title).to.eq("New Title"); // Since get is not directly tied to set chai_1.expect(scoreHeader.movementTitle).to.eq("New Title"); chai_1.expect(scoreHeader.credits[0].creditWords[0].words).to.eq("New Title"); }); it("can correctly add metadata", function () { var mxmljson = musicxml_interfaces_1.parseScore(minimalTest); var scoreHeader = new engine_scoreHeader_1.default(mxmljson); chai_1.expect(scoreHeader.credits.length).eq(0); chai_1.expect(scoreHeader.identification.creators.length).eq(0); scoreHeader.title = "Orig Title"; scoreHeader.composer = "Orig Composer"; scoreHeader.arranger = "Orig Arranger"; scoreHeader.lyricist = "Orig Lyricist"; chai_1.expect(scoreHeader.credits).to.deep.equal([ { creditImage: null, creditTypes: ["title"], creditWords: [{ words: "Orig Title", defaultX: 664.3076923076923, defaultY: 1657.8461538461538, fontSize: "18px", justify: musicxml_interfaces_1.LeftCenterRight.Center }], page: 1 }, { creditImage: null, creditTypes: ["composer"], creditWords: [{ words: "Orig Composer", defaultX: 1234.7692307692307, defaultY: 1596.3076923076922, fontSize: "12px", justify: musicxml_interfaces_1.LeftCenterRight.Right }], page: 1 }, { creditImage: null, creditTypes: ["arranger"], creditWords: [{ words: "Orig Arranger", defaultX: 1234.7692307692307, defaultY: 1503.9999999999998, fontSize: "12px", justify: musicxml_interfaces_1.LeftCenterRight.Right }], page: 1 }, { creditImage: null, creditTypes: ["lyricist"], creditWords: [{ words: "Orig Lyricist", defaultX: 1234.7692307692307, defaultY: 1411.6923076923076, fontSize: "12px", justify: musicxml_interfaces_1.LeftCenterRight.Right }], page: 1 } ]); }); });