UNPKG

satie

Version:

A sheet music renderer for the web

173 lines (172 loc) 5.45 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 document_1 = require("../document"); exports.fakeFactory = { create: function (modelType) { chai.assert(false, "not reached"); return null; }, modelHasType: function (model, modelType) { if (model.divCount === 0) { return modelType === document_1.Type.Attributes; } else if ("length" in model) { return modelType === document_1.Type.Chord; } return modelType === document_1.Type.Spacer; }, search: function (models, idx, modelType) { return exports.fakeFactory.modelHasType(models[idx], modelType) ? [models[idx]] : []; }, fromSpec: function (spec) { throw new Error("Not implemented"); } }; function createFakeStaffSegment(divisions1, divisions2, idx) { var a = [ { divCount: divisions1, staffIdx: 1, refresh: function (cursor) { // pass }, getLayout: function (cursor) { var width = 10; cursor.segmentX += width; return { boundingBoxes: [], division: cursor.segmentDivision, x: cursor.segmentX - width, model: this, renderClass: document_1.Type.Attributes }; } }, { divCount: divisions2, staffIdx: 1, refresh: function (cursor) { // pass }, getLayout: function (cursor) { var width = 10; cursor.segmentX += width; return { boundingBoxes: [], division: cursor.segmentDivision, x: cursor.segmentX - width, model: this, renderClass: document_1.Type.Attributes }; } } ]; a.owner = idx; a.part = "P1"; a.divisions = divisions1 + divisions2; a.ownerType = "staff"; return a; } exports.createFakeStaffSegment = createFakeStaffSegment; function createFakeVoiceSegment(divisions1, divisions2, idx) { var a = [ (_a = { divCount: divisions1, staffIdx: 1, length: 1 }, _a[0] = { pitch: { step: "E", octave: 4 }, noteType: { duration: 8, }, ties: [{}] }, _a.refresh = function (cursor) { // pass }, _a.getLayout = function (cursor) { var width = divisions1 * 10; cursor.segmentX += width; return { boundingBoxes: [], division: cursor.segmentDivision, x: cursor.segmentX - width, expandPolicy: "after", model: this, renderClass: document_1.Type.Chord }; }, _a), (_b = { divCount: divisions2, staffIdx: 1, length: 1 }, _b[0] = { pitch: { step: "E", octave: 4 }, noteType: { duration: 8, }, ties: [{}] }, _b.refresh = function (cursor) { // pass }, _b.getLayout = function (cursor) { var width = divisions2 * 10; cursor.segmentX += width; return { boundingBoxes: [], division: cursor.segmentDivision, x: cursor.segmentX - width, expandPolicy: "after", model: this, renderClass: document_1.Type.Chord }; }, _b) ]; a.owner = idx; a.part = "P1"; a.ownerType = "voice"; a.divisions = divisions1 + divisions2; return a; var _a, _b; } exports.createFakeVoiceSegment = createFakeVoiceSegment; function createFakeLayout(idx, offset, max) { return { model: {}, x: idx * 100 + Math.log(1 + offset) / Math.log(2) * 10, division: idx * 4 + offset, boundingBoxes: [], renderClass: document_1.Type.Attributes }; } exports.createFakeLayout = createFakeLayout;