def set_parameter(cls, param, value, loop_name=None): if loop_name is None: loop_number = cls.get_selected_loop() else: loop_number = cls._get_loop_number(loop_name) logging.debug(f'Setting {param} to {value} for {loop_number} {loop_name} ') SLClient.set_parameter([param, value], loop_number)
def publish_loop(cls): loop = cls.get_selected_loop() name = cls._get_selected_loop_name(loop) file = cls.loop_dir + '/' + name SLClient.save_loop(file, loop_number=loop) time.sleep(2) WavSlicer.slice_and_send(name, file=file)
def loop_rate(cls, rate): loop = cls.get_selected_loop() name = cls._get_selected_loop_name(loop) SLClient.set_rate(rate, loop) if cls.changes[name].get('rate', None) is None: cls.changes[name][rate] = rate cls.changes[name]['rate'] = rate
def loop_load(cls, name): existing = cls._index_contains(name) if existing: loop = existing else: loop = cls.loop_add() SLClient.load_loop(loop, cls.loop_dir + '/' + name + '.wav') if SLClient.get_state(loop) != 'Playing': SLClient.pause(loop)
def _register_loop_updates(cls, loop): SLClient.register_auto_update('loop_pos', '/loop_pos', loop, interval=100) #SLClient.register_auto_update('cycle_len', '/test', loop, interval=100) # SLClient.register_auto_update('free_time', '/test', interval=1, loop_number=cls.loops) SLClient.register_auto_update('total_time', '/test', loop) # SLClient.register_auto_update('waiting', '/test', interval=1, loop_number=cls.loops) SLClient.register_auto_update('state', '/state', loop) # SLClient.register_auto_update('next_state', '/test', interval=1, loop_number=cls.loops) SLClient.register_auto_update('save_loop', '/test', loop) SLClient.register_auto_update('load_loop', '/test', loop)
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 loop_reverse(cls): loop = cls.get_selected_loop() name = cls._get_selected_loop_name(loop) SLClient.reverse(loop) if cls.changes[name].get('reverse', None) is None: cls.changes[name]['reverse'] = 1 else: if cls.changes[name]['reverse'] == 0: cls.changes[name]['reverse'] = 1 if cls.changes[name]['reverse'] == 1: cls.changes[name]['reverse'] = 0
def delete_loop(cls): if cls.get_number_of_loops() == 0: return selected = cls.get_selected_loop() SLClient.loop_del(selected) if cls.loop_index.get(selected, None) is None: logging.warning( f'Unable to delete loop, index is broken! selected_loop = {selected} index = {cls.loop_index}') else: cls.loop_index.pop(selected) loop_number = cls.get_number_of_loops() cls.loop_index = cls._update_loop_index(loop_number)
def undo(cls): SLClient.undo(cls.get_selected_loop())
def set_sync_source(cls): selected = cls.get_selected_loop() SLClient.set_sync_source(selected + 1) cls.global_changes['sync_source'] = selected
def loop_add(cls): SLClient.loop_add() name = TTTruck._generate_name() new_loop_number = cls.get_number_of_loops() cls.loop_index[new_loop_number] = name cls.changes[name] = {} cls.select_loop(new_loop_number) if new_loop_number == 0: # TODO: hack to make the register_auto_updates work on first loop. time.sleep(0.5) cls.select_loop(0) SLClient.set_sync_source(-3) SLClient.set_quantize(2, new_loop_number) else: SLClient.set_sync_source(SLClient.sync_source) SLClient.set_quantize(SLClient.quantize_on, new_loop_number) #SLClient.set_sync(1, new_loop_number) SLClient.set_playback_sync(1, new_loop_number) return new_loop_number
def get_selected_loop(cls): return SLClient.get_selected_loop_num()
def get_number_of_loops(cls): return SLClient.ping()
def redo(cls): SLClient.redo(cls.get_selected_loop())
def select_loop(cls, loop_num): cls._unregister_loop_updates(SLClient.selected_loop) SLClient.set_selected_loop_num(loop_num) SLClient.get_cycle_len(loop_num) cls._register_loop_updates(loop_num)
def loop_multiply(cls): SLClient.multiply(cls.get_selected_loop())
def set_quantize(cls): loop = cls.get_selected_loop() if SLClient.quantize_on == 3: SLClient.set_quantize(0, loop) else: SLClient.set_quantize(SLClient.quantize_on + 1, loop)
def _(event): SLClient.ping()
def loop_overdub(cls): loop = cls.get_selected_loop() SLClient.overdub(loop)
def _delete_all_loops(cls): num_loops = cls.get_number_of_loops() while num_loops >= 0: SLClient.set_selected_loop_num(0) cls.delete_loop() num_loops -= 1
def solo(cls): SLClient.solo(cls.get_selected_loop())
def loop_record(cls): loop = cls.get_selected_loop() SLClient.record(loop)