示例#1
0
 def run(self):
     debug("RGB")
     while True:
         # Check interrupt of all 4 encoders
         # If interrupt, read encoder/button state
         sleep(1)
     return
示例#2
0
 def __init__(self, i2c_bus):
     super().__init__()
     self.led_matrix = [[BLANK for x in range(W)] for y in range(H)]
     self.old_led_matrix = [[BLANK for x in range(W)] for y in range(H)]
     self.trelli = [[] for i in range(int(H/4))]  # [[],[]]
     print("Creating Trelli")
     for x, slice in enumerate(trellis_addresses):
         for y, addr in enumerate(slice):
             t = NeoTrellis(i2c_bus, False, addr=addr)
             t.pixels.auto_write = False
             self.trelli[x].append(t)
             sleep(0.1)
             pass
     print("Linking Trelli")
     self.trellis = MultiTrellis(self.trelli)
     print("Trelli linked")
     button_cb = self.make_button_cb()
     print("Initializing Trelli inputs")
     for y in range(H):
         for x in range(W):
             pass
             sleep(0.01)
             self.trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
             sleep(0.01)
             self.trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
             self.trellis.set_callback(x, y, button_cb)
     debug("Inputs initialized")
     self.blank_screen()
示例#3
0
 def apply_control(self, x, y):
     if y >= 8:  # Control touch, but save it in the page, it's easier that way
         y -= 8
         if x < 8:
             self.densities[y] = x
             c.debug("calling regen...")
             self.regen(x, y)
示例#4
0
 def touch_encoder(self, id, action):
     c.debug("Encoder {id} {action}".format(id=id, action=action))
     scroll_dir = {"+": "up", "-": "down"}.get(action, None)
     if scroll_dir:
         self.OLED_Screens.menu_scroll(id, scroll_dir)
     if action == "button":
         c.debug(self.OLED_Screens.touch(id).get())
     return
示例#5
0
 def _process_incoming_midi(message):
     '''Check for incoming midi messages and categorize so we can do something with them'''
     if message.type == "clock":
         self.count += 1
         self.count %= 24
         debug(self.count)
         tick = self.process_midi_tick()
         self.midi_in_bus.put(tick)
示例#6
0
 def run(self):
     debug("MidiOut starting")
     while self.keep_running:
         msgs = self.midi_out_bus.get()
         for msg in msgs:
             self.mportout.send(msg)
             # debug(msg)
     return
示例#7
0
 def __init__(self, inp):
     Thread.__init__(self, name='Clock')
     self.daemon = True
     self.input = inp
     debug("Clock input is " + str(inp))
     self.ticker_bus = bus_registry.get('ticker_bus')
     self.midi_in_bus = bus_registry.get('midi_in_bus')
     self.clock_bus = bus_registry.get('clock_bus')
     self.keep_running = True
示例#8
0
 def set_input(self, inp):
     # TODO maybe delete this, no need to change inputs mid-set
     if inp == self.input:
         return
     debug("Changing clock input to " + inp)
     self.input = inp
     self.midi_in_bus.queue.clear()
     self.ticker_bus.queue.clear()
     return
示例#9
0
 def run(self):
     self.mportin.callback = self.process_incoming_midi()
     debug("MidiInListener starting")
     while self.keep_running:
         # beat = randint(110,120)
         # debug("midi still running")
         sleep(1)
         # self.midi_in_bus.put("x")
     return
示例#10
0
 def run(self):
     debug("Clock started")
     while self.keep_running:
         if self.input == "midi":
             x = self.midi_in_bus.get()
             self.clock_bus.put(x)
         else:
             x = self.ticker_bus.get()
             self.clock_bus.put(x)
     return
示例#11
0
 def import_yaml(self, yaml):
     self.brightness = yaml['brightness']
     self.gradient_from = Color(yaml['gradient']['from'])
     self.gradient_to = Color(yaml['gradient']['to'])
     c.debug(yaml['pallette'])
     for p in c.pallette_lookup.keys():
         c.debug(p)
         self.pallette[p] = yaml['pallette'][c.pallette_lookup[p]]
     self
     return
示例#12
0
 def add_instrument(self, type):
     if len(self.instruments) == 16:
         return
     ins_type = instrument_lookup(type)
     c.debug(ins_type)
     new_ins = ins_type.start(ins_num=len(self.instruments),
                              **self.instrument_ctx()).proxy()
     c.debug(new_ins)
     self.instruments.append(new_ins)
     return
示例#13
0
 def run(self):
     c.debug("Display thread started")
     while self.keep_running:
         sleep(0.01)
         m = self.get_cmds()
         if m.get('cmd') != None:
             c.debug(m)
             self.button_grid_bus.put(m)
         if not self.LED_grid_bus.empty():
             status, led_grid, oled_data = self.LED_grid_bus.get()
             self.draw_all(status, led_grid, oled_data)
示例#14
0
 def __init__(self, initial_bpm):
     Thread.__init__(self, name='SelfTicker')
     self.daemon = True
     self.bpm = initial_bpm
     if initial_bpm:
         debug("ticker's bpm is " + str(initial_bpm))
     self.ticker_bus = bus_registry.get('ticker_bus')
     self.beat_clock_count = 0
     self.midi_clock_divider = 32
     self.midi_out_bus = bus_registry.get('midi_out_bus')
     self.keep_running = True
示例#15
0
 def regen(self, amt, note):
     '''A randomize menu bar has been clicked, regen that bar's notes'''
     c.debug("regen")
     gen_notes = [self.calc_chance(amt) for x in range(16)]
     page = self.get_curr_page()
     gen_notes = [{
         True: c.NOTE_ON,
         False: c.NOTE_OFF
     }[note] for note in gen_notes]
     for i, beat in enumerate(page.note_grid):
         beat[note] = gen_notes[i]
     return
示例#16
0
    def process_midi_tick(self):
        '''Perform midi tick subdivision so ticks only happen on beats'''
        # self.beat_count += 1
        # if self.beat_count >= self.midi_beat_divider:
        self.clock_count += 1

        if self.clock_count >= self.midi_clock_divider:
            self.clock_count %= self.midi_clock_divider
            debug("----------------------")
            return BEAT
        debug("---")
        return TICK
示例#17
0
 def run(self):
     if not self.bpm:
         debug("Not using self ticker")
         return
     debug("SelfTicker started")
     sleep_period = 60/self.bpm
     while self.keep_running:
         sleep(sleep_period)
         tick = self.process_midi_tick()
         self.ticker_bus.put(tick)
         if self.midi_out_bus:
             self.midi_out_bus.put([Message('clock')])
     return
示例#18
0
    def run(self):
        debug("Display thread started")
        while True:
            sleep(0.01)
            m = self.get_cmds()
            if m.get('cmd') != None:
                debug(m)
                self.button_bus.put(m)
            if not self.led_bus.empty():
                status, led_grid = self.led_bus.get()
                self.draw_all(status, led_grid)

        return
示例#19
0
 def run(self):
     debug("Supervisor running...")
     self.draw()
     while self.keep_running:
         if not self.button_grid_bus.empty():
             # debug("button pressed")
             m = self.button_grid_bus.get()
             self.process_cmds(m)
             self.draw()
         if not self.clock_bus.empty():
             clock_tick = self.clock_bus.get()
             self.conductor.step_beat(clock_tick)
             self.draw()
         sleep(0.01)
     return
示例#20
0
 def cb_instrument_type(self, x, y):
     if self.get_total_instrument_num() >= 16:
         return
     ins = instrument_lookup(y + 1)  # +1 because base class isn't playable
     new_ins = ins.start(ins_num=self.get_total_instrument_num(),
                         **self.instrument_ctx()).proxy()
     self.instruments.append(new_ins)
     lcd.flash("Added {}".format(self.instruments[~0].type))
     try:
         OLED_Screens = proxy_registry('OLED_Screens')
         OLED_Screens.text(0, [str(new_ins.type.get())])
         OLED_Screens.text(1, [str(y + 1)])
         OLED_Screens.text(2, [str(ins)])
     except Exception as e:
         c.debug(str(e))
示例#21
0
 def output(self, notes_off, notes_on):
     """Return all note-ons from the current beat, and all note-offs from the last"""
     notes_off = [n for n in notes_off if n < 128 and n > 0]
     notes_on = [n for n in notes_on if n < 128 and n > 0]
     off_msgs = [
         mido.Message('note_off', note=n, channel=self.ins_num)
         for n in notes_off
     ]
     on_msgs = [
         mido.Message('note_on', note=n, channel=self.ins_num)
         for n in notes_on
     ]
     msgs = off_msgs + on_msgs
     if len(msgs) > 0:
         c.debug(msgs)
         midi_out_bus.put(msgs)
示例#22
0
 def run(self):
     debug(f"{self.name} started")
     while True:
         # sleep(0.01)
         msg = self.inbox.get()
         debug(f"{self.name} received '{msg}'")
         if len(msg) < 2:
             debug(f"{self.name} stopping")
             break
         debug('..')
         self.send(self.buddy, msg[:-1])
         return
示例#23
0
 def get_cmds(self):
     try:
         self.trellis.sync()  # TODO undo? Fails if called too often
     except Exception as e:
         debug("HW error: {}".format(str(e)))
     m = {'cmd': None}
     if self.read_gbl_button():
         if self.state != 'gbl_cfg':
             m['cmd'] = "CONFIG_A"
             self.state = 'gbl_cfg'
         else:
             self.state = 'play'
     elif self.read_ins_button():
         if self.state != 'ins_cfg':
             m['cmd'] = "CONFIG_B"
             self.state = 'ins_cfg'
         else:
             self.state = 'play'
     return m
示例#24
0
 def touch_note(self, state, x, y):
     '''touch the x/y cell on the current page'''
     if not x % 2:
         return
     c.debug("!")
     osc = int((x - 1) / 2)
     # c.debug(osc)
     if y == 15:
         # Play/Pause button
         c.debug(f"play/pause {osc}")
         self.oscillators[osc].running = not self.oscillators[osc].running
     if y == 0:
         c.debug(f"selected {osc}")
         self.selected_osc = osc
         c.debug(self.selected_osc)
     return True
示例#25
0
def hardware_main():
    from interfaces.hardware import Display
    from interfaces.oled_hw import OLED_Screens

    # from interfaces.encoders import Encoder_Inputs, Encoder_RGB
    from interfaces.i2c_bus import i2c_bus
    # TODO create  i2c bus here, pass to Display
    display = Display(i2c_bus)
    # encoders = Encoder_Inputs(encoder_out_bus, button_grid_bus, i2c_bus)
    # encoders.start()
    # encoders_RGB = Encoder_RGB(encoder_in_bus, i2c_bus)
    # encoders_RGB.start()
    debug(mido.get_input_names())
    debug(mido.get_output_names())
    debug("Creating MIDI ports")
    with mido.open_output('f_midi:f_midi 16:0') as mportout:
        with mido.open_input('f_midi:f_midi 16:0') as mportin:
            start_supervisor(display, mportin, mportout, bpm)
示例#26
0
def start_supervisor(display, mportin, mportout, bpm):
    midi_in = MidiInListener(mportin)
    midi_out = MidiOut(mportout)
    ticker = SelfTicker(bpm)
    clock = Clock('tick' if bpm else 'midi')
    midi_in.start()
    midi_out.start()
    ticker.start()
    clock.start()
    display.start()
    supervisor = Supervisor()
    try:
        supervisor.run()
    finally:
        debug("Stopping everything")
        midi_in.keep_running = False
        midi_out.keep_running = False
        ticker.keep_running = False
        clock.keep_running = False
        display.keep_running = False
        supervisor.keep_running = False
        debug("Threads stopped")
        exit()
        debug("exiting?")
示例#27
0
 def add(self, name, bus):
     debug("add")
     debug(name)
     debug(bus)
     self.registry[name] = bus
示例#28
0
from supervisor import Supervisor
import mido
import argparse
from buses import midi_in_bus, midi_out_bus, LED_grid_bus, button_grid_bus, clock_bus, ticker_bus
from midi_input import MidiInListener
from midi_output import MidiOut
from clock import Clock
from ticker import SelfTicker
from constants import debug
# import atexit

parser = argparse.ArgumentParser()
parser.add_argument("--hw", help="Use real hardware", type=bool)
parser.add_argument("--bpm", help="Use real hardware", type=int)
args = parser.parse_args()
debug(args)
bpm = int(args.bpm) if args.bpm else None


def console_main(stdscr):
    from interfaces.console import Display
    from interfaces.oled_sw import OLED_Screens
    OLED_Screens = OLED_Screens.start(4)
    curses.mousemask(1)
    curses.mouseinterval(10)
    curses.curs_set(0)
    stdscr.nodelay(1)
    display = Display(stdscr)
    with mido.open_output('supervisor_Out', autoreset=True,
                          virtual=True) as mportout:
        with mido.open_input('supervisor_In', autoreset=True,
示例#29
0
 def touch(self):
     if self.menu_mode:
         return self.get_menu_item()
     else:
         debug(f"touched encoder {self.num}")
示例#30
0
from constants import debug
from board import SCL, SDA
import busio
debug("Creating i2c bus")
I2C_BUS = busio.I2C(SCL, SDA)
debug("Done")