-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.mjs
40 lines (31 loc) · 1.05 KB
/
render.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { renderLyPattern, renderAsciiPattern } from './render-vex.mjs';
import { lyPatternToAscii } from './ly-pattern-parser.mjs';
import { asciiPatternToLy } from './ascii-pattern-parser.mjs';
import { button, textEditor, checkbox } from './ui-elements.mjs';
let modeLy = true;
let uiText, uiLinearTime;
let score;
uiText = textEditor(`<hh bd>8 hh <hh sn> hh16 bd <hh bd>8 hh <hh sn> hh`);
async function render() {
if (score) {
score.dispose();
score = undefined;
}
const content = uiText.getValue();
const renderer = modeLy ? renderLyPattern : renderAsciiPattern;
score = await renderer(content, uiLinearTime.getValue());
}
async function convert() {
let content = uiText.getValue();
const converter = modeLy ? asciiPatternToLy : lyPatternToAscii;
content = await converter(content);
uiText.setValue(content);
}
button('render', render);
button('change mode', async () => {
modeLy = !modeLy;
await convert();
render();
});
uiLinearTime = checkbox('linear time', render, true);
await render();