View Single Post
Old 03-31-2018, 01:06 PM   #82
Human being with feelings
Join Date: Feb 2016
Posts: 131
Default Repurposing buttons to be learnable with a toggle

Here goes: teach a man to fish, rather than give a fish...

Use this Notepad++ editor to look at the script code.
It will highlight the syntax. aids learning, and helps to ensure that block start and ends (the curved brackets and semicolons etc) align

Then let's start by repurposing a single recarm button. One step at a time to make sure the syntax and intent is correct.

The code needing to be changed is here.
          midimix_mode == 0 ? oscsend(OSC_to_REAPER, reaper_track_recarm_toggle, 1 ) : 
          		      ( oscsend(OSC_to_REAPER, device_track_select, 1); oscsend(OSC_to_REAPER, device_fxparam_bank_select ););
We will change either the first, or more likely the second pair of oscsend() calls (device_track_select & device_fxparam_bank_select: which are made in instrument mode), to instead call a new function toggle_button() which will do the toggle and send the OSC.

Start by declaring a toggle flag. Do this in the // Variable section to be tidy and consistent.

button1 = 0;   // Flag to track button state
Secondly write the new function needed that looks about like this

function toggle_button()
// Send a toggling OSC string on a button press. Sends 1 or 0 value on subsequent button presses
    button1 == 0 ?
       button1 = 1; 
       oscsend(OSC_to_REAPER,"f/midimix/button/1", 1);
       button1 = 0;
       oscsend(OSC_to_REAPER,"f/midimix/button/1", 0);  
Finally call toggle_button() as introduced at the start of this explanation. So the code looks like this. Check the ); so the blocks line and pair up correctly.

          midimix_mode == 0 ? oscsend(OSC_to_REAPER, reaper_track_recarm_toggle, 1 ) : 
          		      toggle_button(); );
There. We have a single toggling button that can be "learnt" to change something in Reaper, using Reaper's learn function instead of Record Arming or opening an effect

To harness all eight buttons, this function can either be cut and pasted and modified to make eight function variants (crude but effective) or by extending to do all eight buttons instead of the first one (better but trickier coding whilst learning).

To do such extension the new toggle_button() function would need extending
- to take a parameter 1-8 passed to it depending on the button (see example of parameters in send_soft_fader() function )
- to use an array of eight flags one per button, rather than a single variable
(see the use of memset(): considerable care needed here to start a second array so it doesn't overlap FX_GUIstate)
- send an OSC string per button like "f/midimix/button/1" where the integer in the string varies from 1-8 per button

Finally tidy up the use of a literal string in the toggle_button() function by declaring the string in the same way as the other strings.

One could even extend the use of this new function to more buttons beyond the eight record arms.

Last edited by goldenarpharazon; 04-16-2018 at 02:33 PM. Reason: Made end intention of changes clearer. Added easy cut and paste suggestion. Added EEL2 syntax aware editor
goldenarpharazon is offline   Reply With Quote