Skip to content

Instantly share code, notes, and snippets.

@lvm
Last active September 5, 2019 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvm/eb0553f35c97d71c6deae84953eb88d1 to your computer and use it in GitHub Desktop.
Save lvm/eb0553f35c97d71c6deae84953eb88d1 to your computer and use it in GitHub Desktop.
Unity + TidalCycles
//https://github.com/heaversm/unity-osc-receiver
public var RemoteIP : String = "127.0.0.1";
public var SendToPort : int = 9000;
public var ListenerPort : int = 8000;
public var cubeReceivers: GameObject[];
public var sphereReceivers: GameObject[];
private var handler : Osc;
private var cyRot : int = 0;
private var cxRot : int = 0;
private var syRot : int = 0;
private var sxRot : int = 0;
public function Start ()
{
var udp : UDPPacketIO = GetComponent("UDPPacketIO");
udp.init(RemoteIP, SendToPort, ListenerPort);
handler = GetComponent("Osc");
handler.init(udp);
handler.SetAllMessageHandler(AllMessageHandler);
cubeReceivers = GameObject.FindGameObjectsWithTag("cube");
sphereReceivers = GameObject.FindGameObjectsWithTag("sphere");
}
function Update () {
if ( cubeReceivers ){
for (var cubeReceiver: GameObject in cubeReceivers) {
cubeReceiver.transform.Rotate(cxRot, cyRot, 0);
}
}
if ( sphereReceivers ){
for (var sphereReceiver: GameObject in sphereReceivers) {
sphereReceiver.transform.Rotate(sxRot, syRot, 0);
}
}
}
public function AllMessageHandler(oscMessage: OscMessage){
var msgString = Osc.OscMessageToString(oscMessage);
var msgAddress = oscMessage.Address;
var msgValue = oscMessage.Values;
Debug.Log(msgString);
Primitives(msgValue);
}
public function Primitives(msgValue) : void
{
var primitive = msgValue[0];
var x = msgValue[1];
var y = msgValue[2];
if( primitive == "cube" ){
cxRot = x;
cyRot = y;
}
else if( primitive == "sphere" ){
sxRot = x;
syRot = y;
}
}
import Sound.Tidal.OscStream
import Sound.Tidal.Context as C
let unity = Shape {
params = [ S "primitive" Nothing,
I "rx" (Just 0),
I "ry" (Just 0)
],
cpsStamp = False,
C.latency = 0
}
unitySlang = OscSlang {path = "/Primitives",
timestamp = NoStamp,
namedParams = False,
preamble = []
}
unityStream = do
s <- makeConnection "127.0.0.1" 8000 unitySlang
stream (Backend s $ (\_ _ _ -> return ())) unity
primitive = makeS unity "primitive"
rx = makeI unity "rx"
ry = makeI unity "ry"
u1 <- unityStream
cps 1
u1 $
density 4 $
sometimes (# ry "0") $
every 2 (# rx "0") $
primitive "cube"
# rx ((floor <$>) $ scale 1 10 rand)
# ry ((floor <$>) $ scale 5 10 rand)
u1 $
slow 4 $
primitive "sphere"
# rx "0"
# ry "0"
u1 silence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment