SWDataSlot

Base class for a data slot.

- Example -


// create a network client:
y = SWDataNetworkClient.new( "192.168.0.104", "myname" );

// subscribe to node 102
y.subscribeNode( 102 );


// -------- working with a single slot of a data node:

// DataNodes can have multiple channels of data, so the above
// approach is mostly useful for multichannel control of data.
// You can also work with a single slot of a node, and control a synth:

// get a reference to a DataSlot in a variable:
a = y.nodes[102].slots[0];

// if the slot has a label, you acces it by its label:
a = y[\minibee102_slot0];

// access the value of the slot:
a.value;

(
SynthDef(\swexample,{ |out=0,amp=0.1,freq=400|
	Out.ar( out, SinOsc.ar( freq, 0, amp ) );
}).send(s)
)

// use it at synth instantiation:
b = Synth.new( \swexample, [\amp,a.value ] );

// set it again:
b.set( \amp, a.value );

// free the synth
b.free;

// instead of setting it manually each time, you can assign
// an action to the data node to do this automatically:

b = Synth.new( \swexample, [\amp,a.value ] );

a.action= { |data| b.set( \amp, data )};

// another method is to put the data automatically on a bus,
// and grab the data from there:

// reset the action:
a.action = {};

// create a bus:
a.createBus(s);

// map the amplitude of b to the bus:
b.map( \amp, a.bus );

b.free;

// alternatively, you can use In.kr in your synthdef:
(
SynthDef(\swexampleBus,{ |out=0,ampbus=0,freq=400|
	Out.ar( out, SinOsc.ar( freq, 0, In.kr( ampbus, 1 ) ) );
}).send(s)
)

b = Synth.new( \swexampleBus, [\ampbus,a.bus ] );

b.free;

- Methods -

*new ( id )
Create a new instance of a slot with identifier id

- Identifier and label -

id ( )
The unique ID of the slot
id_ ( )
key ( )
The label of the slot
key_ ( )
Set the label of the slot (done internally when a mapping is added with the method add of SWDataNetwork)
type ( )
The type of the slot. 0 is number (float), 1 is string (see the subclass SWDataStringSlot).

- Data and action -

value ( )
value_ ( val )
the current value of the slot. When set, it is multiplied by the scale factor of the slot, and remapped according to map and range. The action of the slot is performed, the debugAction is performed (printing), and if a bus has been created the (scaled) value is put on the bus.
action ( )
action_ ( )
Function to be performed each time the data is set

- Scaling, mapping and calibrating -

scale ( )
scale_ ( )
The scaling factor for the data
map ( )
If a map has been set the value will be (after scaling) value = map.map( range.unmap( value ) ). Thus range is the range the incoming values are expected to be in. map is the output range the data is mapped to.
map_ ( )
Sets the output map. If range is not set yet, it will be set to a linear range between 0 and 1.
range ( )
The input range.
range_ ( )
Sets the input range. If map is not set yet, it will be set to a linear range between 0 and 1.
calibrate ( steps )
This method looks at steps amount of times at the incoming data and calculates the mean of this. It assumes this mean is the minimum value the data will have, and it sets the minimum of range accordingly. Note, this method will be improved!

- Bus support -

createBus ( s )
create a Bus for the node on the server
freeBus ( )
free the Bus on the server
bus ( )
Return the Bus object.
kr ( )
JITLib support. This creates the bus (if not already present) and provides an In.kr around the bus.

- Debugging and monitoring -

debug_ ( onoff )
print debugging messages for the slot
monitor ( onoff )
Monitor the data in a plot. This uses the GNUPlot to plot the data and the interface class GNUPlot and BusMonitor, which can be found in the GNUPlot quark.
monitorClose ( )
Cleans up the monitor (closing the pipe to GNUPlot).
busmonitor ( )
Reference to the BusMonitor instance for monitoring the slot.




Marije Baalman 2009-03-16