VexFlowMusicSheetDrawer_Test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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();
  29. drawer.Backends.push(backend);
  30. drawer.drawSheet(gms);
  31. done();
  32. });
  33. it.skip("draws cursor (as rectangle)", (done: MochaDone) => {
  34. const score: Document = TestUtils.getScore("MuzioClementi_SonatinaOpus36No1_Part1.xml");
  35. chai.expect(score).to.not.be.undefined;
  36. const partwise: Element = TestUtils.getPartWiseElement(score);
  37. chai.expect(partwise).to.not.be.undefined;
  38. const calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();
  39. const reader: MusicSheetReader = new MusicSheetReader();
  40. const sheet: MusicSheet = reader.createMusicSheet(new IXmlElement(partwise), "** missing path **");
  41. const gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
  42. gms.Cursors.push(gms.calculateCursorLineAtTimestamp(new Fraction(0, 4), OutlineAndFillStyleEnum.PlaybackCursor));
  43. // Create the canvas in the document:
  44. const canvas: HTMLCanvasElement = document.createElement("canvas");
  45. const backend: VexFlowBackend = new CanvasVexFlowBackend();
  46. backend.initialize(canvas);
  47. const drawer: VexFlowMusicSheetDrawer = new VexFlowMusicSheetDrawer(new DrawingParameters());
  48. drawer.Backends.push(backend);
  49. drawer.drawSheet(gms);
  50. done();
  51. });
  52. });