GetPreference + SetPreference [SOLVED]

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

(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.

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:

error: bad argument type - "1"
Function: #<Subr--: #0x55faec0c1bd8>
Function: #<FSubr-SETF: #0x55faec0b92a8>

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…
    First argument
    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:

(setf newstate (if (string= originalstate "0") "1" "0"))

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

Thank you!!

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.