Преглед изворни кода

add data/images/current to gitignore, add experimental karma test for reference

sschmid пре 5 година
родитељ
комит
dba623ceaa

+ 3 - 0
.gitignore

@@ -14,6 +14,9 @@ pids
 *.pid
 *.seed
 
+# optional npm script-generated data
+data/images/current
+
 # Documentation
 docs
 

+ 1 - 0
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -83,6 +83,7 @@ export class OpenSheetMusicDisplay {
     public load(content: string | Document): Promise<{}> {
         // Warning! This function is asynchronous! No error handling is done here.
         this.reset();
+        //console.log("typeof content: " + typeof content);
         if (typeof content === "string") {
 
             const str: string = <string>content;

+ 59 - 0
test/Util/DiffImages_Test_Experimental.ts

@@ -0,0 +1,59 @@
+import { OpenSheetMusicDisplay, CanvasVexFlowBackend } from "../../src";
+import { TestUtils } from "./TestUtils";
+import * as fs from "fs";
+
+describe("GeneratePNGImages", () => {
+    // Test all the following xml files:
+    const sampleFilenames: string[] = [
+        "Beethoven_AnDieFerneGeliebte.xml",
+        // "CharlesGounod_Meditation.xml",
+        // "Debussy_Mandoline.xml",
+        // "Dichterliebe01.xml",
+        // "JohannSebastianBach_Air.xml",
+        // "JohannSebastianBach_PraeludiumInCDur_BWV846_1.xml",
+        // "JosephHaydn_ConcertanteCello.xml",
+        // "Mozart_AnChloe.xml",
+        // "Mozart_DasVeilchen.xml",
+        "MuzioClementi_SonatinaOpus36No1_Part1.xml",
+        // "MuzioClementi_SonatinaOpus36No1_Part2.xml",
+        // "MuzioClementi_SonatinaOpus36No3_Part1.xml",
+        // "MuzioClementi_SonatinaOpus36No3_Part2.xml",
+        // "Saltarello.xml",
+        // "ScottJoplin_EliteSyncopations.xml",
+        // "ScottJoplin_The_Entertainer.xml",
+        // "TelemannWV40.102_Sonate-Nr.1.1-Dolce.xml",
+        // "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
+    ];
+    for (const score of sampleFilenames) {
+        testFile(score);
+    }
+
+    // Generates a test for a mxl file name
+    function testFile(sampleFilename: string): void {
+        it(sampleFilename, (done: MochaDone) => {
+            // Load the xml file content
+            const score: Document = TestUtils.getScore(sampleFilename);
+            const div: HTMLElement = document.createElement("div");
+            const openSheetMusicDisplay: OpenSheetMusicDisplay =
+                new OpenSheetMusicDisplay(div, { autoResize: false, backend: "canvas"});
+            openSheetMusicDisplay.load(score);
+
+            const testDir: string = "../data/images";
+            fs.mkdirSync(testDir, { recursive: true });
+
+            const fileName: string = `${testDir}/${sampleFilename}.png`;
+
+            console.log("before buffer");
+            const canvasBackend: CanvasVexFlowBackend = openSheetMusicDisplay.Drawer.Backends[0] as CanvasVexFlowBackend;
+            const imageData: string = (canvasBackend.getCanvas() as HTMLCanvasElement).toDataURL().split(";base64,").pop();
+            const imageBuffer: Buffer = Buffer.from(imageData, "base64");
+            //console.log("after buffer");
+            //let arraybuffer = Uint8Array.from(imageBuffer, 'base64').buffer;
+
+            // TODO doesn't work with Karma. This is the big problem that needs to be worked around with ts/Karma.
+            fs.writeFileSync(fileName, imageBuffer, { encoding: "base64" });
+
+            done();
+            }).timeout(10000);
+    }
+});