|
@@ -1,5 +1,14 @@
|
|
-interface VexFlowVoice {
|
|
|
|
|
|
+interface VexFlowBoundingBox {
|
|
|
|
+ mergeWith(bb: VexFlowBoundingBox): VexFlowBoundingBox;
|
|
|
|
+ getX(): number;
|
|
|
|
+ getY(): number;
|
|
|
|
+ getW(): number;
|
|
|
|
+ getH(): number;
|
|
|
|
+}
|
|
|
|
|
|
|
|
+interface VexFlowVoice {
|
|
|
|
+ getBoundingBox(): VexFlowBoundingBox;
|
|
|
|
+ setStave(stave: VexFlowStave): VexFlowVoice;
|
|
}
|
|
}
|
|
|
|
|
|
interface VexFlowStave {
|
|
interface VexFlowStave {
|
|
@@ -11,11 +20,15 @@ interface VexFlowStave {
|
|
setWidth(width: number): VexFlowStave;
|
|
setWidth(width: number): VexFlowStave;
|
|
format(): void;
|
|
format(): void;
|
|
getSpacingBetweenLines(): number;
|
|
getSpacingBetweenLines(): number;
|
|
|
|
+ getNumLines(): number;
|
|
|
|
+ getLineForY(y: number): number;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Usage:
|
|
|
|
+/// TODO
|
|
class MeasureSizeCalculator {
|
|
class MeasureSizeCalculator {
|
|
public stave: VexFlowStave;
|
|
public stave: VexFlowStave;
|
|
- public voices: VexFlowVoice;
|
|
|
|
|
|
+ public voices: VexFlowVoice[];
|
|
public formatter: any;
|
|
public formatter: any;
|
|
|
|
|
|
private offsetLeft: number;
|
|
private offsetLeft: number;
|
|
@@ -44,6 +57,8 @@ class MeasureSizeCalculator {
|
|
}
|
|
}
|
|
|
|
|
|
public getHeight(): number {
|
|
public getHeight(): number {
|
|
|
|
+ // FIXME this formula does not take into account
|
|
|
|
+ // other things like staves and ties!
|
|
return this.stave.getSpacingBetweenLines()
|
|
return this.stave.getSpacingBetweenLines()
|
|
* (this.topBorder - this.bottomBorder);
|
|
* (this.topBorder - this.bottomBorder);
|
|
}
|
|
}
|
|
@@ -61,6 +76,9 @@ class MeasureSizeCalculator {
|
|
|
|
|
|
private format(): void {
|
|
private format(): void {
|
|
let stave: VexFlowStave = this.stave;
|
|
let stave: VexFlowStave = this.stave;
|
|
|
|
+ let voices: VexFlowVoice[] = this.voices;
|
|
|
|
+ let voicesBoundingBox: VexFlowBoundingBox;
|
|
|
|
+ let bb: VexFlowBoundingBox;
|
|
// Compute widths
|
|
// Compute widths
|
|
this.voicesWidth = this.formatter.minTotalWidth;
|
|
this.voicesWidth = this.formatter.minTotalWidth;
|
|
stave.setWidth(this.voicesWidth);
|
|
stave.setWidth(this.voicesWidth);
|
|
@@ -70,6 +88,24 @@ class MeasureSizeCalculator {
|
|
// Compute heights
|
|
// Compute heights
|
|
// Height is:
|
|
// Height is:
|
|
//// height of StaveModifiers + BoundingBox of notes + height of NoteMod's
|
|
//// height of StaveModifiers + BoundingBox of notes + height of NoteMod's
|
|
- // TODO
|
|
|
|
|
|
+ for (let i: number = 0; i < this.voices.length; i ++) {
|
|
|
|
+ voices[i].setStave(stave);
|
|
|
|
+ bb = voices[i].getBoundingBox();
|
|
|
|
+ if (voicesBoundingBox === undefined) {
|
|
|
|
+ voicesBoundingBox = bb;
|
|
|
|
+ } else {
|
|
|
|
+ voicesBoundingBox = voicesBoundingBox.mergeWith(bb);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // TODO voicesBoundingBox.getW() should be similar to this.voicesWidth?
|
|
|
|
+ // FIXME the following: should consider stave modifiers
|
|
|
|
+ //this.height = voicesBoundingBox.getH(); FIXME
|
|
|
|
+ this.topBorder = Math.min(
|
|
|
|
+ 0, stave.getLineForY(voicesBoundingBox.getY())
|
|
|
|
+ );
|
|
|
|
+ this.bottomBorder = Math.max(
|
|
|
|
+ stave.getNumLines(),
|
|
|
|
+ stave.getLineForY(voicesBoundingBox.getY() + voicesBoundingBox.getH())
|
|
|
|
+ )
|
|
}
|
|
}
|
|
}
|
|
}
|