VexFlowGraphicalNote.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Vex = require("vexflow");
  2. import {GraphicalNote} from "../GraphicalNote";
  3. import {Note} from "../../VoiceData/Note";
  4. import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
  5. import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
  6. import {VexFlowConverter} from "./VexFlowConverter";
  7. import {Pitch} from "../../../Common/DataObjects/Pitch";
  8. import {Fraction} from "../../../Common/DataObjects/Fraction";
  9. import {OctaveEnum} from "../../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
  10. export class VexFlowGraphicalNote extends GraphicalNote {
  11. constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE, graphicalNoteLength: Fraction = undefined) {
  12. super(note, parent, graphicalNoteLength);
  13. this.clef = activeClef;
  14. if (note.Pitch) {
  15. this.vfpitch = VexFlowConverter.pitch(note.Pitch, this.clef);
  16. this.vfpitch[1] = undefined;
  17. }
  18. }
  19. public vfpitch: [string, string, ClefInstruction];
  20. private vfnote: [Vex.Flow.StaveNote, number];
  21. private clef: ClefInstruction;
  22. public setPitch(pitch: Pitch): void {
  23. if (this.vfnote) {
  24. let acc: string = VexFlowConverter.accidental(pitch.Accidental);
  25. if (acc) {
  26. alert(acc);
  27. this.vfnote[0].addAccidental(this.vfnote[1], new Vex.Flow.Accidental(acc));
  28. }
  29. } else {
  30. this.vfpitch = VexFlowConverter.pitch(pitch, this.clef);
  31. }
  32. }
  33. /**
  34. * Set the corresponding VexFlow StaveNote together with its index
  35. * @param note
  36. * @param index
  37. */
  38. public setIndex(note: Vex.Flow.StaveNote, index: number): void {
  39. this.vfnote = [note, index];
  40. //if (this.vfpitch && this.vfpitch[1]) {
  41. // note.addAccidental(index, new Vex.Flow.Accidental(this.vfpitch[1]));
  42. //}
  43. }
  44. }