SuperCollider CLASSES

ListView

A view displaying a list of text items.
Inherits from: ItemViewBase : View : QObject : Object
Subclasses: QListView

Description

A view that displays a list of text items and allows one or more of them to be selected, depending on -selectionMode.

In default selection mode (single item selection), clicking on an item will select it, and pressing the up or down arrow keys will move selection to previous or next item, respectively. Other selection modes allow more complex interaction.

There is a difference between the concepts of current item, end selected items. In default selection mode they will always be the same, but not so in other modes.

Class Methods

Inherited class methods

Undocumented class methods

*new (parent, bounds)

*qtClass

Instance Methods

Data

-items

-items = stringArray

From superclass: ItemViewBase

The list of items displayed by the view.

Arguments:

stringArray

An Array of Strings, each String defining the text to represent an item.

-clear

From superclass: ItemViewBase

Removes all items.

-value

-value = val

The index of the current item, or nil when there is no current item. Note that this may be different than -selection when -selectionMode allows multiple items to be selected.

Arguments:

val

An Integer or nil.

-valueAction = val

From superclass: ItemViewBase

Sets -value and triggers the -action.

-selection

-selection = indexes

An array of all selected indexes. When setting selection, either an array or a single integer may be used.

Note that this may be different than -value when -selectionMode allows multiple items to be selected. When setting selection in single-item selection mode, only the last index will remain selected.

Appearance

-colors

-colors = colorArray

The background colors of the items.

Arguments:

colorArray

An Array of Colors, one Color for each item.

-stringColor

-stringColor = color

The color used to display all the text of all unselected items.

Arguments:

color

A Color.

-selectedStringColor

-selectedStringColor = color

The color used to display the selected item's text.

Arguments:

color

A Color.

-hiliteColor

-hiliteColor = color

The color used to indicate the selected item (aside from the color of its text).

Arguments:

color

A Color.

Interaction

-selectionMode

-selectionMode = mode

The allowed mode of item selection, according to the following table:
ValueMeaning
\noneNo item can be selected.
\singleOnly a single item can be selected at once.
\multiMultiple items can be selected. An item's selection is toggled when clicked.
\extendedMultiple items can be selected, individually by holding the Ctrl key, and in a batch by holding the Shift key.
\contiguousMultiple neighbouring items can be selected by holding the Shift key.

Arguments:

mode

One of the Symbols listed in the table above.

Actions

-action

-action = func

From superclass: View

The action object evaluated whenever the user changes the current item, i.e. when -value changes as a result of GUI interaction.

-selectionAction

-selectionAction = func

The action object evaluated whenever -selection changes.

-enterKeyAction

-enterKeyAction = func

The action object evaluated whenever the user presses the Enter (Return) key.

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

From superclass: View

Implements the default effects of key presses as follows:
KeyEffect
spaceselect next item and trigger action
rtrigger enterKeyAction
ntrigger enterKeyAction
a numbertrigger enterKeyAction
up arrowselect previous item and trigger action
down arrowselect next item and trigger action
left arrowselect previous item and trigger action
right arrowselect next item and trigger action

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

-enterKey

-mouseDownEvent (x, y, modifiers, buttonNumber, clickCount)

-mouseMoveEvent (x, y, modifiers, buttons)

Examples

Basic Example

(
w = Window.new.front;

v = ListView(w,Rect(10,10,120,70))
    .items_([ "SinOsc", "Saw", "LFSaw", "WhiteNoise", "PinkNoise", "BrownNoise", "Osc" ])
    .background_(Color.clear)
    .hiliteColor_(Color.green(alpha:0.6))
    .action_({ arg sbs;
        [sbs.value, v.items[sbs.value]].postln; // .value returns the integer
    });
)

Sound Example

Use ListView to switch filters:

(
s.waitForBoot({
    var f, freq, ww;
    n={r=LFSaw.ar([220, 530],0,0.3)*LFPulse.ar(12,0,0.3,0.4); [r[0],Delay2.ar(r[1])]}.play;
    freq={SinOsc.kr(0.5,0,4000,4200)}.play;
    w=Window("Filters").front;
    v = ListView(w,Rect(10,10,180,120))
        .items_([ "No Filter","RLPF", "RHPF", "BPF", "Resonz", "MoogFF" ])
        .background_(Color.clear)
        .hiliteColor_(Color.green(alpha:0.6))
        .action_({arg v;
            v.value.switch(
            0,{try{f.free};"test".postln},
            1,{try{f.free};f={ReplaceOut.ar(0,RLPF.ar(In.ar(0,2),In.kr(0,1),0.2,0.3))}.play(addAction:\addToTail)},
            2,{try{f.free};f={ReplaceOut.ar(0,RHPF.ar(In.ar(0,2),In.kr(0,1),0.2,0.3))}.play(addAction:\addToTail)},
            3,{try{f.free};f={ReplaceOut.ar(0,BPF.ar(In.ar(0,2),In.kr(0,1),0.2,1.5))}.play(addAction:\addToTail)},
            4,{try{f.free};f={ReplaceOut.ar(0,Resonz.ar(In.ar(0,2),In.kr(0,1),0.2,2))}.play(addAction:\addToTail)},
            5,{try{f.free};f={ReplaceOut.ar(0,MoogFF.ar(In.ar(0,2),In.kr(0,1),1.5))}.play(addAction:\addToTail)}
            );
        });

    ww=FreqScope.new(400, 200, 0);
    w.bounds=Rect(50,Window.screenBounds.height-300,200,200);
    ww.window.bounds=ww.window.bounds.moveTo(255,Window.screenBounds.height-328);
    CmdPeriod.doOnce({{ww.window.close}.defer(0.5);w.close;});
            //defer or crash, because FreqScopeWindow Class contains its own routine for cleaning up on CmdPeriod
    w.onClose_({n.free;f.free;freq.free});
});
)