Old 11-13-2009, 08:49 AM   #1
EvilDragon
Human being with feelings
 
EvilDragon's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 24,798
Default Can ReaScript make cycling button actions?

In short what's described here: http://forum.cockos.com/project.php?issueid=346

I bet it can, it's all done with a counter and if-else loops, I reckon. But how to detect a key that is going to be bound to that specific ReaScript, and then detect multiple pressings of that key, AND to preserve last pressed key state?
EvilDragon is offline   Reply With Quote
Old 11-13-2009, 09:54 AM   #2
MikeLacey
Human being with feelings
 
Join Date: Dec 2006
Location: UK
Posts: 789
Default

Hi Dragon,

You don't need to store the last state if you want to cycle through the MIDI Editor modes - you can just ask the MIDI Editor what mode it's in with MIDIEditor_GetMode()

Once you have the current mode you can flick it to the other one with the appropriate MIDIEditor_OnCommand() call.

Mike
__________________
Mike Lacey, Leicestershire, UK
MikeLacey is offline   Reply With Quote
Old 11-13-2009, 10:09 AM   #3
EvilDragon
Human being with feelings
 
EvilDragon's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 24,798
Default

True, but I was asking from a more generalized perspective (and used the link above just for an application example, sorry if I wasn't clear enough!) - so I could use a multitude of actions depending on the key I press multiple times.

Say, I want to write a ReaScript that's gonna cycle through the five envelope modes for the currently selected envelope on the currently selected track. Say I want that ReaScript freely bound to a certain key. How can ReaScript determine to which key was it bound, and use that key to cyclically trigger one of those 5 states?

Now I don't need a solution to this particular ReaScript, I just want to know the general approach of how to do a cycled n-keypress script.


BTW - I can't cycle through all piano roll modes - MIDIEditor_GetMode still doesn't return a value for named notes mode!
EvilDragon is offline   Reply With Quote
Old 11-13-2009, 12:46 PM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by EvilDragon View Post
How can ReaScript determine to which key was it bound, and use that key to cyclically trigger one of those 5 states?

Now I don't need a solution to this particular ReaScript, I just want to know the general approach of how to do a cycled n-keypress script.
That may be a bit tough one. ReaScripts can't retain their state in memory between their executions. The script would need to have a variable that is increased from it's previous value each time it executes. An obvious but slightly complicated approach would be to keep that state in a disk file. It however may be your only way to do this currently.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 11-13-2009, 03:38 PM   #5
MikeLacey
Human being with feelings
 
Join Date: Dec 2006
Location: UK
Posts: 789
Default

"MIDIEditor_GetMode still doesn't return a value for named notes mode!"

No. No it doesn't - and I'm not sure why - just an oversight?

Now - forgive me for being thick... Freely Bound? What do you mean by that?
__________________
Mike Lacey, Leicestershire, UK
MikeLacey is offline   Reply With Quote
Old 11-13-2009, 03:57 PM   #6
EvilDragon
Human being with feelings
 
EvilDragon's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 24,798
Default

Freely bound... That means whichever key I associate to any action in Actions window - a basic Reaper action, an extension action, my custom macro, or my custom ReaScript. Key binding, freely bound key. In essence, this ReaScript should recognize the key to which it was dedicated to, and cycle different actions on multiple presses of that same key.


Also, Xen, doesn't Python support persistent variables that could be used as some kind of memory?
EvilDragon is offline   Reply With Quote
Old 11-13-2009, 04:04 PM   #7
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by EvilDragon View Post
Also, Xen, doesn't Python support persistent variables that could be used as some kind of memory?
Not really, unless the script is continuously running. ReaScripts however get loaded, executed and destroyed from memory at each run. Perhaps you could come up with some way to keep the script running in the background continuously without blocking Reaper's GUI thread, I don't know...Anyway the saving and loading a disk file isn't very hard to do, at least in Python. (And I am quite sure Perl has good facilities for that too.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   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 07:15 PM.


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