VexFlowMusicSheetDrawer_Test.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {VexFlowMusicSheetDrawer} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer";
  2. import {GraphicalMusicSheet} from "../../../../src/MusicalScore/Graphical/GraphicalMusicSheet";
  3. import {OutlineAndFillStyleEnum} from "../../../../src/MusicalScore/Graphical/DrawingEnums";
  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 {Fraction} from "../../../../src/Common/DataObjects/Fraction";
  10. import {VexFlowBackend} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowBackend";
  11. import {CanvasVexFlowBackend} from "../../../../src/MusicalScore/Graphical/VexFlow/CanvasVexFlowBackend";
  12. import {DrawingParameters} from "../../../../src/MusicalScore/Graphical/DrawingParameters";
  13. /* tslint:disable:no-unused-expression */
  14. describe("VexFlow Music Sheet Drawer", () => {
  15. it("draws sheet \"Clementi pt. 1\"", (done: MochaDone) => {
  16. const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  17. chai.expect(score).to.not.be.undefined;
  18. const partwise: Element = TestUtils.getPartWiseElement(score);
  19. chai.expect(partwise).to.not.be.undefined;
  20. const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();
  21. const reader: MusicSheetReader = new MusicSheetReader();
  22. const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  23. const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  24. // Create the canvas in the document:
  25. const canvas: HTMLCanvasElement = document.createElement("canvas");
  26. const backend: VexFlowBackend = new CanvasVexFlowBackend();
  27. backend.initialize(canvas);
  28. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(canvas, backend);
  29. drawer.drawSheet(gms);
  30. done();
  31. });
  32. it.skip("draws cursor (as rectangle)", (done: MochaDone) => {
  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 calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();
  38. const reader: MusicSheetReader = new MusicSheetReader();
  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();
  45. backend.initialize(canvas);
  46. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(canvas, backend, new DrawingParameters());
  47. drawer.drawSheet(gms);
  48. done();
  49. });
  50. });