def __init__(self, inport, split=62, transpose_lower=12, transpose_upper=0, client_name="keyb", port_name="TwoManuals"): self.midiin = rtmidi.MidiIn(client_name, 1000) self.split = split self.transpose_lower = transpose_lower self.transpose_upper = transpose_upper if isinstance(inport, str): try: inport = next(i for i, p in enumerate(self.midiin.ports) if p.startswith(inport)) except StopIteration: raise ValueError( "could not find a midi port with the given name") else: raise ValueError( "The inport should be a string indicating the port name to listen to" ) self.inport = inport self.port_name = port_name self.notes = [0] * 127 self.midiout: rtmidi.MidiOut = None self.start()
def __init__(self, inport, outport='KeyboardPipe'): """ Take the input from inport, transform it and output it to outport. Outport must be a string and defines the name of the virtual port created. Examples ======== >>> keyb = KeyboardPipe("KORG").start() >>> keyb.register_noteon(lambda ch, note, vel, k: (ch, note+1, vel)) # transpose one semitone up # Use note 36 as a channel switch, channel 0 if not pressed, channel 5 if pressed >>> keyb.register_noteon(lambda keyb, ch, note, vel: (keyb.notesdown[36]*5, note, vel)) >>> keyb.register_noteon((lambda keyb, ch, note, val: None), ch='ALL', note=36) """ self.inport = match_port(inport) self.midiin = rtmidi.MidiIn() self.midiout = None self.outport = outport self.noteon_funcs = [None for i in range(128 * 16)] self.noteon_funcs_all = [None for i in range(16)] self.noteoff_funcs = [None for i in range(128 * 16)] self.cc_funcs = [None for i in range(128 * 16)] self.notesdown = [0 for i in range(128 * 16)] self.callback_noteoff = self.callback_noteoff_route
def __init__(self): self._keyboard = Controller() self.in_ports = rtmidi2.get_in_ports() self.out_ports = rtmidi2.get_out_ports() self._midi_in = rtmidi2.MidiIn() self._midi_out = rtmidi2.MidiOut()
def __init__(self, port): self.notes = _np.zeros((127, ), dtype=int) self.mask = _np.zeros((127, ), dtype=int) self.mask[60:90] = 1 self.midiout = rtmidi.MidiOut() self.midiout.open_port() self.midiin = rtmidi.MidiIn('keyb', 1000) if isinstance(port, str): port = match_port(port) self.midiin.open_port(port) self.midiin.callback = self.callback
def __init__(self): self.midi_in = rtmidi2.MidiIn() self.midi_out = rtmidi2.MidiOut() # Enable sysex return self.midi_in.ignore_types(midi_sysex=False) device_name = "Launchpad MK2" try: index = self.midi_in.ports_matching(device_name + "*")[0] self.midi_in.open_port(index) self.midi_out.open_port(index) print("Port opened.") except IndexError: raise (IOError("Port not found."))
def __init__(self, loop=None): if loop is None: loop = asyncio.get_event_loop() self._loop = loop self.ticks = -1 self.bpm = 120 self._last_tick = time.time() self._tick_intervals = collections.deque(maxlen=96) self._tick_event = asyncio.Event() self._rtmin = rtmidi2.MidiIn("RtMidiClock") self._rtmin.ignore_types(True, False, True) self._rtmin.callback = self._on_midi_message self.stopped = False self.start()
def start(self): self.inports = [] for index in self.inport_indexes: port = rtmidi.MidiIn() port.open_port(index) port.callback = self.callback self.inports.append(port) self.outport = rtmidi.MidiOut() if self.outport_name: self.outport.open_virtual_port(self.outport_name) else: # check if we are doing a loop inportnames = get_ports() if get_outports()[0] in inportnames: self.outport_name = 'MERGE' self.outport.open_virtual_port(self.outport_name) else: # open the default port self.outport.open_port()
import rtmidi2 print("##------------------------------ initialize-ports") midi_in = rtmidi2.MidiIn().open_virtual_port("test-In-port") midi_out = rtmidi2.MidiOut().open_virtual_port("test-Out-port") print("#in-ports: ", rtmidi2.MidiIn().ports) print("#out-ports: ", rtmidi2.MidiOut().ports) print("##----------------------- import custom modules") import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk import midisw.mididefs import midisw.gtk3.piano print("##------------------------------------ open port") virt_out_port = midi_out.open_port() last_pressed = None print("##------------------------------------ def GUI and loop") def do_note_on(widget, ev): global virt_out_port, last_pressed note = widget.get_note()
fll_ib_begin_at = 0 spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 100000 spi.mode = 1 # data valid at negative edge of the CLK spi.cshigh = True # configure CS0 as active high if __name__ == '__main__': midi_in = rtmidi2.MidiIn() print(midi_in.ports) midi_in.callback = callback device_name = "nanoPAD2" try: index = midi_in.ports_matching(device_name + "*")[0] input_port = midi_in.open_port(index) print(index) print() print() except indexError: raise (IOError("Input port not found."))
CSOUND_ADDR = liblo.Address('localhost', 30018) s = liblo.Server() def callback(msg, t): msgtype, ch = splitchannel(msg[0]) if msgtype == CC: mapping = ccmap[msg[1]] if mapping: path, func = mapping value = func(ch, msg[1], msg[2]) s.send(CSOUND_ADDR, path, value) def exitfunc(): s.close() m = rtmidi2.MidiIn() m.open_port("BCF*") m.callback = callback atexit.register(exitfunc) try: while True: time.sleep(36000) except KeyboardInterrupt: pass
from collections import namedtuple as _namedtuple import atexit as _atexit import fnmatch as _fnmatch from numbers import Number as _Number import numpy as _np import rtmidi2 as rtmidi _INPORT_GLOBAL = rtmidi.MidiIn(clientname='tmp', queuesize=1000) _OUTPORT_GLOBAL = rtmidi.MidiOut() """ Reference: these values should not be used as globals in a tight loop since there is a global lookup involved. unless python has a way of inlining. use the value directly """ CC = 176 NOTEON = 144 NOTEOFF = 128 def match_port(portname: str): """ return the index of the port matching the given port-name Example ------- >>> get_ports() ['IAC Driver IAC Bus 1', 'Caps Lock Keyboard'] >>> match_port('IAC*') 0 """
def setUp(self): self.midi_out = rtmidi.MidiOut() self.midi_out.open_virtual_port(self.TEST_PORT_NAME) self.midi_in = rtmidi.MidiIn() self.midi_in.open_port(self.TEST_PORT_NAME)