Browse Source

VexFlow Measure test

Andrea Condoluci 9 years ago
parent
commit
eee33259ec

+ 2 - 2
Gruntfile.js

@@ -9,7 +9,7 @@ module.exports = function (grunt) {
         ' * https://github.com/opensheetmusicdisplay/opensheetmusicdisplay\n' +
         ' * https://github.com/opensheetmusicdisplay/opensheetmusicdisplay\n' +
         ' */\n',
         ' */\n',
         typings = [
         typings = [
-            'typings/browser.d.ts',
+            'typings/index.d.ts',
             // Additional manual typings:
             // Additional manual typings:
             'external/vexflow/vexflow.d.ts'
             'external/vexflow/vexflow.d.ts'
             // 'typings/fft.d.ts'
             // 'typings/fft.d.ts'
@@ -21,7 +21,7 @@ module.exports = function (grunt) {
     // Grunt configuration following:
     // Grunt configuration following:
     grunt.initConfig({
     grunt.initConfig({
         pkg: grunt.file.readJSON('package.json'),
         pkg: grunt.file.readJSON('package.json'),
-        banner: banner,
+        banner: '',
         // Build output directories
         // Build output directories
         outputDir: {
         outputDir: {
             build: 'build',
             build: 'build',

+ 1 - 1
package.json

@@ -36,7 +36,7 @@
     "grunt-docco": "",
     "grunt-docco": "",
     "grunt-karma": "",
     "grunt-karma": "",
     "grunt-tslint": "",
     "grunt-tslint": "",
-    "grunt-typings": "0.1.4",
+    "grunt-typings": "",
     "jszip": "",
     "jszip": "",
     "karma": "",
     "karma": "",
     "karma-chai": "",
     "karma-chai": "",

+ 1 - 9
src/MusicalScore/Graphical/StaffMeasure.ts

@@ -85,39 +85,31 @@ export class StaffMeasure extends GraphicalObject {
     }
     }
 
 
     public ResetLayout(): void {
     public ResetLayout(): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public GetLineWidth(line: SystemLinesEnum): number {
     public GetLineWidth(line: SystemLinesEnum): number {
-        throw new Error("not implemented");
+        return undefined;
     }
     }
 
 
     public AddClefAtBegin(clef: ClefInstruction): void {
     public AddClefAtBegin(clef: ClefInstruction): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public AddKeyAtBegin(currentKey: KeyInstruction, previousKey: KeyInstruction, currentClef: ClefInstruction): void {
     public AddKeyAtBegin(currentKey: KeyInstruction, previousKey: KeyInstruction, currentClef: ClefInstruction): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public AddRhythmAtBegin(rhythm: RhythmInstruction): void {
     public AddRhythmAtBegin(rhythm: RhythmInstruction): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public AddClefAtEnd(clef: ClefInstruction): void {
     public AddClefAtEnd(clef: ClefInstruction): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public SetPositionInStaffline(xPos: number): void {
     public SetPositionInStaffline(xPos: number): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public SetWidth(width: number): void {
     public SetWidth(width: number): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public LayoutSymbols(): void {
     public LayoutSymbols(): void {
-        throw new Error("not implemented");
     }
     }
 
 
     public findGraphicalStaffEntryFromTimestamp(relativeTimestamp: Fraction): GraphicalStaffEntry {
     public findGraphicalStaffEntryFromTimestamp(relativeTimestamp: Fraction): GraphicalStaffEntry {

+ 2 - 3
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -22,8 +22,6 @@ export class VexFlowMeasure extends StaffMeasure {
     private stave: Vex.Flow.Stave;
     private stave: Vex.Flow.Stave;
     private voices: { [voiceID: number]: Vex.Flow.Voice; };
     private voices: { [voiceID: number]: Vex.Flow.Voice; };
     //private duration: Fraction;
     //private duration: Fraction;
-    //private begModifiers: number = 0;
-    //private endModifiers: number = 0;
 
 
     /**
     /**
      * Reset all the geometric values and parameters of this measure and put it in an initialized state.
      * Reset all the geometric values and parameters of this measure and put it in an initialized state.
@@ -31,6 +29,7 @@ export class VexFlowMeasure extends StaffMeasure {
      */
      */
     public resetLayout(): void {
     public resetLayout(): void {
         this.beginInstructionsWidth = 0;
         this.beginInstructionsWidth = 0;
+        this.endInstructionsWidth = 0;
     }
     }
 
 
     /**
     /**
@@ -125,7 +124,7 @@ export class VexFlowMeasure extends StaffMeasure {
      * Sets the overall x-width of the measure.
      * Sets the overall x-width of the measure.
      * @param width
      * @param width
      */
      */
-    public setWidth(width: number): void {
+    public SetWidth(width: number): void {
         // Widths in PS and VexFlow work differently.
         // Widths in PS and VexFlow work differently.
         // In VexFlow, width is only the width of the actual voices, without considering
         // In VexFlow, width is only the width of the actual voices, without considering
         // modifiers like clefs. In PS, width is the total width of the stave.
         // modifiers like clefs. In PS, width is the total width of the stave.

+ 52 - 0
test/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -0,0 +1,52 @@
+import {MusicSheetCalculator} from "../../../../src/MusicalScore/Graphical/MusicSheetCalculator";
+import {VexFlowGraphicalSymbolFactory} from "../../../../src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalSymbolFactory";
+import {IGraphicalSymbolFactory} from "../../../../src/MusicalScore/Interfaces/IGraphicalSymbolFactory";
+import {GraphicalMusicSheet} from "../../../../src/MusicalScore/Graphical/GraphicalMusicSheet";
+import {IXmlElement} from "../../../../src/Common/FileIO/Xml";
+import {MusicSheet} from "../../../../src/MusicalScore/MusicSheet";
+import {MusicSheetReader} from "../../../../src/MusicalScore/ScoreIO/MusicSheetReader";
+
+
+describe("VexFlow Measure Test", () => {
+    //it("Read title and composer", (done: MochaDone) => {
+    //    chai.expect(sheet.TitleString).to.equal("Sonatina Op.36 No 1 Teil 1 Allegro");
+    //    chai.expect(sheet.ComposerString).to.equal("Muzio Clementi");
+    //    done();
+    //});
+    //
+    //it("Measures", (done: MochaDone) => {
+    //    chai.expect(sheet.SourceMeasures.length).to.equal(38);
+    //    console.log("First Measure: ", sheet.SourceMeasures[0]);
+    //    done();
+    //});
+    //
+    //it("Instruments", (done: MochaDone) => {
+    //    chai.expect(reader.CompleteNumberOfStaves).to.equal(2);
+    //    chai.expect(sheet.Instruments.length).to.equal(2);
+    //    chai.expect(sheet.InstrumentalGroups.length).to.equal(2);
+    //    chai.expect(sheet.Instruments[0].Name).to.equal("Piano (right)");
+    //    chai.expect(sheet.Instruments[1].Name).to.equal("Piano (left)");
+    //    done();
+    //});
+    //
+    //it("Notes", (done: MochaDone) => {
+    //    // Staff Entries on first measure
+    //
+    //    // chai.expect(sheet.SourceMeasures[0].VerticalSourceStaffEntryContainers[0].StaffEntries.length).to.equal(4);
+    //    done();
+    //});
+
+    it("prepareGraphicalMusicSheet", (done: MochaDone) => {
+        let factory: IGraphicalSymbolFactory = new VexFlowGraphicalSymbolFactory();
+        let calc: MusicSheetCalculator = new MusicSheetCalculator(factory);
+        let path: string = "test/data/MuzioClementi_SonatinaOpus36No1_Part1.xml";
+        let doc: Document = ((window as any).__xml__)[path];
+        chai.expect(doc).to.not.be.undefined;
+        let score: IXmlElement = new IXmlElement(doc.getElementsByTagName("score-partwise")[0]);
+        let reader: MusicSheetReader = new MusicSheetReader();
+        let sheet: MusicSheet = reader.createMusicSheet(score, path);
+        let gms: GraphicalMusicSheet = new GraphicalMusicSheet(sheet, calc);
+        console.log(gms);
+        done();
+    });
+});