GraphicalNote.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {Note} from "../VoiceData/Note";
  2. import {Fraction} from "../../Common/DataObjects/fraction";
  3. import {KeyInstruction} from "../VoiceData/Instructions/KeyInstruction";
  4. import {ClefInstruction} from "../VoiceData/Instructions/ClefInstruction";
  5. import {OctaveEnum} from "../VoiceData/Expressions/ContinuousExpressions/octaveShift";
  6. import {Pitch} from "../../Common/DataObjects/pitch";
  7. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  8. import {GraphicalObject} from "./GraphicalObject";
  9. import {MusicSheetCalculator} from "./MusicSheetCalculator";
  10. export class GraphicalNote extends GraphicalObject {
  11. constructor(note: Note, parent: GraphicalStaffEntry) {
  12. super();
  13. this.sourceNote = note;
  14. this.parentStaffEntry = parent;
  15. }
  16. public sourceNote: Note;
  17. public graphicalNoteLength: Fraction;
  18. public parentStaffEntry: GraphicalStaffEntry;
  19. public get ParentList(): GraphicalNote[] {
  20. for (let idx: number = 0, len: number = this.parentStaffEntry.notes.length; idx < len; ++idx) {
  21. let graphicalNotes: GraphicalNote[] = this.parentStaffEntry.notes[idx];
  22. if (graphicalNotes.indexOf(this) !== -1) {
  23. return graphicalNotes;
  24. }
  25. }
  26. return undefined;
  27. }
  28. public Transpose(keyInstruction: KeyInstruction, activeClef: ClefInstruction, halfTones: number, octaveEnum: OctaveEnum): Pitch {
  29. let transposedPitch: Pitch = this.sourceNote.Pitch;
  30. if (MusicSheetCalculator.transposeCalculator !== undefined) {
  31. transposedPitch = MusicSheetCalculator.transposeCalculator.transposePitch(this.sourceNote.Pitch, keyInstruction, halfTones);
  32. }
  33. return transposedPitch;
  34. }
  35. }