mod-script-pipe: get selection [SOLVED]

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:

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.

I don’t think there is any direct way. Why do you need to?

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.

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:

;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:

LabelSelection:labeltext="Label text here"

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…)

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.