SuperCollider CLASSES

Knob

A rotary controller view
Subclasses: QKnob

Description

Knob displays a value from 0.0 to 1.0 in rotary fashion, and allows to control it with either circular or linear mouse motion.

It also displays the deviation of the value from either 0.0 or 0.5, which you can choose using -centered.

To switch between the mouse interaction modes, use -mode.

The amount by which the value changes at interaction can be fine-tuned using -step, -keystep, -shift_scale, -ctrl_scale, and -alt_scale

Class Methods

*defaultMode

*defaultMode = value

The default -mode for newly created Knobs.

Inherited class methods

Undocumented class methods

*new (parent, bounds)

*qtClass

Instance Methods

Data

-value

-value = val

The displayed value.

Arguments:

val

A Number in the range of 0.0 to 1.0.

-valueAction = val

Sets the value and triggers -action.

-increment (zoom: 1)

Increments the value by -keystep multiplied by the argument.

Arguments:

zoom

A Number.

-decrement (zoom: 1)

Decrements the value by -keystep multiplied by the argument.

Arguments:

zoom

A Number.

Interaction

-mode

-mode = inputMode

The way value is controlled with respect to mouse movement after clicking on the view:

Defaults to \round.

Arguments:

inputMode

One of the symbols listed above.

-keystep

-keystep = value

The amount by which the value is incremented/decremented when pressing a relevant key.

Defaults to 0.01;

Arguments:

(arg1)

A Number.

-step

-step = aFloat

From superclass: AbstractStepValue

The amount by which the value is incremented/decremented using the mouse in 'horizontal' and 'vertical' modes.

Arguments:

aFloat

A Number.

-shift_scale

-shift_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -keystep is multiplied when used at mouse or keyboard interaction while the Shift key is pressed.

Arguments:

aFloat

A Float.

-ctrl_scale

-ctrl_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -keystep is multiplied when used at mouse or keyboard interaction while the Ctrl key is pressed.

Arguments:

aFloat

A Float.

-alt_scale

-alt_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -keystep is multiplied when used at mouse or keyboard interaction while the Alt key is pressed.

Arguments:

aFloat

A Float.

Appearance

-centered

-centered = bool

Whether the deviation of value will be displayed in relation to 0.0 or 0.5 (e.g. as in a panning controller);

Arguments:

bool

A Boolean.

-color

-color = colors

The colors used by the Knob to draw the following elements:

Arguments:

colors

An Array of four Colors in the order listed above.

Actions

-action

-action = func

From superclass: View

The action object evaluated whenever the user interacts with the Knob using the mouse or the keyboard.

-defaultKeyDownAction (char, modifiers, unicode, keycode, key)

Implements the default effects of key presses as follows:
KeyEffect
rvalueAction_(1.0.rand)
nvalueAction_(0)
xvalueAction_(1)
cvalueAction_(0.5)
]increment
[decrement
up arrowincrement
down arrowdecrement
right arrowincrement
left arrowdecrement

See also: -keystep, -shift_scale, -ctrl_scale, -alt_scale.

Drag and drop

-defaultGetDrag

Returns:

The -value.

-defaultCanReceiveDrag

Returns:

True if the current drag data is a Number.

-defaultReceiveDrag

Sets -valueAction to the current drag data.

Inherited instance methods

Undocumented instance methods

-background

-background = color

-getScale (modifiers)

Examples

Basic Example

(
var window, size = 32; // try different sizes - from 15 to 200 or more!
window = Window.new("Knob", Rect(640,630,270,70)).front;
k = Knob.new(window, Rect(20, 10, size, size));
k.action_({|v,x,y,m| postf("action func called: %\n", v.value); });
//k.color[1] = Color.gray(alpha:0);
)

k.value
k.value = 0.25
k.valueAction = 0.125

// modes
k.mode = \vert;
k.mode = \horiz;
k.mode = \round; // default

k.visible
k.visible = false
k.visible = true
k.enabled = false
k.enabled_(true)
k.canFocus = false
k.canFocus = true

Centered Mode

Center mode is useful for pan or eq gain control etc.

(
var window;
window = Window.new("Pan Knob", Rect(640,630,270,70)).front;
k = Knob.new(window, Rect(20,10,36,36));
k.action_({|v,x,y,m| \pan.asSpec.map(v.value).postln; })
//  .mode_(\horiz)
    .centered_(false)
    .value_(\pan.asSpec.unmap(0)); // 0.5
//k.color[1] = Color.gray(alpha:0);
)
k.centered
k.centered = true
k.centered = false

step

-step only affects the 'horiz' and 'vert' modes:

(
var window, midispec;
midispec = [0,127,'linear',1].asSpec;
window = Window.new("step Knob", Rect(640,630,270,70)).front;
k = Knob.new(window, Rect(20,10,32,32));
k.action_({|v,x,y,m| midispec.map(v.value).postln; })
       .value_(midispec.unmap(0));

k.mode = \vert;

)
k.step
k.step = 10/127 // step by 10

k.mode = \horiz;
k.mode = \round;

mouseOverAction

(
var size = 28;
w = Window.new("Knobs", Rect(250,500,270,70));
w.acceptsMouseOver=true; // must be true in parent window!
w.view.decorator = FlowLayout(w.view.bounds);
h = StaticText(w, 150 @ 10);
w.view.decorator.nextLine;
k = Array(8);
8.do({|item, i|
    var knob;
    knob = Knob.new(w, size @ size)
        .action_({|v,x,y,m| h.string = "val: " ++ v.value.asString; })
        .mouseOverAction_({|v,x,y| h.string = "val: " ++ v.value.asString; });

    k = k.add(knob);
});
w.front
)
k[4].value

Drag and Drop

(
var w, txt, size = 36;
w = Window.new("Knobs", Rect(400,400,250,100)).front;
w.acceptsMouseOver=true;
w.view.decorator = FlowLayout(w.view.bounds).gap_(10 @ 10).margin_(10 @10);
txt = StaticText(w, 200 @ 14);
w.view.decorator.nextLine;

k = Knob(w, size @ size);
k.action = {arg v,x,y;  v.value.postln; txt.string_("value: " ++ v.value); };
k.mouseOverAction = {|v| txt.string_("value: " ++ v.value); };

j = Knob(w, size @ size);
j.action = {arg v,x,y;  j.value.postln; txt.string_("value: " ++ v.value); };
j.mouseOverAction = { txt.string_("value: " ++ j.value); };

n = NumberBox(w, 100 @ 20);
//n.setProperty(\boxColor,Color.grey(alpha:0.0));
n.value = 0.0;
)

// customize drag and drop methods
k.canReceiveDragHandler
k.canReceiveDragHandler = false; // don't accept drops

k.canReceiveDragHandler = { View.currentDrag.isFloat }; // accept only if drag is float

k.receiveDragHandler = { ("value dropped in: " ++ View.currentDrag).postln }

k.receiveDragHandler = { k.valueAction = View.currentDrag.clip(0.0, 1.0); }

k.beginDragAction = { ("drag out -> " ++ k.value).postln; }

k.beginDragAction = { k.value.asFloat; }