diff options
author | David Runge <dave@sleepmap.de> | 2016-07-03 16:34:58 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2016-07-03 16:34:58 +0200 |
commit | 8c45cbc006d751df91eb637032190ff4a33fc78e (patch) | |
tree | 998a16b254a51a1b0318b8cc789eace82829b57e /classes/BowelyzerOSCHub.sc | |
parent | 966fa72f9676643b1b56c0d41046055b50b03a41 (diff) | |
download | bowelyzer-8c45cbc006d751df91eb637032190ff4a33fc78e.tar.gz bowelyzer-8c45cbc006d751df91eb637032190ff4a33fc78e.tar.bz2 bowelyzer-8c45cbc006d751df91eb637032190ff4a33fc78e.tar.xz bowelyzer-8c45cbc006d751df91eb637032190ff4a33fc78e.zip |
classes/*.sc: Moving all classes to the proper subfolder classes.0.4
Diffstat (limited to 'classes/BowelyzerOSCHub.sc')
-rw-r--r-- | classes/BowelyzerOSCHub.sc | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/classes/BowelyzerOSCHub.sc b/classes/BowelyzerOSCHub.sc new file mode 100644 index 0000000..8e6bf52 --- /dev/null +++ b/classes/BowelyzerOSCHub.sc @@ -0,0 +1,88 @@ +BowelyzerOSCHub{ + var <hub, <forward, <synthServer, <local; + + *new{ + arg config; + ^super.new.init(config); + } + + // setup a NetAddr object and return it + *getNetAddr{ + arg server, port; + ^NetAddr.new(server, port); + } + + init{ + arg config; + this.setupNetAddressesFromConfig(config); + this.setupSynthListenersFromConfig(config); + } + + setupNetAddressesFromConfig{ + arg config; + forward = BowelyzerOSCHub.getNetAddr(config.at(\forwardAddress), config.at(\forwardPort)); + hub = BowelyzerOSCHub.getNetAddr(config.at(\hubAddress), config.at(\hubPort)); + synthServer = BowelyzerOSCHub.getNetAddr(config.at(\synthServerAddress), config.at(\synthServerPort)); + local = NetAddr.new("127.0.0.1", NetAddr.langPort); + } + + // setup OSCdef for SynthServerAddress:SynthServerPort + setupSynthListenersFromConfig{ + arg config; + // listen for individual SendReply messages + config.at(\inputs).keysValuesDo({|name, input| + postln("Listening for messages called '/"++name++"' coming from scsynth at "++synthServer.ip++":"++synthServer.port++"."); + this.addSynthListener(name); + }); + } + + addSynthListener{ + arg name; + OSCdef.newMatching( + key: name.asSymbol, + func: {|msg, time, addr, recvPort| + this.forwardToNetAddress(msg, time); + }, + path: "/"++name.asString, + srcID: synthServer, + recvPort: hub.port + ); + } + + startSynthListener{ + arg name; + OSCdef(name).enable; + } + + stopSynthListener{ + arg name; + OSCdef(name.asSymbol).disable; + } + + freeSynthListener{ + arg name; + OSCdef(name.asSymbol).free; + } + + //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(amplitude != 0,{ + local.sendMsg("/indicate", msg[0].asString.replace("/","").asSymbol); + if(forward.isLocal && (forward.port == NetAddr.langPort), { + postln(msg[0]++" (amplitude: "++amplitude++"; pitch: "++pitch++"; has pitch: "++hasPitch); + },{ + forward.sendMsg(name, amplitude, pitch, hasPitch, onsetDetect); + }); + }); + } + + //TODO: add functions to modify OSC listener behavior (what data to send from which channel) + +} + |