Difference between revisions of "Nyquist Plug-ins Widgets"

From Audacity Wiki
Jump to: navigation, search
m (String Widget (text input))
(Uppercase variable names)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{intro|1=A [https://en.wikipedia.org/wiki/Widget_(GUI) Widget] is an element of a graphical user interface ([https://en.wikipedia.org/wiki/Graphical_user_interface GUI]), such as a button or slider, which facilitates user interaction. Audacity supplies a number of widget types for Nyquist plug-ins, which are ultimately derived from the [https://www.wxwidgets.org/ WxWidgets] toolkit. Fortunately, Nyquist plug-in developers are largely spared from the complexities of WxWidgets, and can simply select which widgets they need by adding the appropriate [[Nyquist_Plug-ins_Reference#header|"header"]] to the top of the plug-in script.|2=
 
{{intro|1=A [https://en.wikipedia.org/wiki/Widget_(GUI) Widget] is an element of a graphical user interface ([https://en.wikipedia.org/wiki/Graphical_user_interface GUI]), such as a button or slider, which facilitates user interaction. Audacity supplies a number of widget types for Nyquist plug-ins, which are ultimately derived from the [https://www.wxwidgets.org/ WxWidgets] toolkit. Fortunately, Nyquist plug-in developers are largely spared from the complexities of WxWidgets, and can simply select which widgets they need by adding the appropriate [[Nyquist_Plug-ins_Reference#header|"header"]] to the top of the plug-in script.|2=
 
The layout of a Nyquist plug-in GUI is a simple list of widgets, one above the other.}}
 
The layout of a Nyquist plug-in GUI is a simple list of widgets, one above the other.}}
 +
 +
{{Hint|Nyquist code is case insensitive. By convention, Nyquist code is written in lowercase with the exception of variables used in plug-in widgets.
 +
<p>
 +
''Widget variables are defined when the plug-in is initialized and have global scope. These special symbol names are written in uppercase so that they may be easily identified when reading the code. Changing the value of a global variable is a common source of bugs, so it is highly recommended to treat them as constants (avoid changing their values after creation).''</p>}}
 +
  
 
== Slider Widget ==
 
== Slider Widget ==
Line 8: Line 13:
 
Slider widgets are supported in all Audacity Nyquist plug-in versions.
 
Slider widgets are supported in all Audacity Nyquist plug-in versions.
  
   ;control <i>variable-name</i> "<i>text-left</i>" <i>variable-type</i> "<i>text-right</i>" <i>initial-value</i> <i>minimum</i> <i>maximum</i>
+
   ;control VARIABLE-NAME "<i>text-left</i>" <i>variable-type</i> "<i>text-right</i>" <i>initial-value</i> <i>minimum</i> <i>maximum</i>
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the slider.
 
* ''text-left'' : [string] Text that will appear to the left of the slider.
 
* ''variable-type'' : [keyword] A "number" type, either int, float or real*:
 
* ''variable-type'' : [keyword] A "number" type, either int, float or real*:
Line 28: Line 33:
  
 
<div id="numeric"></div>
 
<div id="numeric"></div>
 +
 
== Numeric Text Widget ==
 
== Numeric Text Widget ==
 
[[File:Numeric-text-widget.png]]
 
[[File:Numeric-text-widget.png]]
Line 33: Line 39:
 
The numeric text widget was introduced in Audacity 2.1.2.
 
The numeric text widget was introduced in Audacity 2.1.2.
  
   ;control <i>variable-name</i> "<i>text-left</i>" variable-type "<i>text-right</i>" initial-value minimum maximum
+
   ;control VARIABLE-NAME "<i>text-left</i>" variable-type "<i>text-right</i>" initial-value minimum maximum
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the text box.
 
* ''text-left'' : [string] Text that will appear to the left of the text box.
 
* ''variable-type'' : [keyword] A "number" type, either "int-text" or "float-text":
 
* ''variable-type'' : [keyword] A "number" type, either "int-text" or "float-text":
Line 49: Line 55:
 
'''Examples of undefined minimum / maximum:'''
 
'''Examples of undefined minimum / maximum:'''
  
   ;control <i>pos</i> "<i>Positive Integer</i>" int-text "<i>text-right</i>" initial-value 0 nil
+
   ;control <i>POS</i> "<i>Positive Integer</i>" int-text "<i>text-right</i>" initial-value 0 nil
   ;control <i>neg</i> "<i>Negative Integer</i>" int-text "<i>text-right</i>" initial-value nil 0
+
   ;control <i>NEG</i> "<i>Negative Integer</i>" int-text "<i>text-right</i>" initial-value nil 0
   ;control <i>num</i> "<i>Any number</i>" float-text "<i>text-right</i>" initial-value nil nil
+
   ;control <i>NUM</i> "<i>Any number</i>" float-text "<i>text-right</i>" initial-value nil nil
  
  
 
<div id="string widget"></div>
 
<div id="string widget"></div>
 +
 
== String Widget (text input) ==
 
== String Widget (text input) ==
  
Line 61: Line 68:
 
The text input widget ("string widget") is supported in plug-ins version 2 or above.  
 
The text input widget ("string widget") is supported in plug-ins version 2 or above.  
  
   ;control <i>variable-name</i> "<i>text-left</i>" string "<i>text-right</i>" "<i>default-string</i>"
+
   ;control VARIABLE-NAME "<i>text-left</i>" string "<i>text-right</i>" "<i>default-string</i>"
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the text input field.
 
* ''text-left'' : [string] Text that will appear to the left of the text input field.
 
* ''variable-type'' : [keyword] Declares a "string" input type widget.
 
* ''variable-type'' : [keyword] Declares a "string" input type widget.
Line 79: Line 86:
 
The multiple choice input widget is supported in plug-ins version 3 or above.  
 
The multiple choice input widget is supported in plug-ins version 3 or above.  
  
   ;control <i>variable-name</i> "<i>text-left</i>" choice "<i>string-1,string-2,...</i>" <i>initial-value</i>
+
   ;control VARIABLE-NAME "<i>text-left</i>" choice "<i>string-1,string-2,...</i>" <i>initial-value</i>
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the multiple-choice list.
 
* ''text-left'' : [string] Text that will appear to the left of the multiple-choice list.
 
* ''variable-type'' : [keyword] Declares a "Multiple-Choice" type widget.
 
* ''variable-type'' : [keyword] Declares a "Multiple-Choice" type widget.
Line 90: Line 97:
  
 
An example of the 'choice' widget can be found [https://github.com/audacity/audacity/blob/master/plug-ins/sample-data-export.ny sample-data-export.ny]
 
An example of the 'choice' widget can be found [https://github.com/audacity/audacity/blob/master/plug-ins/sample-data-export.ny sample-data-export.ny]
 
  
 
== Time Widget ==
 
== Time Widget ==
Line 97: Line 103:
 
[[Image:Time-widget.png]]
 
[[Image:Time-widget.png]]
  
   ;control variable-name ''"text-left"'' time ''"text-right"'' ''initial-value'' ''minimum'' ''maximum''
+
   ;control VARIABLE-NAME ''"text-left"'' time ''"text-right"'' ''initial-value'' ''minimum'' ''maximum''
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the time control.
 
* ''text-left'' : [string] Text that will appear to the left of the time control.
 
* time : [keyword] A "time" widget.
 
* time : [keyword] A "time" widget.
Line 112: Line 118:
  
 
Example taken from the Pluck effect:
 
Example taken from the Pluck effect:
   ;control dur "Duration (60s max)" time "" 1 0.0 60
+
   ;control DUR "Duration (60s max)" time "" 1 0.0 60
 
In this example:
 
In this example:
* ''variable name'' is "dur",
+
* ''variable name'' is "DUR",
 
* ''text-left'' is "Duration (60s max)",
 
* ''text-left'' is "Duration (60s max)",
 
* ''text-right'' is "" (empty string).
 
* ''text-right'' is "" (empty string).
Line 126: Line 132:
  
 
The File Button Widget requires Audacity 2.3.0 or later.
 
The File Button Widget requires Audacity 2.3.0 or later.
   ;control <i>variable-name</i> "<i>text-left</i>" file "<i>button-text</i>" "<i>default-file-path</i>" "<i>wildcard-filters</i>" "<i>flags</i>"
+
   ;control VARIABLE-NAME "<i>text-left</i>" file "<i>button-text</i>" "<i>default-file-path</i>" "<i>wildcard-filters</i>" "<i>flags</i>"
  
* ''variable-name'' : [symbol] A Lisp symbol.
+
* ''VARIABLE-NAME'' : [symbol] A Lisp symbol.
 
* ''text-left'' : [string] Text that will appear to the left of the file button widget.
 
* ''text-left'' : [string] Text that will appear to the left of the file button widget.
 
* ''variable-type'' : [keyword] Declares a "File-button" type widget.
 
* ''variable-type'' : [keyword] Declares a "File-button" type widget.

Latest revision as of 20:01, 9 April 2023

A Widget is an element of a graphical user interface (GUI), such as a button or slider, which facilitates user interaction. Audacity supplies a number of widget types for Nyquist plug-ins, which are ultimately derived from the WxWidgets toolkit. Fortunately, Nyquist plug-in developers are largely spared from the complexities of WxWidgets, and can simply select which widgets they need by adding the appropriate "header" to the top of the plug-in script.
The layout of a Nyquist plug-in GUI is a simple list of widgets, one above the other.


Nyquist code is case insensitive. By convention, Nyquist code is written in lowercase with the exception of variables used in plug-in widgets.

Widget variables are defined when the plug-in is initialized and have global scope. These special symbol names are written in uppercase so that they may be easily identified when reading the code. Changing the value of a global variable is a common source of bugs, so it is highly recommended to treat them as constants (avoid changing their values after creation).


Slider Widget

Slider-widget.png

Slider widgets are supported in all Audacity Nyquist plug-in versions.

 ;control VARIABLE-NAME "text-left" variable-type "text-right" initial-value minimum maximum
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the slider.
  • variable-type : [keyword] A "number" type, either int, float or real*:
    • int : integer [FIXNUM, an XLISP whole number]
    • float (or real*) : floating point [FLONUM, an XLISP number supporting decimal places]
  • text-right : [string] Text that will appear to the right of the slider.
  • initial-value : [int / float] Variable value [and slider position] at the first start of the plug-in.
  • minimum : [int / float] Numeric variable value when the slider is moved to the left border.
  • maximum : [int / float] Numeric variable value when the slider is moved to the right border.

The variable value [the slider position] can be referenced by the variable name in the plug-in code.

A text input box to the left of the slider allows the user to type in a value via the keyboard. As of Audacity 2.1.1, input values are validated to only allow input between minimum and maximum values.

  • The "real" keyword is deprecated. New plug-ins should use "float" as the variable type for floating point input.


Numeric Text Widget

Numeric-text-widget.png

The numeric text widget was introduced in Audacity 2.1.2.

 ;control VARIABLE-NAME "text-left" variable-type "text-right" initial-value minimum maximum
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the text box.
  • variable-type : [keyword] A "number" type, either "int-text" or "float-text":
    • int-text : Integer [FIXNUM, an XLISP whole number]
    • float-text : Floating point [FLONUM, an XLISP number supporting decimal places]
  • text-right : [string] Text that will appear to the right of the text box.
  • initial-value : [int / float] Variable value at the first start of the plug-in.
  • minimum : [int / float / NIL] Numeric minimum variable value that will pass validation.
  • maximum : [int / float / NIL] Numeric maximum variable value that will pass validation.

Minimum and maximum may be numeric values or "NIL". The minimum / maximum is not defined when set as "NIL" and is limited only by the numeric limit for the number type. The valid range for numbers depends on the computer platform. Typically the limits for integers are -2147483648 to 2147483647. The limits for floating point numbers are very large.

Examples of undefined minimum / maximum:

 ;control POS "Positive Integer" int-text "text-right" initial-value 0 nil
 ;control NEG "Negative Integer" int-text "text-right" initial-value nil 0
 ;control NUM "Any number" float-text "text-right" initial-value nil nil


String Widget (text input)

String-widget.png

The text input widget ("string widget") is supported in plug-ins version 2 or above.

 ;control VARIABLE-NAME "text-left" string "text-right" "default-string"
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the text input field.
  • variable-type : [keyword] Declares a "string" input type widget.
  • text-right : [string] Text that will appear to the right of the text input field.
  • default-string : [string] The string will appear inside the text field.

The text typed in by the user in the text field of the plug-in window can be referred as a string variable from within the plug-in code. All string characters are valid, though care must be taken with escape characters if the string is to be evaluated.

Examples how to use the text input widget can be found in the source code of the Apropos Plug-in.

Multiple-Choice Widget

Choice-widget.png

The multiple choice input widget is supported in plug-ins version 3 or above.

 ;control VARIABLE-NAME "text-left" choice "string-1,string-2,..." initial-value
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the multiple-choice list.
  • variable-type : [keyword] Declares a "Multiple-Choice" type widget.
  • string-1,... : [string] For every string an entry in a list to choose from will be produced.
  • initial-value : the number of the list entry that will be displayed as the default choice at the first start of the plug-in.

The list entries string-1, string-2, etc. are comma separated and internally represented by integer numbers. The first, top-most list entry string-1 will be represented by the number 0. The list entry chosen by the user can be determined by the integer value of the variable from within the plug-in code.

An example of the 'choice' widget can be found sample-data-export.ny

Time Widget

Introduced in Audacity 2.3.0.

Time-widget.png

 ;control VARIABLE-NAME "text-left" time "text-right" initial-value minimum maximum
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the time control.
  • time : [keyword] A "time" widget.
  • text-right : [string] Text that will appear to the right of the time control.
  • initial-value : [int / float] Default value. Number (float or integer) in seconds.
  • minimum : [number] Minimum numeric value (float or integer) in seconds.
  • maximum : [number] Maximum numeric value (float or integer) in seconds.

Minimum and maximum may be numeric values or "NIL". The minimum / maximum is not defined when set as "NIL" and is limited to a range of 0 and the maximum supported by the current widget view.

This widget is to input durations. The value set is converted to seconds and assigned as the value of the widget variable.

Example taken from the Pluck effect:

 ;control DUR "Duration (60s max)" time "" 1 0.0 60

In this example:

  • variable name is "DUR",
  • text-left is "Duration (60s max)",
  • text-right is "" (empty string).
  • initial-value is 1 second.
  • minimum is 0.0 seconds.
  • maximum is 60 seconds.

File-Button Widget

File-button.png

The File Button Widget requires Audacity 2.3.0 or later.

 ;control VARIABLE-NAME "text-left" file "button-text" "default-file-path" "wildcard-filters" "flags"
  • VARIABLE-NAME : [symbol] A Lisp symbol.
  • text-left : [string] Text that will appear to the left of the file button widget.
  • variable-type : [keyword] Declares a "File-button" type widget.
  • button text : [string] Text that appears on the button.
  • default-file-path : [string] The default file path.
  • wildcard-filters : [string] File types to show in file browser (based on file extensions).
  • flags : [string] Option flags, based on wxWidgets File Dialog Styles).
Warning icon For more information about the File-Button Widget, see the Nyquist File-Button Tutorial.


Text Widget

Text-widget.png

The text widget was introduced in Audacity 2.3.0. Although not actually a "control", it shares similar syntax to all other Nyquist plug-in widgets:

 ;control text "string"

This widget adds a line of text (the "string") to the plug-in GUI.

Warning icon While it may seem convenient to add text to an interface to explain how the plug-in should be used, this widget should be used sparingly. Text descriptions should not be used as a substitute for good design. Plug-in developers should also be aware that it is not currently possible to provide localization (translations) of text in any widgets in third party plug-ins.


|< Nyquist Plug-ins Reference