def cb_display(self, msg): # Raw grid of notes, velocities and tails led_grid = self.instruments[self.current_instrument].grid.display() # Add ornamentation for y in range(H): # add_gridlines for x in range(3, W, 8): if led_grid[y][x] == BLANK: led_grid[y][x] = GRID_4 if led_grid[y][x + 4] == BLANK: led_grid[y][x + 4] = GRID_8 # add_beat_marker if led_grid[y][self.beat] == NOTE: led_grid[y][self.beat] = BEAT_ON else: led_grid[y][self.beat] = BEAT # add_selected_note s_n = self.instruments[self.current_instrument].selected_note if s_n: led_grid[s_n[1]][s_n[0]] = SELECTED # Convert according to color scheme for y in range(H): for x in range(W): led_grid[y][x] = color_scheme(led_grid[y][x], x, y) post('trellis', {'event': 'draw_grid', 'led_grid': led_grid}) return
def cb_midi_tick(self, msg): if self.playing: self.beat = (self.beat + 1) % W # debug(str(self.id) +"/" + str(self.beat)) notes_on = self.grid.notes_at(self.beat) # print(notes_on) post("midiout", { 'event': 'note_on', 'notes': notes_on, 'channel': self.id }) return
def event_loop(self): # {'event': 'press/release', 'x': 0-31, 'y': 0-31} msg = receive('button_grid') # print(msg) event = msg.get('event') x = msg.get('x') y = msg.get('y') k_id = f"{x}.{y}" if event == "release": if k_id in self.button_states: hold_time = datetime.now() - self.button_states.get(k_id) self.button_states.pop(k_id) if int(hold_time.microseconds) > self.long_click_us: msg['event'] = "long_click" else: msg['event'] = "short_click" # print(msg) post('conductor', msg) if event == "press": self.button_states[k_id] = datetime.now() msg['event'] = "touch" post('conductor', msg)
from actors import ActorThread, bus_registry, actor_registry, post, receive # t = Trellis(I2C_BUS).start() # sleep(30) # print("SETUP COMPLETE") # exit() # m = MidiOut(open_output('seq_out', autoreset=True, virtual=True)).start() m = MidiOut(fakeMidiOut()).start() c = MidiClock(120).start() e0 = Encoder(0).start() e1 = Encoder(1).start() e2 = Encoder(2).start() e3 = Encoder(3).start() b = ButtonGrid().start() c = Conductor().start() post('button_grid', {'event': 'press', 'x': 1, 'y': 1}) sleep(0.001) post('button_grid', {'event': 'release', 'x': 1, 'y': 1}) sleep(0.001) post('button_grid', {'event': 'press', 'x': 3, 'y': 3}) sleep(0.001) post('button_grid', {'event': 'release', 'x': 3, 'y': 3}) sleep(0.001) post('button_grid', {'event': 'press', 'x': 2, 'y': 2}) sleep(0.001) post('button_grid', {'event': 'release', 'x': 2, 'y': 2}) sleep(0.001) post('button_grid', {'event': 'press', 'x': 7, 'y': 7}) sleep(0.001) post('button_grid', {'event': 'release', 'x': 7, 'y': 7})
def event_loop(self): # Custom event loop sleep(self.delay_s) post("midiout", {'event': "tick"}) post("conductor", {'event': "midi_tick"})
def cb_midi_tick(self, msg): self.beat = (self.beat + 1) % W for i in range(len(self.instruments)): post(f"instrument{i}", msg) self.cb_display({})
def post_to_ins(self, msg): post(f"instrument{self.current_instrument}", msg)
# print(msg) post('conductor', msg) if event == "press": self.button_states[k_id] = datetime.now() msg['event'] = "touch" post('conductor', msg) # print(msg) if __name__ == "__main__": # trellis_bus = bus_registry.bus('trellis') conductor_bus = bus_registry.bus('conductor') t = ButtonGrid().start() print(t) from time import sleep post('button_grid', {'event': 'press', 'x': 1, 'y': 1}) sleep(0.1) post('button_grid', {'event': 'release', 'x': 1, 'y': 1}) sleep(0.1) post('button_grid', {'event': 'press', 'x': 1, 'y': 1}) sleep(0.3) post('button_grid', {'event': 'release', 'x': 1, 'y': 1}) sleep(0.1) post('button_grid', {'event': 'press', 'x': 1, 'y': 1}) sleep(0.5) post('button_grid', {'event': 'release', 'x': 1, 'y': 1}) sleep(0.1) post('button_grid', {'event': 'press', 'x': 2, 'y': 3})
def button_cb(xcoord, ycoord, edge): if edge == NeoTrellis.EDGE_RISING: post('button_grid', {'event': 'press', 'x': xcoord, 'y': H-1-ycoord}) elif edge == NeoTrellis.EDGE_FALLING: post('button_grid', {'event': 'release', 'x': xcoord, 'y': H-1-ycoord}) return
if action == 'push': print("Push not implemented yet") return dir = 1 if action == "inc" else -1 x, y = self.selected_note self.grid.set_duration(x, y, dir) return def cb_encoder_3(self, msg): if not self.selected_note: return action = msg['action'] if action == 'push': print("Push not implemented yet") return dir = 1 if action == "inc" else -1 x, y = self.selected_note self.grid.set_velocity(x, y, dir) return if __name__ == '__main__': from time import sleep i = Instrument(0).start() post('instrument0', {'event': 'ctl_stop', 'foo': 'bar'}) post('instrument0', {'event': 'foo', 'foo': 'bar'}) post('instrument0', {'event': 'touch_click', 'x': 0, 'y': 1}) post('instrument0', {'event': 'ctl_step'}) sleep(1) print(i.grid.display()) sleep(1)