^ Introduction |
Introduction | How it works - basics | How to exchange data and get states from Reaper? | Security Aspects | Functions and Variables |
^ Special Variables |
g_wwr_timer_freq |
^ Functions |
wwr_start | wwr_req | wwr_req_recur | wwr_req_recur_cancel | mkvolstr | mkpanstr | simple_unescape |
^ ReadMe |
Readme from Reaper\plugins\reaper_www_root\main.js | Reference |
Reaper can be controlled via a web browser interface: Options->Preferences->Control/OSC/Web->Add->Web Browser Interface
where you can choose between several interfaces, included with reaper(basic, click, index, lyrics). The Webinterface can be accessed i.e. via the local internet-adress localhost:8080 or localhost:8080/(interfacename(like click)).html
It can also be accessed via Wireless Lan as well as using rc.reaper.fm(for i.e. cough-buttons with long distance Skype/Studiolink-interview partners).
The Web-Interface-HTML-files can be found, altered or put to the folder Reaper/Plugins/reaper_www_root/ The folder Plugins/reaper_www_root in the application folder is for the standard "built in"-Reaper-WebAPI-files. If you want to place your own files, you should use the reaper_www_root-folder in the ressources folder or in the application-folder(the latter, if you have a portable installation of Reaper).
You can place the files into the application-folder Plugins/reaper_www_root as well, but if you want to export them with the export-function within Reaper, they will simply be ignored.
The Web-Interface is programmed in JavaScript. You need to include main.js first, then call wwr_start(), which tells the Reaper-Server to accept requests. You can now give Reaper requests, using commands like i.e. wwr_req(ActionCommandID) for one time requests. The ActionCommandID tells Reaper, what you want to call, i.e. the ActionCommandID 1007 starts play in Reaper. You can find a full Action Command ID-list in the Action-Dialog in the menu Actions -> Show Action List. Example Code that presses the Play-Button:
<script src="main.js">
/*includes the main.js, which contains a lot of helper functions*/
</script>
<script type="text/javascript">
wwr_start(); /*tells Reaper to accept requests*/
wwr_req(1007); /*presses the Play-Button*/
</script>
You can also start Reascripts or custom actions. You just need to go to Actions->Show Actions List, then you search for the script or action you want to use. Click on it with right-mouse-click and choose "Copy Selected Action Command ID". Paste it into the following example-code:
<script src="main.js">
/*includes the main.js, which contains a lot of helper functions*/
</script>
<script type="text/javascript">
wwr_start(); /*tells Reaper to accept requests*/
wwr_req("_ActionCommandCode"); /*replace "_Action Command Code", by pasting
the action-command-code you copied from Reaper
It could look something like this:
_RS52af5bc23917ea88f42d82f06b1e1683e64c85a8
Please note: the Action-Command-Code MUST be in quotes " " and
start with an underscore _ */
</script>
Sending messages to Reaper, using requests, is easy, as it is only a normal request, where you exchange the parameters with your own. The parameters can be written inside of the request or exchanged by variables. For instance, if you want to set a persistent external state, you could use the request SET/EXTSTATEPERSIST/section/key/value and it would look like the following example:
Example1
<html>
<head>
<script src="main.js"></script>
<script type="text/javascript">
var section="IamASection";
var key="IamAKey";
var value="IamTheValue";
wwr_start();
wwr_req("SET/EXTSTATEPERSIST/"+section+"/"+key+"/"+value);
</script>
</head>
<body>
A value has been sent now to Reaper, via the extstate-mechanism.<p>
Refer to the GetExtState()-function for getting it in ReaScript.<br>
Use the contents of the variables section and key as parameters for GetExtState() to get the stored value.<br>
</body>
</html>
This extstate can now be read from ReaScript like this:
Value = reaper.GetExtState("IamASection", "IamAKey")
reaper.MB(Value, "The Value, that has been sent from WebRC", 0)
When you call a request, that returns data/values/states, like (TRANSPORT, MARKER or GET/EXTSTATE/section/key), the main.js automatically calls a function called wwr_onreply(results).
This function isn't there by default but must be rather defined by you in your script.
In that function, the variable "result" contains the response from Reaper, which can either be a one-liner(like with TRANSPORT) or multiliner(like when getting the data for all markers in your project with MARKER).
Multiliners are separated by a newline "\n", the individual entries in each line are separated with tabs "\t". So if you want to get the individual values, newline and tab will make you very happy.
Every line in the response starts with the exact request you've sent(a "TRANSPORT"-request returns a line, that begins with "TRANSPORT"), so you know exactly, from what request the response came-from. You can also differentiate between different kinds of requests that way, as different requests return different ways of data, states, etc.
There are exceptions to this rule though(e.g. "MARKER", which starts with "MARKER_LIST"), so, if in doubt, just check the "results"-variable using an alert-message and look for yourself, how the response starts. But relax, they keep the same, means: "MARKER" will always return "MARKER_LIST" and not something like Jamboreepop out of a sudden.
The second example in this chapter will show you how to do it.
Example1:
This is a simple example, that shows how to get data from Reaper using the wwr-request "TRANSPORT" and display it with the Javascript-alert-function. Feel free to modify and experiment in the wwr_req()-line, by exchanging "TRANSPORT" with another request(more requests later in this documentation). This example uses code from the lyrics.html page, as included with Reaper. Always include the main.js!
<html>
<head>
<script src="main.js"></script>
<script type="text/javascript">
function wwr_onreply(results) {
//main.js calls wwr_onreply with the response, as sent from Reaper, when
//wwr_req("TRANSPORT") is called.
alert("Reaper returned: "+results); //shows a messagebox with "results", as returned by Reaper
}
wwr_start();//Starts the Server
wwr_req("TRANSPORT");//Calls TRANSPORT, which returns the Transport-state, playstate, time, etc into the wwr_onreply()-function.
</script>
</head>
<body>
Reaper Transport-State Response-Demo1<p>
Show the Transport-State-Response, when this page is (re-)loaded.
</body>
</html>
Example2:
The next example shows you, what to do with the returned data, how to handle it, separate it(also multiline-requests) and putting it into global variables to be used later. It also displays you the content of the variables with an alert()-message. Press the button to execute the request again. Again, this example works with the "TRANSPORT"-request, but covers briefly the request "MARKER" as well. Feel free to experiment with other requests as well to get an idea. This example uses code from the lyrics.html page, as included with Reaper. Always include the main.js!
<html>
<head>
<script src="main.js"></script>
<script type="text/javascript">
// Setup the global variables, that will contain the Transport-States
var playstate="";
var playpos="099";
var isRepeat="";
var position_string="";
var position_string_beats="";
function wwr_onreply(results) {
// main.js calls wwr_onreply with the response, as sent from Reaper, when
// wwr_req("TRANSPORT") is called. Response can be found in the variable "results".
alert("Reaper returned: "+results); // shows a messagebox with "results", as responded from Reaper
var ar=results.split("\n"); // split results into an array, if result has multiple
// lines(e.g. when you call wwr_req("MARKER") )
for (var i=0; i < ar.length; ++i) { // count through the individual array-fields of "ar"; every one of them containing one
// responded line, if results was a multiline-response.
var tok=ar[i].split("\t"); // split a responded line into its individual fields into the array "tok"
if (tok && tok.length > 0) {
switch (tok[0]) {
case "TRANSPORT": // if response was from wwr_req("TRANSPORT") then
// set the individual tok-entries to these global variables
playstate=tok[1];
playpos=tok[2];
isRepeat=tok[3];
position_string=tok[4];
position_string_beats=tok[5];
break;
case "MARKER_LIST": // if response was from wwr_req("MARKER") then display the first three
// markers from the current Reaper-project.
// If you do wwr_req("MARKER"), the markerlist starts with "MARKER_LIST"!
alert(ar[1]);
alert(ar[2]);
alert(ar[3]);
break;
}
}
}
showVariables(); //show the variables, after they've been set
}
function showVariables()
{
// show the variables, set after wwr_req("TRANSPORT") has been called
alert("playstate: "+playstate); //Playstate
alert("playpos: "+playpos); //Position in seconds
alert("isRepeat: "+isRepeat); //is Repeat-Button on?
alert("position_string: "+position_string); //Position-time as a string
alert("position_string_beats: "+position_string_beats); //Position.beats as a string
}
wwr_start();//Starts the Server
wwr_req("TRANSPORT");//Calls TRANSPORT, which returns the Transport-state, playstate, time, etc into the wwr_onreply()-function.
//wwr_req_recur("TRANSPORT",1000);//Does the same as wwr_req("TRANSPORT"), but repeats it over and over until
//wr_req_recur_cancel("TRANSPORT");//stops requests, that were started by wwr_req_recur("TRANSPORT")
</script>
</head>
<body>
Reaper Transport-State Response-Demo<p>
<form name="test">
<input name="test2" style="font-size:50;" type="submit" value="Show Variables" onclick="start()" onsubmit="start()">
</form>
</body>
</html>
g_wwr_timer_freq
wwr_req(string request)
Sends a one-time request to Reaper. Can be a commandID-number, an "_ActionID" or one of the requests listed in the "Readme"-chapter later below.
If a request returns values, they can be accessed in the function wwr_onreply. Refer the Receiving data from Reaper earlier in this document.
string request |
The request to be sent to Reaper. Can be a commandID-number, an "_ActionID" or one of the requests listed in the "Readme"-chapter. |
wwr_req_recur(string request, float timer_frequency)
Just like wwr_req(), but resends the request automatically with a frequency set in timer_frequency. Must be stopped with wwr_req_recur_cancel()
string request |
The request to be sent to Reaper. Can be a commandID-number, an "_ActionID" or one of the requests listed in the "Readme"-chapter. |
float timer_frequency |
the timer frequency in milliseconds, that decides, how often this request shall be repeated. Don't choose to low, or Reaper might get stuck and unresponsive! |
wwr_req_recur_cancel(string request)
Stops a recurring request, that has been started with wwr_req_recur. Can be a commandID-number, an "_ActionID" or one of the requests listed in the "Readme"-chapter later below.
string request |
The request to be stopped from being sent to Reaper. Can be a commandID-number, an "_ActionID" or one of the requests listed in the "Readme"-chapter. |
string db_value = mkvolstr(float vol)
converts a volume-value(as returned by e.g. the request TRANSPORT") into a db-value and returns it. The string could be like "123.45 db" or "-inf db"(if the vol-value is too low).
string db_value |
the converted value as dB |
float vol |
a volume-number as returned from a request like e.g. TRANSPORT. Only positive values are allowed. Minimum 0.00000002980232. Lower returns -inf. |
string pan_percentage_value = mkpanstr(float pan)
returns the pan value converted into percentage. The returned value could look like "10%L" or "25%R" or "center". The function allows values that produce more than 100% left or right, i.e. "1234%L". Keep that in mind!
string pan_percentage_value |
the converted pan-value as percentage |
float pan |
a pan-number as returned from a request like e.g. TRANSPORT. Negative values=left, positive values=right. -1=100%left, 1-100%right, 0.001 to -0.001=center. |
string unescaped_values = simple_unescape(string v)
string unescaped_values |
the string where all newlines, tabs and backslashes are unescaped |
string v |
a string, that contains not-yet-unescaped newlines, tabs and backslashes |
Automatically generated by Ultraschall-API 5 - 55 elements available |