UNPKG

vexflow

Version:

A JavaScript library for rendering music notation and guitar tablature.

142 lines (141 loc) 5.91 kB
import { VexFlowTests } from './vexflow_test_helpers.js'; const ClefTests = { Start() { QUnit.module('Clef'); const run = VexFlowTests.runTests; run('Bounding Box', draw, { drawBoundingBox: true }); run('Bounding Box Clef Change', drawClefChange, { drawBoundingBox: true }); run('Clef Test', draw, { drawBoundingBox: false }); run('Clef End Test', drawEnd); run('Small Clef Test', drawSmall); run('Small Clef End Test', drawSmallEnd); run('Clef Change Test', drawClefChange, { drawBoundingBox: false }); }, }; function draw(options) { const f = VexFlowTests.makeFactory(options, 800, 120); const stave = f .Stave() .addClef('treble') .addClef('treble', 'default', '8va') .addClef('treble', 'default', '8vb') .addClef('alto') .addClef('tenor') .addClef('soprano') .addClef('bass') .addClef('bass', 'default', '8vb') .addClef('mezzo-soprano') .addClef('baritone-c') .addClef('baritone-f') .addClef('subbass') .addClef('percussion') .addClef('french') .addEndClef('treble'); f.draw(); if (options.params.drawBoundingBox === true) { const elements = stave.getModifiers(undefined, 'Clef'); elements.forEach((element) => VexFlowTests.drawBoundingBox(f.getContext(), element)); } options.assert.ok(true, 'all pass'); } function drawEnd(options) { const f = VexFlowTests.makeFactory(options, 800, 120); f.Stave() .addClef('bass') .addEndClef('treble') .addEndClef('treble', 'default', '8va') .addEndClef('treble', 'default', '8vb') .addEndClef('alto') .addEndClef('tenor') .addEndClef('soprano') .addEndClef('bass') .addEndClef('bass', 'default', '8vb') .addEndClef('mezzo-soprano') .addEndClef('baritone-c') .addEndClef('baritone-f') .addEndClef('subbass') .addEndClef('percussion') .addEndClef('french'); f.draw(); options.assert.ok(true, 'all pass'); } function drawSmall(options) { const f = VexFlowTests.makeFactory(options, 800, 120); f.Stave() .addClef('treble', 'small') .addClef('treble', 'small', '8va') .addClef('treble', 'small', '8vb') .addClef('alto', 'small') .addClef('tenor', 'small') .addClef('soprano', 'small') .addClef('bass', 'small') .addClef('bass', 'small', '8vb') .addClef('mezzo-soprano', 'small') .addClef('baritone-c', 'small') .addClef('baritone-f', 'small') .addClef('subbass', 'small') .addClef('percussion', 'small') .addClef('french', 'small') .addEndClef('treble', 'small'); f.draw(); options.assert.ok(true, 'all pass'); } function drawSmallEnd(options) { const f = VexFlowTests.makeFactory(options, 800, 120); f.Stave() .addClef('bass', 'small') .addEndClef('treble', 'small') .addEndClef('treble', 'small', '8va') .addEndClef('treble', 'small', '8vb') .addEndClef('alto', 'small') .addEndClef('tenor', 'small') .addEndClef('soprano', 'small') .addEndClef('bass', 'small') .addEndClef('bass', 'small', '8vb') .addEndClef('mezzo-soprano', 'small') .addEndClef('baritone-c', 'small') .addEndClef('baritone-f', 'small') .addEndClef('subbass', 'small') .addEndClef('percussion', 'small') .addEndClef('french', 'small'); f.draw(); options.assert.ok(true, 'all pass'); } function drawClefChange(options) { const f = VexFlowTests.makeFactory(options, 800, 180); const stave = f.Stave().addClef('treble'); const notes = [ f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'treble' }), f.ClefNote({ type: 'alto', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'alto' }), f.ClefNote({ type: 'tenor', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'tenor' }), f.ClefNote({ type: 'soprano', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'soprano' }), f.ClefNote({ type: 'bass', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'bass' }), f.ClefNote({ type: 'mezzo-soprano', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'mezzo-soprano' }), f.ClefNote({ type: 'baritone-c', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'baritone-c' }), f.ClefNote({ type: 'baritone-f', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'baritone-f' }), f.ClefNote({ type: 'subbass', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'subbass' }), f.ClefNote({ type: 'french', options: { size: 'small' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'french' }), f.ClefNote({ type: 'treble', options: { size: 'small', annotation: '8vb' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'treble', octaveShift: -1 }), f.ClefNote({ type: 'treble', options: { size: 'small', annotation: '8va' } }), f.StaveNote({ keys: ['c/4'], duration: '4', clef: 'treble', octaveShift: 1 }), ]; const voice = f.Voice({ time: '12/4' }).addTickables(notes); f.Formatter().joinVoices([voice]).formatToStave([voice], stave); f.draw(); if (options.params.drawBoundingBox === true) { notes.forEach((element) => VexFlowTests.drawBoundingBox(f.getContext(), element)); } options.assert.ok(true, 'all pass'); } VexFlowTests.register(ClefTests); export { ClefTests };