From c83c7c1fe4186747ab99c7d05401f60be0241147 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 9 Aug 2016 15:23:39 +0200 Subject: classes/Bowelyzer.sc: Adding a postLocally function to postln the received OSC message. Adding a verbose variable, that will be used to post output, when set to true, to minimize the overall bowelyzer output. Refactoring most of forwardToNetAddress back to the per channel OSCdefs: The overall logic now takes place in there and functionality is further externalized into functions. --- classes/Bowelyzer.sc | 83 +++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc index 2ff1a5c..be48cd0 100644 --- a/classes/Bowelyzer.sc +++ b/classes/Bowelyzer.sc @@ -1,15 +1,25 @@ Bowelyzer{ - var verbose; *new{ - arg configFile; - ^super.new.init(configFile); + arg configFile, verbose = false; + ^super.new.init(configFile, verbose); } init{ //initialize with configuration, if available (else use default) - arg configFile; + arg configFile, verbose; + this.verbose = verbose; config = BowelyzerConfig.new(configFile); this.addServer; server.waitForBoot({ @@ -449,7 +459,30 @@ Bowelyzer{ OSCdef.newMatching( key: name.asSymbol, func: {|msg, time, addr, recvPort| - this.forwardToNetAddress(msg, time); + var name = msg[0], + sanitizedName = name.asString.replace("/","").asSymbol, + amplitude = msg[3], + pitch = msg[4], + hasPitch = msg[5], + onsetDetect = msg[6], + range = config.config.at(\controls).at(sanitizedName).at(\freqRange), + onlyForwardOnNewPitch = config.config.at(\controls).at(sanitizedName).at(\onlyForwardOnNewPitch); + // if there is something connected + if(amplitude != 0,{ + // if the pitch is within freqRange + if((pitch >= range[0]) && (pitch <= range[1]),{ + if(onlyForwardOnNewPitch.not || (onlyForwardOnNewPitch && (hasPitch > 0)), { + localAddr.sendMsg("/indicate", sanitizedName); + if(this.verbose,{this.postLocally(name, amplitude, pitch, hasPitch, onsetDetect)}); + try{ + this.forwardToNetAddress(name, amplitude, pitch, hasPitch, onsetDetect); + }{ + if(this.verbose,{error("Couldn't send to NetAddr: "++forwardAddr)}); + gui.pingForwardIndicator; + } + }); + }); + }); }, path: "/"++name.asString, srcID: synthServerAddr, @@ -472,39 +505,15 @@ Bowelyzer{ OSCdef(name.asSymbol).free; } + //post a received OSC message locally + postLocally{ + arg name, amplitude, pitch, hasPitch, onsetDetect; + postln("[ "++name++", "++amplitude++", "++pitch++", "++hasPitch++", "++onsetDetect++" ]"); + } + //forward a received OSC message to the globally specified forward address forwardToNetAddress{ - arg msg, time; - var name = msg[0], - sanitizedName = name.asString.replace("/","").asSymbol, - amplitude = msg[3], - pitch = msg[4], - hasPitch = msg[5], - onsetDetect = msg[6], - range = config.config.at(\controls).at(sanitizedName).at(\freqRange), - onlyForwardOnNewPitch = config.config.at(\controls).at(sanitizedName).at(\onlyForwardOnNewPitch); - // if there is something connected - if(amplitude != 0,{ - // if the pitch is within freqRange - if((pitch >= range[0]) && (pitch <= range[1]),{ - if(onlyForwardOnNewPitch, { - if(hasPitch > 0, { - localAddr.sendMsg("/indicate", sanitizedName); - if((forwardAddr.ip == "127.0.0.1") && (forwardAddr.port == NetAddr.langPort), { - postln(name++": amplitude: "++amplitude++"; pitch: "++pitch++"; hasPitch: "++hasPitch++"; onSet: "++onsetDetect); - },{ - forwardAddr.sendMsg(name, amplitude, pitch, hasPitch, onsetDetect); - }); - }); - },{ - localAddr.sendMsg("/indicate", sanitizedName); - if((forwardAddr.ip == "127.0.0.1") && (forwardAddr.port == NetAddr.langPort), { - postln(name++": amplitude: "++amplitude++"; pitch: "++pitch++"; hasPitch: "++hasPitch++"; onSet: "++onsetDetect); - },{ - forwardAddr.sendMsg(name, amplitude, pitch, hasPitch, onsetDetect); - }); - }); - }); - }); + arg name, amplitude, pitch, hasPitch, onsetDetect; + forwardAddr.sendMsg(name, amplitude, pitch, hasPitch, onsetDetect); } } -- cgit v1.2.3-54-g00ecf