import pubsub # load config with open(COMMON_PATH + "settings.json", "r") as f: SETTINGS = json.load(f) subscribernames = ["nervebox"] def recvCallback(topic, msg): print repr(topic), ":", repr(msg) def netStateCallback(hostname, connected): print "netStateCallback", hostname, connected callerSend.setServerFound(connected) def handleSubscriberFound(msg): pubsub_api["subscribe"](msg["hostname"], msg["ip"], SETTINGS["pubsub_pubPort"], ("__heartbeat__")) pubsub_api = pubsub.init(subscribernames, HOSTNAME, SETTINGS["pubsub_pubPort"], recvCallback, netStateCallback) callerSend = discovery.init_caller( SETTINGS["discovery_multicastGroup"], SETTINGS["discovery_multicastPort"], SETTINGS["discovery_responsePort"], handleSubscriberFound, )
callerSend.setServerFound(connected) def serverFoundCallback(msg): pubsub_api["subscribe"](msg["hostname"],msg["ip"],SETTINGS["pubsub_pubPort"], ("__heartbeat__","osc")) pubsub_api = pubsub.init( subscribernames, HOSTNAME, SETTINGS["pubsub_pubPort"], recvCallback, netStateCallback ) callerSend = discovery.init_caller( SETTINGS["discovery_multicastGroup"], SETTINGS["discovery_multicastPort"], SETTINGS["discovery_responsePort"], serverFoundCallback ) ############################### ##### VITUAL MIDI DEVICES ##### ############################### deviceNames = filter(lambda x: os.path.isdir(os.path.join(DEVICES_PATH, x)), os.listdir(DEVICES_PATH)) statusMap = { 128:"note_off", 144:"note_on", 160:"polyphonic_aftertouch", 176:"control_change",