GraphicalNote.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. import {BoundingBox} from "./BoundingBox";
  11. export class GraphicalNote extends GraphicalObject {
  12. constructor(note: Note, parent: GraphicalStaffEntry) {
  13. super();
  14. this.sourceNote = note;
  15. this.parentStaffEntry = parent;
  16. this.PositionAndShape = new BoundingBox(this, parent.PositionAndShape);
  17. }
  18. public sourceNote: Note;
  19. public graphicalNoteLength: Fraction;
  20. public parentStaffEntry: GraphicalStaffEntry;
  21. public get ParentList(): GraphicalNote[] {
  22. for (let idx: number = 0, len: number = this.parentStaffEntry.notes.length; idx < len; ++idx) {
  23. let graphicalNotes: GraphicalNote[] = this.parentStaffEntry.notes[idx];
  24. if (graphicalNotes.indexOf(this) !== -1) {
  25. return graphicalNotes;
  26. }
  27. }
  28. return undefined;
  29. }
  30. public Transpose(keyInstruction: KeyInstruction, activeClef: ClefInstruction, halfTones: number, octaveEnum: OctaveEnum): Pitch {
  31. let transposedPitch: Pitch = this.sourceNote.Pitch;
  32. if (MusicSheetCalculator.transposeCalculator !== undefined) {
  33. transposedPitch = MusicSheetCalculator.transposeCalculator.transposePitch(this.sourceNote.Pitch, keyInstruction, halfTones);
  34. }
  35. return transposedPitch;
  36. }
  37. }