Old 11-05-2019, 06:33 AM   #1
jbradbury
Human being with feelings
 
Join Date: Sep 2019
Posts: 3
Default reaper.defer() a reaper.execProcess()

Hi everyone,

I am using lua + reascript to call some DSP processes from the command line which take the audio file of a media item as input and return some output. I am using reaper.execProcess to call the commands, and one of the parameters I pass to it is the output file name. With this information I have successfully made the scripts append the output files as takes to the original media item. Here is where the problem starts.

The process is initiated at the reaper side by a dialog box asking the user to input some parameters. Once the user hits OK the GUI blocks up and nothing else can be touched. Ideally, I would like the GUI to dissappear, the execProcess to start running in the background and when its completed the items are appended to the media item. For the life of me, I cannot get reaper.defer() to make this work on the execProcess component. I have separated out my code into the GUI portion which asks the user to input commands and stores these in tables, followed by the execution of the command line program with its various parameters.

In so far, the most functional solution I have been able to make work is to call the GUI function (which is deferred and disappears after the user presses OK) and then call the execProcess function inside a reaper.atext(). Still, this locks up reaper but without the prompt for parameters to be visible. Ideally, this would be completely non-blocking.

Am I chasing a solution which doesn't exist? Is it possible to make execProcess not block Reaper?

Code is here:

https://github.com/jamesb93/ReaCoMa/...fluid-hpss.lua
jbradbury is offline   Reply With Quote
Old 11-05-2019, 07:02 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Without a way to actually run those processes in separate threads, I think Lua's coroutines are your best bet. They're the same thing as generators in Javascript - a function that can pause itself and be resumed later, so if you need to process 100 things you can have it do 5 of them, pause for Reaper to update, then do the next 5, etc.

http://lua-users.org/wiki/CoroutinesTutorial
Lokasenna is online now   Reply With Quote
Old 11-05-2019, 07:05 AM   #3
jbradbury
Human being with feelings
 
Join Date: Sep 2019
Posts: 3
Default

This looks promising! I will have to try this and hope that REAPER doesn't block and wait for all the coroutines to report back.

Thanks for pointing me to this.

Quote:
Originally Posted by Lokasenna View Post
Without a way to actually run those processes in separate threads, I think Lua's coroutines are your best bet. They're the same thing as generators in Javascript - a function that can pause itself and be resumed later, so if you need to process 100 things you can have it do 5 of them, pause for Reaper to update, then do the next 5, etc.

http://lua-users.org/wiki/CoroutinesTutorial
jbradbury is offline   Reply With Quote
Old 11-05-2019, 07:07 AM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Oh, it will 100% block. The idea is to defer a function that keeps calling the coroutines so that they're never doing enough work at one time to visibly freeze Reaper.
Lokasenna is online now   Reply With Quote
Old 11-05-2019, 07:39 AM   #5
jbradbury
Human being with feelings
 
Join Date: Sep 2019
Posts: 3
Default

Quote:
Originally Posted by Lokasenna View Post
Oh, it will 100% block. The idea is to defer a function that keeps calling the coroutines so that they're never doing enough work at one time to visibly freeze Reaper.
Even one execution of a process can block, so I guess this won't be that useful. . The best case scenario would be to execute and update my arrangement on another thread but I guess I'm pushing the API quite hard now.
jbradbury is offline   Reply With Quote
Old 11-05-2019, 07:52 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

How long does a single process take, though? Could you set them up as a queue and only run one at a time, yielding in between?
Lokasenna is online now   Reply With Quote
Old 11-05-2019, 04:07 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,806
Default

Set ExecProcess's timeoutmsec parameter to -1 to start the process without waiting for it to exit.

You could also use Lua's os.execute and tell the shell to run the command in the background: os.execute('sleep 42 &'). There's a number of differences to REAPER's ExecProcess:
  • Can search for the executable in the $PATH
  • Filenames containing the same quotation character surrounding it (" ' or `) can be used (escaping the quotation character is not supported by ExecProcess at least on Linux/macOS)
  • No access to the output (there's io.popen for that but it's broken on Windows 32-bit)
  • The command line goes straight to the shell so proper input sanitizing is in order to avoid command injection
  • Have to deal with cmd.exe not being sh on Windows

Last edited by cfillion; 11-06-2019 at 05:19 PM.
cfillion 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 10:19 PM.


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