Skip to content

Commit

Permalink
StringNumber and TabSlide
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed Aug 1, 2021
1 parent a8c4629 commit d3a4248
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
54 changes: 30 additions & 24 deletions tests/stringnumber_tests.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
// MIT License
//
// StringNumber Tests

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

import { VexFlowTests } from './vexflow_test_helpers';
import { QUnit, ok } from './declarations';
import { TestOptions, VexFlowTests } from './vexflow_test_helpers';
import { QUnit, ok, test, equal } from './declarations';
import { Stroke } from 'strokes';
import { Barline } from 'stavebarline';
import { Renderer } from 'renderer';

/**
* StringNumber Tests
*/
const StringNumberTests = (function () {
const StringNumber = {
Start() {
QUnit.module('StringNumber');
test('VF.* API', this.VF_Prefix);

const run = VexFlowTests.runTests;
run('String Number In Notation', this.drawMultipleMeasures);
run('Fret Hand Finger In Notation', this.drawFretHandFingers);
run('Multi Voice With Strokes, String & Finger Numbers', this.multi);
run('Complex Measure With String & Finger Numbers', this.drawAccidentals);
},

drawMultipleMeasures(options) {
VF_Prefix(): void {
equal(Stroke, VF.Stroke);
equal(Renderer, VF.Renderer);
equal(Barline, VF.Barline);
},

drawMultipleMeasures(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 775, 200);
const score = f.EasyScore();

// bar 1
const stave1 = f.Stave({ width: 300 }).setEndBarType(VF.Barline.type.DOUBLE).addClef('treble');
const stave1 = f.Stave({ width: 300 }).setEndBarType(Barline.type.DOUBLE).addClef('treble');

const notes1 = score.notes('(c4 e4 g4)/4., (c5 e5 g5)/8, (c4 f4 g4)/4, (c4 f4 g4)/4', { stem: 'down' });

Expand All @@ -43,7 +53,7 @@ const StringNumberTests = (function () {
f
.StringNumber({ number: '3', position: 'above' })
.setLastNote(notes1[3])
.setLineEndType(VF.Renderer.LineEndType.DOWN),
.setLineEndType(Renderer.LineEndType.DOWN),
2
);

Expand All @@ -64,7 +74,7 @@ const StringNumberTests = (function () {
// bar 2 - juxtaposing second bar next to first bar
const stave2 = f
.Stave({ x: stave1.width + stave1.x, y: stave1.y, width: 300 })
.setEndBarType(VF.Barline.type.DOUBLE);
.setEndBarType(Barline.type.DOUBLE);

const notes2 = score.notes('(c4 e4 g4)/4, (c5 e5 g5), (c4 f4 g4), (c4 f4 g4)', { stem: 'up' });

Expand Down Expand Up @@ -93,9 +103,7 @@ const StringNumberTests = (function () {
f.Formatter().joinVoices([voice2]).formatToStave([voice2], stave2);

// bar 3 - juxtaposing third bar next to second bar
const stave3 = f
.Stave({ x: stave2.width + stave2.x, y: stave2.y, width: 150 })
.setEndBarType(VF.Barline.type.END);
const stave3 = f.Stave({ x: stave2.width + stave2.x, y: stave2.y, width: 150 }).setEndBarType(Barline.type.END);

const notesBar3 = score.notes('(c4 e4 g4 a4)/1.');

Expand All @@ -114,12 +122,12 @@ const StringNumberTests = (function () {
ok(true, 'String Number');
},

drawFretHandFingers(options) {
drawFretHandFingers(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 725, 200);
const score = f.EasyScore();

// bar 1
const stave1 = f.Stave({ width: 350 }).setEndBarType(VF.Barline.type.DOUBLE).addClef('treble');
const stave1 = f.Stave({ width: 350 }).setEndBarType(Barline.type.DOUBLE).addClef('treble');

const notes1 = score.notes('(c4 e4 g4)/4, (c5 e5 g5), (c4 f4 g4), (c4 f4 g4)', { stem: 'down' });

Expand Down Expand Up @@ -155,9 +163,7 @@ const StringNumberTests = (function () {
f.Formatter().joinVoices([voice1]).formatToStave([voice1], stave1);

// bar 2 - juxtaposing second bar next to first bar
const stave2 = f
.Stave({ x: stave1.width + stave1.x, y: stave1.y, width: 350 })
.setEndBarType(VF.Barline.type.END);
const stave2 = f.Stave({ x: stave1.width + stave1.x, y: stave1.y, width: 350 }).setEndBarType(Barline.type.END);

const notes2 = score.notes('(c4 e4 g4)/4., (c5 e5 g5)/8, (c4 f4 g4)/8, (c4 f4 g4)/4.[stem="down"]', {
stem: 'up',
Expand Down Expand Up @@ -200,39 +206,39 @@ const StringNumberTests = (function () {
ok(true, 'String Number');
},

multi(options) {
multi(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 700, 200);
const score = f.EasyScore();
const stave = f.Stave();

const notes1 = score.notes('(c4 e4 g4)/4, (a3 e4 g4), (c4 d4 a4), (c4 d4 a4)', { stem: 'up' });

notes1[0]
.addStroke(0, new VF.Stroke(5))
.addStroke(0, new Stroke(5))
.addModifier(f.Fingering({ number: '3', position: 'left' }), 0)
.addModifier(f.Fingering({ number: '2', position: 'left' }), 1)
.addModifier(f.Fingering({ number: '0', position: 'left' }), 2)
.addModifier(f.StringNumber({ number: '4', position: 'left' }), 1)
.addModifier(f.StringNumber({ number: '3', position: 'above' }), 2);

notes1[1]
.addStroke(0, new VF.Stroke(6))
.addStroke(0, new Stroke(6))
.addModifier(f.StringNumber({ number: '4', position: 'right' }), 1)
.addModifier(f.StringNumber({ number: '3', position: 'above' }), 2)
.addAccidental(0, f.Accidental({ type: '#' }))
.addAccidental(1, f.Accidental({ type: '#' }))
.addAccidental(2, f.Accidental({ type: '#' }));

notes1[2]
.addStroke(0, new VF.Stroke(2))
.addStroke(0, new Stroke(2))
.addModifier(f.Fingering({ number: '3', position: 'left' }), 0)
.addModifier(f.Fingering({ number: '0', position: 'right' }), 1)
.addModifier(f.StringNumber({ number: '4', position: 'right' }), 1)
.addModifier(f.Fingering({ number: '1', position: 'left' }), 2)
.addModifier(f.StringNumber({ number: '3', position: 'right' }), 2);

notes1[3]
.addStroke(0, new VF.Stroke(1))
.addStroke(0, new Stroke(1))
.addModifier(f.StringNumber({ number: '3', position: 'left' }), 2)
.addModifier(f.StringNumber({ number: '4', position: 'right' }), 1);

Expand Down Expand Up @@ -263,10 +269,10 @@ const StringNumberTests = (function () {
ok(true, 'Strokes Test Multi Voice');
},

drawAccidentals(options) {
drawAccidentals(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 500);

const stave = f.Stave().setEndBarType(VF.Barline.type.DOUBLE).addClef('treble');
const stave = f.Stave().setEndBarType(Barline.type.DOUBLE).addClef('treble');

const notes = [
f.StaveNote({ keys: ['c/4', 'e/4', 'g/4', 'c/5', 'e/5', 'g/5'], stem_direction: 1, duration: '4' }),
Expand Down
38 changes: 24 additions & 14 deletions tests/tabslide_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@
// @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 { Flow } from 'flow';
import { TabSlide } from 'tabslide';
import { Formatter } from 'formatter';
import { TabNote } from 'tabnote';
import { Voice } from 'voice';
import { TabStave } from 'tabstave';

const TabSlideTests = {
Start(): void {
QUnit.module('TabSlide');
test('VF.* API', this.VF_Prefix);

const run = VexFlowTests.runTests;
run('Simple TabSlide', this.simple);
run('Slide Up', this.slideUp);
run('Slide Down', this.slideDown);
},

tieNotes(notes, indices, stave, ctx) {
const voice = new VF.Voice(Flow.TIME4_4);
VF_Prefix(): void {
equal(TabSlide, VF.TabSlide);
equal(TabNote, VF.TabNote);
equal(Voice, VF.Voice);
equal(TabStave, VF.TabStave);
},

tieNotes(notes, indices, stave, ctx): void {
const voice = new Voice(Flow.TIME4_4);
voice.addTickables(notes);

new Formatter().joinVoices([voice]).format([voice], 100);
Expand All @@ -43,13 +55,13 @@ const TabSlideTests = {
tie.draw();
},

setupContext(options, x) {
setupContext(options: TestOptions, width?: number): any {
const ctx = options.contextBuilder(options.elementId, 350, 140);
ctx.scale(0.9, 0.9);
ctx.fillStyle = '#221';
ctx.strokeStyle = '#221';
ctx.font = '10pt Arial';
const stave = new VF.TabStave(10, 10, x || 350).addTabGlyph().setContext(ctx).draw();
const stave = new TabStave(10, 10, width || 350).addTabGlyph().setContext(ctx).draw();

return { context: ctx, stave: stave };
},
Expand All @@ -73,11 +85,9 @@ const TabSlideTests = {
ok(true, 'Simple Test');
},

multiTest(options, factory) {
const c = TabSlideTests.setupContext(options, 440, 100);
function newNote(tab_struct) {
return new VF.TabNote(tab_struct);
}
multiTest(options: TestOptions, factory): void {
const c = TabSlideTests.setupContext(options, 440);
const newNote = (tab_struct: any) => new TabNote(tab_struct);

const notes = [
newNote({ positions: [{ str: 4, fret: 4 }], duration: '8' }),
Expand Down Expand Up @@ -114,8 +124,8 @@ const TabSlideTests = {
}),
];

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 @@ -165,12 +175,12 @@ const TabSlideTests = {

slideUp(options: TestOptions, contextBuilder: ContextBuilder): void {
options.contextBuilder = contextBuilder;
TabSlideTests.multiTest(options, VF.TabSlide.createSlideUp);
TabSlideTests.multiTest(options, TabSlide.createSlideUp);
},

slideDown(options: TestOptions, contextBuilder: ContextBuilder): void {
options.contextBuilder = contextBuilder;
TabSlideTests.multiTest(options, VF.TabSlide.createSlideDown);
TabSlideTests.multiTest(options, TabSlide.createSlideDown);
},
};

Expand Down

0 comments on commit d3a4248

Please sign in to comment.