GraphicalVoiceEntry.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. import { EngravingRules } from ".";
  8. /**
  9. * The graphical counterpart of a [[VoiceEntry]].
  10. */
  11. export class GraphicalVoiceEntry extends GraphicalObject {
  12. constructor(parentVoiceEntry: VoiceEntry, parentStaffEntry: GraphicalStaffEntry) {
  13. super();
  14. this.parentVoiceEntry = parentVoiceEntry;
  15. this.parentStaffEntry = parentStaffEntry;
  16. this.PositionAndShape = new BoundingBox(this, parentStaffEntry ? parentStaffEntry.PositionAndShape : undefined, true);
  17. this.notes = [];
  18. this.rules = parentStaffEntry ?
  19. parentStaffEntry.parentMeasure.parentSourceMeasure.Rules : new EngravingRules();
  20. }
  21. public parentVoiceEntry: VoiceEntry;
  22. public parentStaffEntry: GraphicalStaffEntry;
  23. public notes: GraphicalNote[];
  24. /** Contains octave shifts affecting this voice entry, caused by octave brackets. */
  25. public octaveShiftValue: OctaveEnum;
  26. protected rules: EngravingRules;
  27. /** Sort this entry's notes by pitch.
  28. * Notes need to be sorted for Vexflow StaveNote creation.
  29. * Note that Vexflow needs the reverse order, see VexFlowConverter.StaveNote().
  30. */
  31. public sort(): void {
  32. this.notes.sort((a, b) => {
  33. return b.sourceNote.Pitch.getHalfTone() - a.sourceNote.Pitch.getHalfTone();
  34. });
  35. }
  36. /** (Re-)color notes and stems
  37. */
  38. public color(): void {
  39. // override
  40. }
  41. }