I want to build a web-remote for the DAW Reaper, using Reapers WebRC.
How it works in basic you can read about here:
In my case I want to access the markers set in Reaper.
The minimum example of the code I use you find here:
<!doctype html>
<html>
<head>
<script src="main.js"></script>
<script type="text/javascript">
function wwr_onreply(results) {
var ar = results.split("\n");
for (var i = 0; i < ar.length; i++) {
var tok = ar[i].split("\t");
if (tok.length > 0)
switch (tok[0]) {
case "MARKER":
document.getElementById("marker").innerHTML = tok;
break;
}
}
}
wwr_req_recur("MARKER", 1000);
wwr_start();
</script>
</head>
<body>
<p>tok of "MARKER": <div id="marker"></div></p>
</body>
</html>
So Reaper passes the queried in a single line of text. Each parameter (e.g. "TRANSPORT", "TRACKS", "MARKERS", etc.) is divided by "\n". If a parameter contains multiple parameters (like different markers), they are divided by "\t".
Now the results get split by "\n" and stored in the array "ar". After that, if containing multiples, they get split by "\t" and stored in the array "tok".
My problem: I can only access the last marker in the "tok". The tok.length is always '5' (Marker, Marker name, id, position, color), no matter how many markers are in the project. When I use "alert(tok.length);", the message windows opens and by clicking ok I can step through all the markers.
Can anyone help me, how I can access the other entries in "tok"?
I tried like with nested array (tok[2][3];), but it didn't help...
I tried to display "tok" with document.getElementById("element").innerHTML = tok and document.getElementById("element").innerHTML = tok[x][y]
I tried to display via "alert(tok)"
I would suggest breaking down your process to smaller steps, and solving one at a time.
This could be a step-by-step guide of your algorithm:
\n=> returns an array of strings (arr1)arr1by\t=> returns an array of arrays (arr2)MARKERSas their first item => returns an array of arrays (arr3)In
arr2andarr3you can access individual items byarr2[x][y](orarr3[x][y].This is a snippet that does something like this:
This might feel unnecessarily verbose compared to your try, but it's much easier to debug, if something is not how you imagined it.
Hope this example helps.