Forráskód Böngészése

feat(spacing): Tweaks to compress spacing more (#820)
Testing using formatToStave vs. format

Justin Litten 5 éve
szülő
commit
682f77c613

+ 7 - 7
src/MusicalScore/Graphical/EngravingRules.ts

@@ -180,7 +180,7 @@ export class EngravingRules {
     private minimumCrossedBeamDifferenceMargin: number;
 
     private voiceSpacingMultiplierVexflow: number;
-    private voicingSpaceAddendVexflow: number;
+    private voiceSpacingAddendVexflow: number;
     private displacedNoteMargin: number;
     private minNoteDistance: number;
     private subMeasureXSpacingThreshold: number;
@@ -441,8 +441,8 @@ export class EngravingRules {
         this.minimumCrossedBeamDifferenceMargin = 0.0001;
 
         // xSpacing Variables
-        this.voiceSpacingMultiplierVexflow = 1.0;
-        this.voicingSpaceAddendVexflow = 3.0;
+        this.voiceSpacingMultiplierVexflow = 0.65;
+        this.voiceSpacingAddendVexflow = 2.0;
         this.displacedNoteMargin = 0.1;
         this.minNoteDistance = 2.0;
         this.subMeasureXSpacingThreshold = 35;
@@ -1430,11 +1430,11 @@ export class EngravingRules {
     public set VoiceSpacingMultiplierVexflow(value: number) {
         this.voiceSpacingMultiplierVexflow = value;
     }
-    public get VoicingSpaceAddendVexflow(): number {
-        return this.voicingSpaceAddendVexflow;
+    public get VoiceSpacingAddendVexflow(): number {
+        return this.voiceSpacingAddendVexflow;
     }
-    public set VoicingSpaceAddendVexflow(value: number) {
-        this.voicingSpaceAddendVexflow = value;
+    public set VoiceSpacingAddendVexflow(value: number) {
+        this.voiceSpacingAddendVexflow = value;
     }
     public get DisplacedNoteMargin(): number {
         return this.displacedNoteMargin;

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

@@ -62,7 +62,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
     /** The VexFlow Voices in the measure */
     public vfVoices: { [voiceID: number]: Vex.Flow.Voice; } = {};
     /** Call this function (if present) to x-format all the voices in the measure */
-    public formatVoices: (width: number) => void;
+    public formatVoices: (width: number, parent: VexFlowMeasure) => void;
     /** The VexFlow Ties in the measure */
     public vfTies: Vex.Flow.StaveTie[] = [];
     /** The repetition instructions given as words or symbols (coda, dal segno..) */
@@ -105,7 +105,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
 
         this.stave = new Vex.Flow.Stave(0, 0, 0, {
             space_above_staff_ln: 0,
-            space_below_staff_ln: 0,
+            space_below_staff_ln: 0
         });
 
         if (this.ParentStaff) {
@@ -553,7 +553,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         if (this.formatVoices) {
             // set the width of the voices to the current measure width:
             // (The width of the voices does not include the instructions (StaveModifiers))
-            this.formatVoices((this.PositionAndShape.Size.width - this.beginInstructionsWidth - this.endInstructionsWidth) * unitInPixels);
+            this.formatVoices((this.PositionAndShape.Size.width - this.beginInstructionsWidth - this.endInstructionsWidth) * unitInPixels, this);
         }
     }
 

+ 9 - 10
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -160,24 +160,23 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
     let minStaffEntriesWidth: number = 12; // a typical measure has roughly a length of 3*StaffHeight (3*4 = 12)
     if (allVoices.length > 0) {
       // the voicing space bonus addition makes the voicing more relaxed. With a bonus of 0 the notes are basically completely squeezed together.
-      // let voicingWidthBonus: number = this.rules.VoicingSpaceBonusVexflow;
-      // if (measures[0].staffEntries?.length === 2) {
-      //   voicingWidthBonus = 3;
-      // }
+      const staffEntryFactor: number = 0.3;
+
       minStaffEntriesWidth = formatter.preCalculateMinTotalWidth(allVoices) / unitInPixels
         * this.rules.VoiceSpacingMultiplierVexflow
-        + this.rules.VoicingSpaceAddendVexflow;
+        + this.rules.VoiceSpacingAddendVexflow
+        + measures[0].staffEntries.length * staffEntryFactor;
         // TODO this could use some fine-tuning. currently using *1.5 + 1 by default, results in decent spacing.
       // firstMeasure.formatVoices = (w: number) => {
       //     formatter.format(allVoices, w);
       // };
       MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minStaffEntriesWidth);
 
-      const formatVoicesDefault: (w: number) => void = (w) => {
-        formatter.format(allVoices, w);
+      const formatVoicesDefault: (w: number, p: VexFlowMeasure) => void = (w, p) => {
+        formatter.formatToStave(allVoices, p.getVFStave());
       };
-      const formatVoicesAlignRests: (w: number) => void = (w) => {
-        formatter.format(allVoices, w, {
+      const formatVoicesAlignRests: (w: number,  p: VexFlowMeasure) => void = (w, p) => {
+        formatter.formatToStave(allVoices, p.getVFStave(), {
           align_rests: true,
           context: undefined
         });
@@ -233,7 +232,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
           //vexflowMeasure.formatVoices = formatVoicesDefault;
 
           // format now for minimum width, calculateMeasureWidthFromLyrics later
-          vexflowMeasure.formatVoices(minStaffEntriesWidth * unitInPixels);
+          vexflowMeasure.formatVoices(minStaffEntriesWidth * unitInPixels, vexflowMeasure);
         } else {
           //(measure as VexFlowMeasure).formatVoices = undefined;
           // TODO why was the formatVoices function disabled for other measures? would now disable the new align rests option.