diff options
Diffstat (limited to 'BowelyzerOSCHub.sc')
-rw-r--r-- | BowelyzerOSCHub.sc | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/BowelyzerOSCHub.sc b/BowelyzerOSCHub.sc index a2ec888..b73e201 100644 --- a/BowelyzerOSCHub.sc +++ b/BowelyzerOSCHub.sc @@ -1,5 +1,5 @@ BowelyzerOSCHub{ - var <hub, <forward, <synthServer, <synthServerListener; + var <hub, <forward, <synthServer; *new{ arg config; @@ -15,7 +15,7 @@ BowelyzerOSCHub{ init{ arg config; this.setupNetAddressesFromConfig(config); - this.addAnalysisListener(config); + this.setupSynthListener(config); } setupNetAddressesFromConfig{ @@ -25,28 +25,39 @@ BowelyzerOSCHub{ synthServer = BowelyzerOSCHub.getNetAddr(config.at("synthServerAddress"), config.at("synthServerPort")); } -// setup a new listener for SynthServerAddress:SynthServerPort - addAnalysisListener{ +// setup OSCdef for SynthServerAddress:SynthServerPort + setupSynthListener{ arg config; // listen for individual SendReply messages config.at("names").do({|name| - postln("Listening for messages called '/"++name++"' coming from scsynth."); - //TODO: use OSCdef here to be able to use key and free - synthServerListener = OSCFunc.newMatching( - {|msg, time, addr, recvPort| - postln(time.asString++": "++msg[0]++" (amplitude: "++msg[3]++"; pitch: "++msg[4]++"; has pitch: "++msg[5]++"; note on: "++msg[6]++")"); - if(msg[6] != 0.0,{ - postln(msg[0]++" (amplitude: "++msg[3]++"; pitch: "++msg[4]++"; has pitch: "++msg[5]); - }); - }, + postln("Listening for messages called '/"++name++"' coming from scsynth at "++synthServer.ip++":"++synthServer.port++"."); + OSCdef.newMatching( + name.asSymbol, + {|msg, time, addr, recvPort| this.forwardToNetAddress(msg, time)}, '/'++name.asSymbol, synthServer, hub.port ); + OSCdef(name.asSymbol).enable; }); } - //TODO: add functions to modify OSC listener behavior + //forward a received OSC message to the globally specified forward address + forwardToNetAddress{ + arg msg, time; + var name = msg[0], + amplitude = msg[3], + pitch = msg[4], + hasPitch = msg[5], + onsetDetect = msg[7]; + if(forward.isLocal && (forward.port == NetAddr.langPort), { + postln(msg[0]++" (amplitude: "++amplitude++"; pitch: "++pitch++"; has pitch: "++hasPitch); + },{ + forward.sendMsg(name,"/amplitude", amplitude, "/pitch", pitch, "/hasPitch", hasPitch, "/detect", onsetDetect); + }); + } + + //TODO: add functions to modify OSC listener behavior (what data to send from which channel) } |