VexFlowStaffEntry.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  2. import {VexFlowMeasure} from "./VexFlowMeasure";
  3. import {SourceStaffEntry} from "../../VoiceData/SourceStaffEntry";
  4. import {GraphicalNote} from "../GraphicalNote";
  5. import {unitInPixels} from "./VexFlowMusicSheetDrawer";
  6. export class VexFlowStaffEntry extends GraphicalStaffEntry {
  7. constructor(measure: VexFlowMeasure, sourceStaffEntry: SourceStaffEntry, staffEntryParent: VexFlowStaffEntry) {
  8. super(measure, sourceStaffEntry, staffEntryParent);
  9. }
  10. // The Graphical Notes belonging to this StaffEntry, sorted by voiceID
  11. public graphicalNotes: { [voiceID: number]: GraphicalNote[]; } = {};
  12. // The corresponding VexFlow.StaveNotes
  13. public vfNotes: { [voiceID: number]: Vex.Flow.StaveNote; } = {};
  14. /**
  15. *
  16. * @returns {number} the x-position (in units) of this Staff Entry
  17. */
  18. public getX(): number {
  19. let x: number = 0;
  20. let n: number = 0;
  21. let vfNotes: { [voiceID: number]: Vex.Flow.StaveNote; } = this.vfNotes;
  22. for (let voiceId in vfNotes) {
  23. if (vfNotes.hasOwnProperty(voiceId)) {
  24. x += (vfNotes[voiceId].getNoteHeadBeginX() + vfNotes[voiceId].getNoteHeadEndX()) / 2;
  25. n += 1;
  26. }
  27. }
  28. return x / n / unitInPixels;
  29. }
  30. }