Skip to content

Commit

Permalink
Vibrato Tests.
Browse files Browse the repository at this point in the history
Remove unused import.
Update test case to not use VF global.
  • Loading branch information
ronyeh committed Aug 30, 2021
1 parent b01d464 commit 1937c04
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/easyscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

/* eslint max-classes-per-file: "off" */

import { Note } from 'note';
import { Accidental } from './accidental';
import { Articulation } from './articulation';
import { Factory } from './factory';
Expand Down Expand Up @@ -503,7 +502,7 @@ export class EasyScore {
return this.builder.getElements().notes;
}

voice(notes: Note[], options: { time?: string; options?: { softmaxFactor: number } } = {}): Voice {
voice(notes: StaveNote[], options: { time?: string; options?: { softmaxFactor: number } } = {}): Voice {
options = { time: this.defaults.time, ...options };
return this.factory.Voice(options).addTickables(notes);
}
Expand Down
9 changes: 5 additions & 4 deletions src/flow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Tables } from './tables';

import { Accidental } from './accidental';
import { Annotation } from './annotation';
import { Articulation } from './articulation';
import { Barline } from './stavebarline';
import { BarNote } from './barnote';
import { Beam } from './beam';
import { Bend } from './bend';
Expand Down Expand Up @@ -41,23 +44,20 @@ import { PedalMarking } from './pedalmarking';
import { Registry } from './registry';
import { Renderer } from './renderer';
import { RepeatNote } from './repeatnote';
import { Repetition } from './staverepetition';
import { Stave } from './stave';
import { Barline } from './stavebarline';
import { StaveConnector } from './staveconnector';
import { StaveHairpin } from './stavehairpin';
import { StaveLine } from './staveline';
import { StaveModifier } from './stavemodifier';
import { StaveNote } from './stavenote';
import { Repetition } from './staverepetition';
import { StaveTempo } from './stavetempo';
import { StaveText } from './stavetext';
import { StaveTie } from './stavetie';
import { Volta } from './stavevolta';
import { Stem } from './stem';
import { StringNumber } from './stringnumber';
import { Stroke } from './strokes';
import { System } from './system';
import { Tables } from './tables';
import { TabNote } from './tabnote';
import { TabSlide } from './tabslide';
import { TabStave } from './tabstave';
Expand All @@ -75,6 +75,7 @@ import { Tuplet } from './tuplet';
import { Vibrato } from './vibrato';
import { VibratoBracket } from './vibratobracket';
import { Voice } from './voice';
import { Volta } from './stavevolta';

export const Flow = {
...Tables,
Expand Down
2 changes: 1 addition & 1 deletion src/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class Voice extends Element {
* This method also calculates the voice's boundingBox while drawing
* the notes. Note the similarities with this.getBoundingBox().
*/
draw(context: RenderContext = this.checkContext(), stave?: Stave): void {
draw(context: RenderContext = this.checkContext(), stave?: Stave): void {
stave = stave ?? this.stave;
this.setRendered();
let boundingBox = undefined;
Expand Down
9 changes: 5 additions & 4 deletions tests/staveconnector_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ContextBuilder } from 'renderer';
import { Stave } from 'stave';
import { BarlineType } from 'stavebarline';
import { StaveConnector } from 'staveconnector';
import { Flow } from 'flow';

const StaveConnectorTests = {
Start(): void {
Expand Down Expand Up @@ -50,20 +51,20 @@ const StaveConnectorTests = {
},

drawSingle4pxStaveLines(options: TestOptions, contextBuilder: ContextBuilder): void {
const oldThickness = VF.STAVE_LINE_THICKNESS;
VF.STAVE_LINE_THICKNESS = 4;
const oldThickness = Flow.STAVE_LINE_THICKNESS;
Flow.STAVE_LINE_THICKNESS = 4;
const ctx = contextBuilder(options.elementId, 400, 300);
const stave = new Stave(25, 10, 300);
const stave2 = new Stave(25, 120, 300);
stave.setContext(ctx);
stave2.setContext(ctx);
const connector = new StaveConnector(stave, stave2);
connector.setType(VF.StaveConnector.type.SINGLE);
connector.setType(StaveConnector.type.SINGLE);
connector.setContext(ctx);
stave.draw();
stave2.draw();
connector.draw();
VF.STAVE_LINE_THICKNESS = oldThickness;
Flow.STAVE_LINE_THICKNESS = oldThickness;

ok(true, 'all pass');
},
Expand Down
65 changes: 20 additions & 45 deletions tests/vibrato_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
//
// Vibrato Tests

/* eslint-disable */
// @ts-nocheck

import { VexFlowTests, TestOptions } from './vexflow_test_helpers';
import { ContextBuilder } from 'renderer';
import { Bend } from 'bend';
import { Formatter } from 'formatter';
import { TabNote } from 'tabnote';
import { TabNote, TabNoteStruct } from 'tabnote';
import { TabStave } from 'tabstave';
import { Vibrato } from 'vibrato';

Expand All @@ -32,25 +29,18 @@ const VibratoTests = {
ctx.font = '10pt Arial';
const stave = new TabStave(10, 10, 450).addTabGlyph().setContext(ctx).draw();

function newNote(tab_struct) {
return new TabNote(tab_struct);
}
function newVibrato() {
return new Vibrato();
}

const notes = [
newNote({
tabNote({
positions: [
{ str: 2, fret: 10 },
{ str: 4, fret: 9 },
],
duration: 'h',
}).addModifier(newVibrato(), 0),
newNote({
}).addModifier(new Vibrato(), 0),
tabNote({
positions: [{ str: 2, fret: 10 }],
duration: 'h',
}).addModifier(newVibrato(), 0),
}).addModifier(new Vibrato(), 0),
];

Formatter.FormatAndDraw(ctx, stave, notes);
Expand All @@ -66,25 +56,18 @@ const VibratoTests = {
ctx.font = '10pt Arial';
const stave = new TabStave(10, 10, 450).addTabGlyph().setContext(ctx).draw();

function newNote(tab_struct) {
return new TabNote(tab_struct);
}
function newVibrato() {
return new Vibrato();
}

const notes = [
newNote({
tabNote({
positions: [
{ str: 2, fret: 10 },
{ str: 4, fret: 9 },
],
duration: 'h',
}).addModifier(newVibrato().setHarsh(true), 0),
newNote({
}).addModifier(new Vibrato().setHarsh(true), 0),
tabNote({
positions: [{ str: 2, fret: 10 }],
duration: 'h',
}).addModifier(newVibrato().setHarsh(true), 0),
}).addModifier(new Vibrato().setHarsh(true), 0),
];

Formatter.FormatAndDraw(ctx, stave, notes);
Expand All @@ -99,42 +82,34 @@ const VibratoTests = {
ctx.setFont('Arial', VexFlowTests.Font.size, '');
const stave = new TabStave(10, 10, 450).addTabGlyph().setContext(ctx).draw();

function newNote(tab_struct) {
return new TabNote(tab_struct);
}
function newBend(text, release) {
return new Bend(text, release);
}
function newVibrato() {
return new Vibrato();
}

const notes = [
newNote({
tabNote({
positions: [
{ str: 2, fret: 9 },
{ str: 3, fret: 9 },
],
duration: 'q',
})
.addModifier(newBend('1/2', true), 0)
.addModifier(newBend('1/2', true), 1)
.addModifier(newVibrato(), 0),
newNote({
.addModifier(new Bend('1/2', true), 0)
.addModifier(new Bend('1/2', true), 1)
.addModifier(new Vibrato(), 0),
tabNote({
positions: [{ str: 2, fret: 10 }],
duration: 'q',
})
.addModifier(newBend('Full', false), 0)
.addModifier(newVibrato().setVibratoWidth(60), 0),
newNote({
.addModifier(new Bend('Full', false), 0)
.addModifier(new Vibrato().setVibratoWidth(60), 0),
tabNote({
positions: [{ str: 2, fret: 10 }],
duration: 'h',
}).addModifier(newVibrato().setVibratoWidth(120).setHarsh(true), 0),
}).addModifier(new Vibrato().setVibratoWidth(120).setHarsh(true), 0),
];

Formatter.FormatAndDraw(ctx, stave, notes);
ok(true, 'Vibrato with Bend');
},
};

const tabNote = (tab_struct: TabNoteStruct) => new TabNote(tab_struct);

export { VibratoTests };

0 comments on commit 1937c04

Please sign in to comment.