Old 10-07-2020, 12:36 AM   #1
giohappy
Human being with feelings
 
Join Date: Apr 2020
Posts: 28
Default Schedule action at next beat, bar, measure...

I'm new to Reaper scripting so forgive the basic question.
Is it possible to schedule an action / routine to be executed at a specific time in the future?

As an example:
1 - click a keyboard shortcut while playing
2 - an action fires at next beat which mutes a certain track

Do I need to loop with defer() and manage the elapsed time by myself?
AFAIK defer() is not very reliable though, since Reaper will queue the callback and it will fire as soon as a free slot is available. Would it be enough to make actions like the example above?
giohappy is offline   Reply With Quote
Old 10-07-2020, 01:32 AM   #2
giohappy
Human being with feelings
 
Join Date: Apr 2020
Posts: 28
Default

I think I got it by myself. A script doesn't have any scheduling utility, and the only option (if I'm not wrong) is polling and calculating when the next beat will happen.

I suspect this is not a good use case for a script.
A JSFX (on a utility track) would probably be a better solution. Now I have to understand how to manage keyboard inside a JSFX..
giohappy is offline   Reply With Quote
Old 10-07-2020, 05:53 AM   #3
jrengmusic
Human being with feelings
 
jrengmusic's Avatar
 
Join Date: Jun 2015
Location: Indonesia Raya
Posts: 684
Default

If you have SWS extension installed, you could just use Action Marker.
__________________
JRENG! | M E T R I C
jrengmusic is offline   Reply With Quote
Old 10-07-2020, 06:24 AM   #4
giohappy
Human being with feelings
 
Join Date: Apr 2020
Posts: 28
Default

@jrengmusic I don't think it's my case. What I want to obatin is run an action at a future point in time but depending on a trigger by the user.
My example should be clear:

- a user clicks a key on the keyboard
- an action is scheduled to be triggered at a certain point in the future (e.g. next bar)

After digging more I see that JSFS is not the right tool, since it's not meant to use Reaper API.
I guess the only solution remains using the defer() approach and calculate trigger things based on the playhead status, tempo, etc.
giohappy is offline   Reply With Quote
Old 10-07-2020, 10:04 AM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

You can have a look at my Event-Manager-stuff in my Ultraschall-API:
https://mespotin.uber.space/Ultrasch...1_Introduction

This is intended for event-based stuff. All you basically need to do is writing a function, that can find out that a bar has changed from the previous one to the current one and return true in that case.
If you have such a function, you can pass it over to my EventManager and tell it, how to run it and how often to check for it(30times/sec is maximum).

Is takes away the tedious management of defer and even allows you to pause or end the check, if you don't need it.
__________________
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
Old 10-07-2020, 12:21 PM   #6
giohappy
Human being with feelings
 
Join Date: Apr 2020
Posts: 28
Default

Oh, nice. In my case it should be one-off actions, to be run only once. Is
Code:
StartActionsOnceDuringTrue=true
the paramater value for addEvent() to use in this case? Does it also deregister the event after the action has fired?
giohappy is offline   Reply With Quote
Old 10-07-2020, 12:31 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

StartActionsOnceDuringTrue=true is right.

It does not deregister it after that directly, only by unregistering it yourself.
But this is a good point, to have single-shot events only triggered once and removed as they aren't needed anymore.
I think I'll try to add that in a later version.
__________________
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
Old 10-07-2020, 12:44 PM   #8
giohappy
Human being with feelings
 
Join Date: Apr 2020
Posts: 28
Default

Cool, it would be really useful. For the moment I will unregister the event before adding a new one afterwards.
giohappy 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 11:13 AM.


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