Skip to content

Commit

Permalink
Remove more VF.* prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed Aug 1, 2021
1 parent b8cfe06 commit a8c4629
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/vibrato.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
// MIT Licnse
// MIT License

import { Modifier } from './modifier';
import { Bend } from './bend';
Expand Down
21 changes: 14 additions & 7 deletions tests/tabtie_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
// @ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { QUnit, ok } from './declarations';
import { QUnit, ok, test, equal } from './declarations';
import { ContextBuilder } from 'renderer';
import { TabTie } from 'tabtie';
import { Voice } from 'voice';
import { Flow } from 'flow';
import { Formatter } from 'formatter';
import { TabStave } from 'tabstave';
import { TabNote } from 'tabnote';
import { Annotation } from 'annotation';
import { TieNotes } from 'types/common';

const TabTieTests = {
Start(): void {
QUnit.module('TabTie');
test('VF.* API', this.VF_Prefix);
const run = VexFlowTests.runTests;
run('Simple TabTie', this.simple);
run('Hammerons', this.simpleHammeron);
Expand All @@ -27,6 +30,10 @@ const TabTieTests = {
run('Continuous', this.continuous);
},

VF_Prefix(): void {
equal(TabTie, VF.TabTie);
},

tieNotes(notes: any, indices: any, stave: any, ctx: any, text?: any): void {
const voice = new Voice(Flow.TIME4_4);
voice.addTickables(notes);
Expand Down Expand Up @@ -90,7 +97,7 @@ const TabTieTests = {

TabTieTests.drawTie(
[
newNote({ positions: [{ str: 4, fret: 12 }], duration: 'h' }).addModifier(new VF.Annotation('T'), 0),
newNote({ positions: [{ str: 4, fret: 12 }], duration: 'h' }).addModifier(new Annotation('T'), 0),
newNote({ positions: [{ str: 4, fret: 10 }], duration: 'h' }),
],
[0],
Expand All @@ -101,10 +108,10 @@ const TabTieTests = {
ok(true, 'Tapping Test');
},

multiTest(options, factory) {
multiTest(options: TestOptions, factory: (notes: TieNotes) => TabTie): void {
const c = TabTieTests.setupContext(options, 440, 140);
function newNote(tab_struct) {
return new VF.TabNote(tab_struct);
return new TabNote(tab_struct);
}

const notes = [
Expand Down Expand Up @@ -142,8 +149,8 @@ const TabTieTests = {
}),
];

const voice = new VF.Voice(Flow.TIME4_4).addTickables(notes);
new VF.Formatter().joinVoices([voice]).format([voice], 300);
const voice = new Voice(Flow.TIME4_4).addTickables(notes);
new Formatter().joinVoices([voice]).format([voice], 300);
voice.draw(c.context, c.stave);

factory({
Expand Down Expand Up @@ -205,7 +212,7 @@ const TabTieTests = {
options.contextBuilder = contextBuilder;
const c = TabTieTests.setupContext(options, 440, 140);
function newNote(tab_struct) {
return new VF.TabNote(tab_struct);
return new TabNote(tab_struct);
}

const notes = [
Expand Down
61 changes: 36 additions & 25 deletions tests/textnote_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
// @ts-nocheck

import { TestOptions, VexFlowTests } from './vexflow_test_helpers';
import { QUnit } from './declarations';
import { QUnit, equal, ok, test } from './declarations';
import { Flow } from 'flow';
import { Crescendo } from 'crescendo';
import { TextNote } from 'textnote';
import { Note } from 'note';

const TextNoteTests = {
Start(): void {
QUnit.module('TextNote');
test('VF.* API', this.VF_Prefix);
const run = VexFlowTests.runTests;
run('TextNote Formatting', this.formatTextNotes);
run('TextNote Formatting 2', this.formatTextNotes2);
Expand All @@ -22,6 +27,11 @@ const TextNoteTests = {
run('Text Dynamics', this.textDynamics);
},

VF_Prefix(): void {
equal(TextNote, VF.TextNote);
equal(Crescendo, VF.Crescendo);
},

formatTextNotes(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 400, 200);
const stave = f.Stave({ y: 40 });
Expand All @@ -40,9 +50,9 @@ const TextNoteTests = {
]);

const voice2 = score.voice([
f.TextNote({ text: 'Center Justification', duration: 'h' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'Center Justification', duration: 'h' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ text: 'Left Line 1', duration: 'q' }).setLine(1),
f.TextNote({ text: 'Right', duration: 'q' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'Right', duration: 'q' }).setJustification(TextNote.Justification.RIGHT),
]);

const formatter = f.Formatter();
Expand Down Expand Up @@ -78,28 +88,28 @@ const TextNoteTests = {
]);

const voice2 = score.voice([
f.TextNote({ text: 'C', duration: '16' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'C', duration: '16' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ text: 'L', duration: '16' }),
f.TextNote({ text: 'R', duration: '16' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'R', duration: '16' }).setJustification(TextNote.Justification.RIGHT),

f.TextNote({ text: 'C', duration: '16' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'C', duration: '16' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ text: 'L', duration: '16' }),
f.TextNote({ text: 'R', duration: '16' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'R', duration: '16' }).setJustification(TextNote.Justification.RIGHT),

f.TextNote({ text: 'C', duration: '16' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'C', duration: '16' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ text: 'L', duration: '16' }),
f.TextNote({ text: 'R', duration: '16' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'R', duration: '16' }).setJustification(TextNote.Justification.RIGHT),

f.TextNote({ text: 'C', duration: '16' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'C', duration: '16' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ text: 'L', duration: '16' }),
f.TextNote({ text: 'R', duration: '16' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'R', duration: '16' }).setJustification(TextNote.Justification.RIGHT),

f.TextNote({ text: 'R', duration: 'q' }).setJustification(VF.TextNote.Justification.RIGHT),
f.TextNote({ text: 'R', duration: 'q' }).setJustification(TextNote.Justification.RIGHT),
]);

f.Formatter().joinVoices([voice1, voice2]).formatToStave([voice1, voice2], stave);

voice2.getTickables().forEach((note) => VF.Note.plotMetrics(f.getContext(), note, 170));
voice2.getTickables().forEach((note) => Note.plotMetrics(f.getContext(), note, 170));

f.draw();

Expand All @@ -124,18 +134,18 @@ const TextNoteTests = {
]);

const voice2 = score.voice([
f.TextNote({ text: VF.unicode.flat + 'I', superscript: '+5', duration: '8' }),
f.TextNote({ text: 'D' + VF.unicode.sharp + '/F', duration: '4d', superscript: 'sus2' }),
f.TextNote({ text: Flow.unicode.flat + 'I', superscript: '+5', duration: '8' }),
f.TextNote({ text: 'D' + Flow.unicode.sharp + '/F', duration: '4d', superscript: 'sus2' }),
f.TextNote({ text: 'ii', superscript: '6', subscript: '4', duration: '8' }),
f.TextNote({ text: 'C', superscript: VF.unicode.triangle + '7', subscript: '', duration: '8' }),
f.TextNote({ text: 'vii', superscript: VF.unicode['o-with-slash'] + '7', duration: '8' }),
f.TextNote({ text: 'C', superscript: Flow.unicode.triangle + '7', subscript: '', duration: '8' }),
f.TextNote({ text: 'vii', superscript: Flow.unicode['o-with-slash'] + '7', duration: '8' }),
f.TextNote({ text: 'V', superscript: '7', duration: '8' }),
]);

voice2.getTickables().forEach(function (note) {
note.font = { family: 'Serif', size: 15, weight: '' };
note.setLine(13);
note.setJustification(VF.TextNote.Justification.LEFT);
note.setJustification(TextNote.Justification.LEFT);
});

f.Formatter().joinVoices([voice1, voice2]).formatToStave([voice1, voice2], stave);
Expand All @@ -162,7 +172,7 @@ const TextNoteTests = {
]);

const voice2 = score.voice([
f.TextNote({ text: 'Center', duration: '8' }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ text: 'Center', duration: '8' }).setJustification(TextNote.Justification.CENTER),
f.TextNote({ glyph: 'f', duration: '8' }),
f.TextNote({ glyph: 'p', duration: '8' }),
f.TextNote({ glyph: 'm', duration: '8' }),
Expand All @@ -174,7 +184,7 @@ const TextNoteTests = {
f.TextNote({ glyph: 'coda', duration: '8' }),
]);

voice2.getTickables().forEach((n) => n.setJustification(VF.TextNote.Justification.CENTER));
voice2.getTickables().forEach((n) => n.setJustification(TextNote.Justification.CENTER));

f.Formatter().joinVoices([voice1, voice2]).formatToStave([voice1, voice2], stave);

Expand Down Expand Up @@ -208,10 +218,10 @@ const TextNoteTests = {
f.TextNote({ glyph: 'caesura_straight', duration: '8' }).setLine(3),
f.TextNote({ glyph: 'breath', duration: '8' }).setLine(2),
f.TextNote({ glyph: 'tick', duration: '8' }).setLine(3),
f.TextNote({ glyph: 'tr', duration: '8', smooth: true }).setJustification(VF.TextNote.Justification.CENTER),
f.TextNote({ glyph: 'tr', duration: '8', smooth: true }).setJustification(TextNote.Justification.CENTER),
]);

voice2.getTickables().forEach((n) => n.setJustification(VF.TextNote.Justification.CENTER));
voice2.getTickables().forEach((n) => n.setJustification(TextNote.Justification.CENTER));

f.Formatter().joinVoices([voice1, voice2]).formatToStave([voice1, voice2], stave);

Expand All @@ -227,10 +237,10 @@ const TextNoteTests = {

const voice = score.voice([
f.TextNote({ glyph: 'p', duration: '16' }),
new VF.Crescendo({ duration: '4d' }).setLine(0).setHeight(25).setStave(stave),
new Crescendo({ duration: '4d' }).setLine(0).setHeight(25).setStave(stave),
f.TextNote({ glyph: 'f', duration: '16' }),
new VF.Crescendo({ duration: '4' }).setLine(5).setStave(stave),
new VF.Crescendo({ duration: '4' }).setLine(10).setDecrescendo(true).setHeight(5).setStave(stave),
new Crescendo({ duration: '4' }).setLine(5).setStave(stave),
new Crescendo({ duration: '4' }).setLine(10).setDecrescendo(true).setHeight(5).setStave(stave),
]);

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
Expand Down Expand Up @@ -266,4 +276,5 @@ const TextNoteTests = {
ok(true);
},
};

export { TextNoteTests };
10 changes: 2 additions & 8 deletions tests/vexflow_test_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,8 @@ class VexFlowTests {
}

static makeFactory(options: TestOptions, width: number = 450, height: number = 140): Factory {
return new Factory({
renderer: {
elementId: options.elementId,
backend: options.backend,
width: width || 450,
height: height || 140,
},
});
const { elementId, backend } = options;
return new Factory({ renderer: { elementId, backend, width, height } });
}

// eslint-disable-next-line
Expand Down

0 comments on commit a8c4629

Please sign in to comment.