Bläddra i källkod

Small fixes and documentation

Andrea Condoluci 9 år sedan
förälder
incheckning
63d9586ff8

+ 20 - 2
src/MusicalScore/Calculation/MeasureSizeCalculator.ts

@@ -1,7 +1,25 @@
 import Vex = require("vexflow");
 
-// Usage:
-/// TODO
+/* TODO
+ * Take into account StaveModifiers
+ * Take into account Ties and Slurs
+ */
+
+/* Measure Size Calculator
+ *  Given a stave, voices and a formatter, calculates
+ *  through VexFlow the size of a measure.
+ *  !!! before using this, call the methods
+ *  !!! joinVoices and preCalculateMinTotalWidth
+ *  !!! of the formatter!
+ *
+ * Usage:
+ *   let stave: Vex.Flow.Stave = ...;
+ *   let formatter = new Vex.Flow.Formatter()
+ *   let voices: Vex.Flor.Voice[] = ...;
+ *   formatter.preCalculateMinTotalWidth(voices);
+ *   let calc = new MeasureSizeCalculator(stave, voices, formatter);
+ *   calc.???
+ */
 export class MeasureSizeCalculator {
   private stave: Vex.Flow.Stave;
   private voices: Vex.Flow.Voice[];

+ 5 - 7
test/MusicalScore/Calculation/MeasureSizeCalculator.ts

@@ -9,7 +9,7 @@ describe("Measure Size Calculator Tests", () => {
   let stave: Vex.Flow.Stave = new Vex.Flow.Stave(0, 0, 0);
   let voices: Vex.Flow.Voice[];
   //let formatter: Vex.Flow.Formatter = new Vex.Flow.Formatter();
-  let formatter: any;
+  let formatter: Vex.Flow.Formatter;
   // Create a voice with a note
   let voice: Vex.Flow.Voice;
   let note: Vex.Flow.StaveNote;
@@ -24,9 +24,8 @@ describe("Measure Size Calculator Tests", () => {
 
     chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(22);
 
-    calc = new MeasureSizeCalculator(
-      stave, voices, <Vex.Flow.Formatter> formatter
-    );
+    calc = new MeasureSizeCalculator(stave, voices, formatter);
+
     chai.expect(calc.getBottomBorder()).to.equal(5);
     done();
   });
@@ -43,9 +42,8 @@ describe("Measure Size Calculator Tests", () => {
     voices = [voice];
 
     chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(64);
-    calc = new MeasureSizeCalculator(
-      stave, voices, <Vex.Flow.Formatter> formatter
-    );
+    calc = new MeasureSizeCalculator(stave, voices, formatter);
+
     chai.expect(calc.getWidth()).to.equal(64);
     chai.expect(calc.getBottomBorder()).to.equal(6);
     chai.expect(calc.getTopBorder()).to.equal(0);

+ 2 - 2
typings/vexflow.d.ts

@@ -5,7 +5,7 @@ declare namespace VexFlow {
       public hasMinTotalWidth: boolean;
       public minTotalWidth: number;
 
-      //preCalculateMinTotalWidth(voices: Voices[]);
+      preCalculateMinTotalWidth(voices: Voice[]);
       constructor();
     }
 
@@ -40,7 +40,7 @@ declare namespace VexFlow {
       getSpacingBetweenLines(): number;
       getNumLines(): number;
       getLineForY(y: number): number;
-      
+
       constructor(x: number, y: number, width: number);
     }