VexFlowMusicSheetDrawer_Test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /* tslint:disable:no-unused-expression */
  13. describe("VexFlow Music Sheet Drawer", () => {
  14. it("draws sheet \"Clementi pt. 1\"", (done: MochaDone) => {
  15. const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  16. chai.expect(score).to.not.be.undefined;
  17. const partwise: Element = TestUtils.getPartWiseElement(score);
  18. chai.expect(partwise).to.not.be.undefined;
  19. const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();
  20. const reader: MusicSheetReader = new MusicSheetReader();
  21. const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  22. const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  23. // Create the canvas in the document:
  24. const canvas: HTMLCanvasElement = document.createElement("canvas");
  25. const backend: VexFlowBackend = new CanvasVexFlowBackend();
  26. backend.initialize(canvas);
  27. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(canvas, backend);
  28. drawer.drawSheet(gms);
  29. done();
  30. });
  31. it.skip("draws cursor (as rectangle)", (done: MochaDone) => {
  32. const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  33. chai.expect(score).to.not.be.undefined;
  34. const partwise: Element = TestUtils.getPartWiseElement(score);
  35. chai.expect(partwise).to.not.be.undefined;
  36. const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();
  37. const reader: MusicSheetReader = new MusicSheetReader();
  38. const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  39. const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  40. gms.Cursors.push(gms.calculateCursorLineAtTimestamp(new Fraction(0, 4), OutlineAndFillStyleEnum.PlaybackCursor));
  41. // Create the canvas in the document:
  42. const canvas: HTMLCanvasElement = document.createElement("canvas");
  43. const backend: VexFlowBackend = new CanvasVexFlowBackend();
  44. backend.initialize(canvas);
  45. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(canvas, backend);
  46. drawer.drawSheet(gms);
  47. done();
  48. });
  49. });