Skip to content

Commit

Permalink
revert addModifier parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Jan 4, 2022
1 parent bc06474 commit 37a9fde
Show file tree
Hide file tree
Showing 29 changed files with 357 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/articulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class Articulation extends Modifier {
if (position) artic.position = Modifier.PositionString[position];
return builder.getFactory().Articulation(artic);
})
.map((artic) => note.addModifier(artic, 0));
.map((artic) => note.addModifier(0, artic));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/frethandfinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class FretHandFinger extends Modifier {
if (split[1]) params.position = split[1];
return builder.getFactory().Fingering(params);
})
.map((fingering: Modifier, index: number) => note.addModifier(fingering, index));
.map((fingering: Modifier, index: number) => note.addModifier(index, fingering));
}

protected finger: string;
Expand Down
10 changes: 5 additions & 5 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export abstract class Note extends Tickable {
* @param index of the key to modify.
* @returns this
*/
addModifier(modifier: Modifier, index: number = 0): this {
addModifier(index: number, modifier: Modifier): this {
// Backwards compatibility with 3.0.9.
if (typeof index === 'string') {
index = parseInt(index);
Expand Down Expand Up @@ -564,25 +564,25 @@ export abstract class Note extends Tickable {

// Helper function to add an accidental to a key
addAccidental(index: number, accidental: Modifier): this {
return this.addModifier(accidental, index);
return this.addModifier(index, accidental);
}

// Helper function to add an articulation to a key
addArticulation(index: number, articulation: Modifier): this {
return this.addModifier(articulation, index);
return this.addModifier(index, articulation);
}

// Helper function to add an annotation to a key
addAnnotation(index: number, annotation: Modifier): this {
return this.addModifier(annotation, index);
return this.addModifier(index, annotation);
}

// Helper function to add a dot on a specific key
addDot(index: number): this {
const dot = new Dot();
dot.setDotShiftY(this.glyph.dot_shiftY);
this.dots++;
return this.addModifier(dot, index);
return this.addModifier(index, dot);
}

// Convenience method to add dot to all keys in note
Expand Down
4 changes: 2 additions & 2 deletions src/parenthesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class Parenthesis extends Modifier {
/** Add parentheses to note. */
static addParentheses(note: Note): void {
for (let i = 0; i < note.keys.length; i++) {
note.addModifier(new Parenthesis(ModifierPosition.LEFT), i);
note.addModifier(new Parenthesis(ModifierPosition.RIGHT), i);
note.addModifier(i, new Parenthesis(ModifierPosition.LEFT));
note.addModifier(i, new Parenthesis(ModifierPosition.RIGHT));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tabnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class TabNote extends StemmableNote {
addDot(): this {
const dot = new Dot();
this.dots += 1;
return this.addModifier(dot, 0);
return this.addModifier(0, dot);
}

// Calculate and store the width of the note
Expand Down
8 changes: 6 additions & 2 deletions src/tickable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@ export abstract class Tickable extends Element {
return this;
}

/** Optional, if tickable has modifiers, associate a Modifier. */
/**
* Optional, if tickable has modifiers, associate a Modifier.
* @param index ignored
* @param mod the modifier
*/
// eslint-disable-next-line
addModifier(mod: Modifier, ...optionalArgs: any[]): this {
addModifier(index: number, mod: Modifier): this {
this.modifiers.push(mod);
this._preFormatted = false;
return this;
Expand Down
2 changes: 1 addition & 1 deletion tests/accidental_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ function automaticAccidentals0(options: TestOptions): void {
].map(f.StaveNote.bind(f));

const gracenotes = [{ keys: ['d#/4'], duration: '16', slash: true }].map(f.GraceNote.bind(f));
notes[0].addModifier(f.GraceNoteGroup({ notes: gracenotes }).beamNotes(), 0);
notes[0].addModifier(0, f.GraceNoteGroup({ notes: gracenotes }).beamNotes());

const voice = f
.Voice()
Expand Down
64 changes: 32 additions & 32 deletions tests/annotation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function lyrics(options: TestOptions): void {
const noteGroup = registry.getElementById(noteGroupID) as Tickable;
const lyricsAnnotation = f.Annotation({ text }).setFont('Roboto Slab', fontSize);
lyricsAnnotation.setPosition(ModifierPosition.ABOVE);
noteGroup.addModifier(lyricsAnnotation, verse);
noteGroup.addModifier(verse, lyricsAnnotation);
});

// Second row doesn't have any lyrics.
Expand Down Expand Up @@ -113,13 +113,13 @@ function simple(options: TestOptions, contextBuilder: ContextBuilder): void {
{ str: 4, fret: 9 },
],
duration: 'h',
}).addModifier(new Annotation('T'), 0),
}).addModifier(0, new Annotation('T')),
tabNote({
positions: [{ str: 2, fret: 10 }],
duration: 'h',
})
.addModifier(new Annotation('T'), 0)
.addModifier(new Bend('Full'), 0),
.addModifier(0, new Annotation('T'))
.addModifier(0, new Bend('Full')),
];

Formatter.FormatAndDraw(ctx, stave, notes);
Expand Down Expand Up @@ -159,13 +159,13 @@ function harmonic(options: TestOptions, contextBuilder: ContextBuilder): void {
{ str: 3, fret: 12 },
],
duration: 'h',
}).addModifier(new Annotation('Harm.'), 0),
}).addModifier(0, new Annotation('Harm.')),
tabNote({
positions: [{ str: 2, fret: 9 }],
duration: 'h',
})
.addModifier(new Annotation('(8va)').setFont(Font.SERIF, FONT_SIZE, FontWeight.NORMAL, FontStyle.ITALIC), 0)
.addModifier(new Annotation('A.H.'), 0),
.addModifier(0, new Annotation('(8va)').setFont(Font.SERIF, FONT_SIZE, FontWeight.NORMAL, FontStyle.ITALIC))
.addModifier(0, new Annotation('A.H.')),
];

Formatter.FormatAndDraw(ctx, stave, notes);
Expand Down Expand Up @@ -193,23 +193,23 @@ function picking(options: TestOptions, contextBuilder: ContextBuilder): void {
{ str: 5, fret: 0 },
],
duration: 'h',
}).addModifier(new Vibrato().setVibratoWidth(40)),
}).addModifier(0, new Vibrato().setVibratoWidth(40)),
tabNote({
positions: [{ str: 6, fret: 9 }],
duration: '8',
}).addModifier(annotation('p'), 0),
}).addModifier(0, annotation('p')),
tabNote({
positions: [{ str: 3, fret: 9 }],
duration: '8',
}).addModifier(annotation('i'), 0),
}).addModifier(0, annotation('i')),
tabNote({
positions: [{ str: 2, fret: 9 }],
duration: '8',
}).addModifier(annotation('m'), 0),
}).addModifier(0, annotation('m')),
tabNote({
positions: [{ str: 1, fret: 9 }],
duration: '8',
}).addModifier(annotation('a'), 0),
}).addModifier(0, annotation('a')),
];

Formatter.FormatAndDraw(ctx, stave, notes);
Expand Down Expand Up @@ -246,20 +246,20 @@ function bottomWithBeam(options: TestOptions, contextBuilder: ContextBuilder): v

const notes = [
new StaveNote({ keys: ['a/3'], duration: '8' }).addModifier(
new Annotation('good').setVerticalJustification(Annotation.VerticalJustify.BOTTOM),
0
0,
new Annotation('good').setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
),
new StaveNote({ keys: ['g/3'], duration: '8' }).addModifier(
new Annotation('even').setVerticalJustification(Annotation.VerticalJustify.BOTTOM),
0
0,
new Annotation('even').setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
),
new StaveNote({ keys: ['c/4'], duration: '8' }).addModifier(
new Annotation('under').setVerticalJustification(Annotation.VerticalJustify.BOTTOM),
0
0,
new Annotation('under').setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
),
new StaveNote({ keys: ['d/4'], duration: '8' }).addModifier(
new Annotation('beam').setVerticalJustification(Annotation.VerticalJustify.BOTTOM),
0
0,
new Annotation('beam').setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
),
];

Expand Down Expand Up @@ -377,20 +377,20 @@ function tabNotes(options: TestOptions, contextBuilder: ContextBuilder): void {

const notes3 = specs.map((noteSpec) => new TabNote(noteSpec));

notes1[0].addModifier(new Annotation('Text').setJustification(1).setVerticalJustification(1), 0); // U
notes1[1].addModifier(new Annotation('Text').setJustification(2).setVerticalJustification(2), 0); // D
notes1[2].addModifier(new Annotation('Text').setJustification(3).setVerticalJustification(3), 0); // U
notes1[3].addModifier(new Annotation('Text').setJustification(4).setVerticalJustification(4), 0); // D
notes1[0].addModifier(0, new Annotation('Text').setJustification(1).setVerticalJustification(1)); // U
notes1[1].addModifier(0, new Annotation('Text').setJustification(2).setVerticalJustification(2)); // D
notes1[2].addModifier(0, new Annotation('Text').setJustification(3).setVerticalJustification(3)); // U
notes1[3].addModifier(0, new Annotation('Text').setJustification(4).setVerticalJustification(4)); // D

notes2[0].addModifier(new Annotation('Text').setJustification(3).setVerticalJustification(1), 0); // U
notes2[1].addModifier(new Annotation('Text').setJustification(3).setVerticalJustification(2), 0); // D
notes2[2].addModifier(new Annotation('Text').setJustification(3).setVerticalJustification(3), 0); // U
notes2[3].addModifier(new Annotation('Text').setJustification(3).setVerticalJustification(4), 0); // D
notes2[0].addModifier(0, new Annotation('Text').setJustification(3).setVerticalJustification(1)); // U
notes2[1].addModifier(0, new Annotation('Text').setJustification(3).setVerticalJustification(2)); // D
notes2[2].addModifier(0, new Annotation('Text').setJustification(3).setVerticalJustification(3)); // U
notes2[3].addModifier(0, new Annotation('Text').setJustification(3).setVerticalJustification(4)); // D

notes3[0].addModifier(new Annotation('Text').setVerticalJustification(1), 0); // U
notes3[1].addModifier(new Annotation('Text').setVerticalJustification(2), 0); // D
notes3[2].addModifier(new Annotation('Text').setVerticalJustification(3), 0); // U
notes3[3].addModifier(new Annotation('Text').setVerticalJustification(4), 0); // D
notes3[0].addModifier(0, new Annotation('Text').setVerticalJustification(1)); // U
notes3[1].addModifier(0, new Annotation('Text').setVerticalJustification(2)); // D
notes3[2].addModifier(0, new Annotation('Text').setVerticalJustification(3)); // U
notes3[3].addModifier(0, new Annotation('Text').setVerticalJustification(4)); // D

const voice = new Voice(Flow.TIME4_4).setMode(Voice.Mode.SOFT);

Expand Down
28 changes: 14 additions & 14 deletions tests/articulation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,20 @@ function tabNotes(options: TestOptions, contextBuilder: ContextBuilder): void {

const notes3 = specs.map((noteSpec) => new TabNote(noteSpec));

notes1[0].addModifier(new Articulation('a>').setPosition(3), 0); // U
notes1[1].addModifier(new Articulation('a>').setPosition(4), 0); // D
notes1[2].addModifier(new Articulation('a.').setPosition(3), 0); // U
notes1[3].addModifier(new Articulation('a.').setPosition(4), 0); // D

notes2[0].addModifier(new Articulation('a>').setPosition(3), 0);
notes2[1].addModifier(new Articulation('a>').setPosition(4), 0);
notes2[2].addModifier(new Articulation('a.').setPosition(3), 0);
notes2[3].addModifier(new Articulation('a.').setPosition(4), 0);

notes3[0].addModifier(new Articulation('a>').setPosition(3), 0);
notes3[1].addModifier(new Articulation('a>').setPosition(4), 0);
notes3[2].addModifier(new Articulation('a.').setPosition(3), 0);
notes3[3].addModifier(new Articulation('a.').setPosition(4), 0);
notes1[0].addModifier(0, new Articulation('a>').setPosition(3)); // U
notes1[1].addModifier(0, new Articulation('a>').setPosition(4)); // D
notes1[2].addModifier(0, new Articulation('a.').setPosition(3)); // U
notes1[3].addModifier(0, new Articulation('a.').setPosition(4)); // D

notes2[0].addModifier(0, new Articulation('a>').setPosition(3));
notes2[1].addModifier(0, new Articulation('a>').setPosition(4));
notes2[2].addModifier(0, new Articulation('a.').setPosition(3));
notes2[3].addModifier(0, new Articulation('a.').setPosition(4));

notes3[0].addModifier(0, new Articulation('a>').setPosition(3));
notes3[1].addModifier(0, new Articulation('a>').setPosition(4));
notes3[2].addModifier(0, new Articulation('a.').setPosition(3));
notes3[3].addModifier(0, new Articulation('a.').setPosition(4));

const voice = new Voice(Flow.TIME4_4).setMode(Voice.Mode.SOFT);

Expand Down
Loading

0 comments on commit 37a9fde

Please sign in to comment.