I’ve done some progresses on the Gui for SoX as I said in my previous post, here is a screenshot that shows some informations retrieved invoking sox with the –info argument followed by the file name to scan:
As you can see it works, at least on Windows, but I’ve used a trick because using the more logical command Execute() it was failing without giving any hints, so here is the trick, maybe it could be useful for other Hollywood coders 🙂
Instead of using Execute(), which executes a program synchronously (read: it stops the main program execution flow until the executed program has finished), I’ve used the command Run() to run asynchronously sox.
The first idea was to redirect the output to a temporary file but with Run() there is the possibility to install an event handler that automatically grabs the executed program’s output for you.
I’ve also installed another event handler to signal to my program when sox has finished, so at the end, this is the best solution for me because if sox detects errors they will be grabbed and printed out in the gui like this:
Here is a snippet of the code I used to:
- Install the event handler
- Run an external program
- Wait the program to finish
- Unistall the event handler
Note that while waiting for the program to finish the gui and all the callback functions are still responding to the user’s input!
————————–
; Read source informations
Local waitFinish = True
Local soxInfos = “”
; To grab the output we will install two event handlers,
; one to grab the output
; one to signal that sox has returned
InstallEventHandler(
{ RunOutput =
Function(args)
soxInfos = soxInfos .. args.output
EndFunction,
RunFinished =
Function()
waitFinish = False
EndFunction })
; Time to execute sox and grab the informations
Run(app.prefs.sox_path, “–info ” .. file)
; Wait until sox has finished
While waitFinish
CheckEvents()
Wend
; Remove the previously installed handlers
InstallEventHandler(
{ RunOutput = 0,
RunFinished = 0 })
————————–
That’s all for this update 🙂