UNPKG

satie

Version:

A sheet music renderer for the web

172 lines (171 loc) 6.39 kB
/** * @source: https://github.com/jnetterf/satie/ * * @license * (C) Josh Netterfield <joshua@nettek.ca> 2015. * Part of the Satie music engraver <https://github.com/jnetterf/satie>. * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ "use strict"; var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; /** * @file part of Satie test suite */ var implChord_chordModel_1 = require("../implChord_chordModel"); var musicxml_interfaces_1 = require("musicxml-interfaces"); var chai_1 = require("chai"); var document_1 = require("../document"); var engine_factory_1 = require("../engine_factory"); var implAttributes_attributesModel_1 = require("../implAttributes_attributesModel"); function getAttributes() { return { measureStyle: {}, divisions: 6, time: { beats: ["4"], beatTypes: [4], senzaMisura: null }, clef: { clefOctaveChange: null, sign: "G", line: 2 } }; } function getCursor(factory, model) { var attributes = getAttributes(); var segment = [model]; segment.part = "P1"; segment.ownerType = "voice"; var v = { const: function () { return v; }, document: { __fakeDocument: true }, fixup: null, dangerouslyPatchWithoutValidation: function () { return null; }, patch: function () { return null; }, advance: null, segmentInstance: segment, segmentPosition: 0, print: null, header: null, staffAttributes: attributes, staffAccidentals: {}, staffIdx: 0, measureInstance: { idx: 0, number: "1", implicit: false, version: 0, nonControlling: false, uuid: 1, }, measureIsLast: true, segmentDivision: 0, factory: factory, preview: false, singleLineMode: false, }; return v; } describe("[chord.ts]", function () { describe("ChordModel", function () { var factory = new engine_factory_1.default([implAttributes_attributesModel_1.default, implChord_chordModel_1.default]); it("can be created from scratch", function () { var chord = factory.create(document_1.Type.Chord); chai_1.expect(!!chord).to.be.true; chai_1.expect(chord.length).to.eq(0); }); it("can be correctly created from a simple spec", function () { var chord = factory.fromSpec({ _class: "Note", timeModification: { actualNotes: 3, normalNotes: 2 }, duration: 600, noteType: { duration: musicxml_interfaces_1.Count.Eighth }, pitch: { step: "C", octave: 4, alter: 1 } }); var cursor = getCursor(factory, chord); chord.refresh(cursor); cursor = getCursor(factory, chord); chai_1.expect(cursor.segmentDivision).to.eq(0); var lCursor = __assign({}, cursor, { measureX: 100, lineShortest: 1, lineBarOnLine: 0, lineTotalBarsOnLine: 1, lineIndex: 0, lineCount: 1, segmentX: 100, lineMaxPaddingTopByStaff: [], lineMaxPaddingBottomByStaff: [] }); chord.getLayout(lCursor); chai_1.expect(cursor.segmentDivision).to.eq(0, "layout must not affect cursor division"); var xml = chord.inspect(); chai_1.expect(xml).to.contain("<step>C</step>"); chai_1.expect(xml).to.contain("<alter>1</alter>"); chai_1.expect(xml).to.contain("<octave>4</octave>"); chai_1.expect(xml).to.not.contain("<chord"); chai_1.expect(xml).to.contain("<duration>600</duration>", "Maintains playback data"); }); it("can be a chord generated from specs", function () { var chord = factory.fromSpec({ _class: "Note", timeModification: { actualNotes: 3, normalNotes: 2 }, noteType: { duration: musicxml_interfaces_1.Count.Eighth }, pitch: { step: "C", octave: 4, alter: 1 } }); chord.push({ _class: "Note", timeModification: { actualNotes: 3, normalNotes: 2 }, noteType: { duration: musicxml_interfaces_1.Count.Eighth }, pitch: { step: "E", octave: 4 } }); var cursor = getCursor(factory, chord); chord.refresh(cursor); cursor = getCursor(factory, chord); var lCursor = __assign({}, cursor, { measureX: 100, lineShortest: 1, lineBarOnLine: 0, lineTotalBarsOnLine: 1, lineIndex: 0, lineCount: 1, segmentX: 100, lineMaxPaddingTopByStaff: [], lineMaxPaddingBottomByStaff: [] }); chord.getLayout(lCursor); // let chordDuration = chordFromModel(chord)[0].duration; // expect(chordDuration).to.eq(2, "Duration wasn't specified so should be set here."); // XXX: implement a proper patcher for tests }); }); });