瀏覽代碼

fix(whole rest bbox): fix whole rest bounding box in non-4/4 time (#609)

fix #609

duplicates: #616, #605
sschmid 5 年之前
父節點
當前提交
2b91655ef8
共有 2 個文件被更改,包括 12 次插入1 次删除
  1. 3 1
      src/MusicalScore/Graphical/VexFlow/VexFlowStaffEntry.ts
  2. 9 0
      src/MusicalScore/VoiceData/Note.ts

+ 3 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowStaffEntry.ts

@@ -36,7 +36,9 @@ export class VexFlowStaffEntry extends GraphicalStaffEntry {
                 gve.applyBordersFromVexflow();
                 this.PositionAndShape.RelativePosition.x = gve.vfStaveNote.getBoundingBox().getX() / unitInPixels;
                 const sourceNote: Note = gve.notes[0].sourceNote;
-                if (sourceNote.isRest() && sourceNote.Length.WholeValue === 1) { // whole rest
+                if (sourceNote.isRest() && sourceNote.Length.RealValue === this.parentMeasure.parentSourceMeasure.ActiveTimeSignature.RealValue) {
+                    // whole rest: length = measure length. (4/4 in a 4/4 time signature, 3/4 in a 3/4 time signature, 1/4 in a 1/4 time signature, etc.)
+                    // see Note.isWholeRest(), which is currently not safe
                     this.PositionAndShape.RelativePosition.x +=
                         EngravingRules.Rules.WholeRestXShiftVexflow - 0.1; // xShift from VexFlowConverter
                     gve.PositionAndShape.BorderLeft = -0.7;

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

@@ -211,6 +211,15 @@ export class Note {
         return this.Pitch === undefined;
     }
 
+    /** Note: May be dangerous to use if ParentStaffEntry.VerticalContainerParent etc is not set.
+     * better calculate this directly when you have access to the note's measure.
+     * whole rest: length = measure length. (4/4 in a 4/4 time signature, 3/4 in a 3/4 time signature, 1/4 in a 1/4 time signature, etc.)
+     * TODO give a Note a reference to its measure?
+     */
+    public isWholeRest(): boolean {
+        return this.isRest() && this.Length.RealValue === this.ParentStaffEntry.VerticalContainerParent.ParentMeasure.ActiveTimeSignature.RealValue;
+    }
+
     public ToString(): string {
         if (this.pitch !== undefined) {
             return this.Pitch.ToString() + ", length: " + this.length.toString();