123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- "use strict";
- var __extends = (this && this.__extends) || function (d, b) {
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- var BoundingBox_1 = require("./BoundingBox");
- var fraction_1 = require("../../Common/DataObjects/fraction");
- var LinkedVoice_1 = require("../VoiceData/LinkedVoice");
- var GraphicalObject_1 = require("./GraphicalObject");
- var collectionUtil_1 = require("../../Util/collectionUtil");
- var GraphicalStaffEntry = (function (_super) {
- __extends(GraphicalStaffEntry, _super);
- function GraphicalStaffEntry(parentMeasure, sourceStaffEntry, staffEntryParent) {
- if (sourceStaffEntry === void 0) { sourceStaffEntry = undefined; }
- if (staffEntryParent === void 0) { staffEntryParent = undefined; }
- _super.call(this);
- this.graphicalInstructions = [];
- this.graphicalTies = [];
- this.lyricsEntries = [];
- this.parentMeasure = parentMeasure;
- this.notes = [];
- this.graceStaffEntriesBefore = [];
- this.graceStaffEntriesAfter = [];
- this.sourceStaffEntry = sourceStaffEntry;
- if (staffEntryParent !== undefined) {
- this.staffEntryParent = staffEntryParent;
- this.parentVerticalContainer = staffEntryParent.parentVerticalContainer;
- this.PositionAndShape = new BoundingBox_1.BoundingBox(this, staffEntryParent.PositionAndShape);
- }
- else {
- this.PositionAndShape = new BoundingBox_1.BoundingBox(this, parentMeasure.PositionAndShape);
- }
- if (sourceStaffEntry !== undefined) {
- this.relInMeasureTimestamp = sourceStaffEntry.Timestamp;
- }
- }
- Object.defineProperty(GraphicalStaffEntry.prototype, "GraphicalInstructions", {
- get: function () {
- return this.graphicalInstructions;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphicalStaffEntry.prototype, "GraphicalTies", {
- get: function () {
- return this.graphicalTies;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GraphicalStaffEntry.prototype, "LyricsEntries", {
- get: function () {
- return this.lyricsEntries;
- },
- enumerable: true,
- configurable: true
- });
- GraphicalStaffEntry.prototype.getAbsoluteTimestamp = function () {
- var result = fraction_1.Fraction.createFromFraction(this.parentMeasure.parentSourceMeasure.AbsoluteTimestamp);
- if (this.relInMeasureTimestamp !== undefined) {
- result.Add(this.relInMeasureTimestamp);
- }
- return result;
- };
- GraphicalStaffEntry.prototype.findEndTieGraphicalNoteFromNote = function (tieNote) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- var note = graphicalNote.sourceNote;
- if (note.Pitch !== undefined && note.Pitch.FundamentalNote === tieNote.Pitch.FundamentalNote
- && note.Pitch.Octave === tieNote.Pitch.Octave && note.getAbsoluteTimestamp() === tieNote.getAbsoluteTimestamp()) {
- return graphicalNote;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.findEndTieGraphicalNoteFromNoteWithStartingSlur = function (tieNote, slur) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- var note = graphicalNote.sourceNote;
- if (note.NoteTie !== undefined && note.NoteSlurs.indexOf(slur) !== -1) {
- return graphicalNote;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.findEndTieGraphicalNoteFromNoteWithEndingSlur = function (tieNote) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- var note = graphicalNote.sourceNote;
- if (note.Pitch !== undefined && note.Pitch.FundamentalNote === tieNote.Pitch.FundamentalNote
- && note.Pitch.Octave === tieNote.Pitch.Octave && this.getAbsoluteTimestamp() === tieNote.getAbsoluteTimestamp()) {
- return graphicalNote;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.findGraphicalNoteFromGraceNote = function (graceNote) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- if (graphicalNote.sourceNote === graceNote) {
- return graphicalNote;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.findGraphicalNoteFromNote = function (baseNote) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- if (graphicalNote.sourceNote === baseNote && this.getAbsoluteTimestamp() === baseNote.getAbsoluteTimestamp()) {
- return graphicalNote;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.getGraphicalNoteDurationFromVoice = function (voice) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- if (graphicalNotes[0].sourceNote.ParentVoiceEntry.ParentVoice === voice) {
- return graphicalNotes[0].graphicalNoteLength;
- }
- }
- return new fraction_1.Fraction(0, 1);
- };
- GraphicalStaffEntry.prototype.findLinkedNotes = function (notLinkedNotes) {
- if (this.sourceStaffEntry !== undefined && this.sourceStaffEntry.Link !== undefined) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- if (graphicalNote.parentStaffEntry === this) {
- notLinkedNotes.push(graphicalNote);
- }
- }
- }
- }
- };
- GraphicalStaffEntry.prototype.findVoiceEntryGraphicalNotes = function (voiceEntry) {
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- if (graphicalNote.sourceNote.ParentVoiceEntry === voiceEntry) {
- return graphicalNotes;
- }
- }
- }
- return undefined;
- };
- GraphicalStaffEntry.prototype.isVoiceEntryPartOfLinkedVoiceEntry = function (voiceEntry) {
- if (this.sourceStaffEntry.Link !== undefined) {
- for (var idx = 0, len = this.sourceStaffEntry.Link.LinkStaffEntries.length; idx < len; ++idx) {
- var sEntry = this.sourceStaffEntry.Link.LinkStaffEntries[idx];
- if (sEntry.VoiceEntries.indexOf(voiceEntry) !== -1 && sEntry !== this.sourceStaffEntry) {
- return true;
- }
- }
- }
- return false;
- };
- GraphicalStaffEntry.prototype.getMainVoice = function () {
- for (var idx = 0, len = this.sourceStaffEntry.VoiceEntries.length; idx < len; ++idx) {
- var voiceEntry = this.sourceStaffEntry.VoiceEntries[idx];
- if (!(voiceEntry.ParentVoice instanceof LinkedVoice_1.LinkedVoice)) {
- return voiceEntry.ParentVoice;
- }
- }
- return this.notes[0][0].sourceNote.ParentVoiceEntry.ParentVoice;
- };
- GraphicalStaffEntry.prototype.findStaffEntryMinNoteLength = function () {
- var minLength = new fraction_1.Fraction(Number.MAX_VALUE, 1);
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- var calNoteLen = graphicalNote.graphicalNoteLength;
- if (calNoteLen < minLength && calNoteLen.Numerator > 0) {
- minLength = calNoteLen;
- }
- }
- }
- return minLength;
- };
- GraphicalStaffEntry.prototype.findStaffEntryMaxNoteLength = function () {
- var maxLength = new fraction_1.Fraction(0, 1);
- for (var idx = 0, len = this.notes.length; idx < len; ++idx) {
- var graphicalNotes = this.notes[idx];
- for (var idx2 = 0, len2 = graphicalNotes.length; idx2 < len2; ++idx2) {
- var graphicalNote = graphicalNotes[idx2];
- var calNoteLen = graphicalNote.graphicalNoteLength;
- if (calNoteLen > maxLength && calNoteLen.Numerator > 0) {
- maxLength = calNoteLen;
- }
- }
- }
- return maxLength;
- };
- GraphicalStaffEntry.prototype.findOrCreateGraphicalNotesListFromVoiceEntry = function (voiceEntry) {
- var graphicalNotes;
- if (this.notes.length === 0) {
- graphicalNotes = [];
- this.notes.push(graphicalNotes);
- }
- else {
- for (var i = 0; i < this.notes.length; i++) {
- if (this.notes[i][0].sourceNote.ParentVoiceEntry.ParentVoice === voiceEntry.ParentVoice) {
- return this.notes[i];
- }
- }
- graphicalNotes = [];
- this.notes.push(graphicalNotes);
- }
- return graphicalNotes;
- };
- GraphicalStaffEntry.prototype.findOrCreateGraphicalNotesListFromGraphicalNote = function (graphicalNote) {
- var graphicalNotes;
- var tieStartSourceStaffEntry = graphicalNote.sourceNote.ParentStaffEntry;
- if (this.sourceStaffEntry !== tieStartSourceStaffEntry) {
- graphicalNotes = this.findOrCreateGraphicalNotesListFromVoiceEntry(graphicalNote.sourceNote.ParentVoiceEntry);
- }
- else {
- if (this.notes.length === 0) {
- graphicalNotes = [];
- this.notes.push(graphicalNotes);
- }
- else {
- for (var i = 0; i < this.notes.length; i++) {
- if (this.notes[i][0].sourceNote.ParentVoiceEntry.ParentVoice === graphicalNote.sourceNote.ParentVoiceEntry.ParentVoice) {
- return this.notes[i];
- }
- }
- graphicalNotes = [];
- this.notes.push(graphicalNotes);
- }
- }
- return graphicalNotes;
- };
- GraphicalStaffEntry.prototype.addGraphicalNoteToListAtCorrectYPosition = function (graphicalNotes, graphicalNote) {
- if (graphicalNotes.length === 0 ||
- graphicalNote.PositionAndShape.RelativePosition.y < collectionUtil_1.CollectionUtil.last(graphicalNotes).PositionAndShape.RelativePosition.Y) {
- graphicalNotes.push(graphicalNote);
- }
- else {
- for (var i = graphicalNotes.length - 1; i >= 0; i--) {
- if (graphicalNotes[i].PositionAndShape.RelativePosition.y > graphicalNote.PositionAndShape.RelativePosition.y) {
- graphicalNotes.splice(i + 1, 0, graphicalNote);
- break;
- }
- if (i === 0) {
- graphicalNotes.splice(0, 0, graphicalNote);
- break;
- }
- }
- }
- };
- return GraphicalStaffEntry;
- }(GraphicalObject_1.GraphicalObject));
- exports.GraphicalStaffEntry = GraphicalStaffEntry;
|