Skip to content

Commit

Permalink
fix(dynamics, drawingRange): fix crescendo crashing when partially ou…
Browse files Browse the repository at this point in the history
…t of drawingRange (#644)

fix #644
  • Loading branch information
sschmid committed Jan 15, 2020
1 parent 371cb9f commit 8105270
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/MusicalScore/Graphical/MusicSheetCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,13 +977,24 @@ export abstract class MusicSheetCalculator {
}

graphicalContinuousDynamic.EndMeasure = endMeasure;
const staffLine: StaffLine = graphicalContinuousDynamic.ParentStaffLine;
const endStaffLine: StaffLine = endMeasure.ParentStaffLine;

// check if Expression spreads over the same StaffLine or not
const sameStaffLine: boolean = endStaffLine !== undefined && staffLine === endStaffLine;

let isPartOfMultiStaffInstrument: boolean = false;
if (endStaffLine) { // unfortunately we can't do something like (endStaffLine?.check() || staffLine?.check()) in this typescript version
isPartOfMultiStaffInstrument = endStaffLine.isPartOfMultiStaffInstrument();
} else if (staffLine) {
isPartOfMultiStaffInstrument = staffLine.isPartOfMultiStaffInstrument();
}

const endAbsoluteTimestamp: Fraction = Fraction.createFromFraction(graphicalContinuousDynamic.ContinuousDynamic.EndMultiExpression.AbsoluteTimestamp);

const endPosInStaffLine: PointF2D = this.getRelativePositionInStaffLineFromTimestamp(
endAbsoluteTimestamp, staffIndex, endStaffLine, endStaffLine.isPartOfMultiStaffInstrument(), 0);
endAbsoluteTimestamp, staffIndex, endStaffLine, isPartOfMultiStaffInstrument, 0);

const staffLine: StaffLine = graphicalContinuousDynamic.ParentStaffLine;
//currentMusicSystem and currentStaffLine
const musicSystem: MusicSystem = staffLine.ParentMusicSystem;
const currentStaffLineIndex: number = musicSystem.StaffLines.indexOf(staffLine);
Expand All @@ -996,9 +1007,6 @@ export abstract class MusicSheetCalculator {
// if ContinuousDynamicExpression is given from wedge
let secondGraphicalContinuousDynamic: GraphicalContinuousDynamicExpression = undefined;

// check if Expression spreads over the same StaffLine or not
const sameStaffLine: boolean = endStaffLine !== undefined && staffLine === endStaffLine;

// last length check
if (sameStaffLine && endPosInStaffLine.x - startPosInStaffline.x < this.rules.WedgeMinLength) {
endPosInStaffLine.x = startPosInStaffline.x + this.rules.WedgeMinLength;
Expand All @@ -1007,6 +1015,7 @@ export abstract class MusicSheetCalculator {
// Upper staff wedge always starts at the given position and the lower staff wedge always starts at the begin of measure
const upperStartX: number = startPosInStaffline.x;
const lowerStartX: number = endStaffLine.Measures[0].beginInstructionsWidth - this.rules.WedgeHorizontalMargin - 2;
//TODO fix this when a range of measures to draw is given that doesn't include all the dynamic's measures (e.g. for crescendo)
let upperEndX: number = 0;
let lowerEndX: number = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,13 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
graphicalContinuousDynamic.StartMeasure = startMeasure;

if (!graphicalContinuousDynamic.IsVerbal && continuousDynamic.EndMultiExpression) {
this.calculateGraphicalContinuousDynamic(graphicalContinuousDynamic, dynamicStartPosition);
try {
this.calculateGraphicalContinuousDynamic(graphicalContinuousDynamic, dynamicStartPosition);
} catch (e) {
// TODO this sometimes fails when the measure range to draw doesn't include all the dynamic's measures, method needs to be adjusted
// see calculateGraphicalContinuousDynamic(), also in MusicSheetCalculator.

}
} else if (graphicalContinuousDynamic.IsVerbal) {
this.calculateGraphicalVerbalContinuousDynamic(graphicalContinuousDynamic, dynamicStartPosition);
} else {
Expand Down Expand Up @@ -692,8 +698,13 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
for (const graphicalMusicPage of this.graphicalMusicSheet.MusicPages) {
for (const musicSystem of graphicalMusicPage.MusicSystems) {
for (const staffLine of musicSystem.StaffLines) {
try {
(<VexFlowStaffLine>staffLine).AlignmentManager.alignDynamicExpressions();
staffLine.AbstractExpressions.forEach(ae => ae.updateSkyBottomLine());
} catch (e) {
// TODO still necessary when calculation of expression fails, see calculateDynamicExpressionsForMultiExpression()
// see calculateGraphicalContinuousDynamic(), also in MusicSheetCalculator.
}
}
}
}
Expand Down

0 comments on commit 8105270

Please sign in to comment.