mod-script-pipe: get selection [SOLVED]

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Locked
artificiel
Posts: 4
Joined: Thu Dec 19, 2019 9:39 pm
Operating System: macOS 10.14 Mojave

mod-script-pipe: get selection [SOLVED]

Post by artificiel » Thu Dec 19, 2019 9:49 pm

hello!

is there a way to get the current selection through mod-script-pipe?

searching the docs and forums did not reveal any specific command, nor a "global" or "selection toolbar" scope for GetInfo. the closest i got was with:

Code: Select all

do_command('NyquistPrompt: Command="(format t \"~a~%\" (get \'*selection* \'start))"')
which pops the selection start in the debug window, but does not return the value to the python script.

thanks,
alex.

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: mod-script-pipe: get selection

Post by steve » Fri Dec 20, 2019 3:43 pm

artificiel wrote:
Thu Dec 19, 2019 9:49 pm
is there a way to get the current selection through mod-script-pipe?
I don't think there is any direct way. Why do you need to?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

artificiel
Posts: 4
Joined: Thu Dec 19, 2019 9:39 pm
Operating System: macOS 10.14 Mojave

Re: mod-script-pipe: get selection

Post by artificiel » Fri Dec 20, 2019 6:17 pm

Context is an art performance. The end goal is to have an operator who selects a region on the timeline, which then gets labelled with arbitrary text coming from a remote source. This is done multiple times in a single project, and not necessarily chronologically. The (artistic) logic of all that was prototyped with MaxMSP, but beyond from the labelling function we need a true editor to handle edits to the recordings, and the MaxMSP widgets are not satisfying. Audacity with python scripting (bridging with OSC) seems like a dream come true.

But AddLabel does not take parameters (to set the Text directly) nor does it return an ID. so after the AddLabel i perform GetInfo on Labels to get the list of labels and thought of correlating the current selection times to retrieve the "selected" ID that i can then pass to SetLabel.

It is a workaround. If AddLabel took a Text parameter (creating a label at the selection and setting it in one pass), or if it returned the ID of the newly created label, our workflow would be complete without the need to get the selection times.

Thanks!
Alex.

PS i am currently setting up xcode and wxwidget to build from source on macOS10.14. production platform will most probably be Arch linux.

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: mod-script-pipe: get selection

Post by steve » Sat Dec 21, 2019 10:59 am

The "NyquistPrompt:" scripting command is not currently usable.
The workaround is to write your Nyquist commands as a plug-in, install the plug-in and then you can call the plug-in from the Python script.

In this case, you would write a plug-in to create a label at the current selection. Something like this:

Code: Select all

;nyquist plug-in
;version 4
;type analyze
;name "Label Selection"

;control labeltext "Label Text" string "" "Label"

(setf duration (- (get '*selection* 'end) (get '*selection* 'start)))
(list (list 0 duration txt))

Then from Python, send the command:

Code: Select all

LabelSelection:labeltext="Label text here"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

artificiel
Posts: 4
Joined: Thu Dec 19, 2019 9:39 pm
Operating System: macOS 10.14 Mojave

Re: mod-script-pipe: get selection

Post by artificiel » Wed Jan 08, 2020 2:28 am

after a little hiatus i am back at this problem and confirm your workaround is fine!
thanks,
alex.

(not sure if there is a protocol here to mark a topic "solved" or otherwise closed...)

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: mod-script-pipe: get selection [SOLVED]

Post by steve » Wed Jan 08, 2020 10:26 am

artificiel wrote:
Wed Jan 08, 2020 2:28 am
(not sure if there is a protocol here to mark a topic "solved" or otherwise closed...)
Often we leave topics open, but if there's a clear resolution of the issue, then one of the moderators may decide to close it so that the solution remains at (or near) the end of the topic. I'll close this topic.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Locked