def nameTrackCB(self, msg, source): """Called when a /live/name/track message is received. Messages: /live/name/track Returns a a series of all the track names in the form /live/name/track (int track, string name) /live/name/track (int track) Returns a single track's name in the form /live/name/track (int track, string name) /live/name/track (int track, string name)Sets track number track's name to name """ #Requesting all track names if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"): trackNumber = 0 bundle = OSC.OSCBundle() for track in LiveUtils.getTracks(): bundle.append("/live/name/track", (trackNumber, str(track.name))) trackNumber = trackNumber + 1 self.oscEndpoint.sendMessage(bundle) return #Requesting a single track name if len(msg) == 3: trackNumber = msg[2] self.oscEndpoint.send( "/live/name/track", (trackNumber, str(LiveUtils.getTrack(trackNumber).name))) return #renaming a track if len(msg) == 4: trackNumber = msg[2] name = msg[3] LiveUtils.getTrack(trackNumber).name = name
def nameSceneCB(self, msg, source): """Called when a /live/name/scene message is received. Messages: /live/name/scene Returns a a series of all the scene names in the form /live/name/scene (int scene, string name) /live/name/scene (int scene) Returns a single scene's name in the form /live/name/scene (int scene, string name) /live/name/scene (int scene, string name)Sets scene number scene's name to name """ #Requesting all scene names if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"): bundle = OSC.OSCBundle() sceneNumber = 0 for scene in LiveUtils.getScenes(): bundle.append("/live/name/scene", (sceneNumber, str(scene.name))) sceneNumber = sceneNumber + 1 self.oscEndpoint.sendMessage(bundle) return #Requesting a single scene name if len(msg) == 3: sceneNumber = msg[2] self.oscEndpoint.send( "/live/name/scene", (sceneNumber, str(LiveUtils.getScene(sceneNumber).name))) return #renaming a scene if len(msg) == 4: sceneNumber = msg[2] name = msg[3] LiveUtils.getScene(sceneNumber).name = name
def refresh_state(self): self.add_clip_listeners() self.add_mixer_listeners() self.add_scene_listeners() self.add_tempo_listener() self.add_overdub_listener() self.add_tracks_listener() self.add_device_listeners() self.add_transport_listener() trackNumber = 0 clipNumber = 0 for track in self.song().visible_tracks: bundle = OSC.OSCBundle() bundle.append("/live/name/track", (trackNumber, str(track.name))) for clipSlot in track.clip_slots: if clipSlot.clip != None: bundle.append("/live/name/clip", (trackNumber, clipNumber, str(clipSlot.clip.name), clipSlot.clip.color)) clipNumber = clipNumber + 1 clipNumber = 0 trackNumber = trackNumber + 1 self.oscEndpoint.sendMessage(bundle) self.trBlock(0, len(self.song().visible_tracks))
def send_notes(self): bundle=OSC.OSCBundle() for i in range(0,5): msg = OSC.OSCMessage("/skald/%s"%i) msg.append(self.data[i]) bundle.append(msg) self.client.send(bundle)
def send(self, what, when=None): """ Send an OSC message for the given event. If when is None, will use time.time() """ if when is None: when = time.time() addr = '/event/' + what msg = OSC.OSCMessage(addr) bundle = OSC.OSCBundle(addr, when) bundle.append(msg) self.client.send(bundle)
def on_message(client, userdata, msg): bundle = OSC.OSCBundle() oscmsg = OSC.OSCMessage() # print(msg) parsedMsg = json.loads(msg.payload) # print(parsedMsg) # print(parsedMsg.values()) sensorName = str(parsedMsg.keys()) id = sensorName[9:10] # print("test%d" % int(id)) oscmsg.setAddress('{"/Sensor%d"}' % int(id)) oscmsg.append(parsedMsg.values()) print(oscmsg) osc_client.send(oscmsg)
def nameClipCB(self, msg, source): """Called when a /live/name/clip message is received. Messages: /live/name/clip Returns a a series of all the clip names in the form /live/name/clip (int track, int clip, string name) /live/name/clip (int track, int clip) Returns a single clip's name in the form /live/name/clip (int clip, string name) /live/name/clip (int track, int clip, string name)Sets clip number clip in track number track's name to name """ #Requesting all clip names if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"): trackNumber = 0 clipNumber = 0 for track in LiveUtils.getTracks(): bundle = OSC.OSCBundle() for clipSlot in track.clip_slots: if clipSlot.clip != None: bundle.append( "/live/name/clip", (trackNumber, clipNumber, str( clipSlot.clip.name), clipSlot.clip.color)) clipNumber = clipNumber + 1 self.oscEndpoint.sendMessage(bundle) clipNumber = 0 trackNumber = trackNumber + 1 self.oscEndpoint.send("/live/name/clip/done", "bundle sended") return #Requesting a single clip name if len(msg) == 4: trackNumber = msg[2] clipNumber = msg[3] self.oscEndpoint.send( "/live/name/clip", (trackNumber, clipNumber, str(LiveUtils.getClip(trackNumber, clipNumber).name), LiveUtils.getClip(trackNumber, clipNumber).color)) return #renaming a clip if len(msg) >= 5: trackNumber = msg[2] clipNumber = msg[3] name = msg[4] LiveUtils.getClip(trackNumber, clipNumber).name = name if len(msg) >= 6: trackNumber = msg[2] clipNumber = msg[3] color = msg[5] LiveUtils.getClip(trackNumber, clipNumber).color = color
def scanSongTracks(self, songID): trackNumber = 0 bundle = OSC.OSCBundle() bundle.append(OSC.OSCMessage("/song/" + songID + "/layout/start")) for track in LiveUtils.getTracks(): trackType = 'MIDI' if track.has_midi_input else 'Audio' bundle.append( OSC.OSCMessage("/song/" + songID + "/track/", (trackNumber, str(track.name), str(trackType)))) trackNumber = trackNumber + 1 bundle.append(OSC.OSCMessage("/song/" + songID + "/layout/end")) self.oscEndpoint.sendMessage(bundle) return
def scanTracks(self, msg, source): #/tracks Returns a a series of all the track names in the form /track/name (int track, string name) trackNumber = 0 bundle = OSC.OSCBundle() layoutID = self.makeID() bundle.append(OSC.OSCMessage("/layout/" + layoutID + "/start")) for track in LiveUtils.getTracks(): trackType = 'MIDI' if track.has_midi_input else 'Audio' bundle.append( OSC.OSCMessage("/track/" + layoutID, (trackNumber, str(track.name), str(trackType)))) trackNumber = trackNumber + 1 bundle.append(OSC.OSCMessage("/layout/" + layoutID + "/end")) self.oscEndpoint.sendMessage(bundle) return
def getNotesCB(self, msg, source): """Called when a /live/clip/notes message is received Messages: /live/clip/notes Return all notes in the clip in /live/clip/note messages. Each note is sent in the format (int trackNumber) (int clipNumber) (int pitch) (double time) (double duration) (int velocity) (int muted) """ trackNumber = msg[2] clipNumber = msg[3] LiveUtils.getClip(trackNumber, clipNumber).select_all_notes() bundle = OSC.OSCBundle() for note in LiveUtils.getClip(trackNumber, clipNumber).get_selected_notes(): pitch = note[0] time = note[1] duration = note[2] velocity = note[3] muted = 0 if note[4]: muted = 1 bundle.append('/live/clip/note', (trackNumber, clipNumber, pitch, time, duration, velocity, muted)) self.oscEndpoint.sendMessage(bundle)
def scanSceneClips(self, msg, source): scene = LiveUtils.getScene(int(msg[2])) oscEndpoint.sendMessage(OSC.OSCMessage("/clips/start")) slotNumber = 0 for slot in scene.clip_slots: clipBundle = OSC.OSCBundle() clip = slot.clip scanID = CLIP_IDENTIFIER + self.makeID() if clip is None: # if there's no control clip in this slot let's add one if slotNumber == 0: slot.create_clip(32.0) slot.clip.name = "<!LC>" + scanID clip = slot.clip if clip is not None: clipBundle.append(OSC.OSCMessage("/clip/start")) if (clip.name.find(CLIP_IDENTIFIER) == -1): clip.name = clip.name + scanID warping = True if clip.is_midi_clip else clip.warping arguments = (slotNumber, str(clip.name), int(clip.length), str(warping), str(clip.looping), int(clip.loop_start), int(clip.loop_end), int(clip.signature_numerator), int(clip.signature_denominator)) clipBundle.append(OSC.OSCMessage("/clip", arguments)) clipBundle.append(OSC.OSCMessage("/clip/end")) oscEndpoint.sendMessage(clipBundle) foundClip = True slotNumber = slotNumber + 1 oscEndpoint.sendMessage(OSC.OSCMessage("/clips/end")) #self.oscEndpoint.send(clipBundle) return # proof of concept to duplicate scenes and move them into separate scenes """i = 0
def main(self): """ Main loop """ while 1: if self.dataReady("control"): msg = self.recv("control") if (isinstance(msg, producerFinished) or isinstance(cmsg, shutdownMicroprocess)): self.send(msg, "signal") break while self.dataReady("inbox"): data = self.recv("inbox") if self.index: msgTuple = data[self.index] else: msgTuple = data address = msgTuple[0] arguments = msgTuple[1] if len(msgTuple) > 2: timetag = msgTuple[3] else: timetag = 0 # Prepend forward slash to address if address[0] != "/": address = "/" + address if self.addressPrefix: address = self.addressPrefix + address bundle = OSC.OSCBundle(address, timetag) bundle.append(arguments) if self.index: data = list(data) data[self.index] = bundle.getBinary() self.send(data, "outbox") else: self.send(bundle.getBinary(), "outbox") self.pause() yield 1
def bundle(self): return OSC.OSCBundle()
def osc_bnd_send(self,oscmsgs): oscbnd = OSC.OSCBundle() for oscmsg in oscmsgs: oscbnd.append(oscmsg) self.client.send(oscbnd)
def oscSendMsg(client, msg): bundle = OSC.OSCBundle() bundle.append({'addr': '/schedRequest', 'args': msg}) client.send(bundle)
class tuioServerClass(object): # alive point vars alivePointCount = 0 # the cursor buffer cursorBuffer = two2dCurBuffer() # bundles for TUIO messages, one for cursors, one for objects twoDcurBundle = OSC.OSCBundle() twoDobjBundle = OSC.OSCBundle() # connect the tangibles container function getAllCursorsInBuffer with buffer tangibles.registerCursorProvider(cursorBuffer.getCursors) # function to start the TUIO server def start(self): print "Starting OSC server" # setup ips and ports receiveAddress = settings.get('receiveAddress') receivePort = settings.get('receivePort') sendAddress = settings.get('sendAddress') sendPort = settings.get('sendPort') receive_settings = receiveAddress, receivePort send_settings = sendAddress, sendPort # declare server and client self.oscServer = OSC.OSCServer(receive_settings) self.oscClient = OSC.OSCClient() self.oscClient.connect(send_settings) # declare message handler self.oscServer.addMsgHandler("/tuio/2Dobj", self.twoDobj_handler) self.oscServer.addMsgHandler("/tuio/2Dcur", self.twoDcur_handler) # start server thread self.oscServerThread = threading.Thread( target = self.oscServer.serve_forever ) self.oscServerThread.start() # function to stop the TUIO server def stop(self): print "Stopping OSC server" self.oscServer.close() print "Waiting for server thread to finish" self.oscServerThread.join() # function that is called when a message with "/tuio/2Dobj" is received def twoDobj_handler(self, addr, tags, payload, source): messageType = payload[0] if messageType == 'alive': #print "2Dobj ALIVE", tags, payload[1:] pass elif messageType == 'set': #print "2Dobj SET" pass elif messageType == 'fseq': #print "2Dobj FSEQ" pass # function that is called when a message with "/tuio/2Dcur" is received def twoDcur_handler(self,addr, tags, payload, source): #print "A" messageType = payload[0] if messageType == 'alive': #start stopwatch #stopwatch.start() # save number of alive points self.alivePointCount = tags.count('i') # delete non alive point from cursor buffer cursorIDs = payload[1:] self.cursorBuffer.cleanNonAliveCursors(cursorIDs) elif messageType == 'set': # set 2Dcur in 2Dcur buffer self.cursorBuffer.setCursor(id = payload[1], x = payload[2]*settings.get('touchScreenAspect'), xRaw = payload[2],y = payload[3], vX = payload[4], vY = payload[5], mA = payload[6]) #print "B" elif messageType == 'fseq': #check number of alive points if self.alivePointCount < 3: # create 2Dcur bundle with the points in the buffer self.addAliveIDsTo2DcurBundle() self.addCursorsTo2DcurBundle() self.addFseqTo2DcurBundle() # send 2Dcur bundle self.send2DcurBundle() # create empty 2Dobj message bundle self.addEmptyAliveTo2DobjBundle() self.addFseqTo2DobjBundle() # send 2Dobj bundle self.send2DobjBundle() #stopwatch.stop() #stopwatch.getAverage() else: cursorsOnScreen = self.cursorBuffer.getCursors() # compare registered tangible triangles with triangles created at the moment # calculate tangible postions and rotations tangibles.checkForKnownTriangles(cursorsOnScreen) # remove points belonging to recognized tangibles from 2Dcur buffer if (settings.get('tangibleCursorFilter') == 'on'): self.cursorBuffer.removeCursorsWithIDs(tangibles.getRecognizedCursors()) # remove cursors that could be created by fingers touching the tangible if (settings.get('realFingerFilter') == 'on'): self.removeRealFingersAroundTangibles() # create 2Dcur bundle with the points in the buffer self.addAliveIDsTo2DcurBundle() self.addCursorsTo2DcurBundle() self.addFseqTo2DcurBundle() # send 2Dcur bundle self.send2DcurBundle() # create 2Dobj message bundle with all tangibles self.addAliveIDsTo2DobjBundle() self.addObjectsTo2DobjBundle() self.addFseqTo2DobjBundle() # send 2Dobj bundle self.send2DobjBundle() #print "H" #stopwatch.stop() #stopwatch.getAverage() # function to remove all cursors in a circle around the tangible def removeRealFingersAroundTangibles(self): radius = settings.get('realFingerFilterRadius') aspectCorrectionFactor = settings.get('touchScreenAspect') cursorsToDelete = [] for tan in tangibles.getRecognizedTangibles(): #get tangible position centerX = tan.position.x /aspectCorrectionFactor centerY = tan.position.y # check for all cursors in the 2DCur buffer if they are in a circle around the tangible center for cursor in self.cursorBuffer.getCursors(): pointX = cursor.x /aspectCorrectionFactor pointY = cursor.y if isPointInCircle(centerX, centerY, radius, pointX, pointY, aspectCorrectionFactor): cursorsToDelete.append(cursor.id) self.cursorBuffer.removeCursorsWithIDs(cursorsToDelete) # function to add an initial alive message to the cursor bundle def addAliveIDsTo2DcurBundle(self): message = OSC.OSCMessage() message.setAddress("/tuio/2Dcur") message.append('alive') for id in self.cursorBuffer.getCursorIDs(): message.append(id) self.twoDcurBundle.append(message) # function to add all cursors in the buffer to the cursor bundle def addCursorsTo2DcurBundle(self): # load the aspect correction to set the TUIO cursor x values back to a range between 0 and 1 aspectCorrectionFactor = settings.get('touchScreenAspect') for cursor in self.cursorBuffer.getCursors(): message = OSC.OSCMessage() message.setAddress("/tuio/2Dcur") message.append('set') message.append(cursor.id) message.append(cursor.x / aspectCorrectionFactor) message.append(cursor.y) message.append(cursor.vX) message.append(cursor.vY) message.append(cursor.mA) self.twoDcurBundle.append(message) # function to add a seqence message to the cursor bundle def addFseqTo2DcurBundle(self): message = OSC.OSCMessage() message.setAddress("/tuio/2Dcur") message.append('fseq') message.append(numberGenerator.newFseq()) self.twoDcurBundle.append(message) # function to send the bundle of TUIO cursor messages over OSC def send2DcurBundle(self): self.oscClient.send(self.twoDcurBundle) self.twoDcurBundle = OSC.OSCBundle() # function to add an initial alive message to the object bundle def addAliveIDsTo2DobjBundle(self): message = OSC.OSCMessage() message.setAddress("/tuio/2Dobj") message.append('alive') for id in tangibles.getRecognizedTangibleIDs(): message.append(id) self.twoDobjBundle.append(message) # function to create an empty 2d object bundle header def addEmptyAliveTo2DobjBundle(self): message = OSC.OSCMessage() message.setAddress("/tuio/2Dobj") message.append('alive') self.twoDobjBundle.append(message) # function to add all recognized objects in the buffer to the object bundle def addObjectsTo2DobjBundle(self): # load the aspect correction to set the TUIO cursor x values back to a range between 0 and 1 aspectCorrectionFactor = settings.get('touchScreenAspect') for tan in tangibles.getRecognizedTangibles(): message = OSC.OSCMessage() message.setAddress("/tuio/2Dobj") message.append('set') message.append(tan.id) #s,id message.append(tan.id) #marker Id message.append(tan.position.x / aspectCorrectionFactor) #x message.append(tan.position.y) #y message.append(tan.rotation) #angle in radiant message.append(0.0) #vX message.append(0.0) #vY message.append(0.0) #vA message.append(0.0) #m message.append(0.0) #rotation acceleration self.twoDobjBundle.append(message) # function to add a seqence message to the object bundle def addFseqTo2DobjBundle(self): message = OSC.OSCMessage() message.setAddress("/tuio/2Dobj") message.append('fseq') message.append(numberGenerator.newFseq()) self.twoDobjBundle.append(message) # function to send the bundle of TUIO object messages over OSC def send2DobjBundle(self): self.oscClient.send(self.twoDobjBundle) self.twoDobjBundle = OSC.OSCBundle() # function to return all cursors curently in the 2D cursor buffer def getAllCursorsInBuffer(self): return self.cursorBuffer.values()
midiList = formMidiList() zerotime = time() mytime = 0.0 client = OSC.OSCClient() # connect to OSCmidi.py client.connect( ('127.0.0.1', 9002)) # argument is a tupple and not two arguments midiEvents = midiList.events while mytime < timeScale * 76.0: try: bundle = OSC.OSCBundle() # Bundle all events that have occurred mylist = midiEvents for iEvent, l in enumerate(mylist): if (timeScale * (float(l[4]) / 1000.0)) < mytime: velocity = 0 #vel[2] deltav = 0 deltaf = 0.1 * deltav #change in frequency for normalization fade = 0.5 #left/right pan paramter 0 is left, 1 is right if (l[5] == 1):
def osc_send_msg(client, addr, msg): bundle = OSC.OSCBundle() bundle.append({'addr': addr, 'args': msg}) client.send(bundle) print('-----> OSC out: ' + addr + ' ' + msg)
def sendPeerList(self, address, port): # FIXME: Ugly - manual creation of OSC bundle = not very Kamaelia-ific # Better to have a pipeline here with the OSC component in bundle = OSC.OSCBundle("/Jam/PeerList", 0) bundle.append(list(self.peers)) self.send(bundle.getBinary(), "outbox_%s_%s" % (address, port))
def main(): (options, args) = setup() context = zmq.Context() # subscribe to fwdr logging.debug("Connecting to fwdr...%s:%d" % (options.server, options.port)) socket = context.socket(zmq.SUB) socket.hwm = 10 socket.connect("tcp://%s:%d" % (options.server, options.port)) # Subscribe to limited msgs or empty string for all msgs filter = '' socket.setsockopt(zmq.SUBSCRIBE, filter) try: c.connect(('127.0.0.1', 57120)) except: raise if options.test: note = 30 inst = 4 track = 0 velocity = 64 txt = 'startup note_on:', inst, track, note, velocity logging.info(txt) noteon(inst, track, note, velocity) time.sleep(2) txt = 'startup note_off:', inst, track, note, velocity logging.info(txt) noteoff(inst, track, note) # using OSCBundle is more natural, just get timeTags to work # bundle = OSC.OSCBundle() # oscmsg = OSC.OSCMessage(address='/renoise/trigger/note_off') # oscmsg.append([inst, track, note]) # bundle.append(oscmsg) # bundle.setTimeTag(time.time()+3) # c.send(bundle) # bundle.clearData() # Process each msg rate = 50 note = 60 thisnote = 60 inst = 0 track = 1 velocity = 127 logging.debug('Entering socket loop') while True: # if content is parsable as json then the content is converted # to a python object via json.loads, hopefully a dict # if not parsable the a dict is created with key 'content' try: content = socket.recv() msg = json.loads(content) except ValueError: msg = {'content': content} except KeyboardInterrupt: logging.info("Keyboard interrupt, closing OSCClient") oscmsg = OSC.OSCMessage(address='/renoise/transport/panic') c.send(oscmsg) c.close() return 1 except KeyError: pass except: logging.error(content) raise logging.debug("RAW: %s" % content) logging.debug(msg) if options.test: # send a ping on every incoming msg note = 60 inst = 1 oscmsg = OSC.OSCMessage(address='/renoise/trigger/note_on') oscmsg.append([inst, track, note, 127]) c.send(oscmsg) logging.info(oscmsg) oscmsg.clearData() continue if options.ping: if 'PING' in msg.get('content', ''): # send a ping on select msgs note = 40 inst = 1 oscmsg = OSC.OSCMessage(address='/renoise/trigger/note_on') oscmsg.append([inst, track, note, 127]) logging.info(oscmsg) if options.muteosc: continue c.send(oscmsg) oscmsg.clearData() continue else: continue if options.debug: pass if 'meter' in msg.get('tags', []): rate = msg.get('events.rate_1m', rate) # bundle = OSC.OSCBundle() oscmsg = OSC.OSCMessage() previousnote = thisnote thisnote = int(rate) + 20 meterinst = 7 metertrack = 2 velocity = 64 oscmsg = OSC.OSCMessage(address='/renoise/trigger/note_off') oscmsg.append([meterinst, metertrack, previousnote]) bundle.append(oscmsg) oscmsg = OSC.OSCMessage(address='/renoise/trigger/note_on') oscmsg.append([meterinst, metertrack, thisnote, velocity]) bundle.append(oscmsg) if 'meter' in args: txt = 'RATE:', rate, meterinst, metertrack, thisnote, velocity logging.info(txt) if not options.muteosc: c.send(bundle) bundle.clearData() # demo has these instruments: # 1. dh_perc_click_signal # 2. ech_perc_vinyltriangle # 3. dh_perc_nu_dropdown # 4. Pad - VP - 330 Stringer # 5. dh_perc_shake_chimes # 6. Noise - Turbine (Instr./Elements) # 7. Noise - 100Hz # 8. # 9. Pad - Mind War #10. dh_kick_sub_pitchy # track assignment is: # 0. testing # 1. apache # 2. meter if msg.get('type', None) == 'apache': if msg['response'] in ['200']: note = max(0, int(rate)) note = random.randint(50, 60) note = 50 inst = 1 velocity = 32 if '200' in args: txt = '200:', inst, track, note, velocity logging.info(txt) noteon(inst, track, note, velocity) elif msg['response'] in ['201']: note = max(10, int(rate) - 40) note = random.randint(25, 35) note = 30 inst = 2 velocity = 16 if '201' in args: txt = '201:', inst, track, note, velocity logging.info(txt) noteon(inst, track, note, velocity) elif msg['response'] in ['404', '400']: note = 40 note = random.randint(40, 55) inst = 10 velocity = 96 if '4xx' in args: txt = '404:', inst, track, note, velocity, msg[ 'request'], msg['clientip'] logging.info(txt) noteon(inst, track, note, velocity) elif msg['response'] in ['500']: logging.info(msg) note = 40 inst = 3 velocity = 127 if '5xx' in args: txt = '500:', inst, track, note, velocity logging.info(txt) noteon(inst, track, note, velocity) else: txt = 'unhandled', msg['response'] logging.warn(txt) logging.debug(msg) continue
def playOSC(self, path, panning, amp): bundle = OSC.OSCBundle() bundle.setAddress("playsound") bundle.append((path, panning[0], panning[1], panning[2], panning[3], amp)) self.client.send(bundle)
c = OSC.OSCClient() c.connect( send_address ) # set the address for all following messages # single message msg = OSC.OSCMessage() msg.setAddress("/print") # set OSC address msg.append(44) # int msg.append(4.5233) # float msg.append( "the white cliffs of dover" ) # string c.send(msg) # send it! # bundle : few messages sent together # use them to send many different messages on every loop for instance in a game. saves CPU and it is faster bundle = OSC.OSCBundle() bundle.append(msg) # append prev mgs bundle.append( {'addr':"/print", 'args':["bundled messages:", 2]} ) # and some more stuff ... bundle.setAddress("/*print") bundle.append( ("no,", 3, "actually.") ) c.send(bundle) # send it! # lets try sending a different random number every frame in a loop try : seed = random.Random() # need to seed first while 1: # endless loop rNum= OSC.OSCMessage()
def scanScenes(self, songID): #cycle through the scenes for IDs sceneNumber = 0 self.sceneScanLengths = {} sceneIDs = [] #songID = makeID() self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/start/")) tempo = LiveUtils.getTempo() self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/tempo/", float(tempo))) numerator = LiveUtils.getNumerator() self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/numerator/", int(numerator))) denominator = LiveUtils.getDenominator() self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/denominator/", int(denominator))) #sceneBundle.append(OSC.OSCMessage("/scenes/start")) for scene in LiveUtils.getScenes(): sceneArgs = {} sceneBundle = OSC.OSCBundle() sceneID = re.findall("(\#cS.{8})", scene.name) if (not sceneID): sceneID = SCENE_IDENTIFIER + self.makeID() sceneName = scene.name scene.name = scene.name + sceneID else: #sceneID = scene.name[idIndex:] try: usedAlready = sceneIDs.index(sceneID) except ValueError: usedAlready = -1 if usedAlready != -1: sceneID = SCENE_IDENTIFIER + self.makeID() sceneName = scene.name[:usedAlready] scene.name = sceneName + newID self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/scene/" + sceneID + "/start/")) sceneIDs.append(sceneID) length, signature_numerator, signature_denominator = self.findLongestClip( sceneNumber) sceneSignature = re.findall("\d+\/\d+", scene.name) if (sceneSignature): separator = sceneSignature[0].find('/') signature_numerator = int(sceneSignature[0][:separator]) separator += 1 signature_denominator = int(sceneSignature[0][separator:]) #log(signature_denominator) self.sceneScanLengths[sceneNumber] = { 'length': length, 'signature_numerator': signature_numerator, 'signature_denominator': signature_denominator } sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/abletonIndex/", int(sceneNumber))) sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/name/", str(scene.name))) sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/tempo/", float(scene.tempo))) sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/length/", float(length))) sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/numerator/", int(signature_numerator))) sceneBundle.append( OSC.OSCMessage( "/song/" + songID + "/scene/" + sceneID + "/denominator/", int(signature_denominator))) self.oscEndpoint.sendMessage(sceneBundle) self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/scene/" + sceneID + "/end/")) sceneNumber += 1 self.oscEndpoint.sendMessage( OSC.OSCMessage("/song/" + songID + "/end/")) return
def send2DobjBundle(self): self.oscClient.send(self.twoDobjBundle) self.twoDobjBundle = OSC.OSCBundle()