Browse Source

Wrote python script to use rtMidi rather than JackConnect. This simplifies the Midi message management, but complicates the initial connection. JackConnection kit is still being used to connect the devices together, but this is clunky at the moment.

master
Max Franklin 3 years ago
parent
commit
4818bfa94c
1 changed files with 90 additions and 0 deletions
  1. +90
    -0
      python/pushControl.rtMidi.py

+ 90
- 0
python/pushControl.rtMidi.py View File

@ -0,0 +1,90 @@
#!/usr/bin/env python3
import rtmidi_python as rtmidi
import jack
from pythonosc import dispatcher
from pythonosc import osc_server
from pythonosc import osc_message_builder
from pythonosc import udp_client
midi_out = rtmidi.MidiOut(b'py2push')
midi_in = rtmidi.MidiIn(b'in')
print('midiOut ports')
for port in midi_in.ports:
print(port)
midi_in.open_port(2)
midi_out.open_virtual_port(b'out')
jClient = jack.Client('pushControl')
# OSC Functions
def play_head(addr, note, vel):
if vel > 0:
midi_out.send_message([0x90, 36+note, 112])
else :
midi_out.send_message([0x90, 36+note, 0])
def rec_head (addr, note, vel):
if vel > 0:
midi_out.send_message([0x90, 36+note, 5])
else :
midi_out.send_message([0x90, 36+note, 0])
def volume(addr, txt):
volume = 'Vol: ' + str(txt) + '%'
lcdWrite(volume, 3, 59)
def tempo(addr, txt):
tempo = str(txt) + ' bpm'
lcdWrite(tempo, 3, 0)
def pat_note(addr, note, vel):
print("patnote")
print(addr,note,vel)
if vel > 0:
midi_out.send_message([0x90, note, 124])
else :
midi_out.send_message([0x90, note, 0])
def clearLCD():
for l in range(0,4):
midi_out.send_message([240,71,127,21,28+l,0,0,247])
def lcdWrite(text,lo = 0,co = 0):
i = 0
clearLCD()
for l in str(text):
midi_out.send_message([240,71,127,21,24+lo,0,2,(co+0)+i,ord(l),247])
i += 1
@jClient.set_process_callback
def process(frames):
dispatcher.map("/rechead", rec_head)
dispatcher.map("/plyhead", play_head)
dispatcher.map("/volume", volume)
dispatcher.map("/tempo", tempo)
dispatcher.map("/patnote", pat_note)
while True:
message, delta_time = midi_in.get_message()
if message != None:
# print(message, delta_time)
if message[2] > 0:
midi_out.send_message([message[0], message[1], 45])
else :
midi_out.send_message(message)
with jClient:
jClient.connect('a2j:py2push [132] (capture): out', 'a2j:Ableton Push [36] (playback): Ableton Push MIDI 2')
clearLCD()
dispatcher = dispatcher.Dispatcher()
print('#' * 80)
server = osc_server.ThreadingOSCUDPServer(('127.0.0.1', 3000), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()

Loading…
Cancel
Save