satie
Version:
A sheet music renderer for the web
"use strict";
var musicxml_interfaces_1 = require("musicxml-interfaces");
var chai_1 = require("chai");
var document_1 = require("../document");
var engine_songImpl_1 = require("../engine_songImpl");
var satie_1 = require("../satie");
var songTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 3.0 Partwise//EN\"\n \"http://www.musicxml.org/dtds/partwise.dtd\">\n<score-partwise>\n <movement-title>Satie Sandbox</movement-title>\n <identification>\n <miscellaneous>\n <miscellaneous-field name=\"description\">\n A test song\n </miscellaneous-field>\n </miscellaneous>\n </identification>\n <part-list>\n <score-part id=\"P1\">\n <part-name>Cello</part-name>\n </score-part>\n </part-list>\n <!--=========================================================-->\n <part id=\"P1\">\n <measure number=\"1\">\n <attributes>\n <divisions>1</divisions>\n <key>\n <fifths>-3</fifths>\n <mode>minor</mode>\n </key>\n <time symbol=\"common\">\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 <note>\n <rest measure=\"yes\" />\n <duration>4</duration>\n <voice>1</voice>\n <type>whole</type>\n </note>\n </measure>\n </part>\n</score-partwise>";
function getDivisionBreakdown(song, patches) {
var doc = song.getDocument(patches);
chai_1.expect(doc.measures.length).to.equal(1, "there should only be one measure");
return doc
.measures[0]
.parts["P1"]
.voices[1]
.filter(function (n) { return doc.modelHasType(n, document_1.Type.Chord); })
.map(function (n) { return n.divCount + (n[0].rest ? "R" : "N"); })
.filter(function (n) { return n; });
}
function insertNote(song, patches, idx, count) {
var doc = song.getDocument(patches);
var measure1 = doc.measures[0].uuid;
var patch = satie_1.Patch.createPatch(false, doc, function (document) { return document
.measure(measure1, function (measure) { return measure
.part("P1", function (part) { return part
.voice(1, function (voice) { return voice
.at(idx)
.insertChord([function (note) { return note.pitch(function (p) { return p.octave(2).step("C"); }).noteType(function (t) { return t.duration(count); }); }]); }); }); }); });
return song.createCanonicalPatch(patches, { raw: patch });
}
describe("patch metre", function () {
var song;
beforeEach(function (done) {
song = new engine_songImpl_1.default({
baseSrc: songTemplate,
onError: done,
onLoaded: function () {
done();
},
});
song.run();
});
it("4/4, whole note", function () {
var patch = insertNote(song, null, 0, musicxml_interfaces_1.Count.Whole);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["4N"]);
});
it("4/4, half notes", function () {
var patch = insertNote(song, null, 0, musicxml_interfaces_1.Count.Half);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["2N", "2R"]);
patch = insertNote(song, patch, 0, musicxml_interfaces_1.Count.Half);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["2N", "2N"]);
});
it("4/4, quarter notes", function () {
var patch = insertNote(song, null, 0, musicxml_interfaces_1.Count.Quarter);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["1N", "1R", "2R"]);
patch = insertNote(song, patch, 1, musicxml_interfaces_1.Count.Quarter);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["1N", "1N", "2R"]);
patch = insertNote(song, patch, 2, musicxml_interfaces_1.Count.Quarter);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["1N", "1N", "1N", "1R"]);
patch = insertNote(song, patch, 3, musicxml_interfaces_1.Count.Quarter);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["1N", "1N", "1N", "1N"]);
});
it("4/4, eighth notes", function () {
var patch = insertNote(song, null, 0, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5R", "1R", "2R"]);
patch = insertNote(song, patch, 1, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "1R", "2R"]);
patch = insertNote(song, patch, 2, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5R", "2R"]);
patch = insertNote(song, patch, 3, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5N", "2R"]);
patch = insertNote(song, patch, 4, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5R", "1R"]);
patch = insertNote(song, patch, 5, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "1R"]);
patch = insertNote(song, patch, 6, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5R"]);
patch = insertNote(song, patch, 6, musicxml_interfaces_1.Count.Eighth);
chai_1.expect(getDivisionBreakdown(song, patch)).to.deep.equal(["0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N", "0.5N"]);
});
});