diff --git a/config.ini b/config.ini index df3a19d..91dfe9a 100644 --- a/config.ini +++ b/config.ini @@ -17,6 +17,7 @@ USE_BUTTONS = True USE_GUI = False SAMPLES_DIR = None AUDIO_DEVICE_ID = -1 +USE_LAUNCHPAD = True AUDIO_DEVICE_NAME = autodetect BOXRELEASE = 30 PRESET_BASE = 0 diff --git a/modules/globalvars.py b/modules/globalvars.py index 605bfc9..7dc694e 100644 --- a/modules/globalvars.py +++ b/modules/globalvars.py @@ -72,6 +72,7 @@ USE_HD44780_16x2_LCD = cp.get_option_by_name('USE_HD44780_16x2_LCD') USE_HD44780_20x4_LCD = cp.get_option_by_name('USE_HD44780_20x4_LCD') USE_FREEVERB = cp.get_option_by_name('USE_FREEVERB') +USE_LAUNCHPAD = cp.get_option_by_name('USE_LAUNCHPAD') USE_TONECONTROL = cp.get_option_by_name('USE_TONECONTROL') USE_I2C_7SEGMENTDISPLAY = cp.get_option_by_name('USE_I2C_7SEGMENTDISPLAY') USE_GUI = cp.get_option_by_name('USE_GUI') diff --git a/samplerbox.py b/samplerbox.py index f4c4f0a..6e5ea0b 100644 --- a/samplerbox.py +++ b/samplerbox.py @@ -183,7 +183,11 @@ ########################## midi_in = rtmidi2.MidiInMulti() +excluded_ports = ['Midi Through', 'LoopBe Internal'] +if gv.USE_LAUNCHPAD: + excluded_ports.extend(['Launchpad', 'RtMidiOut', 'RTMIDI']) + curr_ports = [] prev_ports = [] first_loop = True @@ -205,8 +209,10 @@ def midi_devices_loop(): midi_in.close_ports() prev_ports = [] for port in curr_ports: - if port not in prev_ports and 'Midi Through' not in port and ( - len(prev_ports) != len(curr_ports) and 'LoopBe Internal' not in port): + if len([excluded_port_name for excluded_port_name in excluded_ports if excluded_port_name in port]) > 0 : + print "Ignored MIDI port: ", port + continue + if port not in prev_ports and (len(prev_ports) != len(curr_ports)): midi_in.open_ports(port) midi_in.callback = gv.midicallback.callback if first_loop: @@ -218,6 +224,43 @@ def midi_devices_loop(): first_loop = False time.sleep(0.2) + if gv.USE_LAUNCHPAD: + + import grid_instrument + + def LaunchpadNoteCallback(messageType, midiNote, velocity): + if messageType is "note_on": + # MidiCallback([0b10010001, midiNote, velocity], None) + gv.ac.noteon(midiNote, 1, velocity) + elif messageType is "note_off": + # MidiCallback([0b10000001, midiNote, velocity], None) + gv.ac.noteoff(midiNote, 1) + + def LaunchpadButtonCallback(x, y, pressed): + if gv.SYSTEM_MODE is 1: + if x is 1 and y is 9 and pressed: + gv.nav.state.left() + elif x is 2 and y is 9 and pressed: + gv.nav.state.right() + if gv.SYSTEM_MODE is 2: + if x is 1 and y is 9 and pressed: + gv.nav.down() + elif x is 2 and y is 9 and pressed: + gv.nav.up() + + instrument = grid_instrument.GridInstrument(); + # set the callback for midi events + instrument.note_callback = LaunchpadNoteCallback + # set the callback for function buttons + instrument.func_button_callback = LaunchpadButtonCallback + + instrument.kid_mode = False + instrument.debugging = False + instrument.intro_message = "SamplerBox" + + LaunchpadThread = threading.Thread(target=instrument.start) + LaunchpadThread.daemon = True + LaunchpadThread.start() if gv.USE_GUI and not gv.IS_DEBIAN: