Page 1 of 1

Better way to send MIDI over Wifi ?

Posted: Thu Apr 10, 2025 7:05 am
by mattjakob
Id like to experiment with creating live visuals on my laptop using midi output from Push3 SA over Wifi. I already wrote python script and run it via ssh on the Push3 (see below) and it works but wonder if there's maybe a better way to do this (eg. with M4L device) ?

Code: Select all

import rtmidi
    import socket
    import time
    
    HOSTNAME = "mycelium.local"
    PORT = 5500
    
    # Resolve hostname to IP
    try:
        HOSTIP = socket.gethostbyname(HOSTNAME)
        print(f"📡 Resolved {HOSTNAME} to {HOSTIP}")
    except socket.gaierror:
        print("❌ Could not resolve hostname.")
        exit(1)
    
    # Set up UDP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    # Initialize MIDI input
    midiin = rtmidi.MidiIn()
    ports = midiin.get_ports()
    
    print("Available MIDI Ports:")
    for i, port in enumerate(ports):
        print(f"  [{i}] {port}")
    
    # Open working port (index 0)
    midiin.open_port(0)
    print(f"✅ Listening on: {ports[0]}")
    print(f"🚀 Streaming MIDI to {HOSTIP}:{PORT}")
    
    try:
        while True:
            msg = midiin.get_message()
            if msg:
                message, _ = msg
                status = message[0] & 0xF0
                channel = (message[0] & 0x0F) + 1
    
                # Debug print
                if status == 0x90 and message[2] > 0:
                    print(f"🎵 Note On : {message[1]} vel {message[2]} (ch {channel})")
                elif status == 0x80 or (status == 0x90 and message[2] == 0):
                    print(f"🎹 Note Off: {message[1]} vel {message[2]} (ch {channel})")
                elif status == 0xB0:
                    print(f"?. CC      : CC#{message[1]} val {message[2]} (ch {channel})")
                else:
                    print(f"🔧 Other   : {message}")
    
                sock.sendto(bytearray(message), (HOSTIP, PORT))
            time.sleep(0.001)
    
    except KeyboardInterrupt:
        print("?.? Stopped.")
        midiin.close_port()
        
        

Re: Better way to send MIDI over Wifi ?

Posted: Mon Apr 28, 2025 1:44 am
by lookmom
+1 on a much needed standard feature!
in the meantime any chance you could do a step by step of this current rtmidi setup? its the only think holding me back from going fully standalone and would love to give it a try.