Mxl.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {IXmlElement} from "../../../src/Common/FileIO/Xml";
  2. import JSZip = require("jszip");
  3. // typings for JSZip module
  4. // type JSZip = any;
  5. // declare var JSZip: any;
  6. function extractSheetFromMxl(data: string): any {
  7. "use strict";
  8. // let buf = Buffer.concat(data);
  9. let zip: any = new JSZip();
  10. return zip.loadAsync(data).then((_: any) => {
  11. return zip.file("META-INF/container.xml").async("string");
  12. }).then((content: string) => {
  13. let parser: DOMParser = new DOMParser();
  14. let doc: Document = parser.parseFromString(content, "text/xml");
  15. console.log(content);
  16. // doc.Root.Element("rootfiles").Element("rootfile").Attribute("full-path").Value;
  17. let rootFile: string = doc.getElementsByTagName("rootfile")[0].getAttribute("full-path");
  18. console.log("success..", rootFile);
  19. return zip.file(rootFile).async("string");
  20. }).then((content: string) => {
  21. console.log("success...", content);
  22. let parser: DOMParser = new DOMParser();
  23. let doc: Document = parser.parseFromString(content, "text/xml");
  24. console.log("success...", doc);
  25. return new IXmlElement(doc.documentElement);
  26. }, (reason: any) => {
  27. chai.assert.fail(0, 1, reason.message);
  28. });
  29. }
  30. describe("MXL Tests", () => {
  31. // Initialize variables
  32. let path: string = "test/data/MozartTrio.mxl";
  33. // let score: IXmlElement;
  34. function getSheet(filename: string): string {
  35. console.log(((window as any).__mxl__));
  36. return ((window as any).__mxl__)[filename];
  37. }
  38. before((): void => {
  39. // Load the xml file
  40. let mxl: string = getSheet(path);
  41. chai.expect(mxl).to.not.be.undefined;
  42. extractSheetFromMxl(mxl).then((elem: any) => {
  43. console.log("success!", elem);
  44. }, (reason: any) => {
  45. chai.assert.fail(0, 1, reason.message);
  46. });
  47. // score = new IXmlElement(doc.getElementsByTagName("score-partwise")[0]);
  48. // // chai.expect(score).to.not.be.undefined;
  49. // sheet = reader.createMusicSheet(score, path);
  50. });
  51. it("Success", (done: MochaDone) => {
  52. chai.expect(extractSheetFromMxl).to.equal(extractSheetFromMxl);
  53. done();
  54. });
  55. });