Creating a client in SuperCollider

How to use SuperCollider

Code in SuperCollider is executed by putting the cursor on the line, or selecting a block of text, and pressing:

  • On OSX: [Enter] (this is the one next to the spacebar or on the numpad), or Cmd-[Return], or Shift-[Return], or Cmd-C.
  • On Linux: [C-c C-c] (in Emacs/scel), F5 (in scvim), or Ctrl-E (in gedit/sced).
  • On Windows: Ctrl-[Enter]

Dependencies

For the client, you will need to have curl installed, in order to be able to retrieve a file from the host. On Linux this program is available from most distributions. On OSX it should be available by default.

Starting the DataNetwork client in SuperCollider

Now in order to create a client within SuperCollider, you execute this code:


// create a client:
y = SWDataNetworkClient( "192.168.0.104", "myname");
// where "192.168.0.104" is the IP-address of the host,
// and "myname" is the unique name for you in the datanetwork.

To create a graphical user interface for the DataNetwork execute:

y.makeGui;

Subscribing to data on the network

Now suppose there is interesting data on node 101:


// subscribe to node 101, by number:
y.subscribeNode( 101 );

Instead of subscribing by number, you can also pass an instance of a SWDataNode to the method:


// subscribe to node 101 by passing in an instance of SWDataNode as an argument:
y.subscribeNode( y.nodes[101] );

You can also subscribe to a DataNode from the GUI with the [sub] button, or get the data once with the [get] button.

Using the data

Now you have several ways to do something with the data:


// get a reference to a DataNode in a variable:
a = y.nodes[101];
// if the node has a label, you acces it by its label:
a = y[\minibee101];

Use the value directly:


// access the values of all slots of the node:
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;

Create an action that is performed each time the value changes:


// 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 )};
// reset the action:
a.action = {};

Automatically putting the value on a bus and map your synth parameters to a bus:


// create a bus:
a.createBus(s);
// map the amplitude of b to the bus:
b.map( \amp, a.bus );
// cleaning up the synth:
b.free;

Supplying data to the network

To create a DataNode in the network, execute the following:


// creating a node with number and label "mynode"
y.addExpected( 500, \mynode );

Now to set data to it:


// creating a node with number and label "mynode"
y.setData( 500, [0,2,3,2,3,4].normalizeSum );

The data supplied to the node must have the same size each time, i.e. the number of slots in the DataNode is constant.

More information

For more information please check the extensive help documentation that is supplied with the classes. To get an overview execute:

"SenseWorldDataNetwork".openHelpFile;

Comments/Questions

Comments are closed.