os/net/ ZeroMQ
ZeroMQ is a framework for writing distribute applications. Homepage
RtMidi Pipe
Example that takes midi from a device (here an M32), and forwards the raw midi messages via ZeroMQ.
Server
import time
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
message = socket.recv()
print("Received request: ",end="")
for i,x in enumerate(message):
print(f"{x:02x}",end=" ")
if (i+1)%32 == 0:
print()
if (i+1)%32 != 0:
print()
# Send reply back to client
socket.send(b"ACK")
Client
import zmq
from time import sleep
from rtmidi import RtMidiIn
context = zmq.Context()
# Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
pat = "M32"
midiin = RtMidiIn()
for i in range(midiin.getPortCount()):
name = midiin.getPortName(i)
if pat in name:
midiin.openPort(i)
break
else:
print(f"Didn't find port with name containing {pat}")
exit(1)
def cb(e):
a = e.getRawData()
print(a)
socket.send(a)
message = socket.recv()
print(f"received {message}")
midiin.setCallback(cb)
try:
while True:
sleep(0.01)
except KeyboardInterrupt:
exit(0)