Skip to content

Commit

Permalink
AccidentalTests, AnnotationTests, ArticulationTests, AutoBeamFormatti…
Browse files Browse the repository at this point in the history
…ngTests, BendTests, ChordSymbolTests, DotTests, and more...
  • Loading branch information
ronyeh committed Aug 30, 2021
1 parent 0c04294 commit 9cecd99
Show file tree
Hide file tree
Showing 36 changed files with 968 additions and 1,051 deletions.
47 changes: 20 additions & 27 deletions tests/accidental_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ModifierContext } from 'modifiercontext';
import { Stave } from 'stave';
import { StaveNote, StaveNoteStruct } from 'stavenote';
import { Stem } from 'stem';
import { Tickable } from 'tickable';
import { TickContext } from 'tickcontext';
import { TimeSigNote } from 'timesignote';
import { RenderContext } from 'types/common';
Expand Down Expand Up @@ -112,13 +111,9 @@ const AccidentalTests = {
stave.setContext(context).draw();
formatter.format([voice], width);
voice.draw(context, stave);
beams.forEach(function (b) {
b.setContext(context).draw();
});
beams.forEach((b) => b.setContext(context).draw());

notes.forEach(function (note) {
VexFlowTests.plotNoteWidth(context, note, 30);
});
notes.forEach((note) => VexFlowTests.plotNoteWidth(context, note, 30));

VexFlowTests.plotLegendForNoteWidth(context, 300, 150);
ok(true);
Expand Down Expand Up @@ -167,7 +162,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes, 10, { paddingBetween: 45 });

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Modifier, index: number) => {
Expand All @@ -187,23 +182,21 @@ const AccidentalTests = {
const stave = f.Stave({ x: 0, y: 10, width: 780 });
const score = f.EasyScore();

const accids = Object.keys(Flow.accidentalMap).filter(function (accid) {
return accid !== '{' && accid !== '}';
});
const accids = Object.keys(Flow.accidentalMap).filter((accid) => accid !== '{' && accid !== '}');

const notes = accids.map(function (accid) {
return f
const notes = accids.map((accid) =>
f
.StaveNote({ keys: ['a/4'], duration: '4', stem_direction: Stem.UP })
.addAccidental(0, f.Accidental({ type: accid }));
});
.addAccidental(0, f.Accidental({ type: accid }))
);

const voice = score.voice(notes, { time: accids.length + '/4' });

voice.getTickables().forEach((tickable: Tickable) => {
voice.getTickables().forEach((tickable) => {
tickable
.getModifiers()
.filter((modifier: Modifier) => modifier.getAttribute('type') === 'Accidental')
.forEach((accid: Modifier) => (accid as Accidental).setAsCautionary());
.filter((modifier) => modifier.getAttribute('type') === 'Accidental')
.forEach((accid) => (accid as Accidental).setAsCautionary());
});

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
Expand Down Expand Up @@ -259,7 +252,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes, 0, { paddingBetween: 20 });

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Accidental, index: number): void => {
Expand Down Expand Up @@ -308,7 +301,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes, 0, { paddingBetween: 30 });

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Accidental, index: number) => {
Expand Down Expand Up @@ -432,7 +425,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes, 0, { paddingBetween: 35 });

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Accidental, index: number) => {
Expand Down Expand Up @@ -496,7 +489,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes, 0, { paddingBetween: 35 });

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Accidental, index: number) => {
Expand Down Expand Up @@ -597,7 +590,7 @@ const AccidentalTests = {

Formatter.SimpleFormat(notes);

notes.forEach(function (note, index) {
notes.forEach((note, index) => {
VexFlowTests.plotNoteWidth(f.getContext(), note, 140);
ok(note.getAccidentals().length > 0, 'Note ' + index + ' has accidentals');
note.getAccidentals().forEach((accid: Accidental, index: number) => {
Expand Down Expand Up @@ -837,7 +830,7 @@ const AccidentalTests = {
},

autoAccidentalWorking(): void {
function makeNote(noteStruct: StaveNoteStruct) {
function createStaveNote(noteStruct: StaveNoteStruct) {
return new StaveNote(noteStruct);
}

Expand All @@ -850,7 +843,7 @@ const AccidentalTests = {
{ keys: ['b/4'], duration: '4' },
{ keys: ['a#/4'], duration: '4' },
{ keys: ['g#/4'], duration: '4' },
].map(makeNote);
].map(createStaveNote);

let voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);

Expand All @@ -875,7 +868,7 @@ const AccidentalTests = {
{ keys: ['cb/5'], duration: '4' },
{ keys: ['fb/5'], duration: '4' },
{ keys: ['e#/4'], duration: '4' },
].map(makeNote);
].map(createStaveNote);

voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);

Expand Down Expand Up @@ -903,7 +896,7 @@ const AccidentalTests = {
{ keys: ['c##/4'], duration: '4' },
{ keys: ['c/4'], duration: '4' },
{ keys: ['c/4'], duration: '4' },
].map(makeNote);
].map(createStaveNote);

voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);

Expand Down
47 changes: 23 additions & 24 deletions tests/annotation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// @ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { QUnit, ok } from './support/qunit_api';
import { ContextBuilder } from 'renderer';
import { Annotation } from 'annotation';
import { Beam } from 'beam';
Expand Down Expand Up @@ -113,7 +112,7 @@ const AnnotationTests = {
ctx.strokeStyle = '#221';
const stave = new Stave(10, 10, 450).addClef('treble').setContext(ctx).draw();

function annotation(text) {
function annotation(text: string) {
return new Annotation(text).setFont('Times', FONT_SIZE, 'italic');
}

Expand Down Expand Up @@ -162,7 +161,7 @@ const AnnotationTests = {
ctx.setFont('Arial', FONT_SIZE, '');
const stave = new TabStave(10, 10, 450).addTabGlyph().setContext(ctx).draw();

function newAnnotation(text: string) {
function annotation(text: string) {
return new Annotation(text).setFont('Times', FONT_SIZE, 'italic');
}

Expand All @@ -180,19 +179,19 @@ const AnnotationTests = {
tabNote({
positions: [{ str: 6, fret: 9 }],
duration: '8',
}).addModifier(newAnnotation('p'), 0),
}).addModifier(annotation('p'), 0),
tabNote({
positions: [{ str: 3, fret: 9 }],
duration: '8',
}).addModifier(newAnnotation('i'), 0),
}).addModifier(annotation('i'), 0),
tabNote({
positions: [{ str: 2, fret: 9 }],
duration: '8',
}).addModifier(newAnnotation('m'), 0),
}).addModifier(annotation('m'), 0),
tabNote({
positions: [{ str: 1, fret: 9 }],
duration: '8',
}).addModifier(newAnnotation('a'), 0),
}).addModifier(annotation('a'), 0),
];

Formatter.FormatAndDraw(ctx, stave, notes, 200);
Expand All @@ -206,17 +205,17 @@ const AnnotationTests = {
ctx.strokeStyle = '#221';
const stave = new Stave(10, 10, 300).addClef('treble').setContext(ctx).draw();

function newAnnotation(text: string) {
function annotation(text: string) {
return new Annotation(text)
.setFont('Times', FONT_SIZE)
.setVerticalJustification(Annotation.VerticalJustify.BOTTOM);
}

const notes = [
staveNote({ keys: ['f/4'], duration: 'w' }).addAnnotation(0, newAnnotation('F')),
staveNote({ keys: ['a/4'], duration: 'w' }).addAnnotation(0, newAnnotation('A')),
staveNote({ keys: ['c/5'], duration: 'w' }).addAnnotation(0, newAnnotation('C')),
staveNote({ keys: ['e/5'], duration: 'w' }).addAnnotation(0, newAnnotation('E')),
staveNote({ keys: ['f/4'], duration: 'w' }).addAnnotation(0, annotation('F')),
staveNote({ keys: ['a/4'], duration: 'w' }).addAnnotation(0, annotation('A')),
staveNote({ keys: ['c/5'], duration: 'w' }).addAnnotation(0, annotation('C')),
staveNote({ keys: ['e/5'], duration: 'w' }).addAnnotation(0, annotation('E')),
];

Formatter.FormatAndDraw(ctx, stave, notes, 100);
Expand Down Expand Up @@ -262,7 +261,7 @@ const AnnotationTests = {
ctx.fillStyle = '#221';
ctx.strokeStyle = '#221';

function newAnnotation(text: string, hJustification, vJustification) {
function annotation(text: string, hJustification, vJustification) {
return new Annotation(text)
.setFont('Arial', FONT_SIZE)
.setJustification(hJustification)
Expand All @@ -274,10 +273,10 @@ const AnnotationTests = {

const notes = [];

notes.push(staveNote({ keys: ['c/3'], duration: 'q' }).addAnnotation(0, newAnnotation('Text', 1, v)));
notes.push(staveNote({ keys: ['c/4'], duration: 'q' }).addAnnotation(0, newAnnotation('Text', 2, v)));
notes.push(staveNote({ keys: ['c/5'], duration: 'q' }).addAnnotation(0, newAnnotation('Text', 3, v)));
notes.push(staveNote({ keys: ['c/6'], duration: 'q' }).addAnnotation(0, newAnnotation('Text', 4, v)));
notes.push(staveNote({ keys: ['c/3'], duration: 'q' }).addAnnotation(0, annotation('Text', 1, v)));
notes.push(staveNote({ keys: ['c/4'], duration: 'q' }).addAnnotation(0, annotation('Text', 2, v)));
notes.push(staveNote({ keys: ['c/5'], duration: 'q' }).addAnnotation(0, annotation('Text', 3, v)));
notes.push(staveNote({ keys: ['c/6'], duration: 'q' }).addAnnotation(0, annotation('Text', 4, v)));

Formatter.FormatAndDraw(ctx, stave, notes, 100);
}
Expand All @@ -291,7 +290,7 @@ const AnnotationTests = {
ctx.fillStyle = '#221';
ctx.strokeStyle = '#221';

function newAnnotation(text: string, hJustification, vJustification) {
function annotation(text: string, hJustification, vJustification) {
return new Annotation(text)
.setFont('Arial', FONT_SIZE)
.setJustification(hJustification)
Expand All @@ -304,16 +303,16 @@ const AnnotationTests = {
const notes = [];

notes.push(
staveNote({ keys: ['c/3'], duration: 'q', stem_direction: -1 }).addAnnotation(0, newAnnotation('Text', 1, v))
staveNote({ keys: ['c/3'], duration: 'q', stem_direction: -1 }).addAnnotation(0, annotation('Text', 1, v))
);
notes.push(
staveNote({ keys: ['c/4'], duration: 'q', stem_direction: -1 }).addAnnotation(0, newAnnotation('Text', 2, v))
staveNote({ keys: ['c/4'], duration: 'q', stem_direction: -1 }).addAnnotation(0, annotation('Text', 2, v))
);
notes.push(
staveNote({ keys: ['c/5'], duration: 'q', stem_direction: -1 }).addAnnotation(0, newAnnotation('Text', 3, v))
staveNote({ keys: ['c/5'], duration: 'q', stem_direction: -1 }).addAnnotation(0, annotation('Text', 3, v))
);
notes.push(
staveNote({ keys: ['c/6'], duration: 'q', stem_direction: -1 }).addAnnotation(0, newAnnotation('Text', 4, v))
staveNote({ keys: ['c/6'], duration: 'q', stem_direction: -1 }).addAnnotation(0, annotation('Text', 4, v))
);

Formatter.FormatAndDraw(ctx, stave, notes, 100);
Expand Down Expand Up @@ -360,13 +359,13 @@ const AnnotationTests = {
},
];

const notes1 = specs.map(function (noteSpec) {
const notes1 = specs.map((noteSpec) => {
const tabNote = new TabNote(noteSpec);
tabNote.render_options.draw_stem = true;
return tabNote;
});

const notes2 = specs.map(function (noteSpec) {
const notes2 = specs.map((noteSpec) => {
const tabNote = new TabNote(noteSpec);
tabNote.render_options.draw_stem = true;
tabNote.setStemDirection(-1);
Expand Down
2 changes: 1 addition & 1 deletion tests/articulation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ArticulationTests = {
Formatter.FormatAndDraw(ctx, staveBar1, notesBar1);

// bar 2 - juxtaposing second bar next to first bar
const staveBar2 = new Stave(staveBar1.width + staveBar1.x, staveBar1.y, 125);
const staveBar2 = new Stave(staveBar1.getWidth() + staveBar1.getX(), staveBar1.getY(), 125);
staveBar2.setEndBarType(Barline.type.DOUBLE);
staveBar2.setContext(ctx).draw();

Expand Down
Loading

0 comments on commit 9cecd99

Please sign in to comment.