def note_handler(addr, note, velocity, chan): harmnote = 0 if vhWrap.playChannels[chan - 1]: while harmnote > -999: if velocity > 0: harmnote, fracinstr = vhWrap.vectorHarmonizeMidiNote( note, chan, 0) else: pass harmnote, fracinstr = vhWrap.vectorHarmonizeMidiNoteOff( note, chan) if harmnote > -999: returnmsg = [harmnote, velocity, chan, fracinstr] msg = oscbuildparse.OSCMessage("/vectorHarmonizerReturnNote", None, returnmsg) osc_send(msg, "vectorHarmClient") if vhWrap.vectorHarmonizeAutoVoiceRange: low, high = vhWrap.getVectorHarmonizeVoiceRange() rangemsg = [low, high] msg = oscbuildparse.OSCMessage( "/vectorHarmonizerControlReturn/range", None, rangemsg) osc_send(msg, "vectorHarmClient") if vhWrap.recordChannels[chan - 1] and velocity > 0: vector = vhWrap.recordIntervalVector(note) if vector != None: msg = oscbuildparse.OSCMessage( "/vectorHarmonizerControlReturn/vector", None, vector) osc_send(msg, "vectorHarmClient")
def buttonNetworkClicked(self): def handlerfunction(x): print("get cmd: " + x) sender = self.sender() self.statusBar().showMessage(sender.text() + ' pressed') # # send out START command as a bundle msg1 = oscbuildparse.OSCMessage("/pc1/cmd/control/ruthere", None, ["1111"]) msg2 = oscbuildparse.OSCMessage("/pc2/cmd/control/ruthere", None, ["1111"]) msg3 = oscbuildparse.OSCMessage("/pc3/cmd/control/ruthere", None, ["1111"]) msg4 = oscbuildparse.OSCMessage("/pc4/cmd/control/ruthere", None, ["1111"]) bun = oscbuildparse.OSCBundle(oscbuildparse.OSC_IMMEDIATELY, [msg1, msg2, msg3, msg4]) osc_send(bun, "oscclient") # receive echo back osc_process() osc_method("/pc1/cmd/control/ruthere", handlerfunction) osc_process()
def send(path, *argv): msg = None if len(argv): msg = oscbuildparse.OSCMessage(path, *argv) else: msg = oscbuildparse.OSCMessage(path, None, []) osc_send(msg, "ardour")
def detected_callback(): pygame.mixer.init() #1 osc_method("/state_receive", handlerfunction) state = osc_message msg = oscbuildparse.OSCMessage("/event_state", None, [state]) osc_send(msg, "input_state") osc_process() pygame.mixer.music.load(filename1) mp3_length = mp3(filename1).info.length pygame.mixer.music.play(1) sleep(mp3_length + 0.25) pygame.mixer.music.stop() #2 osc_method("/state_receive", handlerfunction) state = osc_message msg = oscbuildparse.OSCMessage("/event_state", None, [state]) osc_send(msg, "input_state") osc_process() pygame.mixer.music.load(filename2) mp3_length = mp3(filename2).info.length pygame.mixer.music.play(1) sleep(mp3_length + 0.25) pygame.mixer.music.stop() #3 osc_method("/state_receive", handlerfunction) state = osc_message msg = oscbuildparse.OSCMessage("/event_state", None, [state]) osc_send(msg, "input_state") osc_process() pygame.mixer.music.load(filename3) mp3_length = mp3(filename3).info.length pygame.mixer.music.play(1) sleep(mp3_length + 0.25) pygame.mixer.music.stop() #4 osc_method("/state_receive", handlerfunction) state = osc_message msg = oscbuildparse.OSCMessage("/event_state", None, [state]) osc_send(msg, "input_state") osc_process() pygame.mixer.music.load(filename4) mp3_length = mp3(filename4).info.length pygame.mixer.music.play(1) sleep(mp3_length + 0.25) pygame.mixer.music.stop()
def pass_emotion_to_client(self, uid, age, isMale): print( "EmotionCommunicator.pass_demographic_to_client() -> age: {0}, gender(isMale): {1}" .format(age, isMale)) if isMale: msg = oscbuildparse.OSCMessage("/control/demographic", ",ifT", [uid, age, True]) else: msg = oscbuildparse.OSCMessage("/control/demographic", ",ifF", [uid, age, False]) osc_send(msg, "demographicclient")
def main(sample_rate, device_name): # See http://g.co/cloud/speech/docs/languages # for a list of supported languages. language_code = 'en-US' # a BCP-47 language tag client = speech.SpeechClient() config = types.RecognitionConfig( encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=sample_rate, language_code=language_code, max_alternatives=1, enable_word_time_offsets=True) streaming_config = types.StreamingRecognitionConfig(config=config, interim_results=True) mic_manager = ResumableMicrophoneStream(sample_rate, int(sample_rate / 10), device_name, max_replay_secs=5) osc_startup() osc_udp_client('127.0.0.1', 2781, 'python-speech-to-text') msg = oscbuildparse.OSCMessage('/start', None, oscbuildparse.OSCbang()) osc_send(msg, 'python-speech-to-text') osc_process() with mic_manager as stream: resume = False while True: audio_generator = stream.generator(resume=resume) requests = (types.StreamingRecognizeRequest(audio_content=content) for content in audio_generator) responses = client.streaming_recognize(streaming_config, requests) try: # Now, put the transcription responses to use. listen_print_loop(responses, stream) # Teardown code should be executed here msg = oscbuildparse.OSCMessage('/stop', None, oscbuildparse.OSCbang()) osc_send(msg, 'python-speech-to-text') osc_process() osc_terminate() break except (exceptions.OutOfRange, exceptions.InvalidArgument) as e: if not ('maximum allowed stream duration' in e.message or 'deadline too short' in e.message): raise print('Resuming...') resume = True
def pass_decision_to_client(self, retrieved_uid): print("\nOscManager.pass_decision_to_client()") msg = None if retrieved_uid is None: retrieved_uid = -1 msg = oscbuildparse.OSCMessage("/control/detected", ",iT", [retrieved_uid, True]) else: msg = oscbuildparse.OSCMessage("/control/detected", ",iF", [retrieved_uid, False]) # Override decision for testing purposes msg = oscbuildparse.OSCMessage("/control/detected", ",iT", [retrieved_uid, True]) osc_send(msg, "recogniserclient")
def playback_started(self, loop, preschedule_ms): self.loop = loop self.preschedule_ms = int(preschedule_ms) / 1000 self.recording_start_time = self.start_loop_time log.info("Started recording {}".format( self.recording.summary["title"])) if self.recording.detail is not None: key_name = self.recording.detail["tonal"]["key_key"] key_scale = self.recording.detail["tonal"]["key_scale"] key_strength = self.recording.detail["tonal"]["key_strength"] key_number = key_to_index(key_name) scale_number = scale_to_index(key_scale) else: key_number = -1 scale_number = -1 key_strength = 0 msg = oscbuildparse.OSCMessage( "/songdata/songstart".format(self.recording.get_persistent_id()), ",hsiif", [ self.recording.get_persistent_id(), self.recording.summary["title"], key_number, scale_number, key_strength ]) osc_send(msg, "lightjams")
def send_cue(req_cue): if (disable): print(f"Cues disabled {req_cue}") return if req_cue not in cue_sheet["cues"]: print(f"Cue '{req_cue}' not found.") for target in cue_sheet["targets"].values(): ip = target["ip"] cues = target["cues"] if req_cue in cues: cue = cues[req_cue] if not cue: continue port = cue["port"] if (ip, port) not in osc_channels: client_uuid = str(uuid.uuid4()) osc_channels[(ip, port)] = client_uuid osc_udp_client(ip, port, client_uuid) else: client_uuid = osc_channels[(ip, port)] addr = cue["addr"] data = cue["data"] msg = oscbuildparse.OSCMessage(addr, None, data) print(msg) osc_send(msg, client_uuid) osc_process()
def scheduler(arg1, arg2): global signal_count global loopCount global loopChange #毎フレやること #現在のループの位置を送る msg_send_loopCount = oscbuildparse.OSCMessage("/get/loopcount", None, [loopCount]) osc_send(msg_send_loopCount, "aclientname") osc_process() #もしかしたらLight()の後の方がいいかもしれない #スイッチの値を読み込む global switch_flag if GPIO.input(SWITCH_PIN): #スイッチがオンのとき switch_flag = True #スイッチフラグをTrueにする else: switch_flag = False #スイッチフラグをFalseにする ###loopCountの処理 loopCount = loopCount + loopChange loopChange = 0 if loopCount < 0: loopCount = 0 #print("error:loopCount is negative") if loopCount > LIGHT_SEC * FPS: loopCount = LIGHT_SEC * FPS #print("error:loopCount is over") #print("loopCount:"+str(loopCount)) ### Light() #call light function signal_count = signal_count + 1
def run(self): while True: #print("THREAD DIM RUN: " + str(self.dim)) # Helpful for observing threads running behaviours. sa.seg_dim_analysis(self.dim) msg = oscbuildparse.OSCMessage("/kodama/", None, sa.get_nearest(self.dim)) osc_send(msg, "Kodama") time.sleep(args.audio_length/(self.dim+1))
def action_util(action: bool, cmd): if action: try: #osc_startup() #osc_udp_client(config.parms[ "atemOsc_ip" ], config.parms[ "atemOsc_port" ], config.parms[ "atemOsc_cn" ]) addr = cmd args = [1.0] msg = oscbuildparse.OSCMessage(addr, ",f", args) x = osc_send(msg, cn) x = osc_process() status = "ok" result = "cmd=" + cmd except Exception as e: result = ["Failed:" + e.strerror] status = "exception" else: result = ["No action"] status = "ok" res = {"status": status, "result": result} return (res)
def add_loop(self): """ /loop_add i:#channels f:min_length_seconds """ msg = oscbuildparse.OSCMessage("/loop_add", None, [STEREO, MINIMUM_LOOP_DURATION]) self._send_message(msg)
def playReaperPauseMusic(): pauseMessage = oscbuildparse.OSCMessage("/marker/11", None, [1]) finished = False while not finished: osc_send(pauseMessage, REAPER_CLIENT_NAME) osc_process() finished = True
def oscOut(gaze_left_eye): #gaze_left_eye = list(gaze_left_eye) print(gaze_left_eye) msg = oscbuildparse.OSCMessage("/test/me", None, (gaze_left_eye)) osc_send(msg, "tobiiSend") osc_process()
def playReaperAudio(): playMessage = oscbuildparse.OSCMessage("/action/40317", None, [1]) finished = False while not finished: finished = True osc_send(playMessage, REAPER_CLIENT_NAME) osc_process()
def get(self, param, loop=None): """ /get s:param s:return_url s:retpath OR /sl/#/get s:control s:return_url s: return_path Which returns an OSC message to the given return url and path with the arguments: i:loop_index s:control f:value """ if loop is None: msg = oscbuildparse.OSCMessage("/get", None, [param, self.return_url, "/get"]) else: assert loop >= -3 and loop <= MAX_LOOP_COUNT-1 msg = oscbuildparse.OSCMessage("/sl/{}/get".format(loop), None, [param, self.return_url, "/get"]) self._send_message(msg)
def __init__(self, ip, port, name): self.outboundIP = str(ip) self.outboundPort = int(port) self.oscName = name osc_startup() osc_udp_client(self.outboundIP, self.outboundPort, self.oscName) msg = oscbuildparse.OSCMessage("/test/message", ',is', [123, "test"]) osc_send(msg, self.oscName)
def load_session(self, infile): """ /load_session s:filename s:return_url s:error_path """ print('Loading session from file: {}'.format(infile)) msg = oscbuildparse.OSCMessage("/load_session", None, [infile, self.return_url, "/ping"]) self._send_message(msg)
def printing_handler(addr, tags, stuff, source): msg_string = "%s [%s] %s" % (addr, tags, str(stuff)) logger.info("OSCServer Got: '%s' from %s", msg_string, source) # send a reply to the client. msg = oscbuildparse.OSCMessage("/printed", None, msg_string) osc.osc_send(msg, "main") osc.osc_process()
def _construct_msg(self, data): ''' None as second argument to OSCMessage means datatypes are autodetected. replace None with explicit datatype formatted as ',sif' for string, integer, float. data should be a list or tuple of args to pass in message like ['string', 42, 4.2] ''' return oscbp.OSCMessage(self.address, None, data)
def on_holdStr(self, inst, val): # update seconds when holdStr changes self.seconds = int(self.holdStr[2:]) + (int(self.holdStr[:2]) * 60) # update TouchOSC Label tmr = time.gmtime(self.updateEndTime() - time.time() + 1) oscLabel = oscbuildparse.OSCMessage('/1/label1', None, [time.strftime('%M:%S', tmr)]) osc_send(oscLabel, 'OSC_client')
def setReaperMarker(currentNumber): markerMessage = oscbuildparse.OSCMessage("/marker/" + str(currentNumber), None, [1]) finished = False while not finished: osc_send(markerMessage, REAPER_CLIENT_NAME) osc_process() finished = True
def test(address, in_num): # Will receive message data unpacked in s print("test function=======>>>>>>> address:" + str(address) + " get data: " + str(in_num)) if in_num == "alive": msg_send = oscbuildparse.OSCMessage("/get/alive_check", None, ["alive"]) osc_send(msg_send, "aclientname") osc_process()
def set(self, param, value, loop=None): """ /set s:param f:value sync_source: [-3 = internal, -2 = midi, -1 = jack, 0 = none, # > 0 = loop number (1 indexed)] """ if param in 'sync_source': assert value >= -3 and value <= MAX_LOOP_COUNT if param == 'selected_loop_num': assert value >= 0 and value <= MAX_LOOP_COUNT-1 if loop is None: msg = oscbuildparse.OSCMessage("/set", None, [param, value]) else: assert loop >= -3 and loop <= MAX_LOOP_COUNT-1 msg = oscbuildparse.OSCMessage("/sl/{}/set".format(loop), None, [param, value]) if self.verbose: print("Set param={}, value={}, loop={}".format(param, value, loop)) self._send_message(msg)
def save_session(self, outfile): """ /save_session s:filename s:return_url s:error_path saves current session description to filename. """ print('Saving session to file: {}'.format(outfile)) msg = oscbuildparse.OSCMessage("/save_session", None, [outfile, self.return_url, "/ping"]) self._send_message(msg)
def ping(self): """ /ping s:return_url s:return_path If engine is there, it will respond with to the given URL and PATH with an OSC message with arguments: s:hosturl s:version i:loopcount """ msg = oscbuildparse.OSCMessage("/ping", None, [self.return_url, "/ping"]) self._send_message(msg)
def sendChordSC(self, chord): midiChord = [str2midi(note) for note in chord] chordOSC = oscbuildparse.OSCMessage('/chord', None, midiChord) arpeggiateOSC = oscbuildparse.OSCMessage('/arpeggiate', None, [self.arpBool]) durationOSC = oscbuildparse.OSCMessage('/duration', None, [self.durVal]) scrambleOSC = oscbuildparse.OSCMessage('/scramble', None, [self.scrambleBool]) numRepeatsOSC = oscbuildparse.OSCMessage('/numRepeats', None, [self.numRepeats]) messages = [ arpeggiateOSC, durationOSC, scrambleOSC, chordOSC, numRepeatsOSC ] for msg in messages: osc_send(msg, self.clientNameOSC) osc_process()
def clear_loops(self): """ Crude way to clear out loops from the looper. Works so long as you don't have more than 10 in there! """ for i in range(10): msg = oscbuildparse.OSCMessage("/loop_del", ",i", [-1]) osc_send(msg, "SooperLooper") osc_process() time.sleep(0.1)
def save_loop_audio(self, index, outfile): """ /sl/#/save_loop s:filename s:format s:endian s:return_url s:error_path saves current loop to given filename, may return error to error_path format and endian currently ignored, always uses 32 bit IEEE float WAV """ print('Saving audio in loop {} to file: {}'.format(index, outfile)) msg = oscbuildparse.OSCMessage("/sl/{}/save_loop".format(index), None, [outfile, '', '', self.return_url, "/ping"]) self._send_message(msg)