Skip to content

Commit

Permalink
Add input boxes for repeat begins ends and custom text
Browse files Browse the repository at this point in the history
  • Loading branch information
sonph committed Jun 2, 2024
1 parent 51cff4d commit 7c1cfca
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
60 changes: 53 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

input#url,
input#convertedUrl,
input#text {
width: 70%;
input#subText,
input#measureText {
width: 90%;
}
</style>
</head>
Expand All @@ -31,12 +32,28 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
<form>
<label for="url">URL:</label>
<input type="text" id="url" name="url"><br><br>
<label for="text">Text:</label>
<input type="text" id="text" name="text"><br><br>

<label for="subText">Sub Text:</label>
<input type="text" id="subText" name="subText" placeholder="chorus (8 bars)"><br><br>

<label for="repeatBegins">Begin repeat at measures (separated by ;):</label>
<input type="text" id="repeatBegins" name="repeatBegins" placeholder="1;3"><br><br>

<label for="repeatEnds">End repeat at measures (separated by ;):</label>
<input type="text" id="repeatEnds" name="repeatEnds" placeholder="2;4"><br><br>

<label for="repeatEndings">Alternate endings at measures (separated by ;):</label>
<input type="text" id="repeatEndings" name="repeatEndings" placeholder="2:1;3:2"><br><br>

<label for="measureText">Text at begin or end of measure (separated by ;):</label>
<input type="text" id="measureText" name="measureText" placeholder="1:b:start here;2:e:end here"><br><br>

<label for="showTempo">Show Tempo</label>
<input type="checkbox" id="showTempo" name="showTempo"><br><br>

<label for="convertedUrl">Converted URL:</label>
<input type="text" id="convertedUrl" name="convertedUrl"><br><br>

<button type="button" id="convertBtn">Convert</button>
<button type="button" id="copyBtn">Convert & copy to clipboard</button>
<button type="button" id="openLink">Open link</button>
Expand All @@ -63,6 +80,15 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
}, 2000 /* ms */);
}

function encodeAfterLastColon(str) {
return str.split(";").map(e => {
const parts = e.trim().split(":");
const encodedPart = encodeURIComponent(parts[parts.length - 1])
return parts.slice(0, parts.length - 1).concat([encodedPart]).join(":");
})
.join(";")
}

function convert() {
const url = document.getElementById("url").value;
if (url.length == 0) {
Expand All @@ -79,9 +105,29 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
convertedUrl = convertedUrl + "&EmbedTempoTimeSig=true";
}

const text = document.getElementById("text").value;
if (text.length > 0) {
convertedUrl += "&text=" + encodeURIComponent(text);
const subText = document.getElementById("subText").value;
if (subText.length > 0) {
convertedUrl += "&subText=" + encodeURIComponent(subText);
}

const repeatBegins = document.getElementById("repeatBegins").value;
if (repeatBegins.length > 0) {
convertedUrl += "&RepeatBegins=" + repeatBegins;
}

const repeatEnds = document.getElementById("repeatEnds").value;
if (repeatEnds.length > 0) {
convertedUrl += "&RepeatEnds=" + repeatEnds;
}

const repeatEndings = document.getElementById("repeatEndings").value;
if (repeatEndings.length > 0) {
convertedUrl += "&RepeatEndings=" + repeatEndings;
}

const measureText = document.getElementById("measureText").value;
if (measureText.length > 0) {
convertedUrl += "&MeasureText=" + encodeAfterLastColon(measureText);
}

const convertedUrlElement = document.getElementById("convertedUrl");
Expand Down
20 changes: 10 additions & 10 deletions js/groove_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class GrooveData {
this.repeatBegins = []
this.repeatEnds = []
this.repeatEndings = new Map()
this.text = new Map()
this.measureText = new Map()
}
}

Expand Down Expand Up @@ -760,7 +760,7 @@ class GrooveUtils {
myGrooveData.repeatBegins = this.parseIntSet(this.getQueryVariableFromString("RepeatBegins", "", encodedURLData));
myGrooveData.repeatEnds = this.parseIntSet(this.getQueryVariableFromString("RepeatEnds", "", encodedURLData));
myGrooveData.repeatEndings = this.parseMeasureMapping(this.getQueryVariableFromString("RepeatEndings", "", encodedURLData));
myGrooveData.text = this.parseTextMapping(this.getQueryVariableFromString("Text", "", encodedURLData));
myGrooveData.measureText = this.parseTextMapping(this.getQueryVariableFromString("MeasureText", "", encodedURLData));

myGrooveData.debugMode = parseInt(this.getQueryVariableFromString("Debug", this.debugMode, encodedURLData), 10);

Expand Down Expand Up @@ -1239,8 +1239,8 @@ class GrooveUtils {
stickings_voice_string += "[" + repeatEndings.get(currentMeasure)
hh_snare_voice_string += "[" + repeatEndings.get(currentMeasure)
}
if (grooveData.text.has(currentMeasure) && grooveData.text.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.text.get(currentMeasure).text + "\"";
if (grooveData.measureText.has(currentMeasure) && grooveData.measureText.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.measureText.get(currentMeasure).text + "\"";
}
}

Expand Down Expand Up @@ -1430,8 +1430,8 @@ class GrooveUtils {
// add a bar line every measure
if (((i + 1) % (12 * timeSigTop * (4 / timeSigBottom))) === 0) {
kick_voice_string += "|";
if (grooveData.text.has(currentMeasure) && !grooveData.text.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.text.get(currentMeasure).text + "\"";
if (grooveData.measureText.has(currentMeasure) && !grooveData.measureText.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.measureText.get(currentMeasure).text + "\"";
}
if (repeatEnds.has(currentMeasure)) {
hh_snare_voice_string += ":|"
Expand Down Expand Up @@ -1525,8 +1525,8 @@ class GrooveUtils {
stickings_voice_string += "[" + repeatEndings.get(currentMeasure)
hh_snare_voice_string += "[" + repeatEndings.get(currentMeasure)
}
if (grooveData.text.has(currentMeasure) && grooveData.text.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.text.get(currentMeasure).text + "\"";
if (grooveData.measureText.has(currentMeasure) && grooveData.measureText.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.measureText.get(currentMeasure).text + "\"";
}
}

Expand Down Expand Up @@ -1581,8 +1581,8 @@ class GrooveUtils {

// add a bar line every measure. 32 notes in 4/4 time. (32/timeSigBottom * timeSigTop)
if (((i + 1) % ((32 / timeSigBottom) * timeSigTop)) === 0) {
if (grooveData.text.has(currentMeasure) && !grooveData.text.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.text.get(currentMeasure).text + "\"";
if (grooveData.measureText.has(currentMeasure) && !grooveData.measureText.get(currentMeasure).begin) {
hh_snare_voice_string += "\"" + grooveData.measureText.get(currentMeasure).text + "\"";
}
kick_voice_string += "|";
if (repeatEnds.has(currentMeasure)) {
Expand Down

0 comments on commit 7c1cfca

Please sign in to comment.