GetPreference + SetPreference [SOLVED]

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
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
jozefh
Posts: 48
Joined: Wed Nov 27, 2019 10:06 am
Operating System: Windows 10 / 11

GetPreference + SetPreference [SOLVED]

Post by jozefh » Wed Aug 03, 2022 8:03 am

Hello, I have a problem to finalize one plugin. Can you help me please? Here is the main code without the header:

Code: Select all

(setf originalstate (first (AUD-DO "GetPreference:Name=\"/GUI/EditClipCanMove\"")))
(setf newstate (- 1 originalstate))
(AUD-DO-COMMAND "SetPreference" :Name "/GUI/EditClipCanMove" :Reload "0" :Value newstate)
The purpose of the plugin is to toggle the option Editing a clip can move other clips. Then I can assign a keyboard shortcut for that.
Plugin should read the preferences value "/GUI/EditClipCanMove" and then set it the opposite state [0;1].

It does not work, instead it return a message with the value of variable originalstate.

Thank you for looking into this.

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

Re: GetPreference + SetPreference

Post by steve » Wed Aug 03, 2022 10:34 am

butterfly wrote:
Wed Aug 03, 2022 8:03 am

Code: Select all

(setf newstate (- 1 originalstate))
This line won't work because "originalstate" is a string "0" or "1", not numbers 0 or 1.
We can see this in the debug message:

Code: Select all

error: bad argument type - "1"
Function: #<Subr--: #0x55faec0c1bd8>
Arguments:
  1
  "1"
Function: #<FSubr-SETF: #0x55faec0b92a8>
Arguments:
  NEWSTATE
  (- 1 ORIGINALSTATE)
Reading Nyquist debug messages is not easy, especially as they don't give line numbers, but reading through this debug message line by line:
  • error: bad argument type - "1"
    Error: we are passing the string value "1" to a function, which is the wrong data type.
  • Function: #<Subr--: #0x55faec0c1bd8>
    The function's id is #0x55faec0c1bd8. This isn't very useful, other than it tells us that we are looking into a function ...
  • Arguments:
    and now the arguments that are being passed to that function...
  • 1
    The argument being passed to the function...
  • "1"
    Oh, look, it is a string value "1"
  • Function: #<FSubr-SETF: #0x55faec0b92a8>
    The containing function's id
  • Arguments:
    and now the argument list for the containing function...
  • NEWSTATE
    First argument
  • (- 1 ORIGINALSTATE)
    Second argument.
The debug error messages start with the fatal error, then work backwards, so we can deduce that:
1. We are passing a string, which is the wrong data type for the function that we are passing it to.
2. The function that we are passing it to (id = #0x55faec0b92a8) has arguments "NEWSTATE" and "(- 1 ORIGINALSTATE)".

So we are looking for the error in a line that looks like:
(some-function NEWSTATE (- 1 ORIGINALSTATE))

Looking at our code, this line looks very much like the above:
(setf newstate (- 1 originalstate))

------

Try something like this instead:

Code: Select all

(setf newstate (if (string= originalstate "0") "1" "0"))
Learn more about Nyquist programming at audionyq.com

jozefh
Posts: 48
Joined: Wed Nov 27, 2019 10:06 am
Operating System: Windows 10 / 11

Re: GetPreference + SetPreference

Post by jozefh » Wed Aug 03, 2022 11:48 am

You are simply amazing! Problem solved. Moreover, I have learnt something new.

Thank you!!

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

Re: GetPreference + SetPreference [SOLVED]

Post by steve » Wed Aug 03, 2022 12:27 pm

You're welcome. I'll close this topic as "solved", but please feel free to create a new topic if you would like to make your plug-in available to other Audacity users.
Learn more about Nyquist programming at audionyq.com

Locked