Explorar o código

Working on note durations

Andrea Condoluci %!s(int64=9) %!d(string=hai) anos
pai
achega
951af192b0

+ 1 - 1
karma.conf.js

@@ -55,7 +55,7 @@ module.exports = function (config) {
 
         // level of logging
         // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
-        logLevel: config.LOG_INFO,
+        logLevel: config.LOG_DEBUG,
 
         // enable / disable watching file and executing tests whenever any file changes
         autoWatch: false,

+ 19 - 16
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -24,21 +24,20 @@ export class VexFlowConverter {
 
     public static duration(fraction: Fraction): string {
         let dur: number = fraction.RealValue;
-        switch (dur) {
-            case 0.25:
-                return "q";
-            case 0.5:
-                return "h";
-            case 1:
-                return "w";
-            case 0.125:
-                return "8";
-            case 0.0625:
-                return "16";
-            // FIXME TODO
-            default:
-                return "16";
+        if (dur === 1) {
+            return "w";
+        } else if (dur < 1 && dur >= 0.5) {
+            return "h";
+        } else if (dur < 0.5 && dur >= 0.25) {
+            return "q";
+        } else if (dur < 0.25 && dur >= 0.125) {
+            return "8";
+        } else if (dur < 0.125 && dur >= 0.0625) {
+            return "16";
+        } else if (dur < 0.0625 && dur >= 0.03125) {
+            return "32";
         }
+        return "128";
     }
 
     /**
@@ -74,7 +73,8 @@ export class VexFlowConverter {
 
     public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
         let keys: string[] = [];
-        let duration: string = VexFlowConverter.duration(notes[0].sourceNote.Length);
+        let frac: Fraction = notes[0].sourceNote.Length;
+        let duration: string = VexFlowConverter.duration(frac);
         let accidentals: string[] = [];
         let vfclef: string;
         for (let note of notes) {
@@ -95,6 +95,10 @@ export class VexFlowConverter {
             auto_stem: true,
             clef: vfclef,
             duration: duration,
+            duration_override: {
+                denominator: frac.Denominator,
+                numerator: frac.Numerator,
+            },
             keys: keys,
         });
         for (let i: number = 0, len: number = keys.length; i < len; i += 1) {
@@ -126,7 +130,6 @@ export class VexFlowConverter {
                 break;
             default:
         }
-        console.log("CLEF", clef, type);
         return type;
     }
 

+ 1 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -73,7 +73,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
                 if (mvoices.hasOwnProperty(voiceID)) {
                     voices.push(mvoices[voiceID]);
                     allVoices.push(mvoices[voiceID]);
-    }
+                }
             }
             if (voices.length === 0) {
                 console.log("Found a measure with no voices... Continuing anyway.", mvoices);

+ 17 - 0
src/MusicalScore/VoiceData/Note.ts

@@ -8,6 +8,7 @@ import {Tie} from "./Tie";
 import {Staff} from "./Staff";
 import {Slur} from "./Expressions/ContinuousExpressions/Slur";
 import {NoteState} from "../Graphical/DrawingEnums";
+import {MusicSymbol} from "../Graphical/MusicSymbol";
 
 export class Note {
 
@@ -158,6 +159,22 @@ export class Note {
         }
         return false;
     }
+
+    //public calculateTailSymbol(): number {
+    //    let length: number = this.Length.RealValue;
+    //    if (this.NoteTuplet) {
+    //        length = this.NoteTuplet.Fractions[this.NoteTuplet.getNoteIndex(this)].RealValue;
+    //    }
+    //    if (length < 0.25 && length >= 0.125) {
+    //        return 8;
+    //    } else if (length < 0.125 && length >= 0.0625) {
+    //        return 16;
+    //    } else if (length < 0.0625 && length >= 0.03125) {
+    //        return 32;
+    //    } else {
+    //        return 64;
+    //    }
+    //}
 }
 
 export enum Appearance {

+ 1 - 0
test/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -10,6 +10,7 @@ describe("VexFlow Music Sheet Drawer", () => {
 
     it(".drawSheet (Clementi pt. 1)", (done: MochaDone) => {
         let path: string = "test/data/MuzioClementi_SonatinaOpus36No1_Part1.xml";
+        // "test/data/MuzioClementi_SonatinaOpus36No1_Part1.xml";
         let score: IXmlElement = TestUtils.getScore(path);
         chai.expect(score).to.not.be.undefined;
         let calc: VexFlowMusicSheetCalculator = new VexFlowMusicSheetCalculator();