python-drum-sequencer/midihelp.py

69 lines
2.3 KiB
Python
Executable file

import mido
import time
import sys
def test_midi():
print("=== MIDI Connection Test ===")
# Check available ports
try:
ins = mido.get_input_names()
print("\nAvailable MIDI input ports:")
for i, port in enumerate(ins):
print(f"{i + 1}. {port}")
if not ins:
print("No MIDI input ports found!")
return False
# Look for LPD8
lpd8_ports = [port for port in ins if 'LPD8' in port]
if lpd8_ports:
print("\nFound LPD8 device:", lpd8_ports[0])
port_name = lpd8_ports[0]
else:
print("\nLPD8 not found. Please select a port number:")
choice = input("> ")
try:
port_name = ins[int(choice) - 1]
except (ValueError, IndexError):
print("Invalid selection!")
return False
# Try to open the port
print(f"\nAttempting to connect to: {port_name}")
with mido.open_input(port_name) as inport:
print("✓ Successfully opened MIDI port")
print("\nNow listening for MIDI messages...")
print("Press pads/knobs on your controller (Ctrl+C to exit)")
try:
while True:
msg = inport.poll()
if msg:
print(f"Received: {msg}")
time.sleep(0.1) # Small delay to prevent CPU hogging
except KeyboardInterrupt:
print("\nTest completed!")
return True
except Exception as e:
print(f"\nError: {e}")
print("\nTroubleshooting tips:")
print("1. Make sure your MIDI device is properly connected")
print("2. Try unplugging and reconnecting the USB cable")
print("3. Check if device shows up in your system's MIDI devices")
print("4. Ensure no other applications are using the MIDI port")
return False
if __name__ == "__main__":
success = test_midi()
if success:
print("\n✓ MIDI system is working correctly!")
else:
print("\n✗ MIDI test failed. Please check your MIDI configuration.")
print("\nPress Enter to exit...")
input()