VexFlowGraphicalNote_Test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* eslint-disable @typescript-eslint/no-unused-expressions */
  2. import { GraphicalMeasure } from "../../../../src/MusicalScore/Graphical/GraphicalMeasure";
  3. import { VexFlowGraphicalNote } from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalNote";
  4. import { OpenSheetMusicDisplay } from "../../../../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay";
  5. import { TestUtils } from "../../../Util/TestUtils";
  6. describe("VexFlow GraphicalNote", () => {
  7. it("Can get SVG elements for note, stem and beam", (done: Mocha.Done) => {
  8. //const url: string = "base/test/data/test_rest_positioning_8th_quarter.musicxml"; // doesn't work, works for Mozart Clarinet Quintet
  9. const score: Document = TestUtils.getScore("test_beam_svg_double.musicxml");
  10. // sample should start with a beamed 8th note, and be simple.
  11. const div: HTMLElement = TestUtils.getDivElement(document);
  12. const osmd: OpenSheetMusicDisplay = TestUtils.createOpenSheetMusicDisplay(div);
  13. // we need this way of creating the score to get the SVG elements, doesn't work with creating MusicSheet by hand
  14. osmd.load(score).then(
  15. (_: {}) => {
  16. osmd.render();
  17. const gm: GraphicalMeasure = osmd.GraphicSheet.findGraphicalMeasure(0, 0);
  18. const note1: VexFlowGraphicalNote = (gm.staffEntries[0].graphicalVoiceEntries[0].notes[0] as VexFlowGraphicalNote);
  19. const noteSVG: SVGGElement = note1.getSVGGElement();
  20. chai.expect(noteSVG).to.not.be.null;
  21. chai.expect(noteSVG).to.not.be.undefined;
  22. // const noteSVGId: string = "vf-" + firstNote.getSVGId();
  23. // const noteSVG: HTMLElement = document.getElementById(noteSVGId);
  24. //const stemSVGId: string = noteSVGId + "-stem";
  25. //const stemSVG: HTMLElement = document.getElementById(stemSVGId);
  26. const stemSVG: HTMLElement = note1.getStemSVG();
  27. chai.expect(stemSVG).to.not.be.null;
  28. chai.expect(stemSVG).to.not.be.undefined;
  29. // const beamSVGId: string = noteSVGId + "-beam";
  30. // const beamSVG: HTMLElement = document.getElementById(beamSVGId);
  31. const beamSVGs: HTMLElement[] = note1.getBeamSVGs();
  32. chai.expect(beamSVGs.length).to.equal(1); // 8th beam start. (16th beam starts on note2)
  33. chai.expect(beamSVGs[0]).to.not.be.null;
  34. chai.expect(beamSVGs[0]).to.not.be.undefined;
  35. const note2: VexFlowGraphicalNote = (gm.staffEntries[1].graphicalVoiceEntries[0].notes[0] as VexFlowGraphicalNote);
  36. chai.expect(note2.getBeamSVGs().length).to.equal(1); // start of 16th beam
  37. const note3: VexFlowGraphicalNote = (gm.staffEntries[2].graphicalVoiceEntries[0].notes[0] as VexFlowGraphicalNote);
  38. chai.expect(note3.getBeamSVGs().length).to.equal(0); // end of 16th beam
  39. const note4: VexFlowGraphicalNote = (gm.staffEntries[3].graphicalVoiceEntries[0].notes[0] as VexFlowGraphicalNote);
  40. chai.expect(note4.getBeamSVGs().length).to.equal(2); // 16th beams start
  41. done();
  42. },
  43. done
  44. );
  45. });
  46. });