Skip to content

Commit

Permalink
fix(whole rest bbox): fix whole rest bounding box in non-4/4 time (#609)
Browse files Browse the repository at this point in the history
fix #609

duplicates: #616, #605
  • Loading branch information
sschmid committed Dec 4, 2019
1 parent d3299b9 commit 2b91655
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/MusicalScore/Graphical/VexFlow/VexFlowStaffEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/MusicalScore/VoiceData/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2b91655

Please sign in to comment.