import {VoiceEntry} from "./VoiceEntry"; import {SourceStaffEntry} from "./SourceStaffEntry"; import {Fraction} from "../../Common/DataObjects/Fraction"; import {Pitch} from "../../Common/DataObjects/Pitch"; import {Beam} from "./Beam"; import {Tuplet} from "./Tuplet"; import {Tie} from "./Tie"; import {Staff} from "./Staff"; import {Slur} from "./Expressions/ContinuousExpressions/Slur"; import {NoteState} from "../Graphical/DrawingEnums"; import {NoteHead} from "./NoteHead"; /** * Represents a single pitch with a duration (length) */ export class Note { constructor(voiceEntry: VoiceEntry, parentStaffEntry: SourceStaffEntry, length: Fraction, pitch: Pitch) { this.voiceEntry = voiceEntry; this.parentStaffEntry = parentStaffEntry; this.length = length; this.pitch = pitch; if (pitch !== undefined) { this.halfTone = pitch.getHalfTone(); } else { this.halfTone = 0; } } /** * The transposed (!!!) HalfTone of this note. */ public halfTone: number; public state: NoteState; private voiceEntry: VoiceEntry; private parentStaffEntry: SourceStaffEntry; private length: Fraction; /** * The untransposed (!!!) source data. */ private pitch: Pitch; private beam: Beam; private tuplet: Tuplet; private tie: Tie; private slurs: Slur[] = []; private playbackInstrumentId: string = undefined; private noteHead: NoteHead = undefined; public get ParentVoiceEntry(): VoiceEntry { return this.voiceEntry; } public set ParentVoiceEntry(value: VoiceEntry) { this.voiceEntry = value; } public get ParentStaffEntry(): SourceStaffEntry { return this.parentStaffEntry; } public get ParentStaff(): Staff { return this.parentStaffEntry.ParentStaff; } public get Length(): Fraction { return this.length; } public set Length(value: Fraction) { this.length = value; } public get Pitch(): Pitch { return this.pitch; } public get NoteBeam(): Beam { return this.beam; } public set NoteBeam(value: Beam) { this.beam = value; } public get NoteTuplet(): Tuplet { return this.tuplet; } public set NoteTuplet(value: Tuplet) { this.tuplet = value; } public get NoteTie(): Tie { return this.tie; } public set NoteTie(value: Tie) { this.tie = value; } public get NoteSlurs(): Slur[] { return this.slurs; } public set NoteSlurs(value: Slur[]) { this.slurs = value; } public get PlaybackInstrumentId(): string { return this.playbackInstrumentId; } public set PlaybackInstrumentId(value: string) { this.playbackInstrumentId = value; } public set NoteHead(value: NoteHead) { this.noteHead = value; } public get NoteHead(): NoteHead { return this.noteHead; } public isRest(): boolean { return this.Pitch === undefined; } public ToString(): string { if (this.pitch !== undefined) { return this.Pitch.ToString() + ", length: " + this.length.toString(); } else { return "rest note, length: " + this.length.toString(); } } public getAbsoluteTimestamp(): Fraction { return Fraction.plus( this.voiceEntry.Timestamp, this.parentStaffEntry.VerticalContainerParent.ParentMeasure.AbsoluteTimestamp ); } public checkForDoubleSlur(slur: Slur): boolean { for (let idx: number = 0, len: number = this.slurs.length; idx < len; ++idx) { const noteSlur: Slur = this.slurs[idx]; if ( noteSlur.StartNote !== undefined && noteSlur.EndNote !== undefined && slur.StartNote !== undefined && slur.StartNote === noteSlur.StartNote && noteSlur.EndNote === this ) { return true; } } return false; } } export enum Appearance { Normal, Grace, Cue }