Rtmidi - Ableton Remote Script - How to send MIDI_CC signals from rtmidi to Ableton Python remote script

422 views Asked by At

I wrote an util to send midi data from a python script to ableton, mostly using rtmidi.

On the ableton side, I have a remote script, fairly simple with just couple of buttons in the main class:

...
self._session = SessionComponent(8, 1, is_enabled=True)

self.next_track_button = ButtonElement(True, MIDI_CC_TYPE, 0, 25, *a, **k)
self.previous_track_button = ButtonElement(True, MIDI_CC_TYPE, 0, 26, *a, **k)

self.next_track_button.add_value_listener(self._next_track)
self.previous_track_button.add_value_listener(self._prev_track)

    def _next_track(self, value):
        self.log_message("Next Track")
        self._session.set_offsets(1, 0)
        self._session.update()

    def _prev_track(self, value):
        self.log_message("Prev Track")
        self._session.set_offsets(-1, 0)
        self._session.update()
...

The remote scripts compile with no errors, but the two callbacks (_next_track and _prev_track) are never hit.

I was wondering if it has to do with the way I send the midi signal from rtmidi?

import rtmidi
from rtmidi.midiconstants import *

class MidiController:
...
    def send_midi_signal(self, data):
        self._init_midi_out()
        with self.midiout:
        #The issue is probably here
            msg = [(CONTROL_CHANGE & 0xF0) | ((self.channel) - 1 & 0xF)]
            msg.append(data & 0x7F)
            self.midiout.send_message(msg)
            time.sleep(0.5)
            del self.midiout
...

Ableton is definitely receiving a midi signal as I can see on the top left MIDI icon lighting. The issue is that it's not hitting the callbacks, changing track offset as requested.

Any idea of where the issue is? Been hitting my head on this many days.

I even tried to set the buttons to listen for MIDI_CC, no luck. Thanks.

1

There are 1 answers

0
jackyroo On

I finally solved this. For whoever looking for the same answer, I did many mistakes:

  1. The channel was set to 0 in python instead of 1. It's correct to use 0 if you want to send it on channel 1, but the msg concatenation was causing it to become 16.
  2. I changed the ButtonElement construction in the following way: self.previous_track_button = ButtonElement(True, MIDI_CC_TYPE, 0, 102)

To check the MIDI commands I was sending, I've used MIDI-OX, really useful.