Go Back   Cockos Incorporated Forums > REAPER Forums > JSFX and ReaScript Discussion

Reply
 
Thread Tools Display Modes
Old 07-13-2018, 05:44 PM   #1
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 399
Default Lua Reascript Is there a "wait ()" statement equivalent?

I'm coding some mixer toggle states and would like to minimize clicking by ducking volume and then waiting and then resuming functions.

Is there a Reascript or Lua command that would be equivalent to a simple wait(ms/Ms) command?

Thanks.

Cheers,

Andrew K
Thonex is online now   Reply With Quote
Old 07-13-2018, 06:32 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,487
Default

os.sleep, but that will cause Reaper to wait as well.

You can use defer to let a function keep checking the time and then do something if time_now - time_started > X.

Code:
local function Msg(str)
   reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

time_start = reaper.time_precise()
Msg("Starting a timer for 2 seconds...")

local function Main()

    local elapsed = reaper.time_precise() - time_start

    if elapsed >= 3 then
        Msg("2 seconds have elapsed! Ending the loop.")
        return
    else
        reaper.defer(Main)
    end
    
end

Main()
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 07-13-2018, 07:47 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 399
Default

Thanks Loka!! Again!!

Will try it out this weekend.

Here's to hoping it will give milli or micro second precision.

Cheers,

Andrew K
Thonex is online now   Reply With Quote
Old 07-13-2018, 07:49 PM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,338
Default

Quote:
Originally Posted by Thonex View Post
Here's to hoping it will give milli or micro second precision.
Sorry to say, but it won't. The deferred functions are called about in the 30-50 millisecond range without any guarantees. (If anything in the GUI thread stalls due to Reaper's operations or 3rd party plugins, the ReaScript deferred functions will also stall.)
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 07-13-2018, 09:24 PM   #5
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 399
Default

Quote:
Originally Posted by Xenakios View Post
Sorry to say, but it won't. The deferred functions are called about in the 30-50 millisecond range without any guarantees. (If anything in the GUI thread stalls due to Reaper's operations or 3rd party plugins, the ReaScript deferred functions will also stall.)
DARN!!

whaaa!



Cheers,

Andrew K
Thonex 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 06:17 PM.


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