def get_devices(): devices = [] input_names = set(rtmidi.MidiIn().ports) output_names = set(rtmidi.MidiOut().ports) for name in sorted(input_names | output_names): devices.append({ 'name': name, 'is_input': name in input_names, 'is_output': name in output_names, }) return devices
def get_devices(api=None, **kwargs): devices = {} input_names = rtmidi.MidiIn().ports output_names = rtmidi.MidiOut().ports for name in input_names + output_names: if name not in devices: devices[name] = { 'name': name, 'is_input': name in input_names, 'is_output': name in output_names, } return list(devices.values())
def create_midi(self, midiportindex): # Midi startup. Try creating a virtual port. Doesn't work on Windows midi_out = rtmidi.MidiOut() if midiportindex: if platform.system() == "Windows": if len(midi_out.ports) > 1: print "Can't open virtual midi port on windows. Using midi loopback instead." midi_out.open_port(midiportindex) self.set_midi_active(True) else: return None else: midi_out.open_virtual_port("LiveShowtime_Midi") self.set_midi_active(True) return midi_out
def _open(self, virtual=False, **kwargs): self._queue = queue.Queue() self._callback = None # rtapi = _get_api_id(api) opening_input = hasattr(self, 'receive') if opening_input: self._rt = rtmidi.MidiIn() self._rt.ignore_types(False, False, True) self.callback = kwargs.get('callback') else: self._rt = rtmidi.MidiOut() # rtapi=rtapi) # Turn of ignore of sysex, time and active_sensing. ports = self._rt.ports if virtual: if self.name is None: raise IOError('virtual port must have a name') self._rt.open_virtual_port(self.name) else: if self.name is None: # TODO: this could fail if list is empty. # In RtMidi, the default port is the first port. try: self.name = ports[0] except IndexError: raise IOError('no ports available') try: port_id = ports.index(self.name) except ValueError: raise IOError('unknown port {!r}'.format(self.name)) try: self._rt.open_port(port_id) except RuntimeError as err: raise IOError(*err.args) # api = _api_to_name[self._rt.get_current_api()] api = '' self._device_type = 'RtMidi/{}'.format(api) if virtual: self._device_type = 'virtual {}'.format(self._device_type)
def __init__(self, machine_type): super(FapoGame, self).__init__(machine_type) self.gameConfig = GameConfig.GameConfig() self.ball_start_time = 0 self.midiMap = None self.midiLampMap = None if self.gameConfig.inputKeyboardTest: self.midiMap = self.gameConfig.midiKeyboardMap self.midiLampMap = None if self.gameConfig.inputLaunchpadTest: self.midiLampMap = self.gameConfig.midiLaunchpadMap self.load_config('config/funhouse.yaml') ### ALPHANUMERIC DISPLAY ### self.aux_port = auxport2.AuxPort(self) self.alpha_display = alphanumeric2.AlphanumericDisplay(self.aux_port) # self.scoredisplay = scoredisplay.AlphaScoreDisplay(self,4) # blink text ### MODES ### self.basic_mode = BasicMode.BasicMode(game=self) self.idle_mode = IdleMode.IdleMode(game=self) self.steps_mode = StepsMode.StepsMode(game=self) self.alpha_mode = scoredisplay.AlphaScoreDisplay(game=self, priority=5) self.trough_mode = procgame.modes.trough.Trough( self, ["trough1", "trough2", "trough3"], "trough1", "trough", [], "shooterR", self.ballDrained) ### MIDI HANDLING ### self.midi_in_sol = rtmidi.MidiIn() self.midi_in_sol.open_port(self.gameConfig.inputMidiSolenoids) self.midi_in_lamp = rtmidi.MidiIn() self.midi_in_lamp.open_port(self.gameConfig.inputMidiLamps) self.midi_out = rtmidi.MidiOut() self.midi_out.open_port(self.gameConfig.outputMidiSwitches) self.addSwitchHandlers() ### LAMP SHOWS ### self.lampctrl = procgame.lamps.LampController(self) self.lampctrl.register_show('attract', 'lamps/attract.lampshow') self.lampctrl.register_show('start', 'lamps/start.lampshow') self.lampctrl.register_show('trapdoorOpen', 'lamps/trapdoorOpen.lampshow') print self.lamps
def _open(self, virtual=False, callback=None): opening_input = hasattr(self, 'receive') if opening_input: self._rt = rtmidi.MidiIn() self._rt.ignore_types(False, False, False) if callback: def callback_wrapper(message, delta_time): self._parser.feed(message) for message in self._parser: callback(message) self._rt.callback = self._callback = callback_wrapper self._has_callback = True else: self._has_callback = False else: self._rt = rtmidi.MidiOut() # Turn of ignore of sysex, time and active_sensing. ports = self._rt.ports if virtual: if self.name is None: raise IOError('virtual port must have a name') self._rt.open_virtual_port(self.name) else: if self.name is None: # Todo: this could fail if list is empty. # In RtMidi, the default port is the first port. try: self.name = ports[0] except IndexError: raise IOError('no ports available') try: port_id = ports.index(self.name) except ValueError: raise IOError('unknown port {!r}'.format(self.name)) self._rt.open_port(port_id) self._device_type = 'rtmidi_python'
def connect_midi(cli_port, settings_port): port = None midiout = rtmidi_python.MidiOut() midiin = rtmidi_python.MidiIn() midiin.ignore_types(midi_sysex=False) if cli_port is None: port = settings_port or None else: port = cli_port if port is None: raise click.UsageError( "No port specified ({} currently connected)".format(", ".join( midiin.ports))) try: midiin.open_port(port) midiout.open_port(port) except ValueError: raise click.UsageError( "Unable to connect to {}. Is the device connected?".format(port)) return midiin, midiout, port
def __init__(self, bpm=120, time_sig=4, real_hardware=False): self.bpm = bpm self.real_hardware = real_hardware self.bps = bpm/60.0 self._valid_time_sigs = [2, 3, 4] if time_sig not in self._valid_time_sigs: print("uh oh time sig not valid") raise self.time_sig = time_sig self.current_time = time.time() self.bar_length_seconds = self.bps * time_sig self.last_remainder = 0 self.data = MidiData("test") self.beat_time_s = self.bar_length_seconds / 20 self.timer2 = time.time() self.buffer = {(self.beat_time_s*x):None for x in range(0, 100)} if self.real_hardware: self.midi_in = rtmidi.MidiIn() self.midi_in.callback = self.callback self.midi_in.open_port(0) self.midi_out = rtmidi.MidiOut() self.midi_out.open_port(0) self.samples = [] self.beat_dict = {j:None for j in range(0, 16)}
import sys sys.setcheckinterval(1) import rtmidi_python as rtmidi midi_out = rtmidi.MidiOut() midi_out.open_port(3) # port starts with 0 from available OUT to rtmidi/OS #import random BPM = 120.0 # Beats per minute BPS = BPM / 60.0 # Beats per second 60 seconds in a minute beatsPerBar = 4.0 # 4/4 Timing ratio = BPS / beatsPerBar NWhole = ratio NHalf = ratio * 0.5 NTrip = ratio * 0.33 NQuarter = ratio * 0.25 NEighth = NQuarter * 0.5 NSixteenth = NEighth * 0.5 NThirtySecond = NSixteenth * 0.5 NSixtyForth = NThirtySecond * 0.5 #standard SPD-SX Mapping FtSw2 = 74 FtSw1 = 73 Trig4 = 72 Trig3 = 71 Trig2 = 70 Trig1 = 69 Pad9 = 68 Pad8 = 67
CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 1 WAVE_NAME = "output" WAVE_ENDING = ".wav" p = pyaudio.PyAudio() print("* recording") streams = [] count = 1 next_downbeat_millis = [10000000000000000000000] bpm = 120 midi_out = rtmidi.MidiOut(b'out') midi_out.open_port(0) def callback(in_data, frame_count, time_info, status): #print("saving to disk. frame_count is " +str(frame_count)) frames = [] frames.append(in_data) timestamp = datetime.datetime.now().time() timestring = str(timestamp) cur_millis = int(round(time.time() * 1000)) print('cur_millis is ' + str(cur_millis)) cur_filename = WAVE_NAME + timestring[-12:-10] + '.' + timestring[ -9:-5] + WAVE_ENDING
import rtmidi_python as rtmidi import RPi.GPIO as gpio import time as t gpio.setmode(gpio.BOARD) gpio.setup(10, gpio.IN, pull_up_down=gpio.PUD_DOWN) outport = rtmidi.MidiOut() outport.open_virtual_port("vp") while True: if gpio.input(10) == gpio.HIGH: outport.send_message([0xb0, 0x74, 124]) print('BUTTON PRESSED') t.sleep(0.05) #outport.send_message([0x90, 60, 0])
import time import rtmidi_python as rtmidi midiout = rtmidi.MidiOut() #available_ports = midiout.get_ports() #if available_ports: #midiout.open_port(1) #else: midiout.open_virtual_port("My virtual output") note_on = [0x90, 60, 112] # channel 1, middle C, velocity 112 note_off = [0x80, 60, 0] midiout.send_message(note_on) time.sleep(0.5) #midiout.send_message(note_off) midiout.send_message([0x90, 63, 112]) midiout.send_message([0x90, 64, 90]) midiout.send_message([0x90, 65, 127]) midiout.send_message([0x90, 66, 112]) midiout.send_message([0x90, 67, 112]) midiout.send_message([0x90, 68, 112]) midiout.send_message([0x90, 69, 90]) midiout.send_message([0x90, 70, 127]) midiout.send_message([0x90, 71, 112]) midiout.send_message([0x90, 72, 112]) midiout.send_message([0x90, 73, 112]) midiout.send_message([0x90, 74, 90]) midiout.send_message([0x90, 75, 127])
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)
print "------------------" preset = 0 LoadSamples() ######################################### # MIDI DEVICES DETECTION # MAIN LOOP ######################################### midi_in = [rtmidi.MidiIn()] print len(midi_in[0].ports) if len(midi_in[0].ports) < 2: if USE_MIDI_VIRTUAL_PORT: midi_virtual = rtmidi.MidiOut() midi_virtual.open_virtual_port("Midi") print "No midi device detected, Loading Midi Virtual port..." previous = [] display('Running') try: while True: for port in midi_in[0].ports: if port not in previous and 'Midi Through' not in port: midi_in.append(rtmidi.MidiIn()) midi_in[-1].callback = MidiCallback midi_in[-1].open_port(port) print '[MIDI]: ' + port
def _setup_midi_ports(self): self._stop_midi_in = Event() def midi_read(socket_io, stop): midi_in = rtmidi_python.MidiIn(b'in') if self._debug: for port in midi_in.ports: print("In Port: %s" % port) midi_in.open_port(self._config['midi_port_in']) knob_temp_values = {} while not self._stop_midi_in.is_set(): now = time.time() keys_to_delete = [] for knob_key, knob_value in knob_temp_values.items(): if now - knob_value['time'] >= self._config['knob_accept_time_ms'] / 1000: # Fire the knob change event new_value = self.compute_knob_value(knob_key, knob_value['value']) device_id, value_change = self._set_value_by_key( key='midi_port', value=knob_key, new_value=new_value, update_types=[Update.PIMATIC] ) # We cannot delete the key while iterating, so we do this after the iteration keys_to_delete.append(knob_key) for key in keys_to_delete: del knob_temp_values[key] message, delta_time = midi_in.get_message() if message: if message[0] == self._config['midi_pad_on']: pass elif message[0] == self._config['midi_pad_off']: # A pad button was released device_id, value_change = self._set_value_by_key( key='midi_port', value=message[1], update_types=[Update.PIMATIC, Update.MIDI] ) elif message[0] == self._config['knob_type']: # A knob was changed # print("Knob was changed: %s" % message) knob_temp_values[message[1]] = { 'value': message[2], 'time': time.time() } elif self._debug: print("Unrecognized midi input: %s" % message) time.sleep(0.01) midi_read_thread = Thread(target=midi_read, args=(self._socket_io, self._stop_midi_in)) midi_read_thread.start() # There seems to be a timing issue if we dont sleep here time.sleep(0.1) self._midi_out = rtmidi_python.MidiOut(b'out') if self._debug: for port in self._midi_out.ports: print("Out Port: %s" % port) self._midi_out.open_port(self._config['midi_port_out'])
def __init__(self): print("initialized MIDI") self.midi_out = rtmidi.MidiOut() self.midi_out.open_port(self.kMidiPortNumber) self.channel = 1
def initmidiinout(): global midiout, midiin midiout = rtmidi.MidiOut(b'out') midiin = rtmidi.MidiIn(b'in')
def get_ports(): midi_out = rtmidi.MidiOut(b'out') available_ports = midi_out.ports return available_ports
def __init__(self): midi_out = rtmidi.MidiOut(b'out') midi_out.open_port(get_bus()) self.midi_out = midi_out
def build_device(self, **kwargs): return rtmidi.MidiOut()
import time import rtmidi_python as rtmidi import numpy as np # TODO: Put this in a settings file YAW_CC = 10 PITCH_CC = 11 ROLL_CC = 12 FRAMERATE = 30 CC_HEX = 0xb0 # Setup midi midi_out = rtmidi.MidiOut(b'in') midi_port = midi_out.ports[0] midi_out.open_port(midi_port) while True: t = time.time() pitch = 127 * 0.5 * (1 + np.sin(t)) yaw = 127 * 0.5 * (1 + np.sin(t - (1 / 3.0) * 2 * np.pi)) roll = 127 * 0.5 * (1 + np.sin(t - (2 / 3.0) * 2 * np.pi)) midi_out.send_message([CC_HEX, YAW_CC, pitch]) midi_out.send_message([CC_HEX, PITCH_CC, yaw]) midi_out.send_message([CC_HEX, ROLL_CC, roll]) time.sleep(1.0 / FRAMERATE)