Skip to content

Commit 2b63498

Browse files
committed
Refactor visual test tool
1 parent df5c88b commit 2b63498

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

visual-tool/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ <h2>abcjs-vexflow-renderer visual comparison tool</h2>
1515

1616
<div id="selectWrapper" style="display:flex;flex-direction:column;">
1717
<select id="tunebookSelect" multiple style="width:300px;height:195px">
18-
<option value="nottingham">Nottingham Dataset</option>
19-
<option value="decorations">Visual Test - Decorations</option>
20-
<option value="durations">Visual Test - Durations</option>
21-
<option value="curves">Visual Test - Curves</option>
22-
<option value="grace">Visual Test - Grace</option>
23-
<option value="custom">Custom file at visual-tool/tunes.txt</option>
2418
</select>
2519
<select id="tuneSelect" multiple style="width:300px;height:235px;">
2620
</select>

visual-tool/scripts/index.js

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import TestGrace from '../visual-test-cases/grace.abc';
2626
import '../index.css';
2727

2828
const allNottinghamTunes = Tunes1 + Tunes2 + Tunes3 + Tunes4 + Tunes5 + Tunes6 + Tunes7 + Tunes8 + Tunes9 + Tunes10 + Tunes11 + Tunes12 + Tunes13 + Tunes14;
29+
const tunebookFiles = {
30+
'Nottingham Dataset': allNottinghamTunes,
31+
'Decorations Test': TestDecorations,
32+
'Durations Test': TestDurations,
33+
'Curves Test': TestCurves,
34+
'Grace Test': TestGrace,
35+
'Custom file at visual-tool/tunes.txt': CustomTunes
36+
};
2937

3038
const defaultRenderOptions = {
3139
xOffset: 3,
@@ -43,7 +51,7 @@ const defaultRenderOptions = {
4351
tuning: AbcjsVexFlowRenderer.TUNINGS.GUITAR_STANDARD,
4452
};
4553

46-
let renderOptions = {};
54+
const renderOptions = {};
4755

4856
const renderOptionsControls = [
4957
$('#xOffset')[0],
@@ -67,15 +75,73 @@ renderOptionsControls.forEach((control) => {
6775
};
6876
});
6977

78+
// merge this with the above, just conditionally check if it's #tuning? to clean up the global space
7079
$('#tuning')[0].onchange = (e) => {
7180
renderOptions.tuning = AbcjsVexFlowRenderer.TUNINGS[e.target.value];
7281
renderTune($('#abcText')[0].innerText);
7382
};
7483

75-
const vexRendererWidth = 500;
76-
const vexRendererHeight = 2000;
84+
$('#applyDefaultOptions')[0].onclick = () => {
85+
setDefaultRenderOptions();
86+
};
87+
88+
$('#testForErrors')[0].onclick = () => {
89+
let exceptionsText = '';
90+
$('#tuneSelect')[0].childNodes.forEach((option) => {
91+
setTimeout(() => {
92+
try {
93+
$('#abcText')[0].innerText = option.value;
94+
renderTune($('#abcText')[0].innerText);
95+
} catch (err) {
96+
exceptionsText += `${option.value}FAILED WITH: ${err}\n\n\n`;
97+
$('#errorText')[0].innerText = exceptionsText;
98+
}
99+
}, 1);
100+
});
101+
};
102+
103+
$('#tunebookSelect')[0].onchange = (event) => {
104+
while ($('#tuneSelect')[0].firstChild) {
105+
$('#tuneSelect')[0].removeChild($('#tuneSelect')[0].firstChild);
106+
}
77107

78-
setDefaultRenderOptions();
108+
const optionsToSet = getOptions(generateTunesArray(tunebookFiles[event.target.value]));
109+
110+
optionsToSet.forEach((option) => {
111+
$('#tuneSelect')[0].add(option);
112+
});
113+
};
114+
115+
$('#tuneSelect')[0].onchange = (event) => {
116+
$('#abcText')[0].innerText = event.target.value;
117+
renderTune($('#abcText')[0].innerText);
118+
};
119+
120+
function init() {
121+
const result = [];
122+
123+
Object.keys(tunebookFiles).forEach((key) => {
124+
const option = document.createElement('option');
125+
option.text = key;
126+
option.value = key;
127+
result.push(option);
128+
});
129+
130+
result.forEach((option) => {
131+
$('#tunebookSelect')[0].add(option);
132+
});
133+
134+
// to get the default tunes to populate in the <select>
135+
const event = new Event('change', { value: 'Nottingham Dataset' });
136+
$('#tunebookSelect')[0].dispatchEvent(event);
137+
138+
// set up the renderOptions
139+
Object.assign(renderOptions, defaultRenderOptions);
140+
renderOptionsControls.forEach((control) => {
141+
control.value = renderOptions[control.id];
142+
});
143+
$('#tuning')[0].value = 'GUITAR_STANDARD';
144+
}
79145

80146
function generateTunesArray(abcSongbookString) {
81147
return abcSongbookString.split('\nX:').filter((tune) => {
@@ -126,64 +192,6 @@ function getOptions(tunesArray) {
126192
return result;
127193
}
128194

129-
function setDefaultRenderOptions() {
130-
renderOptions = Object.assign({}, defaultRenderOptions);
131-
132-
renderOptionsControls.forEach((control) => {
133-
control.value = renderOptions[control.id];
134-
});
135-
$('#tuning')[0].value = 'GUITAR_STANDARD';
136-
}
137-
138-
$('#applyDefaultOptions')[0].onclick = () => {
139-
setDefaultRenderOptions();
140-
};
141-
142-
$('#testForErrors')[0].onclick = () => {
143-
let exceptionsText = '';
144-
$('#tuneSelect')[0].childNodes.forEach((option, i) => {
145-
setTimeout(() => {
146-
try {
147-
$('#abcText')[0].innerText = option.value;
148-
renderTune($('#abcText')[0].innerText);
149-
} catch (err) {
150-
exceptionsText += `${option.value}FAILED WITH: ${err}\n\n\n`;
151-
$('#errorText')[0].innerText = exceptionsText;
152-
}
153-
}, 1);
154-
});
155-
};
156-
157-
$('#tunebookSelect')[0].onchange = (event) => {
158-
while ($('#tuneSelect')[0].firstChild) {
159-
$('#tuneSelect')[0].removeChild($('#tuneSelect')[0].firstChild);
160-
}
161-
162-
let optionsToSet = [];
163-
if (event.target.value === 'nottingham') {
164-
optionsToSet = getOptions(generateTunesArray(allNottinghamTunes));
165-
} else if (event.target.value === 'decorations') {
166-
optionsToSet = getOptions(generateTunesArray(TestDecorations));
167-
} else if (event.target.value === 'durations') {
168-
optionsToSet = getOptions(generateTunesArray(TestDurations));
169-
} else if (event.target.value === 'curves') {
170-
optionsToSet = getOptions(generateTunesArray(TestCurves));
171-
} else if (event.target.value === 'grace') {
172-
optionsToSet = getOptions(generateTunesArray(TestGrace));
173-
} else {
174-
optionsToSet = getOptions(generateTunesArray(CustomTunes));
175-
}
176-
177-
optionsToSet.forEach((option) => {
178-
$('#tuneSelect')[0].add(option);
179-
});
180-
};
181-
182-
$('#tuneSelect')[0].onchange = (event) => {
183-
$('#abcText')[0].innerText = event.target.value;
184-
renderTune($('#abcText')[0].innerText);
185-
};
186-
187195
function renderTune(abc) {
188196
// render abcjs
189197
ABCJS.renderAbc('abcjsRendered', abc);
@@ -197,7 +205,7 @@ function renderTune(abc) {
197205

198206
// render abcjs-vexflow-renderer
199207
const renderer = new Vex.Flow.Renderer($('#vexflowRendered')[0], Vex.Flow.Renderer.Backends.SVG);
200-
renderer.resize(vexRendererWidth, vexRendererHeight);
208+
renderer.resize(500, 2000);
201209
const context = renderer.getContext();
202210

203211
context.setViewBox(0, 0, renderOptions.renderWidth + 5, renderOptions.renderWidth + 5);
@@ -212,6 +220,4 @@ function renderTune(abc) {
212220
}
213221
}
214222

215-
// to get the default tunes to populate in the <select>
216-
const event = new Event('change', { value: 'nottingham' });
217-
$('#tunebookSelect')[0].dispatchEvent(event);
223+
init();

0 commit comments

Comments
 (0)