Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 09-12-2019, 06:52 PM   #1
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
Default Trigger Action/Run Script on Transport Play/Pause/Stop/Record, etc.

Does anyone know if it's possible to trigger an action/run a script when any of the transport buttons are pressed?

I found GetPlayState() but that assumes you are periodically polling for any state change.

Is there another way?

Thanks,
Ken
kenm is offline   Reply With Quote
Old 09-13-2019, 06:04 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Unfortunately Reaper doesn't have any event hooks, so a background script that polls the current state is all you can do.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 09-13-2019, 09:01 AM   #3
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
Default

Quote:
Originally Posted by Lokasenna View Post
Unfortunately Reaper doesn't have any event hooks, so a background script that polls the current state is all you can do.
Thank @Lokasenna. I suspected as much.

Is there any examples of background scripts? Do I just start a script that never ends with something like "while(1) do" or do I need to use the defer() or runloop() API functions for this? Obviously my code needs to be nice as to not load the system down.

Thanks again,
Ken
kenm is offline   Reply With Quote
Old 09-13-2019, 09:51 AM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Scripts are run in the main thread, so a loop will freeze Reaper. :P Deferring is the way to go.
Code:
local function main()
  -- check stuff
  if stuff then
    -- do stuff
  end

  reaper.defer(main)
end

main()
Just be aware that your polling will take resources away from Reaper, so depending on the time resolution you need it may be a good idea to only do the polling every second, or every third loop, etc.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 09-13-2019, 10:10 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

example script which could be used for 'relaxed polling' (what Lokasenna said above):
https://forum.cockos.com/showthread.php?t=168270

(post #14)
nofish is offline   Reply With Quote
Old 09-13-2019, 10:37 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by nofish View Post
example script which could be used for 'relaxed polling' (what Lokasenna said above):
https://forum.cockos.com/showthread.php?t=168270

(post #14)
Schwa's comment in the example code about needing to use "Terminate all running scripts" to stop it is thankfully outdated - the Actions menu now lists all running scripts at the bottom, and clicking one will stop it.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 09-13-2019, 08:06 PM   #7
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
Default

Thanks All. This has been very helpful. I now have a working background script that doesn't cause Reaper to grind to a halt.

BTW, my scripting is just to prototype what I ultimately want to re-implement in an extension.

The wall I have to climb is the fact that I don't know C++.

Thanks again,
Ken
kenm is offline   Reply With Quote
Old 09-13-2019, 08:24 PM   #8
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

That could be a pretty hefty wall. What are you trying to do?
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 09-14-2019, 09:24 AM   #9
kenm
Human being with feelings
 
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
Default

Quote:
Originally Posted by Lokasenna View Post
That could be a pretty hefty wall. What are you trying to do?
Hi @Lokasenna,

It's probably easier to show you. I want to do this (or at least some of it) except with Reaper: https://www.youtube.com/watch?v=OGEHenHxpVk

I've started documenting my research here: https://forum.cockos.com/showthread.php?t=224472 and here: https://github.com/kmitch95120/Reaper-ATOM-Integration

While I know I can do a lot with scripts, it concerns me that all scripts run in the same thread and deferred scripts run in the GUI thread. I've been a user for a while now, but I'm just starting to get into the expansion/integration side of things. For example, I'm not sure what the differences are, if any, between an extension and a control surface plugin.

I regularly work with Python for my day job so I want to do this project in anything but Python. I also have several co-workers who are C++ experts so I plan/hope to lean on them for help when I need it.

Ken
kenm is offline   Reply With Quote
Old 09-14-2019, 11:42 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

For your goal the C++ route seems indeed the way to go, because this way you can utilize callbacks from Reaper (rather than polling) which is not possible via scripts, as been mentioned.
https://forum.cockos.com/showthread.php?t=209187

Last edited by nofish; 09-14-2019 at 11:53 AM.
nofish is offline   Reply With Quote
Old 09-14-2019, 01:07 PM   #11
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by kenm View Post
Does anyone know if it's possible to trigger an action/run a script when any of the transport buttons are pressed?

I found GetPlayState() but that assumes you are periodically polling for any state change.

Is there another way?

Thanks,
Ken
I'm working on such a feature for my Ultraschall-API. Watch out for it...

Hope I can put it already in the next release...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine 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 04:57 AM.


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