def test_ping(self): OSCServer.start(port=8852) OSCClient.start(port=8852, client_name='test') OSCServer.register_handler('/test', self.handler) OSCClient.send_message('/test', type=',s', args=['hello']) time.sleep(0.5) self.assertEqual(self.ping, 'hello')
def test_loop_index(self): OSCServer.start(port=9952) t = threading.Thread(target=OSCClient.start(client_name='test'), daemon=True) t.start() SLClient.ping() #time.sleep(0.3) TTTruck._delete_all_loops() self.assertEqual(0, SLClient.loops) self.assertFalse(TTTruck.loop_index) # one loop TTTruck.loop_add() #time.sleep(1) self.assertEqual(0, TTTruck.get_number_of_loops()) self.assertTrue(TTTruck.loop_index) first_loop = TTTruck.loop_index[0] #print(first_loop) # second loop TTTruck.loop_add() second_loop = TTTruck.loop_index[1] #print(second_loop) #time.sleep(1) self.assertEqual(1, TTTruck.get_number_of_loops()) # third loop TTTruck.loop_add() #time.sleep(1) self.assertEqual(2, TTTruck.get_number_of_loops()) third_loop = TTTruck.loop_index[2] TTTruck.select_loop(1) #time.sleep(1) TTTruck.loop_reverse() #time.sleep(1) self.assertEqual(1, TTTruck.changes[second_loop]['reverse']) #time.sleep(1) TTTruck.loop_reverse() #time.sleep(1) self.assertEqual(0, TTTruck.changes[second_loop]['reverse']) TTTruck.delete_loop() #time.sleep(1) #print(OSCServer.selected_loop, 's') # third loop should now be the second of two loops self.assertEqual(1, TTTruck.get_number_of_loops()) self.assertEqual(third_loop, TTTruck.loop_index[1]) # delete second loop again and ensure first loop is all that's left TTTruck.delete_loop() #time.sleep(1) self.assertEqual(0, TTTruck.get_number_of_loops()) self.assertEqual(first_loop, TTTruck.loop_index[0])
def main(config=None): logging.basicConfig( filename='log_file.log', encoding='utf-8', level=logging.DEBUG, filemode='w+', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', force=True) sl_host = '127.0.0.1' sl_port = 9951 server_host = '192.168.0.38' server_port = 9999 debug = False peers = None if config is not None: if config.sooperlooper_host is not None: sl_host = config.sooperlooper_host if config.sooperlooper_port is not None: sl_port = config.sooperlooper_port if config.server_host is not None: server_host = config.server_host if config.server_port is not None: server_port = config.server_port if config.peers is not None: peers = config.peers import subprocess BuTTTruck.sooperlooper = subprocess.Popen(['sooperlooper', '-l', '0']) # TODO: scheduled tasks won't reschedule if they take longer than the reschedule period BuTTTruck.scheduled_tasks.enter( 0, 1, periodic, (BuTTTruck.scheduled_tasks, 0.05, process_incoming)) BuTTTruck.scheduled_tasks.enter( 10, 2, periodic, (BuTTTruck.scheduled_tasks, 5, process_loops)) BuTTTruck.scheduled_tasks.enter( 1, 2, periodic, (BuTTTruck.scheduled_tasks, 10, resend_missing_chunks)) if peers is not None: peer_list = peers.strip('\'').split(',') for i in peer_list: logging.info(f'Adding peer: {i}') ip, port = i.split(':') PeerClient.add_peer((ip, int(port)), server=False) else: logging.info(f'Adding server: {server_host}:{server_port}') PeerClient.add_peer((server_host, server_port), server=True) BuTTTruck.pool.submit( OSCClient.start(host=sl_host, port=sl_port, debug=debug)) BuTTTruck.pool.submit(BuTTTruck.scheduled_tasks.run) BuTTTruck.pool.submit(PeerClient.run) BuTTTruck.pool.submit(midi.run) OSCServer.start() import jack with jack.Client('TTTruck') as jack_client: capture = jack_client.get_ports(is_physical=True, is_output=True) output = jack_client.get_ports(is_physical=True, is_input=True) sooperlooper_common_in = jack_client.get_ports( name_pattern='sooperlooper.*common.*in') sooperlooper_common_out = jack_client.get_ports( name_pattern='sooperlooper.*common.*out') for src, dest in zip(sooperlooper_common_out, output): logging.debug(f'Connecting {src} to: {dest}') jack_client.connect(src, dest) for src, dest in zip(capture, sooperlooper_common_in): logging.debug(f'Connecting {src} to: {dest}') jack_client.connect(src, dest)