Skip to content

Commit

Permalink
Merge pull request 0xfe#796 from sschmidTU/fix/volta-length-with-modi…
Browse files Browse the repository at this point in the history
…fiers-and-ds-offset

Fix volta length with modifiers, D.S. position
  • Loading branch information
0xfe authored Jun 17, 2020
2 parents 3cc8680 + 11c9583 commit 0c51ce4
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/stave.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export class Stave extends Element {
return 0;
}

// for right position modifiers zero shift seems correct, see 'Volta + Modifier Measure Test'
if (this.modifiers[index].getPosition() === StaveModifier.Position.RIGHT) {
return 0;
}

let start_x = this.start_x - this.x;
const begBarline = this.modifiers[0];
if (begBarline.getType() === Barline.type.REPEAT_BEGIN && start_x > begBarline.getWidth()) {
Expand Down
4 changes: 4 additions & 0 deletions src/staverepetition.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class Repetition extends StaveModifier {
// Offset Coda text to right of stave beginning
text_x = this.x + stave.options.vertical_bar_width;
symbol_x = text_x + ctx.measureText(text).width + 12;
} else if (this.symbol_type === Repetition.type.DS) {
const modifierWidth = stave.start_x - this.x;
text_x = this.x + x + this.x_shift + stave.width - 5 - modifierWidth - ctx.measureText(text).width;
// TODO this is weird. setting the x position should probably be refactored, parameters aren't clear here.
} else {
// Offset Signo text to left stave end
symbol_x = this.x + x + stave.width - 5 + this.x_shift;
Expand Down
2 changes: 1 addition & 1 deletion src/stavevolta.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Volta extends StaveModifier {
const ctx = stave.checkContext();
this.setRendered();

let width = stave.width;
let width = stave.width - x; // don't include x (offset) for width
const top_y = stave.getYForTopText(stave.options.num_lines) + this.y_shift;
const vert_height = 1.5 * stave.options.spacing_between_lines_px;
switch (this.volta) {
Expand Down
92 changes: 92 additions & 0 deletions tests/stave_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ VF.Test.Stave = (function() {
runTests('Multiple Stave Repeats Test', Stave.drawRepeats);
runTests('Stave End Modifiers Test', Stave.drawEndModifiersTest);
runTests('Multiple Staves Volta Test', Stave.drawVoltaTest);
runTests('Volta + Modifier Measure Test', Stave.drawVoltaModifierTest);
runTests('Tempo Test', Stave.drawTempo);
runTests('Single Line Configuration Test', Stave.configureSingleLine);
runTests('Batch Line Configuration Test', Stave.configureAllLines);
Expand Down Expand Up @@ -516,6 +517,97 @@ VF.Test.Stave = (function() {
VF.Formatter.FormatAndDraw(ctx, mm9, notesmm9);
},

drawVoltaModifierTest: function(options, contextBuilder) {
expect(0);

// Get the rendering context
var ctx = contextBuilder(options.elementId, 1100, 200);

// bar 1: volta begin, with modifiers (clef, keysignature)
var mm1 = new VF.Stave(10, 50, 175);
mm1.setBegBarType(VF.Barline.type.REPEAT_BEGIN);
mm1.setVoltaType(VF.Volta.type.BEGIN_END, '1.', -5);
mm1.addClef('treble');
mm1.addKeySignature('A');
mm1.setMeasure(1);
mm1.setSection('A', 0);
mm1.setContext(ctx).draw();
var notesmm1 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
// Helper function to justify and draw a 4/4 voice
VF.Formatter.FormatAndDraw(ctx, mm1, notesmm1);

// bar 2: volta begin_mid, with modifiers (clef, keysignature)
var mm2 = new VF.Stave(mm1.x + mm1.width, mm1.y, 175);
mm2.setBegBarType(VF.Barline.type.REPEAT_BEGIN);
mm2.setRepetitionTypeRight(VF.Repetition.type.DS, 25);
mm2.setVoltaType(VF.Volta.type.BEGIN_MID, '2.', -5);
mm2.addClef('treble');
mm2.addKeySignature('A');
mm2.setMeasure(2);
mm2.setContext(ctx).draw();
var notesmm2 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
VF.Formatter.FormatAndDraw(ctx, mm2, notesmm2);

// bar 3: volta mid, with modifiers (clef, keysignature)
var mm3 = new VF.Stave(mm2.x + mm2.width, mm2.y, 175);
mm3.setVoltaType(VF.Volta.type.MID, '', -5);
mm3.setRepetitionTypeRight(VF.Repetition.type.DS, 25);
mm3.addClef('treble');
mm3.addKeySignature('B');
mm3.setMeasure(3);
mm3.setSection('B', 0);
mm3.setContext(ctx).draw();
var notesmm3 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
VF.Formatter.FormatAndDraw(ctx, mm3, notesmm3);

// bar 4: volta end, with modifiers (clef, keysignature)
var mm4 = new VF.Stave(mm3.x + mm3.width, mm3.y, 175);
mm4.setVoltaType(VF.Volta.type.END, '1.', -5);
mm4.setRepetitionTypeRight(VF.Repetition.type.DS, 25);
mm4.addClef('treble');
mm4.addKeySignature('A');
mm4.setMeasure(4);
mm4.setSection('C', 0);
mm4.setContext(ctx).draw();
var notesmm4 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
VF.Formatter.FormatAndDraw(ctx, mm4, notesmm4);

// bar 5: d.s. shift (similar potential x-shift concern)
var mm5 = new VF.Stave(mm4.x + mm4.width, mm4.y, 175);
// mm5.addModifier(new VF.Repetition(VF.Repetition.type.DS, mm4.x + mm4.width, 50), VF.StaveModifier.Position.RIGHT);
mm5.setEndBarType(VF.Barline.type.DOUBLE);
mm5.setRepetitionTypeRight(VF.Repetition.type.DS, 25);
mm5.addClef('treble');
mm5.addKeySignature('A');
mm5.setMeasure(5);
mm5.setSection('D', 0);
mm5.setContext(ctx).draw();
var notesmm5 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
VF.Formatter.FormatAndDraw(ctx, mm5, notesmm5);

// bar 6: d.s. without modifiers
var mm6 = new VF.Stave(mm5.x + mm5.width, mm5.y, 175);
// mm5.addModifier(new VF.Repetition(VF.Repetition.type.DS, mm4.x + mm4.width, 50), VF.StaveModifier.Position.RIGHT);
mm6.setRepetitionTypeRight(VF.Repetition.type.DS, 25);
mm6.setMeasure(6);
mm6.setSection('E', 0);
mm6.setContext(ctx).draw();
var notesmm6 = [
new VF.StaveNote({ keys: ['c/4'], duration: 'w' }),
];
VF.Formatter.FormatAndDraw(ctx, mm6, notesmm6);
},

drawTempo: function(options, contextBuilder) {
expect(0);

Expand Down

0 comments on commit 0c51ce4

Please sign in to comment.