VexFlowMusicSheetDrawer_Test.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-disable @typescript-eslint/no-unused-expressions */
  2. import {VexFlowMusicSheetDrawer} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer";
  3. import {GraphicalMusicSheet} from "../../../../src/MusicalScore/Graphical/GraphicalMusicSheet";
  4. import {MusicSheet} from "../../../../src/MusicalScore/MusicSheet";
  5. import {MusicSheetReader} from "../../../../src/MusicalScore/ScoreIO/MusicSheetReader";
  6. import {VexFlowMusicSheetCalculator} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator";
  7. import {TestUtils} from "../../../Util/TestUtils";
  8. import {IXmlElement} from "../../../../src/Common/FileIO/Xml";
  9. import {VexFlowBackend} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowBackend";
  10. import {CanvasVexFlowBackend} from "../../../../src/MusicalScore/Graphical/VexFlow/CanvasVexFlowBackend";
  11. describe("VexFlow Music Sheet Drawer", () => {
  12. it("draws sheet \"Clementi pt. 1\"", (done: Mocha.Done) => {
  13. const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  14. chai.expect(score).to.not.be.undefined;
  15. const partwise: Element = TestUtils.getPartWiseElement(score);
  16. chai.expect(partwise).to.not.be.undefined;
  17. const reader: MusicSheetReader = new MusicSheetReader();
  18. const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator(reader.rules);
  19. const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  20. const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  21. // Create the canvas in the document:
  22. const canvas: HTMLCanvasElement = document.createElement("canvas");
  23. const backend: VexFlowBackend = new CanvasVexFlowBackend(sheet.Rules);
  24. backend.initialize(canvas, 1.0);
  25. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer();
  26. drawer.Backends.push(backend);
  27. drawer.drawSheet(gms);
  28. done();
  29. });
  30. // Test ignored for now, gms.calculateCursorLineAtTimestamp returns null instead of a GraphicalLine,
  31. // and in any case, this test doesn't test that the cursor is actually drawn, there are no expects for that etc.
  32. // it.only("draws cursor (as rectangle)", (done: Mocha.Done) => {
  33. // const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  34. // chai.expect(score).to.not.be.undefined;
  35. // const partwise: Element = TestUtils.getPartWiseElement(score);
  36. // chai.expect(partwise).to.not.be.undefined;
  37. // const reader: MusicSheetReader = new MusicSheetReader();
  38. // const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator(reader.rules);
  39. // const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  40. // const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  41. // gms.Cursors.push(gms.calculateCursorLineAtTimestamp(new Fraction(0, 4), OutlineAndFillStyleEnum.PlaybackCursor));
  42. // // Create the canvas in the document:
  43. // const canvas: HTMLCanvasElement = document.createElement("canvas");
  44. // const backend: VexFlowBackend = new CanvasVexFlowBackend(sheet.Rules);
  45. // backend.initialize(canvas);
  46. // const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(new DrawingParameters());
  47. // drawer.Backends.push(backend);
  48. // drawer.drawSheet(gms);
  49. // done();
  50. // });
  51. });