aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-07-24 20:02:25 +0200
committerDavid Runge <dave@sleepmap.de>2016-07-24 20:02:25 +0200
commit419ec811180089ed5db4cc3dbd9a5425d8496279 (patch)
tree67c74125949ba9c7d75b50aba4745df0b93746bd
parent3596bc7746eca614bc315cf41bbffedb02a7a8e8 (diff)
downloadbowelyzer-419ec811180089ed5db4cc3dbd9a5425d8496279.tar.gz
bowelyzer-419ec811180089ed5db4cc3dbd9a5425d8496279.tar.bz2
bowelyzer-419ec811180089ed5db4cc3dbd9a5425d8496279.tar.xz
bowelyzer-419ec811180089ed5db4cc3dbd9a5425d8496279.zip
classes/Bowelyzer.sc: Merging classes/BowelyzerOSCHub.sc into classes/Bowelyzer.sc to have easier access to the configuration during message parsing.
-rw-r--r--classes/Bowelyzer.sc116
1 files changed, 92 insertions, 24 deletions
diff --git a/classes/Bowelyzer.sc b/classes/Bowelyzer.sc
index f286587..98817fe 100644
--- a/classes/Bowelyzer.sc
+++ b/classes/Bowelyzer.sc
@@ -1,6 +1,6 @@
Bowelyzer{
- var <gui, <server, <analyzer, <config, <hub;
+ var <gui, <server, <analyzer, <config, <hubAddr, <forwardAddr, <localAddr, <synthServerAddr;
*new{
arg configFile;
@@ -13,14 +13,12 @@ Bowelyzer{
config = BowelyzerConfig.new(configFile);
server = Server.new(
\bowelyzer,
- BowelyzerOSCHub.getNetAddr(
- config.config.at(\synthServerAddress),
- config.config.at(\synthServerPort)
- )
+ NetAddr.new(config.config.at(\synthServerAddress), config.config.at(\synthServerPort))
);
Server.default = server;
server.waitForBoot({
- hub = BowelyzerOSCHub.new(config.config);
+ this.setupNetAddressesFromConfig(config.config);
+ this.setupSynthListenersFromConfig(config.config);
analyzer = BowelyzerAnalyzer.new(config.config);
gui = BowelyzerGUI.new(config);
this.addGUIListeners;
@@ -90,7 +88,7 @@ Bowelyzer{
gui.addOSCIndicatorFadeOutTask(update);
// stop the listener for LevelIndicator by name and start a new one based upon the updated name
OSCdef(("levels_"++name).asSymbol).free;
- this.setupLevelListener(update, hub.synthServer);
+ this.setupLevelListener(update, synthServerAddr);
//TODO: refactor into function
// free the synth on the server and start a new one according to the config
analyzer.freeAnalysisSynth(name.asSymbol);
@@ -104,9 +102,9 @@ Bowelyzer{
}.play;
//TODO: refactor into function
// rename the hub listener for the Synth
- hub.freeSynthListener(name);
- hub.addSynthListener(update);
- hub.startSynthListener(update);
+ this.freeSynthListener(name);
+ this.addSynthListener(update);
+ this.startSynthListener(update);
},{
("New name not valid: "++update).error;
gui.setChannelText(name, name);
@@ -189,11 +187,11 @@ Bowelyzer{
postln("Received: "++msg);
if(type.notNil && config.config.includesKey(type),{
config.config.put(type.asSymbol, address.asString);
- hub.setupNetAddressesFromConfig(config.config);
+ this.setupNetAddressesFromConfig(config.config);
});
},
path: "/address",
- srcID: hub.local
+ srcID: localAddr
);
// listen for port messages to change OSC ports
@@ -205,11 +203,11 @@ Bowelyzer{
postln("Received: "++msg);
if(type.notNil && config.config.includesKey(type),{
config.config.put(type.asSymbol, port.asInteger);
- hub.setupNetAddressesFromConfig(config.config);
+ this.setupNetAddressesFromConfig(config.config);
});
},
path: "/port",
- srcID: hub.local
+ srcID: localAddr
);
// listen for message to save configuration to current file
@@ -225,7 +223,7 @@ Bowelyzer{
});
},
path: "/save",
- srcID: hub.local
+ srcID: localAddr
);
// listen for message to save configuration to current file
@@ -248,7 +246,7 @@ Bowelyzer{
});
},
path: "/saveas",
- srcID: hub.local
+ srcID: localAddr
);
// listen for messages to load configuration from file
@@ -264,15 +262,15 @@ Bowelyzer{
});
// read the configuration file
if(config.readConfigurationFile(fileName),{
- hub.setupNetAddressesFromConfig(config.config);
- hub.setupSynthListenersFromConfig(config.config);
+ this.setupNetAddressesFromConfig(config.config);
+ this.setupSynthListenersFromConfig(config.config);
analyzer.setupSynthsFromConfig(config.config);
config.config.at(\inputs).keysDo({ |name|
gui.setupChannelView(name, config.config);
// setup a LevelListener for the new Synth
- this.setupLevelListener(name, hub.synthServer);
+ this.setupLevelListener(name, synthServerAddr);
// setup a OSC listener for the Synth by name
- hub.addSynthListener(name);
+ this.addSynthListener(name);
});
// reload the addresses and ports Views
gui.removeSettingsView("synthServer");
@@ -288,7 +286,7 @@ Bowelyzer{
});
},
path: "/load",
- srcID: hub.local
+ srcID: localAddr
);
// listen for messages to free (close) channels
@@ -323,7 +321,7 @@ Bowelyzer{
this.setupIndicatorListener;
// add and start a listener for each channel's LevelIndicator
config.config.at(\inputs).pairsDo({|key,value|
- this.setupLevelListener(key, hub.synthServer);
+ this.setupLevelListener(key, synthServerAddr);
});
}
@@ -379,9 +377,9 @@ Bowelyzer{
analyzer.startSynthWithNameAndControls(name, config.config.at(\controls).at(name), config.config.at(\inputs).at(name));
}.play;
// setup a LevelListener for the new Synth
- this.setupLevelListener(name, hub.synthServer);
+ this.setupLevelListener(name, synthServerAddr);
// setup a OSC listener for the Synth by name
- hub.addSynthListener(name);
+ this.addSynthListener(name);
}
// free (remove) a channel
@@ -410,4 +408,74 @@ Bowelyzer{
gui.removeChannelView(name, config.config.at(\inputs).size);
}
+ // setup the NetAddresses from configuration
+ setupNetAddressesFromConfig{
+ arg config;
+ forwardAddr = NetAddr.new(config.at(\forwardAddress), config.at(\forwardPort));
+ hubAddr = NetAddr.new(config.at(\hubAddress), config.at(\hubPort));
+ synthServerAddr = NetAddr.new(config.at(\synthServerAddress), config.at(\synthServerPort));
+ localAddr = 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 "++synthServerAddr.ip++":"++synthServerAddr.port++".");
+ this.addSynthListener(name);
+ });
+ }
+
+ // add a listener for a specific Synth (by name)
+ addSynthListener{
+ arg name;
+ OSCdef.newMatching(
+ key: name.asSymbol,
+ func: {|msg, time, addr, recvPort|
+ this.forwardToNetAddress(msg, time);
+ },
+ path: "/"++name.asString,
+ srcID: synthServerAddr,
+ recvPort: hubAddr.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[6],
+ range = config.config.at(\controls).at(name.asString.replace("/","").asSymbol).at(\freqRange);
+ // if there is something connected
+ if(amplitude != 0,{
+ // if the pitch is within freqRange
+ if((pitch >= range[0]) && (pitch <= range[1]),{
+ localAddr.sendMsg("/indicate", name.asString.replace("/","").asSymbol);
+ if(forwardAddr.isLocal && (forwardAddr.port == NetAddr.langPort), {
+ postln(name++": amplitude: "++amplitude++"; pitch: "++pitch++"; hasPitch: "++hasPitch++"; onSet: "++onsetDetect);
+ },{
+ forwardAddr.sendMsg(name, amplitude, pitch, hasPitch, onsetDetect);
+ });
+ });
+ });
+ }
}