Old 01-20-2019, 11:16 AM   #1
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default Deferred script acting on MIDI input

Hi all

Another question please - I appreciate all the help and advice here.

Suppose I want to create a script which can be "switched on and off" so it persists once turned on, until it's turned off. Whilst running, I need it to act based on MIDI input from a control knob.

I understand (or at least, I think I do!) that I defer the script main function once it's started, in order for it to keep running repeatedly. But beyond that, some questions about how to do it....

1) I think I need get_action_context in order to "listen" for the MIDI input, but I can't find a resource to explain properly how to use it.

2) I need to execute one block of code if the MIDI knob value is increased from the last time, and another if decreased. I'm sure this should be possible if I can figure out how to get the MIDI value change into a variable.

3) How do I terminate the deferred script with an atexit section?

Sorry for all the basic questions, but I'm a beginner at coding of any kind, not just ReaScript!

Thanks
Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 02:56 PM   #2
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 744
Default

Have you made a demo-script, where calling get_action_context() change its returned values in every defer-cycle?
That way you can see, whether it's possible in the first place(as far as I remember not, but I might be wrong).
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-20-2019, 03:09 PM   #3
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

No, because I don't understand enough about get-action-context to do so.

I don't know how to tell it which controller/input to "look at" for example.
Hence asking for a basic explanation of how to use it.

Thanks

Andy
andyp24 is online now   Reply With Quote
Old 01-20-2019, 10:59 PM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 6,467
Default

To handle Midi input it might be a better idea to do a JSFX instead of a script.

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Old 01-21-2019, 02:24 AM   #5
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

LOL the last thing I need right now is to have to learn a whole new language!!

What I'm trying to do is create some item editing scripts which respond to some kind of physical controller (I don't actually care whether it's a MIDI knob, or something like a Contour Shuttle which can send standard key commands).

So, for instance, a rotary knob which sends a "click up/down" command as it is turned. I need the script to recognise a "click down", and do its stuff (which acts on lots of items, conditional on Ripple states etc).

The only reasons I'm thinking of making this a "persistent" script are 1) that running a single script each time the "click" input is received makes Undo History management harder (because I might turn the knob 50 clicks to get to where I want it, and then I don't want 50 entries in the Undo to go through) and b) some of the items move according to conditions met on the FIRST click.

I can solve the second one using ExtStates and a "toggle mode" kind of script to define when I want to consider the editing to start and stop, and then call each click of the wheel/knob as a separate script. But the Undo History thing is trickier, unless I can stop some of the functions I'm using within the script from generating entries in the Undo list (even though the whole script has no Undo block code).

Does that make sense?
andyp24 is online now   Reply With Quote
Old 01-21-2019, 06:28 AM   #6
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 6,467
Default

Quote:
Originally Posted by andyp24 View Post
LOL the last thing I need right now is to have to learn a whole new language!!
???

JSFX and ReaScript both can be done using EEL.


Quote:
Originally Posted by andyp24 View Post
What I'm trying to do is create some item editing scripts which respond to some kind of physical controller
Maybe "CSI" can help without you doing any programming/scripting but just providing configuration files. See the "Control Surface" subforum.

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Old 01-21-2019, 06:44 AM   #7
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 614
Default

Thanks.... I've been trying to learn Lua, as I was told it's easier than EEL. So, although ReaScript and JS both use EEL, it's still another language I'd have to learn.

And the item editing I'm creating is something that can't be done natively (it changes the way Ripple works, among other things) so I do need the scripting element either way.

Cheers
andyp24 is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.