SuperCollider CLASSES

NumberBox

A view displaying a modifiable numerical value.
Subclasses: QNumberBox

Description

A view that displays a numerical value and allows to modify it by typing the value in, and incrementing or decrementing it using the keyboard, or mouse.

Using the keyboard, the value will change on each arrow key press by the amount defined by -step.

Mouse scrolling is performed by pressing a mouse button inside the view and dragging the mouse vertically. The value will change according to the mouse cursor movement, in steps defined by -scroll_step.

By default, holding down the Shift, Ctrl, or Alt key while incrementing or decrementing the value will multiply the steps by 100, 10, or 0.1 respectively, though you can customize this by setting -shift_scale, -ctrl_scale, or -alt_scale. Scrolling can be enabled or disabled by modifying the -scroll variable.

Class Methods

Inherited class methods

Undocumented class methods

*new (parent, bounds)

*qtClass

Instance Methods

Data

-value

-value = value

Numerical value between 0 and 1.

Arguments:

value

A Float.

-valueAction = val

Sets -value to the argument and triggers -action.

-increment (factor: 1)

From superclass: AbstractStepValue

Increments the value by -step multiplied by 'factor'.

Arguments:

factor

Any number.

-decrement (factor: 1)

From superclass: AbstractStepValue

Decrements the value by -step multiplied by 'factor'.

Arguments:

factor

Any number.

-string

-string = string

Text to be displayed instead of the numerical value. Setting -value after this will display the value again.

Arguments:

string

A String.

-object

-object = obj

If -setBoth is true, setting this variable also sets -string to the argument interpreted as String.

Arguments:

obj

Any object, typically one which makes sense to display as a string, such as a Float.

-setBoth

-setBoth = value

A variable stating whether setting -object will also set -string.

Arguments:

(arg1)

A Boolean.

Restrictions on data

-clipLo

-clipLo = aFloat

The lowest numerical value allowed. Trying to set a lower value will clip it to this.

Arguments:

aFloat

A Float.

-clipHi

-clipHi = aFloat

The highest numerical value allowed. Trying to set a higher value will clip it to this.

Arguments:

aFloat

A Float.

-minDecimals

-minDecimals = decimals

The minimum amount of decimal places displayed. If the value can be completely described with less decimal places, zeros will be appended until reaching this.

Arguments:

decimals

An Integer.

-maxDecimals

-maxDecimals = decimals

The maximum amount of decimal places displayed. The value will always be rounded to this amount of decimals.

Arguments:

decimals

An Integer.

-decimals

-decimals = decimals

Sets both -minDecimals and -maxDecimals to the argument.

Arguments:

decimals

An Integer.

Appearance

-align

-align = alignment

The alignment of the displayed value. See Alignment for possible values.

-stringColor

-stringColor = color

The color used to display the value before it is ever changed by user interaction.

Arguments:

color

A Color.

-normalColor

-normalColor = aColor

The color used to display the value after is has been typed in.

Arguments:

aColor

A Color.

-typingColor

-typingColor = aColor

The color used to display the value while it is being typed in.

Arguments:

aColor

A Color.

Interaction

-step

-step = aFloat

From superclass: AbstractStepValue

The amount by which the value will changed when -increment or -decrement is called, or when related keys are pressed.

Arguments:

aFloat

A Float.

-scroll_step

-scroll_step = aFloat

The amount by which the value will changed when scrolled using the mouse.

Arguments:

aFloat

A Float.

-shift_scale

-shift_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -scroll_step is multiplied when incrementing or decrementing the value using keyboard or mouse while the Shift key is pressed.

Arguments:

aFloat

A Float.

-ctrl_scale

-ctrl_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -scroll_step is multiplied when incrementing or decrementing the value using keyboard or mouse while the Ctrl key is pressed.

Arguments:

aFloat

A Float.

-alt_scale

-alt_scale = aFloat

From superclass: AbstractStepValue

The factor by which -step or -scroll_step is multiplied when incrementing or decrementing the value using keyboard or mouse while the Alt key is pressed.

Arguments:

aFloat

A Float.

Actions

-action

-action = func

From superclass: View

The action object evaluated whenever the user changes the value by interacting with the view.

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

From superclass: View

Any key representing a character that can make part of a floating point number representation will initiated the editing of the value. Pressing Return (or Enter) will finish the editing and store the value typed in as a Float.

Aside from that, this method implements the default effects of key presses as follows:
KeyEffect
up arrowincrement
down arrowdecrement
right arrowincrement
left arrowdecrement

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

-buttonsVisible

-buttonsVisible = aBool

-initNumberBox

-scroll

-scroll = aBool

Examples

Basic Example

(
    w = Window("NumberBox Example", Rect(100, 500, 400, 120));
    b =     NumberBox(w, Rect(150, 10, 100, 20));
    b.value = rrand(1,15);
    b.action = {arg numb; numb.value.postln; };
    w.front
)
// try these one at time
b.value = rrand(1,15) ;     // sets the value but does not perform the action
b.valueAction_(5);      // sets the value and performs the action
b.step_(0.1);           // change the increment/decrement size for the arrow keys
b.scroll_step=10;    // change the increment/decrement size for the mosueScrolling

b.background_(Color.grey);          // change the background color of the box
b.typingColor_(Color(0.3,1,0.3));   // change the typing color for the box
b.normalColor_(Color.white);        // change the normal color for the box. won't change until next value change

b.stringColor = Color.red;
b.align = \center;

b.increment; // increment or decrement by step
b.decrement;

Sound Example

Change frequency of a playing synth by step using arrow keys:

(
s.waitForBoot({

    n={arg freq=220;
        var out;
        out=SinOsc.ar(freq,0,0.2);
        8.do{out = AllpassN.ar(out, 0.2,0.02+0.20.rand,8)};
        out;
    }.play;

    w = Window("Use arrow keys to change the frequency by steps", Rect(100, 500, 500, 120));
    b = NumberBox(w, Rect(200, 10, 100, 20));
    b.value = 220;
    b.action = {arg numb; n.set(\freq,numb.value); };
    b.step=55; //make the step a fraction of the freq
    b.focus;
    w.front;

    CmdPeriod.doOnce({w.close});

});
)