MusicSheetAPI.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. var Xml_1 = require("./Common/FileIO/Xml");
  3. var VexFlowMusicSheetCalculator_1 = require("./MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator");
  4. var MusicSheetReader_1 = require("./MusicalScore/ScoreIO/MusicSheetReader");
  5. var GraphicalMusicSheet_1 = require("./MusicalScore/Graphical/GraphicalMusicSheet");
  6. var VexFlowMusicSheetDrawer_1 = require("./MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer");
  7. var VexFlowTextMeasurer_1 = require("./MusicalScore/Graphical/VexFlow/VexFlowTextMeasurer");
  8. var MusicSheetAPI = (function () {
  9. function MusicSheetAPI() {
  10. this.zoom = 1.0;
  11. this.unit = 10;
  12. return;
  13. }
  14. MusicSheetAPI.prototype.load = function (sheet) {
  15. var score = new Xml_1.IXmlElement(sheet.getElementsByTagName("score-partwise")[0]);
  16. var calc = new VexFlowMusicSheetCalculator_1.VexFlowMusicSheetCalculator();
  17. var reader = new MusicSheetReader_1.MusicSheetReader();
  18. this.sheet = reader.createMusicSheet(score, "path missing");
  19. this.graphic = new GraphicalMusicSheet_1.GraphicalMusicSheet(this.sheet, calc);
  20. this.display();
  21. };
  22. MusicSheetAPI.prototype.setCanvas = function (canvas) {
  23. this.canvas = canvas;
  24. this.drawer = new VexFlowMusicSheetDrawer_1.VexFlowMusicSheetDrawer(canvas, new VexFlowTextMeasurer_1.VexFlowTextMeasurer());
  25. };
  26. MusicSheetAPI.prototype.setWidth = function (width) {
  27. if (width === this.width) {
  28. return;
  29. }
  30. this.width = width;
  31. this.display();
  32. };
  33. MusicSheetAPI.prototype.scale = function (k) {
  34. this.zoom = k;
  35. this.display();
  36. };
  37. MusicSheetAPI.prototype.display = function () {
  38. if (this.width === undefined) {
  39. return;
  40. }
  41. if (this.canvas === undefined) {
  42. return;
  43. }
  44. if (this.sheet === undefined) {
  45. return;
  46. }
  47. this.sheet.pageWidth = this.width / this.zoom / this.unit;
  48. this.graphic.reCalculate();
  49. // Update Sheet Page
  50. var height = this.graphic.MusicPages[0].PositionAndShape.BorderBottom * this.unit * this.zoom;
  51. this.drawer.resize(this.width, height);
  52. // Fix the label problem
  53. this.drawer.translate(0, 100);
  54. this.drawer.scale(this.zoom);
  55. this.drawer.drawSheet(this.graphic);
  56. };
  57. MusicSheetAPI.prototype.free = function () {
  58. this.canvas = undefined;
  59. this.sheet = undefined;
  60. return;
  61. };
  62. return MusicSheetAPI;
  63. }());
  64. exports.MusicSheetAPI = MusicSheetAPI;
  65. window.osmd = {
  66. "MusicSheet": MusicSheetAPI,
  67. };