aboutsummaryrefslogtreecommitdiffstats
path: root/BowelyzerOSCHub.sc
blob: a2ec888279f3e7fd04458cc20f39a80cc5e3044d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
BowelyzerOSCHub{
  var <hub, <forward, <synthServer, <synthServerListener;

  *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.addAnalysisListener(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"));
  }

// setup a new listener for SynthServerAddress:SynthServerPort
  addAnalysisListener{
    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]);
          });
        },
        '/'++name.asSymbol,
        synthServer,
        hub.port
      );
    });
  }

  //TODO: add functions to modify OSC listener behavior

}