Last active
September 5, 2019 06:06
-
-
Save lvm/eb0553f35c97d71c6deae84953eb88d1 to your computer and use it in GitHub Desktop.
Unity + TidalCycles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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