GraphicalVoiceEntry.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {GraphicalObject} from "./GraphicalObject";
  2. import { VoiceEntry } from "../VoiceData/VoiceEntry";
  3. import { BoundingBox } from "./BoundingBox";
  4. import { GraphicalNote } from "./GraphicalNote";
  5. import { GraphicalStaffEntry } from "./GraphicalStaffEntry";
  6. import { OctaveEnum } from "../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  7. /**
  8. * The graphical counterpart of a [[VoiceEntry]].
  9. */
  10. export class GraphicalVoiceEntry extends GraphicalObject {
  11. constructor(parentVoiceEntry: VoiceEntry, parentStaffEntry: GraphicalStaffEntry) {
  12. super();
  13. this.parentVoiceEntry = parentVoiceEntry;
  14. this.parentStaffEntry = parentStaffEntry;
  15. this.PositionAndShape = new BoundingBox(this, parentStaffEntry ? parentStaffEntry.PositionAndShape : undefined, true);
  16. this.notes = [];
  17. }
  18. public parentVoiceEntry: VoiceEntry;
  19. public parentStaffEntry: GraphicalStaffEntry;
  20. public notes: GraphicalNote[];
  21. /** Contains octave shifts affecting this voice entry, caused by octave brackets. */
  22. public octaveShiftValue: OctaveEnum;
  23. /** Sort this entry's notes by pitch.
  24. * Notes need to be sorted for Vexflow StaveNote creation.
  25. * Note that Vexflow needs the reverse order, see VexFlowConverter.StaveNote().
  26. */
  27. public sort(): void {
  28. this.notes.sort((a, b) => {
  29. return b.sourceNote.Pitch.getHalfTone() - a.sourceNote.Pitch.getHalfTone();
  30. });
  31. }
  32. }