Help for simply copy paste a selection.

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

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

Help for simply copy paste a selection.

Permanent link to this post Posted by haute » Sun Mar 04, 2018 2:37 pm

Hello, I want to make a plugin to copy a selection of a track and paste it in the next track in the same position. But I want to do it just by pressing a key (associated with a plugin).
But I can not find the right command to use the copy / paste functions.
I know it has to be simple, few lines of language xlisp.
I studied some lisp when I used autocad for years, but with Nyquist, something as simple as copy / paste I do not know how to face it.

I'm sorry for my English.
A greeting.
haute
 
Posts: 7
Joined: Sun Mar 04, 2018 2:11 pm
Operating System: Windows 7

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by steve » Sun Mar 04, 2018 4:03 pm

It is possible to make a Nyquist plug-in to copy and paste from one track to the next, but it is quite tricky because Nyquist plug-ins process tracks sequentially and Lisp variables are reset when processing a track is complete. This means that the copied region must be stored somewhere that can survive beyond the processing of that track.

One option is to use the special Nyquist variable *SCRATCH*. This variable is unique in that it survives in memory after the Nyquist instance finishes.

In the simplest form, you cans test the value of *SCRATCH* to the selected audio when the plug-in processes the first track, and then return the value of *SCRATCH* when the plug-in processes the second track. This is not the recommended way for public release plug-ins as it could lead to plug-ins overwriting data required by other plug-ins, or reading data put there by unrelated plug-ins. The recommended way is to use "property lists", and save data as a uniquely named property. (more information HERE). Nevertheless, setting the value of *SCRATCH* is quick and easy for an experimental plug-in.

Another problem is that internally, Nyquist uses pointers. In this case, we want *SCRATCH* to point to the audio data of the first track, but normally the audio data in *track* is cleared when Nyquist has finished processing the track, so this will not work:
Code: Select all
(if (not (boundp '*scratch*))
    (setf *scratch* *track*)
    *scratch*)  ; returns nil audio because *track* was cleared.


So we need to ensure that the audio data from *track* is retained in memory.
An easy way to do this is with SND-LENGTH

So this will work once:
Code: Select all
(if (not (boundp '*scratch*))
  (progn
    (setf *scratch* *track*)
    (snd-length *scratch* ny:all)
    "") ;Null string return value
    *scratch*)  ; returns the audio from *scratch*

but will fail on subsequent runs because we have left *scratch" with Null audio after the second track. We need to reset the plug-in after the second track.
To clear *scratch* we can set it to '*unbound*

Code: Select all
(setf *scratch* '*unbound*)

(do this before proceeding)

So putting this altogether:
Code: Select all
(if (not (boundp '*scratch*))
  (progn
    (setf *scratch* *track*)
    (snd-length *scratch* ny:all)
    "") ;Null string return value
  (progn
    (setf rval *scratch*)
    (setf *scratch* '*unbound*)
    rval))

Note that this does not have any error checking, and it is not the recommended way to use *scratch*, but hopefully it will get you started.
Also note that as the selected audio is retained in RAM, this is not suitable for very long selections.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46978
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by haute » Sun Mar 04, 2018 6:00 pm

Hi, thanks steve. I did not think that such a simple action would have so many problems.
I tested it on the Nyquest promt and it worked, but only once, it never worked again.
I have tried before to clean the variable scratch * with (setf * scratch * '* unbound *) but it still does not work.
It seems like the scratch variable is not cleaned
haute
 
Posts: 7
Joined: Sun Mar 04, 2018 2:11 pm
Operating System: Windows 7

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by steve » Sun Mar 04, 2018 6:08 pm

haute wrote:I have tried before to clean the variable scratch * with (setf * scratch * '* unbound *) but it still does not work.

With any kind of programming, you have to be very precise.
It is not:
Code: Select all
* scratch *

it is:
Code: Select all
*scratch*

Same goes for
Code: Select all
'*unbound*
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46978
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by steve » Sun Mar 04, 2018 6:37 pm

To check if *scratch* is bound to a value or not, enter this in the Nyquist Prompt and click the Debug button:
Code: Select all
(print *scratch*)


If *scratch* is bound to a sound, even a Null sound, the debug window will show something like:
Code: Select all
#<Sound: #373b2e0>


If *scratch* is not bound to any value, the debug window will show:
Code: Select all
error: unbound variable - *SCRATCH*
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46978
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by haute » Sun Mar 04, 2018 8:09 pm

the debug show :
error: unbound variable - *SCRATCH*
if continued: try evaluating symbol again
1> error: unbound variable - *SCRATCH*
if continued: try evaluating symbol again
1>
haute
 
Posts: 7
Joined: Sun Mar 04, 2018 2:11 pm
Operating System: Windows 7

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by haute » Sun Mar 04, 2018 8:16 pm

The debug info if use the code:

Code: Select all
error: unbound variable - *TRACK*
if continued: try evaluating symbol again
Function: #<FSubr-SETF: #a955fa8>
Arguments:
  *SCRATCH*
  *TRACK*
Function: #<FSubr-PROGN: #a95b378>
Arguments:
  (SETF *SCRATCH* *TRACK*)
  (SND-LENGTH *SCRATCH* NY:ALL)
  ""
Function: #<FSubr-IF: #a95aa68>
Arguments:
  (NOT (BOUNDP (QUOTE *SCRATCH*)))
  (PROGN (SETF *SCRATCH* *TRACK*) (SND-LENGTH *SCRATCH* NY:ALL) "")
  (PROGN (SETF RVAL *SCRATCH*) (SETF *SCRATCH* (QUOTE *UNBOUND*)) RVAL)
1> error: unbound variable - *TRACK*
if continued: try evaluating symbol again
Function: #<FSubr-SETF: #3ccdcb0>
Arguments:
  *SCRATCH*
  *TRACK*
Function: #<FSubr-PROGN: #3cd3080>
Arguments:
  (SETF *SCRATCH* *TRACK*)
  (SND-LENGTH *SCRATCH* NY:ALL)
  ""
Function: #<FSubr-IF: #3cd2770>
Arguments:
  (NOT (BOUNDP (QUOTE *SCRATCH*)))
  (PROGN (SETF *SCRATCH* *TRACK*) (SND-LENGTH *SCRATCH* NY:ALL) "")
  (PROGN (SETF RVAL *SCRATCH*) (SETF *SCRATCH* (QUOTE *UNBOUND*)) RVAL)
1>
haute
 
Posts: 7
Joined: Sun Mar 04, 2018 2:11 pm
Operating System: Windows 7

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by steve » Sun Mar 04, 2018 8:24 pm

Are you using the current version of Audacity? The current version is 2.2.2
If you're using an older version, get the current version from here: https://www.audacityteam.org/download/

Also, ensure that the "Use legacy (version 3) syntax" option is not selected in the Nyquist Prompt (that's only for compatibility with old code).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46978
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by haute » Sun Mar 04, 2018 8:48 pm

i am using version 2.2.2
in Nyquist promt i disable "Use legacy (version 3) syntax" and now work. ;)

In Nyquest pluguin format dont work, i need to define "use legacy " or similar in the header?

Code: Select all
 ;nyquist plug-in
 ;name "Copy-Paste"
 ;type process
 ;version 1
(if (not (boundp '*scratch*))
  (progn
    (setf *scratch* *track*)
    (snd-length *scratch* ny:all)
    "") ;Null string return value
  (progn
    (setf rval *scratch*)
    (setf *scratch* '*unbound*)
    rval))
haute
 
Posts: 7
Joined: Sun Mar 04, 2018 2:11 pm
Operating System: Windows 7

Re: Help for simply copy paste a selection.

Permanent link to this post Posted by steve » Sun Mar 04, 2018 9:02 pm

haute wrote:
Code: Select all
;version 1

Change that to:
Code: Select all
;version 4
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46978
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Next

Return to Nyquist



Who is online

Users browsing this forum: No registered users and 5 guests