Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Jan 2, 2022
1 parent 0191f4f commit bc06474
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class Dot extends Modifier {
protected radius: number;
protected dot_shiftY: number;

/** Returns the dots associated to a Note. */
static getDots(note: Note): Dot[] {
return note.getModifiersByType(Dot.CATEGORY) as Dot[];
}

// Arrange dots inside a ModifierContext.
static format(dots: Dot[], state: ModifierContextState): boolean {
const right_shift = state.right_shift;
Expand Down
11 changes: 3 additions & 8 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,9 @@ export abstract class Note extends Tickable {
return this;
}

// Get all accidentals in the `ModifierContext`
getAccidentals(): Modifier[] {
return this.checkModifierContext().getMembers('Accidental') as Modifier[];
}

// Get all dots in the `ModifierContext`
getDots(): Modifier[] {
return this.checkModifierContext().getMembers('Dot') as Modifier[];
// Get all modifiers of a specific type in the `ModifierContext`
getModifiersByType(type: string): Modifier[] {
return this.checkModifierContext().getMembers(type) as Modifier[];
}

/** Get the coordinates for where modifiers begin. */
Expand Down
28 changes: 14 additions & 14 deletions tests/accidental_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ function basic(options: TestOptions): void {

notes.forEach((note, index) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Modifier, index: number) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid: Modifier, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -370,8 +370,8 @@ function specialCases(options: TestOptions): void {

notes.forEach((note, index) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid, index) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid, index) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -419,8 +419,8 @@ function basicStemDown(options: TestOptions): void {

notes.forEach((note, noteIndex) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + noteIndex + ' has accidentals');
note.getAccidentals().forEach((accid, accidIndex) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + noteIndex + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid, accidIndex) => {
ok(accid.getWidth() > 0, 'Accidental ' + accidIndex + ' has set width');
});
});
Expand Down Expand Up @@ -558,8 +558,8 @@ function microtonal(options: TestOptions): void {

notes.forEach((note, index) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Modifier, index: number) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid: Modifier, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -622,8 +622,8 @@ function microtonal_iranian(options: TestOptions): void {

notes.forEach((note, index) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Modifier, index: number) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid: Modifier, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -719,8 +719,8 @@ function sagittal(options: TestOptions): void {

notes.forEach((note, index) => {
Note.plotMetrics(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Modifier, index: number) => {
ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
note.getModifiersByType('Accidental').forEach((accid: Modifier, index: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
});
});
Expand Down Expand Up @@ -1185,8 +1185,8 @@ function factoryAPI(options: TestOptions): void {
Formatter.SimpleFormat(notes);

notes.forEach((n, i) => {
ok(n.getAccidentals().length > 0, 'Note ' + i + ' has accidentals');
n.getAccidentals().forEach((accid: Modifier, i: number) => {
ok(n.getModifiersByType('Accidental').length > 0, 'Note ' + i + ' has accidentals');
n.getModifiersByType('Accidental').forEach((accid: Modifier, i: number) => {
ok(accid.getWidth() > 0, 'Accidental ' + i + ' has set width');
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/dot_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function basic(options: TestOptions, contextBuilder: ContextBuilder): void {

for (let i = 0; i < notes.length; i++) {
showOneNote(notes[i], stave, ctx, 30 + i * 65);
const dots = notes[i].getDots();
const dots = notes[i].getModifiersByType('Dot');
ok(dots.length > 0, 'Note ' + i + ' has dots');

for (let j = 0; j < dots.length; ++j) {
Expand Down

0 comments on commit bc06474

Please sign in to comment.