Skip to content

Commit

Permalink
Change parameter order of Note.addModifier(...) and
Browse files Browse the repository at this point in the history
Tickable.addModifier(...). The modifier argument is now first, and the
index is now second (defaults to 0).
  • Loading branch information
ronyeh committed Jan 20, 2022
1 parent a70c6d6 commit 27a587d
Show file tree
Hide file tree
Showing 39 changed files with 780 additions and 791 deletions.
2 changes: 1 addition & 1 deletion src/accidental.ts
Expand Up @@ -456,7 +456,7 @@ export class Accidental extends Modifier {
const accidental = new Accidental(accidentalString);

// Attach the accidental to the StaveNote
staveNote.addModifier(keyIndex, accidental);
staveNote.addModifier(accidental, keyIndex);

// Add the pitch to list of pitches that modified accidentals
modifiedPitches.push(keyString);
Expand Down
2 changes: 1 addition & 1 deletion src/articulation.ts
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(0, artic));
.map((artic) => note.addModifier(artic, 0));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/dot.ts
Expand Up @@ -33,16 +33,16 @@ export class Dot extends Modifier {
for (let i = 0; i < note.keys.length; i++) {
const dot = new Dot();
dot.setDotShiftY(note.glyph.dot_shiftY);
note.addModifier(i, dot);
note.addModifier(dot, i);
}
} else if (options?.index != undefined) {
const dot = new Dot();
dot.setDotShiftY(note.glyph.dot_shiftY);
note.addModifier(options?.index, dot);
note.addModifier(dot, options?.index);
} else {
const dot = new Dot();
dot.setDotShiftY(note.glyph.dot_shiftY);
note.addModifier(0, dot);
note.addModifier(dot, 0);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/easyscore.ts
Expand Up @@ -372,7 +372,7 @@ export class Builder {
const accid = notePiece.accid;
if (typeof accid === 'string') {
const accidental = factory.Accidental({ type: accid });
note.addModifier(index, accidental);
note.addModifier(accidental, index);
accidentals.push(accidental);
} else {
accidentals.push(undefined);
Expand Down
2 changes: 1 addition & 1 deletion src/frethandfinger.ts
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(index, fingering));
.map((fingering: Modifier, index: number) => note.addModifier(fingering, index));
}

protected finger: string;
Expand Down
21 changes: 7 additions & 14 deletions src/note.ts
Expand Up @@ -532,30 +532,23 @@ export abstract class Note extends Tickable {
* @param index of the key to modify.
* @returns this
*/
addModifier(index: number, modifier: Modifier): this {
addModifier(modifier: Modifier, index: number = 0): this {
const signature = 'Note.addModifier(modifier: Modifier, index: number=0)';
// Backwards compatibility with 3.0.9.
if (typeof index === 'string') {
index = parseInt(index);
// eslint-disable-next-line
console.warn(
'Note.addModifier(modifier: Modifier, index?: number) ' +
'expected a number for `index`, but received a string. ' +
'Please provide a number for the `index` argument.'
);
console.warn(signature + ' expected a number for `index`, but received a string.');
}

// Legacy versions of VexFlow had the two parameters swapped.
// We check here and throw an error if the argument types are not correct.
// Some versions of VexFlow had the two parameters reversed.
// Check here and throw an error if the argument types are not correct.
if (typeof modifier !== 'object' || typeof index !== 'number') {
throw new RuntimeError(
'WrongParams',
'Call signature to addModifier not supported, use addModifier(modifier: Modifier, index) instead.'
);
throw new RuntimeError('WrongParams', 'Incorrect call signature. Use ' + signature + ' instead.');
}
modifier.setNote(this);
modifier.setIndex(index);
this.modifiers.push(modifier);
this.preFormatted = false;
super.addModifier(modifier, index);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/parenthesis.ts
Expand Up @@ -20,8 +20,8 @@ export class Parenthesis extends Modifier {
static buildAndAttach(notes: Note[]): void {
for (const note of notes) {
for (let i = 0; i < note.keys.length; i++) {
note.addModifier(i, new Parenthesis(ModifierPosition.LEFT));
note.addModifier(i, new Parenthesis(ModifierPosition.RIGHT));
note.addModifier(new Parenthesis(ModifierPosition.LEFT), i);
note.addModifier(new Parenthesis(ModifierPosition.RIGHT), i);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tickable.ts
Expand Up @@ -278,7 +278,7 @@ export abstract class Tickable extends Element {
* @param mod the modifier
*/
// eslint-disable-next-line
addModifier(index: number, mod: Modifier): this {
addModifier(mod: Modifier, index: number = 0): this {
this.modifiers.push(mod);
this._preFormatted = false;
return this;
Expand Down

0 comments on commit 27a587d

Please sign in to comment.