Button to execute shell script on Push 3SA ?

Learn about building and using Max for Live devices.
Post Reply
mattjakob
Posts: 10
Joined: Sat Sep 30, 2023 10:20 pm

Button to execute shell script on Push 3SA ?

Post by mattjakob » Thu Apr 10, 2025 7:58 am

I wrote this python script and can run it successfully on Push3 SA via ssh but I was wondering if theres an easier way to do this… either create a button in M4L that triggers the shell script (tried max shell object but doesnt seem to work on Push) or maybe if there’s an easier way to do with a M4L device ?
(basically Id like to experiment with creating live visuals on my laptop using midi output from Push3 SA over Wifi)

Thanks 🙏🏼

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()
        
        

Post Reply