Mrmr wrapper for communication with mrmr clients


Inherits from: Object


Mrmr creates an easy to use interface for communicating with Mrmr Clients, such as the one available for the iPhone/iPodTouch. More information about the mrmr system can be found at http://mrmr.noisepages.com/ . Mrmr allows supercollider to define an interface, push it to the client, and respond to the messages sent by that interface.


See also: NetAddr, Bus, In, OSCresponderNode


Other Issues


Mrmr does not autodiscover the device, so that aspect of communication must be done manually.


Creation / Class Methods


*new (host, port, name)

BE SURE THE DEVICE IS ON AND READY TO CONNECT BEFORE EXECUTING THIS!

phone - hostname of the device as expected by NetAddr.new. Default value is nil.

port - port to send mrmrIB commands to (usually 31337). Default value is nil.

name - name of the device. Found in the preferences of the device.. Default value is nil.

// Example

a = Mrmr("iphone.local",31337,"iphone");

a.free;


Accessing Instance and Class Variables


interfaceLabels

Read/write List of Symbol labels for controls

Instance Methods


Note the example at the end of the file for proper use.


performanceMode (this)

Brings mrmr into performance mode.
This method should be run before sending interface commands.


bundleStyle (style )

Sets the style of messages sent back from mrmr. This class expects bundle messages.

style - bundle style or alternate style (\true or \false). Default value is 'true'.

// Example

//These two commands do the same thing.

//Run either one to use this class.

a.bundleStyle;

a.bundleStyle(\true);

//The alternative style.

a.bundleStyle(\false);


precision (type)

Sets the format of the data sent back from mrmr.

type - \float returns floating point numbers from 0 to 1. \int returns integers from 0 to 1000.. Default value is nil.

// Example

//floating point format

a.precision(\float);

//integer format

a.precision(\int);


accelerometerSmoothing (amount)

Sets the amount of smoothing applied to the accelerometer data.

amount - a floating point number between 0 and 1, 1 producing the most smoothing. Default value is nil.


accelerometerRate (miliseconds)

Sets the update rate of the accelerometer data.

miliseconds - an integer between 8 and 1000 miliseconds between each accelerometer update. Default value is nil.


accelerometerEnabled (boolean)

Globally enables or disables all accelerometers.

boolean - wether or not to enable the accelerometers (true or false). Default value is nil.


alert (title, body)

Sends an alert message to the device to be displayed to the user.

title - the title of the alert message. Default value is nil.

body - the contents of the alert message. Default value is nil.

// Example

a.alert("Alert Title","the body of the alert is here.");


addControl (type, gridCols, gridRows, posCol, posRow, colSpan , rowSpan , title , style )

Adds an element (control) to the interface. For more information on the available controls, go to http://mrmr.noisepages.com/mrmr-interface-protocol/ . A detailed example of the various controls can be found at the end of this document.

type - the kind of control. Can be one of the following. Default value is nil.

gridCols - number of grid columns for layout. Default value is nil.

gridRows - number of grid rows for layout. Default value is nil.

posCol - the column position of the element. Default value is nil.

posRow - the row position of the element. Default value is nil.

colSpan - the number of columns spanned by the element. Default value is 1.

rowSpan - the number of rows spanned by the element. Default value is 1.

title - the title associated with the element. Default value is "_".

style - the style of the element. Default value is 1.


addPageBreak (this)

Marks the beginning of a new page of controls


setupInterface (debug )

Sends the current form of the interface to the device and begins listening for messages returned by the device.

debug - wether or not to also post the values returned by the device. Default value is false.


resetInterface (this)

Resets the internal representation of the interface.
Be sure to run this before creating a new interface!


bus (label)

Returns the bus associated with the specific control label. See example at the end of this file.

label - one of the Symbol labels in mrmr.interfaceLabels. Default value is nil.

Examples


//boot and set up mrmr

(

s.boot;

//BE SURE THAT THE DEVICE IS TURNED ON AND READY TO CONNECT!!!

a = Mrmr("iphone.local",31337,"iphoneName"); //or: a = Mrmr("192.168.1.50",31337,"iphoneName");

"sclang port:"+NetAddr.langPort; //make sure mrmr is sending data to this address.

)


//set up and sent interface

//this set shows an example of each of the currently supported controls

(

a.resetInterface; //make sure to call this before resending an interface


a.performanceMode; //put the device into performance mode


//three buttons on the top row: a pushbutton, a small pushbutton (style:2), and a toggle button

a.addControl(\pushbutton,3,6,1,1);

a.addControl(\pushbutton,3,6,2,1,style:2);

a.addControl(\togglebutton,3,6,3,1);


//sliders on the second row: a horintal slider, a vertical slider (style:2)

//also a text input view on the second row, any text typed in sends that text back to supercollider

a.addControl(\slider,3,6,1,2);

a.addControl(\slider,3,6,2,2,style:2);

a.addControl(\textinputview,3,6,3,2,title:"type here");


//a title view on the third row

a.addControl(\titleview,3,6,1,3,3,title:"some more things below...");


//a tactile zone on the fourth row

a.addControl(\tactilezone,3,6,1,4,3);


//three types of accelerometers on the fifth row: an XYZ accelerometer, a cardinal direction/force accelerometer, and an angular direction/force accelerometer

a.addControl(\accelerometer,3,6,1,5);

a.addControl(\accelerometer,3,6,2,5,style:2);

a.addControl(\accelerometer,3,6,3,5,style:3);


//a titleview on the sixth row

a.addControl(\titleview,3,6,1,6,3,title:"see next page for more");


//a page break

a.addPageBreak;


//a web view showing google.com

a.addControl(\webview,1,1,1,1,title:"http://google.com");


// setup the interface showing incoming data.

a.setupInterface(true);

)


//Setup a synthdef to work with the mrmr interface

//note that the inputs are busses which are read using the In UGen.

(

SynthDef(\mrmrTest,

{ | freq, mul, gate(0) |

var z;

mul = (In.kr(mul)-1)*(-1);

freq = In.kr(freq);

z = EnvGen.kr(Env.asr,In.kr(gate))*SinOsc.ar(freq*500,0,mul);

Out.ar([0,1],z);

}

).send(s);

)


//maps the gate to the toggle button, freqency to the x axis of the touch area, amplitude to the y axis of the touch area.  this format requires the precision to be float.

(

a.precision(\float);

x=Synth.new(\mrmrTest,[\freq,a.bus('TX(7)'),\mul,a.bus('TY(7)'),\gate,a.bus('PB(2)')]);

)


//clean up

(

a.free;

x.free;

)


//this block is useful if you are not seeing what you expect

//this code shows all of the messages coming into sclang

(

(

thisProcess.recvOSCfunc = { |time, addr, msg| 

if(msg[0] != 'status.reply') {

"time: % sender: %\nmessage: %\n".postf(time, addr, msg); 

}  

}

);

)