Mxl.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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(
  21. (content: string) => {
  22. console.log("success...", content);
  23. let parser: DOMParser = new DOMParser();
  24. let doc: Document = parser.parseFromString(content, "text/xml");
  25. console.log("success...", doc);
  26. return new IXmlElement(doc.documentElement);
  27. },
  28. (reason: any) => {
  29. chai.assert.fail(0, 1, reason.message);
  30. }
  31. );
  32. }
  33. describe("MXL Tests", () => {
  34. // Initialize variables
  35. let path: string = "test/data/MozartTrio.mxl";
  36. // let score: IXmlElement;
  37. function getSheet(filename: string): string {
  38. console.log(((window as any).__mxl__));
  39. return ((window as any).__mxl__)[filename];
  40. }
  41. before((): void => {
  42. // Load the xml file
  43. let mxl: string = getSheet(path);
  44. chai.expect(mxl).to.not.be.undefined;
  45. extractSheetFromMxl(mxl).then(
  46. (elem: any) => {
  47. console.log("success!", elem);
  48. },
  49. (reason: any) => {
  50. chai.assert.fail(0, 1, reason.message);
  51. }
  52. );
  53. // score = new IXmlElement(doc.getElementsByTagName("score-partwise")[0]);
  54. // // chai.expect(score).to.not.be.undefined;
  55. // sheet = reader.createMusicSheet(score, path);
  56. });
  57. it("Success", (done: MochaDone) => {
  58. chai.expect(extractSheetFromMxl).to.equal(extractSheetFromMxl);
  59. done();
  60. });
  61. });