VexFlowGraphicalNote.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. export class VexFlowGraphicalNote extends GraphicalNote {
  9. constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction) {
  10. super(note, parent);
  11. this.clef = activeClef;
  12. if (note.Pitch) {
  13. this.vfpitch = VexFlowConverter.pitch(note.Pitch, this.clef);
  14. this.vfpitch[1] = undefined;
  15. }
  16. }
  17. public vfpitch: [string, string, ClefInstruction];
  18. private vfnote: [Vex.Flow.StaveNote, number];
  19. private clef: ClefInstruction;
  20. public setPitch(pitch: Pitch): void {
  21. if (this.vfnote) {
  22. let acc: string = VexFlowConverter.accidental(pitch.Accidental);
  23. if (acc) {
  24. alert(acc);
  25. this.vfnote[0].addAccidental(this.vfnote[1], new Vex.Flow.Accidental(acc));
  26. }
  27. } else {
  28. this.vfpitch = VexFlowConverter.pitch(pitch, this.clef);
  29. }
  30. }
  31. /**
  32. * Set the corresponding VexFlow StaveNote together with its index
  33. * @param note
  34. * @param index
  35. */
  36. public setIndex(note: Vex.Flow.StaveNote, index: number): void {
  37. this.vfnote = [note, index];
  38. //if (this.vfpitch && this.vfpitch[1]) {
  39. // note.addAccidental(index, new Vex.Flow.Accidental(this.vfpitch[1]));
  40. //}
  41. }
  42. }