Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice cross stave support in System #1434

Merged
merged 3 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cross-stave test case file, and some test cases
  • Loading branch information
AaronDavidNewman authored and rvilarl committed Sep 26, 2022
commit 7b96443e8583109e665c6ae466b5dce7d8360518
341 changes: 341 additions & 0 deletions tests/crossbeam_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
// [VexFlow](https://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
// MIT License
//
// Formatter Tests

import { TestOptions, VexFlowTests } from './vexflow_test_helpers';

import { Stave } from '../src/stave';
import { StaveNote } from '../src/stavenote';

interface crossStaveNotes {
notestring: string;
clef: string;
}
interface crossStaveVoice {
notes: crossStaveNotes[];
stavemask: number[];
beammask: number[];
clef: string;
}
interface crossStaveBeamTest {
title: string;
time: string;
voices: crossStaveVoice[];
}
const CrossBeamTests = {
Start(): void {
QUnit.module('CrossBeam');

const run = VexFlowTests.runTests;
const crossStaveTests: crossStaveBeamTest[] = [];
crossStaveTests.push({
title: 'Single clef mixed 1',
time: '3/4',
voices: [
{
notes: [{ notestring: 'g4/16, f4/16, a6/16, g6/16, b4/4/r, g6/8, g4/8 ', clef: 'treble' }],
stavemask: [0, 0, 0, 0, 0, 0, 0],
beammask: [1, 1, -1, -1, 0, -1, 1],
clef: 'treble',
},
],
});
crossStaveTests.push({
title: 'Single clef mixed 2',
time: '3/4',
voices: [
{
notes: [{ notestring: 'g4/16, f6/16, a4/16, g6/16, b4/4/r, g6/8, g4/8 ', clef: 'treble' }],
stavemask: [0, 0, 0, 0, 0, 0, 0],
beammask: [1, -1, 1, -1, 0, -1, 1],
clef: 'treble',
},
],
});

crossStaveTests.push({
title: 'Mixed clef voice middle',
time: '2/4',
voices: [
{
notes: [{ notestring: 'e#5/4, b4/16/r, b4/16, d5/16., c5/32 ', clef: 'treble' }],
stavemask: [0, 0, 0, 0, 0],
beammask: [0, 0, 1, 1, 1],
clef: 'treble',
},
{
notes: [
{ notestring: 'C3/16, B3/16, C4/16', clef: 'bass' },
{ notestring: 'E#4/16', clef: 'treble' },
{ notestring: 'C4/4', clef: 'bass' },
],
stavemask: [1, 1, 1, 0, 1],
beammask: [1, 1, 1, -1, 0],
clef: 'bass',
},
],
});

crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam up1)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, 1, 1, 1, 1],
stavemask: [0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});

crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam up2)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, 1, 1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});

crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam up3)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, 1, 1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam up4)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/8, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, 1, 1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam down1)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, -1, -1, -1, -1],
stavemask: [0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam down2)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, -1, -1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});

crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam down3)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, -1, -1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam down4)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/8, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, -1, -1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam middle1)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, -1, -1, 1, 1],
stavemask: [0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam middle2)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/8, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});

crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam middle3)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/16, B4/q, A4/8, E4/8', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.push({
title: 'Vertical alignment - cross stave (beam middle4)',
time: '4/4',
voices: [
{
notes: [
{ notestring: 'C#5/q, C5/8, B4/q, A4/8, E4/16', clef: 'treble' },
{ notestring: 'C4/16, D4/8', clef: 'bass' },
],
beammask: [0, 0, 0, -1, -1, 1, 1],
stavemask: [0, 0, 0, 0, 0, 1, 1],
clef: 'treble',
},
{ notes: [{ notestring: '', clef: 'bass' }], beammask: [], stavemask: [], clef: 'bass' },
],
});
crossStaveTests.forEach((cst) => {
run(cst.title, crossClef, cst);
});
},
};

function crossClef(options: TestOptions): void {
const f = VexFlowTests.makeFactory(options, 400 + Stave.defaultPadding, 250);
f.getContext().scale(0.8, 0.8);
const score = f.EasyScore();
const system = f.System({
details: { softmaxFactor: 100 },
autoWidth: true,
debugFormatter: false,
});

const testdata = options.params;
const voicedata: crossStaveVoice[] = testdata.voices;
const stavemap: Stave[] = [];
for (let i = 0; i < voicedata.length; ++i) {
const clef = voicedata[i].clef;
stavemap.push(system.addStave({ voices: [] }).addClef(clef).addTimeSignature(testdata.time));
}
for (let i = 0; i < voicedata.length; ++i) {
const stavemask = voicedata[i].stavemask;
let scoreNotes: StaveNote[] = [];
const voicenotes = voicedata[i].notes;
for (let k = 0; k < voicenotes.length; ++k) {
scoreNotes = scoreNotes.concat(
score.notes(voicenotes[k].notestring, { clef: voicenotes[k].clef }) as StaveNote[]
);
}
const beammask: number[] = voicedata[i].beammask;
let curGroup: StaveNote[] = [];
const beamGroups: StaveNote[][] = [];
for (let j = 0; j < scoreNotes.length; ++j) {
const note = scoreNotes[j];
note.setStave(stavemap[stavemask[j]]);

if (beammask[j] !== 0) {
note.setStemDirection(beammask[j]);
curGroup.push(note);
} else {
if (curGroup.length) {
beamGroups.push(curGroup);
curGroup = [];
}
}
}
if (curGroup.length) {
beamGroups.push(curGroup);
}
beamGroups.forEach((bg) => {
score.beam(bg);
});
if (scoreNotes.length > 0) {
const voice = score.voice(scoreNotes, { time: testdata.time });
system.addVoices([voice]);
}
}
f.draw();
ok(true);
}

VexFlowTests.register(CrossBeamTests);
export { CrossBeamTests };
1 change: 1 addition & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from './boundingbox_tests';
export * from './boundingboxcomputation_tests';
export * from './chordsymbol_tests';
export * from './clef_tests';
export * from './crossbeam_tests';
export * from './curve_tests';
export * from './dot_tests';
export * from './easyscore_tests';
Expand Down