CVWidget is the abstract superclass of all CVWidgets (CVWidgetKnob, CVWidget2D and CVWidgetMS). However, it implements a couple of useful methods that are common to all its subclasses.
A Boolean, indicating whether MIDI- and OSC-responders shall be removed upon hitting Cmd/Ctrl-period. If it is set to false
unreferenced ghost-responders are left that may be hard to remove.
this
(CVWidget)
A Boolean, allowing (or disallowing) introspection of the internal working of a CVWidget. This is e.g. useful if the user wants to extend the widget's API. Whenever a the content of a model changes the corresponding controller gets triggered and executes its actions. So, if a message like
widget 'freq' (CVWidget2D) at slot 'lo' midiDisplay.model: `(( 'learn': L, 'src': source, 'chan': chan, 'ctrl': ctrl ))
gets posted, it means the midiDisplay.controller has just executed its actions using the model's values.
Also see Models and Controllers, internal bookkeeping and Extending the API.
this
(CVWidget)
An Event, containing all currently registered MIDIEndPoints and their correspondant numeric IDs. The IDs can be used to identify a device when creating a MIDI-responder though this is usually not necessary as the inbuilt learn functionality will take care of this automatically.
an Event
An IdentityDictionary containing all currently defined shortcuts for any CVWidget. Though this is a getter/setter it is recomended to add/remove shortcuts via the GUI within the preferences-interface (changes will become active after recompilation of the class-library) or the shortcuts-interface (changes become active immediatly but get reset after recompilation of the class-library).
See KeyDownActions for more information about the internal structure of the shortcuts
dictionary resp. the workings of shortcuts in general. Also have a look at the list of default shortcuts that can be modified by the user at any time.
The current widget-setup, returned as an Event. If the widget is a CVWidget2D each key of the returned Event will be split in a \lo
and a \hi
value:
0
true
ctrlButtonBank
parameter, reflecting a MIDI-device's bank-layout is set. This can be set with -setCtrlButtonBank. default: nil
midiMode
is set to 1
this will be the mean output-value. Can be set with -setMidiMean. default: 64
midiMode
is set to 1
the step-size of each slider is determined by this parameter. Can be set with -setMidiResolution. default: 1
midiMode
is set to 0
this determines the tolerance at which a MIDI-slider will respond when moved. For a more detailed explanation see -setSoftWithin. default: 0.1
an Event
Different MIDI-devices may have different output modes: either values from 0-127 or an in-/decremental value (e.g. -1 or +1). These modes may be taken in account as follows:
0 | the device outputs a values 0-127 |
1 | the device outputs in-/decremental values |
mode |
an Integer |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current midiMode (0 or 1).
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
an Integer
Devices which output a in-/decremental may output a standard value + in-/decrement. midiMean
gets automatically subtracted from this value, so in-/decrement remains. Applies only if midiMode is set to 1
.
meanval |
an Integer. default: |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current midiMean value.
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
an Integer
If midiMode
has been set to 0
moving a widget-slider will set the CV to a new value. However, if a MIDI-slider is connected to that widget, moving the MIDI-slider will set the CV's value immediatly to the value that is stored in the MIDI-slider i.e. a "jump" will happen. softWithin
will ease this behavior by setting the CV's value only if the slider gets within softWithin/2
. A threshold =< 0
will deactivate snap-to. Applies only if midiMode is set to 0
.
threshold |
a Float - default: |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current softWithin threshold.
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
a Float
Some MIDI-devices provide several banks of sliders. I.e. a device may be equipped with 16 sliders and 4 banks that can be switched. So, slider 1 in bank 2 is slider nr. 17, slider 3 in bank 3 is slider nr. 35. By default these sliders would have to be addressed in a CCResponder as 16 (slider 17) and 34 (slider 35) which makes it hard to immediately get the right slider from what is displayed within the GUI. ctrlButtonBank
translates the hardware-layout in a way that makes it easy to see the slider's bank and number: slider 17 becomes 2:1 (bank 2, nr. 1).
numSliders |
an Integer, representing the number of sliders in one bank. |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current ctrlButtonBank value
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
an Integer, representing the number of sliders in one bank.
If midiMode
has been set to 1 (by calling -setMidiMode), this method allows to set the resolution (= stepsize) of the connected hardware MIDI-sliders.
resolution |
a Float, representing the stepsize: lower values -> higher resolution higher values -> lower resolution default: |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current value midiResolution value.
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
a Float
Unlike MIDI the range of incoming OSC-values isn't 0-127 - it is unknown at the time of initialization of the OSC-responder. All CVWidgets have an inbuilt calibration mechanism that determines the range automatically. At initialization the range is set to [0.0001, 0.0001]. If the mechanism detects a value that is lower or higher than the values set at initialization it will set the constraints accordingly. This method allows to stop or start the calibration-process.
bool |
a Boolean, indicating whether the calibration-process shall be started or stopped. |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current calibration-status
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
a Boolean
Every CVWidget wraps one or more CVs whose internal spec can be set with this method.
spec |
can either be:
|
slot |
only needed if the widget is a CVWidget2D - either |
the receiver
Get the current spec of the widget's CV.
slot |
only needed if the widget is a CVWidget2D - either |
Within an OSCresponder's function values coming in are being mapped to the ControlSpec's range, defined by its minval
and maxval
. Furthermore a spec may implement a non-linear warp
for the transition from minval
to maxval
. Especially when work with accelerometers and orientation-sensors setting oscMapping to some non-linear mode will allow a much more fine-grained control.
mapping |
a Symbol - can be:
|
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current oscMapping-mode
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
a Symbol, indicating the oscMapping-mode
Connect a widget to an OSC-device resp. a program that sends OSC-messages to SuperCollider
ip |
optional - if set the OSCresponder will only listen to messages coming from that IP-address. |
port |
optional - if set the OSCresponder will only listen to messages coming from that port. |
name |
a String or a Symbol\: The OSC-command-name to which the OSCresponder will listen. E.g. |
oscMsgIndex |
messages you receive from an OSC-device/-program usually consist of the commend-name and one or more slots, containing numerical values. An orientation-sensor might e.g. send a message like the following:
the first slot is the command-name and the subsequent slots are |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Disconnects the OSC-device/-application reps. removes the OSCresponder
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Connect a widget to a MIDI-device utilizing a CCResponder.
uid |
optional - the ID under which the device gets registered in SuperCollider |
chan |
optional - the MIDI-channel to which the program will listen |
num |
optional - the controller-number to which the program will listen |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Terminate a MIDi-connection reps. remove the CCResponder.
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Any widget has a mechanism built in that is supposed to detect the constraints of the values coming in via OSC. However, you my set these constraints manually as well with this method.
constraintsHiLo |
a Point - e.g. |
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
the receiver
Get the current oscInputConstraints. This will return nil
as the widget is not connected and the calibration-mechanism hasn't set any values.
slot |
only needed if the widget is a CVWidget2D or a CVWidgetMS - either |
nil
or an Event containing the constraints in the keys \lo
and \hi
(not related to the \lo and \hi keys in a CVWidget2D)
Add an action to the widget's CV.
See also the related class method CVCenter: *addActionAt
name |
a Symbol or a String, representing the name under which the action will be stored |
action |
a |
slot |
only needed if the widget is a CVWidget2D - either |
active |
a Boolean, indicating whether the action shall become active immediatly |
the receiver
Remove an action given by its name
name | |
slot |
only needed if the widget is a CVWidget2D - either |
the receiver
Activate or deactivate a stored action
name | |
activate |
a Boolean, indicating whether the action shall be activated or deactivated |
slot |
only needed if the widget is a CVWidget2D - either |
the receiver
CVWidgets are designed in an MVC-architecture (MVC = "model - view - controller"). Any time a new CVWidget gets instantiated the models get initialized. Any time the model is changed the function in the regarding controller gets invoked.
myWidget.wdgtControllersAndModels.someModel = someValue
Models are designed for internal bookkeeping and all methods within CVWidget are supposed to do the right thing with them.
All models and controllers are stored within the wdgtControllersAndModels instance-var. If the widget is a CVWidget2D wdgtControllersAndModels will be split up in a \lo
and a \hi
slot, each containing the following models ( CVWidgetKnob simply keeps them under wdgtControllersAndModels):
Ref(true)
(default at initialization) or Ref(false)
.setSpec
- a Ref to a ControlSpec.setInputRange
- default at initialization: Ref([0.0001, 0.0001])
.Ref([<IP-address>, <port>, <command-name>, <message-index>])
. If no connection is present it will be Ref(false)
.false
Ref((src\: <val>, chan\: <val>, num\: <val>))
. If no connection is present this will be: Ref(nil)
.midiMode
- see also -setMidiModemidiMean
- see also -setMidiMeanctrlButtonBank
- see also -setCtrlButtonBankmidiResolution
- see also -setMidiResolutionsoftWithin
- see also -setSoftWithin[-inf, inf].asSpec
and oscInputRange.model.value[0]
as value[-inf, inf].asSpec
and oscInputRange.model.value[1]
as valueRef((numActions\: <val>, activeActions\: <val>))
. This model reflects the number of actions resp. active actions as displayed in the 'actions'-button of the widget.an Event
Get the current MIDI-/OSC-environment of the widget. If the widget is a CVWidget2D calling this method will return an Event containing the environments in 2 slots: \lo
and \hi
, else the environment will be returned:
\linlin
, \linexp
, \explin
or \expexp
(see also: -setOscMapping). By default the entry will be \linlin
.an Event
The widget's CV. If the widget is a CVWidget2D an Event, containing to slots \lo
and \hi
is returned.
either a CV ( CVWidgetKnob) or an Event ( CVWidget2D)
All actions (active and inactive) specified for the given widget.
myWidget.wdgtActions_(some action)
. Rather use -addAction, -removeAction resp. -activateActionan Event, containing active and inactive actions of a widget.
If \explin
or \expexp
has been chosen for input to output mapping with -setOscMapping both constraints of the input-range have to be same-signed - otherwise the operation would produce NaN
s. alwaysPositive
will be calculated automatically, so the user shouldn't have to worry about it.
the receiver
Within a CVWidget the functionality of most of its methods is implemented within a MVC-paradigm (model-view-controller) which means that rather than executing an action within a method directly the method updates a model (an object keeping some data) and triggers the controller via a 'changed'-message (non-working example-code):
myModel.value_(someValue).changed(\key)
When the 'changed'-message is sent the controller will execute its action. By default there is only one key specified: \default
(see -synchKeys). However, it is possible to extend the functionality of a controller with one or more custom key/function
pairs which means one can sync custom-guis and its elements to a given CVWidget (e.g. a button in some GUI cannot only connect MIDI or OSC but can also immediatly reflect the current connection-status). Have a look at the examples-section for a simple example. Extending the API in the suggested way should keep the CVWidget-functionality unobstrusive!
A slightly more practical (but also more complex) example: Edit an OSC-connection.
adds a custom function to one or all of the widget's internal SimpleControllers. These can also keep references to user-defined GUIs resp. their elements, thus allowing the user to synch his/her GUIs with CVWidgets.
key |
a Symbol or a String - mandatory, used internally by the widget's SimpleControllers |
func |
a Function - mandatory. A custom function, extending the widget's resp. your custom GUI's functionality. The user may pass the content of the model, the key and more to the function if they are stated as arguments at the beginning of the function. See the SimpleController-helpfile for more info. |
... controllers |
Controllers, given as Symbols or Strings. A CVWidget contains several models and controllers, contained in -wdgtControllersAndModels. If no specific controllers are given the function will be added to all controllers within -wdgtControllersAndModels. If one or more specific controllers are provided the function will only be added to these controllers which might make calculations a bit cheaper. However, if the user provides a specific controller (s)he should know under which circumstances the given controller is being triggered in order to get the desired result. |
the receiver
removes user-defined functions that have been added to the widget's inbuilt SimpleControllers.
key |
a Symbol or a String - indicating which function shall be removed. Will not touch the default functionality of a CVWidget. If no key is given all functions added by the user will be removed. |
the receiver
an Array of Symbols, keeping the keys over which a SimpleController within a CVWidget will iterate. By default it is [ \default ]
. The user should not alter this directly as adding and removing keys is handled within -extend resp. -reduce.
optional - CVWidget implements a few GUI-elements that are common to CVWidgetKnob as well as CVWidget2D. Descriptions of the rest of the elements can be found in the documentation for the regarding classes.
CVWidgets cannot gain focus themselves. However, their elements (buttons, slider, textfields etc.) can. focusElements
returns a collection of elements which, when focused (indicated by the green border), function as the widget's shortcut transmitters.
an Array of GUI elements
Sends the widget's window to front.
the receiver
Every widget has one or more editors that will open in a new window ( CVWidgetKnob 1 editor, CVWidget2D 2 editors - \lo
and \hi
). This method returns a reference to them.
a CVWidgetEditor or an Event, containing a reference to 2 or more CVWidgetEditors
Get the name of a widget. This corresponds with the key under which the widget's CV(s) is/are stored in CVCenter: *all.
a Symbol
A button, containing the name of the widget. When clicked the widget will switch to a TextView that can be used to write down notices.
a Button
Toggles between nameField
and the regular widget-appearance.
visible |
a Boolean |
the receiver
Determine whether sliders and number/textfields CV shall update according to the value of the internal CV. This may be useful especially if many CVs (e.g. within CVCenter) are updated simultaniously at a high rate as that will cause a high CPU load and the GUI may quickly freeze.
connectSlider |
a Boolean (optional), determining whether the CVWidget's sliders/knob shall update to the value of the internal CV |
connectTextField |
a Boolean (optional), determining whether the CVWidget's number-/textfield shall update to the value of the internal CV |
the receiver
Sets/gets the XY-position of a widget within its parent window.
point |
a Point |
a Point
Removes all GUI-elements (buttons, text-fields, sliders etc.) from a widget.
the receiver
If the widget is part of the CVCenter-GUI all its elements will be removed, otherwise close the widget.
the receiver
true
if the widget has been closed, otherwise false
By default windows created in SC lack the ability to be opened again once they're closed (even evaluating the variable under which the window has been created will still return the window). The following section describes a workaround in CVWidget (resp. CVWidgetKnob and CVWidget2D) that enables the user to keep a widget's responders and open and close it as many times as the user needs to ( open is implemented in CVWidgetKnob and CVWidget2D).
When CVWidgets get created within CVCenter GUI a number of shortcuts apply after a widget has gained focus (i.e. rather than the widget itself one of its GUI-elements gained focus which will be indicated by a green border around the regarding element).