eriknie
Jun 01, 2022 - 10:50
I wrote an Pythonista application to show lyrics and chord for live performance. It also plays backingtracks and is able to sort setlists. Works great. But I missed the option to use it with MIDI program changes to also setup my synths to the matching programs.
Finally I found a way to get this working: Pythonista --> UDP --> MidiFire --> MIDI-out
Could also be used the other way to receive midi data
Use MidiFire with OSC Exchange to MIDI synth. Setup UDP to port 8051, wrap data in sysex to no.
From Pythonista use the simple code that i found elsewhere, easy to tweak into program changes or other midi commands.
I hope this helps others
#https://adamsiembida.com/how-to-send-a-udp-packet-in-python/
import socket
# addressing information of target
#fill in your ip and port
IPADDR = '127.0.0.1'
PORTNUM = 8051
# enter the data content of the UDP packet as hex
msg1 = bytearray([0x90, 0x40, 0x60])
msg2 = bytes.fromhex('903e70')
#or using variable for midi note message
midi_message = '903c50'
midi_packet = bytes.fromhex(midi_message)
# initialize a socket, think of it as a cable
# SOCK_DGRAM specifies that this is UDP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
try:
# connect the socket, think of it as connecting the cable to the address location
s.connect((IPADDR, PORTNUM))
# send the command
s.send(midi_packet)
s.send(msg1)
s.send(msg2)
# close the socket
except:
pass
# close the socket
s.close()