Arrangement display
This commit is contained in:
parent
fccc3ae235
commit
1b41322b9e
|
@ -4,21 +4,23 @@ const string_replacements_element = document.querySelector('#word_replacements_p
|
||||||
const word_overrides_element = document.querySelector('#word_replacements_post');
|
const word_overrides_element = document.querySelector('#word_replacements_post');
|
||||||
const lyrics_input_element = document.querySelector('#lyrics_input_textarea');
|
const lyrics_input_element = document.querySelector('#lyrics_input_textarea');
|
||||||
const lyrics_output_element = document.querySelector('#lyrics_output');
|
const lyrics_output_element = document.querySelector('#lyrics_output');
|
||||||
|
const arrangement_input_element = document.querySelector('#arrangement_input_textarea');
|
||||||
|
const arrangement_output_element = document.querySelector('#arrangement_output');
|
||||||
const lyrics_output_show_romaji_element = document.querySelector('#lyrics_output_show_romaji');
|
const lyrics_output_show_romaji_element = document.querySelector('#lyrics_output_show_romaji');
|
||||||
const lyrics_output_show_kanji_element = document.querySelector('#lyrics_output_show_kanji');
|
const lyrics_output_show_kanji_element = document.querySelector('#lyrics_output_show_kanji');
|
||||||
const req_tokenization_url = './tokenize';
|
const req_tokenization_url = './tokenize';
|
||||||
// let has_lyrics_changed = false
|
// let has_lyrics_changed = false
|
||||||
let tokenized_lyric_lines = [];
|
let tokenized_lyric_lines = [];
|
||||||
|
let lyric_section_ranges = {}; // [start, end) line indices
|
||||||
|
const re_lyric_section = /\[(.+)\]/;
|
||||||
|
|
||||||
function update_lyrics_output(data) {
|
function format_parsed_line(line) {
|
||||||
tokenized_lyric_lines = data.parsed_lines;
|
|
||||||
var html = '';
|
var html = '';
|
||||||
tokenized_lyric_lines.forEach(line => {
|
|
||||||
if ((typeof line) == "string") {
|
if ((typeof line) == "string") {
|
||||||
console.log(`${line} is a string`);
|
// console.log(`${line} is a string`);
|
||||||
html += line + '<br>';
|
html += line + '<br>';
|
||||||
} else {
|
} else {
|
||||||
console.log(`${line} is not a string`);
|
// console.log(`${line} is not a string`);
|
||||||
// Tokenized object
|
// Tokenized object
|
||||||
html += '<span class="lyrics-romaji">';
|
html += '<span class="lyrics-romaji">';
|
||||||
html += line.romaji_syllables.join('');
|
html += line.romaji_syllables.join('');
|
||||||
|
@ -33,10 +35,64 @@ function update_lyrics_output(data) {
|
||||||
});
|
});
|
||||||
html += '<br></span>';
|
html += '<br></span>';
|
||||||
}
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_lyrics_output(data) {
|
||||||
|
tokenized_lyric_lines = data.parsed_lines;
|
||||||
|
var html = '';
|
||||||
|
|
||||||
|
lyric_section_ranges = {};
|
||||||
|
var current_lyric_section
|
||||||
|
var line_counter = 0
|
||||||
|
tokenized_lyric_lines.forEach(line => {
|
||||||
|
if ((typeof line) == "string") {
|
||||||
|
// console.log(`${line} is a string`);
|
||||||
|
const section_match = re_lyric_section.exec(line);
|
||||||
|
if (section_match) {
|
||||||
|
if (current_lyric_section) {
|
||||||
|
// Clean up current section
|
||||||
|
lyric_section_ranges[current_lyric_section].push(line_counter);
|
||||||
|
}
|
||||||
|
current_lyric_section = section_match[1];
|
||||||
|
lyric_section_ranges[current_lyric_section] = [line_counter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html += format_parsed_line(line);
|
||||||
|
line_counter++;
|
||||||
});
|
});
|
||||||
|
if (current_lyric_section) {
|
||||||
|
// Clean up current section
|
||||||
|
lyric_section_ranges[current_lyric_section].push(line_counter);
|
||||||
|
}
|
||||||
lyrics_output_element.innerHTML = html;
|
lyrics_output_element.innerHTML = html;
|
||||||
console.log(`updating lyrics: ${tokenized_lyric_lines}`);
|
console.log(`updating lyrics: ${tokenized_lyric_lines}`);
|
||||||
|
|
||||||
|
update_arrangement_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_arrangement_output() {
|
||||||
|
console.log('Updating arrangement output');
|
||||||
|
|
||||||
|
const arrangement_str = arrangement_input_element.value;
|
||||||
|
var html = '';
|
||||||
|
arrangement_str.split(',').forEach(section => {
|
||||||
|
const s = section.trim();
|
||||||
|
if (s in lyric_section_ranges) {
|
||||||
|
console.log(`Adding section [${s}]`);
|
||||||
|
|
||||||
|
// html += `[${s}]<br>`; // Section name is already in the line range :)
|
||||||
|
const [i0, i1] = lyric_section_ranges[s];
|
||||||
|
for (let i = i0; i < i1; i++) {
|
||||||
|
html += format_parsed_line(tokenized_lyric_lines[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`Cannot add section [${s}]`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
arrangement_output_element.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
function lyrics_input_updated() {
|
function lyrics_input_updated() {
|
||||||
const content = lyrics_input_element.value;
|
const content = lyrics_input_element.value;
|
||||||
const pre_replacements = string_replacements_element.value;
|
const pre_replacements = string_replacements_element.value;
|
||||||
|
@ -73,6 +129,7 @@ function lyrics_input_updated() {
|
||||||
}
|
}
|
||||||
// lyrics_input_element.addEventListener('keyup', (event) => {if (update_lyrics_keys.has(event.key)) lyrics_input_updated();});
|
// lyrics_input_element.addEventListener('keyup', (event) => {if (update_lyrics_keys.has(event.key)) lyrics_input_updated();});
|
||||||
lyrics_input_element.addEventListener('change', lyrics_input_updated);
|
lyrics_input_element.addEventListener('change', lyrics_input_updated);
|
||||||
|
arrangement_input_element.addEventListener('change', update_arrangement_output);
|
||||||
|
|
||||||
function update_output_styles() {
|
function update_output_styles() {
|
||||||
style_lyrics_kanji.style.display = lyrics_output_show_kanji_element.value > 0 ? "inline" : "none";
|
style_lyrics_kanji.style.display = lyrics_output_show_kanji_element.value > 0 ? "inline" : "none";
|
||||||
|
|
|
@ -22,10 +22,10 @@ input {
|
||||||
min-width: 400px;
|
min-width: 400px;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
}
|
}
|
||||||
#lyrics_output_outer {
|
#lyrics_output_outer, #arrangement_output_outer {
|
||||||
min-width: 600px;
|
min-width: 600px;
|
||||||
}
|
}
|
||||||
#lyrics_output {
|
#lyrics_output, #arrangement_output {
|
||||||
background-color: beige;
|
background-color: beige;
|
||||||
/* border-color: grey; */
|
/* border-color: grey; */
|
||||||
border-color: #47c7ce;
|
border-color: #47c7ce;
|
||||||
|
|
|
@ -55,6 +55,12 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Arrangement input -->
|
||||||
|
<div id="arrangement_input">
|
||||||
|
<h2>Arrangement Input</h2>
|
||||||
|
Comma-separated section tags, numbers are beats to insert between sections.<br>
|
||||||
|
<textarea id="arrangement_input_textarea" rows="4" cols="30" wrap="soft" placeholder="v1, c, 8, v2, c, c, 16, b, c"></textarea>
|
||||||
|
</div>
|
||||||
<!-- Lyrics input -->
|
<!-- Lyrics input -->
|
||||||
<div id="lyrics_input">
|
<div id="lyrics_input">
|
||||||
<h2>Lyrics Input</h2>
|
<h2>Lyrics Input</h2>
|
||||||
|
@ -72,11 +78,11 @@
|
||||||
<div id="lyrics_output">
|
<div id="lyrics_output">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Arrangement input -->
|
<!-- Arrangement output -->
|
||||||
<div id="arrangement_input">
|
<div id="arrangement_output_outer">
|
||||||
<h2>Arrangement Input</h2>
|
<h2>Arrangement Output</h2>
|
||||||
Comma-separated section tags, numbers are beats to insert between sections.<br>
|
<div id="arrangement_output">
|
||||||
<textarea id="arrangement" rows="4" cols="30" wrap="soft" placeholder="v1, c, 8, v2, c, c, 16, b, c"></textarea>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Embedded video player for subtitle timing and preview -->
|
<!-- Embedded video player for subtitle timing and preview -->
|
||||||
<div id="embedded_video">
|
<div id="embedded_video">
|
||||||
|
|
Loading…
Reference in New Issue