How to use the mido.open_input function in mido

To help you get started, we’ve selected a few mido examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onlaj / Piano-LED-Visualizer / tests / printmidimessages.py View on Github external
import mido
from mido import MidiFile, Message, tempo2bpm, MidiTrack,MetaMessage

ports = mido.get_input_names()

for port in ports:
	if "Through" not in port and "RPi" not in port and "RtMidOut" not in port:
		try:
			inport =  mido.open_input(port)
			print("Inport set to "+port)
		except:
			print ("Failed to set "+port+" as inport")

while True:
	for msg in inport.iter_pending():
		print(msg)
github onlaj / Piano-LED-Visualizer / tests / lightkeys.py View on Github external
parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()

        # Create NeoPixel object with appropriate configuration.
        self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        self.strip.begin()

ledstrip = LedStrip()

ports = mido.get_input_names()

for port in ports:
	if "Through" not in port and "RPi" not in port and "RtMidOut" not in port:
		try:
			inport =  mido.open_input(port)
			print("Inport set to "+port)
		except:
			print ("Failed to set "+port+" as inport")

green = 255
red = 255
blue = 255

while True:
	for msg in inport.iter_pending():
		note = find_between(str(msg), "note=", " ")
		original_note = note
		note = int(note)
		if "note_off" in str(msg):
			velocity = 0
		else:
github lebaston100 / MIDItoOBS / setup.py View on Github external
action_select = int(input("Select 1 or 2: "))
        if action_select == 1:
            configureDevices(1) #start device settings dialog because user choice
        elif action_select == 2:
            pass #leave configuration as is
        else:
            print("Invalid selection")
            ScriptExit(0, 0)
    else:
        configureDevices(0) #start device settings dialog because nothing is set up yet
        #the functions will return and we'll continue here

    devices = devdb.all()
    for device in devices: #gave up on documentation here
        try:
            tempmidiport = mido.open_input(device["devicename"])
            tempobj = {"id": device.doc_id, "object": tempmidiport, "devicename": device["devicename"]}
            midiports.append(tempobj)
        except:
            print("\nCould not open device", device["devicename"])
            print("The midi device might be used by another application/not plugged in/have a different name.")
            print("Please close the device in the other application/plug it in/edit the name in the config.json and restart this script.\n")
            database.close()
            sys.exit(5)

    print("\nPlease press key or move fader/knob on midi controller")
    mainLoop()
    ScriptExit(0, 0)
github mido / mido / examples / ports / receive.py View on Github external
#!/usr/bin/env python
"""
Receive messages from the input port and print them out.
"""
from __future__ import print_function
import sys
import mido

if len(sys.argv) > 1:
    portname = sys.argv[1]
else:
    portname = None  # Use default port

try:
    with mido.open_input(portname) as port:
        print('Using {}'.format(port))
        print('Waiting for messages...')
        for message in port:
            print('Received {}'.format(message))
            sys.stdout.flush()
except KeyboardInterrupt:
    pass
github mido / mido / examples / ports / multi_receive.py View on Github external
#!/usr/bin/env python
"""
Receive messages from multiple ports.
"""
import mido
from mido.ports import MultiPort

# Open all available inputs.
ports = [mido.open_input(name) for name in mido.get_input_names()]
for port in ports:
    print('Using {}'.format(port))
print('Waiting for messages...')

multi = MultiPort(ports)
try:
    for message in multi:
        print('Received {}'.format(message))
except KeyboardInterrupt:
    pass
github segfault16 / modular-led-controller-workstation / audioled / generative.py View on Github external
def __initstate__(self):
        super(MidiKeyboard, self).__initstate__()
        try:
            import mido
        except ImportError as e:
            logger.error('Unable to import the mido library')
            logger.error('You can install this library with `pip install mido`')
            raise e
        try:
            self._midi.close()
        except Exception:
            pass
        try:
            self._midi = mido.open_input(self.midiPort)
        except OSError as e:
            self._midi = mido.open_input()
            self.midiPort = self._midi.name
            logger.info("Not connected midi device {}".format(self.midiPort))
            logger.error(e)
        self._on_notes = []
github icaroferre / MIDIRouter / midirouter.py View on Github external
def changeinputPort(x):
    global inputPort
    try:
        inputPort.close()
    except NameError:
        pass
    inputPort = mido.open_input(x, callback=InMSG)
    print("Input port changed to: " + x)
github eegsynth / eegsynth / module / launchcontrol / launchcontrol.py View on Github external
mididevice_output = EEGsynth.trimquotes(mididevice_output)

    mididevice_input  = process.extractOne(mididevice_input, mido.get_input_names())[0] # select the closest match
    mididevice_output = process.extractOne(mididevice_output, mido.get_output_names())[0] # select the closest match

    # this is only for debugging, check which MIDI devices are accessible
    monitor.info('------ INPUT ------')
    for port in mido.get_input_names():
      monitor.info(port)
    monitor.info('------ OUTPUT ------')
    for port in mido.get_output_names():
      monitor.info(port)
    monitor.info('-------------------------')

    try:
        inputport = mido.open_input(mididevice_input)
        monitor.info("Connected to MIDI input")
    except:
        raise RuntimeError("cannot connect to MIDI input")

    try:
        outputport = mido.open_output(mididevice_output)
        monitor.info("Connected to MIDI output")
    except:
        raise RuntimeError("cannot connect to MIDI output")

    # channel 1-16 in the ini file should be mapped to 0-15
    if not midichannel is None:
        midichannel-=1
    monitor.update('midichannel', midichannel)

    # these are the MIDI values for the LED color