[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] SF.net SVN: quarks:[2817] MOSCion/HelpSource
- To: sc-dev@xxxxxxxxxxxxxxxx
- Subject: [sc-dev] SF.net SVN: quarks:[2817] MOSCion/HelpSource
- From: joshpar@xxxxxxxxxxxxxxxxxxxxx
- Date: Fri, 28 Nov 2014 04:42:06 +0000
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:Subject:To:From:MIME-Version:Date; bh=C8nwXGp1tZ286FicHS6iWBi1PZksc6FSeZuPd4gWZUA=; b=AHKlTAgqmaG7CSJS28l71kxKBUo8YeXBYiFR0DKAqFTseYQTwQ0yqhhuBnIPZPW+WkbTYp9Zmu5t5wTNMmua4Y1Ilg6ItCCFBCzUmDO1XTBRkxRaYmAaOALCcCugQNK3cYeGnjlC8Jo31cru32vWzq9ssM1yd8HvHebZrDE7fK4=;
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Transfer-Encoding:Content-Type:Subject:To:From:MIME-Version:Date; bh=C8nwXGp1tZ286FicHS6iWBi1PZksc6FSeZuPd4gWZUA=; b=RdQfe1BLaYRzsF3D3tty/2EyQDJqwzMNxHq4cQdN22L56ipQZhxDlueBF1gb7aqouZqz8jEA4BkfXXm7RcC3aepI4im66+5ySPqIeIgbC9Xnbj5MHhJyOFG/jQ9E/ox54/Zc+DcpDYGOYrTN3obRS8jKBcHFzfpDefWOKQ1URsk=;
- List-id: SuperCollider developers mailing list <sc-devel.create.ucsb.edu>
- Reply-to: sc-dev@xxxxxxxxxxxxxxxx
- Sender: owner-sc-dev@xxxxxxxxxxxxxxxx
Revision: 2817
http://sourceforge.net/p/quarks/code/2817
Author: joshpar
Date: 2014-11-28 04:42:04 +0000 (Fri, 28 Nov 2014)
Log Message:
-----------
add MOSCion quark
Added Paths:
-----------
DIRECTORY/MOSCion.quark
MOSCion/
MOSCion/HelpSource/
MOSCion/HelpSource/Classes/
MOSCion/HelpSource/Classes/MOSCion.schelp
MOSCion/MOSCion.sc
Added: DIRECTORY/MOSCion.quark
===================================================================
--- DIRECTORY/MOSCion.quark (rev 0)
+++ DIRECTORY/MOSCion.quark 2014-11-28 04:42:04 UTC (rev 2817)
@@ -0,0 +1,7 @@
+(
+// a must:
+ \name: "MOSCion",
+ \path: "MOSCion",
+ \summary: "Control for the reading data values from the iOS app MOSCion",
+ \author: "Joshua Parmenter"
+)
Added: MOSCion/HelpSource/Classes/MOSCion.schelp
===================================================================
--- MOSCion/HelpSource/Classes/MOSCion.schelp (rev 0)
+++ MOSCion/HelpSource/Classes/MOSCion.schelp 2014-11-28 04:42:04 UTC (rev 2817)
@@ -0,0 +1,145 @@
+TITLE:: MOSCion
+summary:: class to respond to the iOS app MOSCion by Op 133 Studios LLC (http://www.op133studios.com).
+categories:: OSC control
+
+DESCRIPTION::
+mOSCion (https://itunes.apple.com/us/app/moscion/id918992600?mt=8) turns your iPhone or iPad into a gestural and environmental sensing device. Information about the device’s motion, surroundings and your touches are converted into data that can be sent with the Open Sound Control (OSC) network protocol to another device that is listening for this information.
+
+
+CLASSMETHODS::
+
+METHOD:: showComputerIP
+Posts your computer iP address and the port that sclang is listening on.
+
+METHOD:: dumpAllOSC
+For debugging, when set to 'true' all incoming OSC messages will be dumped to the post window. Call the method again with 'false' to turn off OSC dumping.
+
+METHOD:: new
+creates a new instance of MOSCion
+
+ARGUMENT:: port
+the port to listen on
+
+ARGUMENT:: baseAddr
+the base of the OSC addr that mOSCion will be sending. Multiple instances of MOSCion can be set up to support multiple devices. Changing the base addr on the device will make message handling easier.
+
+INSTANCEMETHODS::
+
+METHOD:: listen
+listens for the '/pong' message from the mOSCion app. If port is nil, the port from the OSC message will be saved for you, and this instance of MOSCion will filter for messages on this port.
+
+ARGUMENT:: action
+a Function to evaluate when the message comes in
+
+ARGUMENT:: remove
+a boolean that tells the class whether or not to remove this responder when the message comes in.
+
+METHOD:: clearResponders
+removes all responders associated with this instance of MOSCion.
+
+METHOD:: addResponderForAccelerometer
+adds the necessary responders to react to accerlerometer data.
+
+ARGUMENT:: key
+a unique key for this set of responders. Reassigning with the same key will overwrite a previous set of responders.
+
+ARGUMENT:: allFunc
+a function that has the x, y and z values passed into it. This function will be executed with every message received.
+
+ARGUMENT:: xFunc
+a function that has the x value passed into it. This function will be executed with every message received.
+
+ARGUMENT:: yFunc
+a function that has the y value passed into it. This function will be executed with every message received.
+
+ARGUMENT:: zFunc
+a function that has the z value passed into it. This function will be executed with every message received.
+
+METHOD:: removeAccelerometerResponder
+removes a set of responders with the key id.
+
+ARGUMENT:: key
+the key to search for.
+
+METHOD:: addResponderForGyroscope
+METHOD:: addResponderForMagnetometer
+see accelerometer details above.
+
+METHOD:: addResponderForAttitude
+similar to accelerometer, except the functions are for all controls, pitch, yaw and roll.
+
+METHOD:: addResponderForSpeed
+similar to accelerometer, except the functions are for all controls, speed (in meters/sec) and course.
+
+METHOD:: addResponderForHeading
+similar to accelerometer, except the functions are for all controls, true heading and magnetic heading.
+
+METHOD:: addResponderForGPS
+similar to accelerometer, except the functions are for all controls, latitude, longitude and altitude
+
+METHOD:: addResponderForMicrophone
+similar to accelerometer, except the functions are for all controls, linear amplitude, frequency and a floating point midi keynum
+
+METHOD:: addRespondersForTouch
+ARGUMENT:: key
+a unique key for this set of responders. Reassigning with the same key will overwrite a previous set of responders.
+
+ARGUMENT:: touchBeganFunc
+ARGUMENT:: touchMovedFunc
+ARGUMENT:: touchEndedFunc
+methods to respond to touch began, move and ended. All functions are passed a unique integer touch ID (to track touches with) and current x and y position.
+
+METHOD:: removeGyroscopeResponder
+METHOD:: removeMagnetometerResponder
+METHOD:: removeAttitudeResponder
+METHOD:: removeSpeedResponder
+METHOD:: removeHeadingResponder
+METHOD:: removeGPSResponder
+METHOD:: removeMicrophoneResponder
+METHOD:: removeTouchResponders
+similar to the method for removing accelerometer responders
+
+METHOD:: clearAllTouches
+sends the touch end for all current tracked touches. Touches on the device are sometimes lost, and this helps clear out stuck touches.
+
+
+EXAMPLES::
+
+code::
+m = MOSCion.new;
+
+// send pong from MOSCion to filter only this port
+m.listen(nil, true);
+
+MOSCion.showComputerIP;
+MOSCion.dumpAllOSC;
+MOSCion.dumpAllOSC(false);
+
+s.boot;
+
+SynthDef(\test, {arg freq, offset;
+ var out;
+ out = Pluck.ar(PinkNoise.ar.dup, Impulse.kr(0), 0.2, (freq * Lag2.kr(offset, 0.4)).reciprocal, 4, 0.03);
+ DetectSilence.ar(out , doneAction: 2);
+ Out.ar(0, out);
+}).add;
+
+g = Group.new;
+
+// turn on Attitude in MOSCion- adjusting pitch of the device will update the p variable and any current notes
+p = 0;
+m.addResponderForAttitude(\test, {arg pitch;
+ p = pitch;
+ g.set(\offset, (p*7).midiratio)}, nil, nil, nil);
+
+
+// touches start new notes.
+
+m.addRespondersForTouch(\test, {arg id, x, y;
+ id.postln;
+ Synth(\test, [\freq, 800, \amp, y, \offset, (p*7).midiratio], g);
+}, nil, nil);
+
+// clean up
+m.clearResponders;
+::
\ No newline at end of file
Added: MOSCion/MOSCion.sc
===================================================================
--- MOSCion/MOSCion.sc (rev 0)
+++ MOSCion/MOSCion.sc 2014-11-28 04:42:04 UTC (rev 2817)
@@ -0,0 +1,311 @@
+MOSCion {
+ var sendingPort, baseAddr, <pongResp, <listenResp;
+ var <responders;
+ var <accelX, <accelY, <accelZ;
+ var <gyroX, <gyroY, <gyroZ;
+ var <magX, <magY, <magZ;
+ var <pitch, <yaw, <roll;
+ var <speed, <course;
+ var <trueHeading, <magneticHeading;
+ var <lat, <long, <alt;
+ var <amp, <freq, <keynum;
+ var <touches, touchEndedFuncs;
+
+ classvar tmpFunc;
+
+ *new {arg sendingPort, baseAddr = "/mOSCion";
+ ^super.newCopyArgs(sendingPort, baseAddr).initMOSCion;
+ }
+
+ initMOSCion {
+ responders = IdentityDictionary.new;
+ [\accelerometer, \gyroscope, \magnetometer, \attitude, \gps, \speed, \heading, \microphone, \touchBegan, \touchMoved, \touchEnded].do({arg thisKey;
+ responders.add(thisKey -> IdentityDictionary.new);
+ });
+ touches = IdentityDictionary.new;
+ touchEndedFuncs = IdentityDictionary.new;
+ }
+
+ listen {arg action, remove = true;
+ "Listen for '/pong' from mOSCion".postln;
+ listenResp = OSCdef(\mOSCionListen, {arg msg, time, addr, recvPort;
+ sendingPort = addr.port;
+ ("Heard mOSCion! Filtering messages to port: " ++ sendingPort).postln;
+ action.value;
+ remove.if({listenResp.free});
+ }, '/pong');
+ }
+
+ *showComputerIP {
+ var tmpDef;
+ var before = NetAddr.broadcastFlag;
+ NetAddr.broadcastFlag = true;
+ tmpDef = OSCdef(\tmp, { arg msg,time, addr, recvPort;
+ NetAddr.broadcastFlag = before;
+ ("Set the IP in mOSCion to: " ++ addr.ip ++ " and port: "++NetAddr.langPort).postln;
+ tmpDef.free;
+ }, '/getMyIP');
+
+ NetAddr("255.255.255.255", NetAddr.langPort).sendMsg('/getMyIP');
+ }
+
+ *dumpAllOSC {arg bool = true;
+ bool.if({
+ thisProcess.addOSCRecvFunc(tmpFunc = { arg msg, time, replyAddr, port;
+ if(msg[0] != '/status.reply') {
+ "At time %s received message % from % on port %\n".postf( time, msg, replyAddr )
+ }
+ })
+ }, {
+ thisProcess.removeOSCRecvFunc(tmpFunc)
+ });
+ }
+
+ clearResponders {
+ responders.do({arg responderDict;
+ var keysToRemove = [];
+ responderDict.keysValuesDo({arg key, resp;
+ keysToRemove = keysToRemove.add(key);
+ resp.free;
+ });
+ keysToRemove.do({arg thisKey;
+ responderDict[thisKey] = nil;
+ });
+ });
+ }
+
+ removeResponderForType {arg type, key;
+ (responders[type][key].notNil).if({
+ responders[type][key].free;
+ responders[type][key] = nil;
+ })
+ }
+
+ addResponder {arg respDictKey, key, resp;
+ var respDict, curResp;
+ respDict = responders[respDictKey];
+ curResp = respDict[key];
+ curResp.notNil.if({
+ curResp.free;
+ });
+ respDict.add(key -> resp);
+ }
+
+ check {arg addr;
+ var check;
+ ^(sendingPort.notNil and:{addr.port != sendingPort}).not;
+ }
+
+ addResponderForAccelerometer {arg key, allFunc, xFunc, yFunc, zFunc;
+ var resp;
+ resp = OSCdef(\accelerometer, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ accelX = msg[2];
+ accelY = msg[4];
+ accelZ = msg[6];
+ xFunc.value(accelX);
+ yFunc.value(accelY);
+ zFunc.value(accelZ);
+ allFunc.value(accelX, accelY, accelZ);
+ });
+ }, baseAddr ++ "/accelerometer");
+ this.addResponder(\accelerometer, key, resp);
+ }
+
+ removeAccelerometerResponder {arg key;
+ this.removeResponderForType(\accelerometer, key);
+ }
+
+ addResponderForGyroscope {arg key, allFunc, xFunc, yFunc, zFunc;
+ var resp;
+ resp = OSCdef(\gyroscope, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ gyroX = msg[2];
+ gyroY = msg[4];
+ gyroZ = msg[6];
+ xFunc.value(gyroX);
+ yFunc.value(gyroY);
+ zFunc.value(gyroZ);
+ allFunc.value(gyroX, gyroY, gyroZ);
+ });
+ }, baseAddr ++ "/gyroscope");
+ this.addResponder(\gyroscope, key, resp);
+ }
+
+ removeGyroscopeResponder {arg key;
+ this.removeResponderForType(\gyroscope, key);
+ }
+
+ addResponderForMagnetometer {arg key, allFunc, xFunc, yFunc, zFunc;
+ var resp;
+ resp = OSCdef(\magnetometer, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ magX = msg[2];
+ magY = msg[4];
+ magZ = msg[6];
+ xFunc.value(magX);
+ yFunc.value(magY);
+ zFunc.value(magZ);
+ allFunc.value(magX, magY, magZ);
+ });
+ }, baseAddr ++ "/magnetometer");
+ this.addResponder(\magnetometer, key, resp);
+ }
+
+ removeMagnetometerResponder {arg key;
+ this.removeResponderForType(\magnetometer, key);
+ }
+
+ addResponderForAttitude {arg key, allFunc, pitchFunc, yawFunc, rollFunc;
+ var resp;
+ resp = OSCdef(\attitude, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ pitch = msg[2];
+ yaw = msg[4];
+ roll = msg[6];
+ pitchFunc.value(pitch);
+ yawFunc.value(yaw);
+ rollFunc.value(roll);
+ allFunc.value(pitch, yaw, roll);
+ });
+ }, baseAddr ++ "/attitude");
+ this.addResponder(\attitude, key, resp);
+ }
+
+ removeAttitudeResponder {arg key;
+ this.removeResponderForType(\attitude, key);
+ }
+
+ addResponderForSpeed {arg key, allFunc, speedFunc, courseFunc;
+ var resp;
+ resp = OSCdef(\speed, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ speed = msg[2];
+ course = msg[4];
+ speedFunc.value(speed);
+ courseFunc.value(course);
+ allFunc.value(speed, course);
+ });
+ }, baseAddr ++ "/speed");
+ this.addResponder(\speed, key, resp);
+ }
+
+ removeSpeedResponder {arg key;
+ this.removeResponderForType(\attitude, key);
+ }
+
+ addResponderForHeading {arg key, allFunc, trueFunc, magneticFunc;
+ var resp;
+ resp = OSCdef(\heading, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ trueHeading = msg[2];
+ magneticHeading = msg[4];
+ trueFunc.value(trueHeading);
+ magneticFunc.value(magneticHeading);
+ allFunc.value(trueHeading, magneticHeading);
+ });
+ }, baseAddr ++ "/heading");
+ this.addResponder(\heading, key, resp);
+ }
+
+ removeHeadingResponder {arg key;
+ this.removeResponderForType(\heading, key);
+ }
+
+ addResponderForGPS {arg key, allFunc, latFunc, longFunc, altFunc;
+ var resp;
+ resp = OSCdef(\gps, {arg msg, time, addr, recvPort;
+ this.check(addr).if({
+ lat = msg[2];
+ long = msg[4];
+ alt = msg[6];
+ latFunc.value(lat);
+ longFunc.value(long);
+ altFunc.value(alt);
+ allFunc.value(lat, long, alt);
+ });
+ }, baseAddr ++ "/gps");
+ this.addResponder(\gps, key, resp);
+ }
+
+ removeGPSResponder {arg key;
+ this.removeResponderForType(\gps, key);
+ }
+
+ addResponderForMicrophone {arg key, allFunc, ampFunc, freqFunc, keynumFunc;
+ var resp;
+ resp = OSCdef(\microphone, {arg msg, time, addr, recvPort;
+
+ this.check(addr).if({
+ amp = msg[2];
+ freq = msg[4];
+ keynum = msg[6];
+ ampFunc.value(amp);
+ freqFunc.value(freq);
+ keynumFunc.value(keynum);
+ allFunc.value(amp, freq, keynum);
+ });
+ }, baseAddr ++ "/microphone");
+ this.addResponder(\microphone, key, resp);
+ }
+
+ removeMicrophoneResponder {arg key;
+ this.removeResponderForType(\microphone, key);
+ }
+
+ addRespondersForTouch {arg key, touchBeganFunc, touchMovedFunc, touchEndedFunc;
+ var resp;
+ resp = OSCdef(\touchBegan, {arg msg, time, addr, recvPort;
+ var touchID, touchX, touchY;
+ this.check(addr).if({
+ touchID = msg[2];
+ touchX = msg[4];
+ touchY = msg[6];
+ touchBeganFunc.value(touchID, touchX, touchY);
+ touches.add(touchID -> [touchX, touchY]);
+ });
+ }, baseAddr ++ "/touchBegan");
+ this.addResponder(\touchBegan, key, resp);
+ resp = OSCdef(\touchMoved, {arg msg, time, addr, recvPort;
+ var touchID, touchX, touchY;
+ this.check(addr).if({
+ touchID = msg[2];
+ touchX = msg[4];
+ touchY = msg[6];
+ touchMovedFunc.value(touchID, touchX, touchY);
+ touches.add(touchID -> [touchX, touchY]);
+ });
+ }, baseAddr ++ "/touchMoved");
+ touchEndedFuncs.add(key -> touchEndedFunc);
+ this.addResponder(\touchMoved, key, resp);
+ resp = OSCdef(\touchEnded, {arg msg, time, addr, recvPort;
+ var touchID, touchX, touchY;
+ this.check(addr).if({
+ touchID = msg[2];
+ touchX = msg[4];
+ touchY = msg[6];
+ touchEndedFunc.value(touchID, touchX, touchY);
+ this.cleanupTouch(touchID);
+ });
+ }, baseAddr ++ "/touchEnded");
+ this.addResponder(\touchEnded, key, resp);
+ }
+
+ removeTouchResponders {arg key;
+ [\touchBegan, \touchMoved, \touchEnded].do({arg thisKey;
+ this.removeResponderForType(thisKey, key);
+ });
+ }
+
+ clearAllTouches {
+ touches.keysValuesDo({arg key, value;
+ touchEndedFuncs[key].value(key, value[0], value[1]);
+ this.cleanupTouch(key);
+ });
+ }
+
+ cleanupTouch {arg key;
+ touchEndedFuncs.removeAt(key);
+ touches.removeAt(key)
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
sc-dev mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/