The MIDIBus in python mode

edited June 2016 in Python Mode

I'm trying to receive midi beat clock information from a DAW into processing via the IAC driver. I have got MIDI note information going out from processing into the DAW fine, but I want to sync up with the tempo of the project.

From examples in the Java info for The MIDIBus library I am getting something that looks like it is the midi clock info with this:

  import themidibus.*; //Import the library
  MidiBus myBus; // The MidiBus

  void setup() {
    size(400, 400);

    myBus = new MidiBus(this, 0, 0); // Create a new MidiBus object

  // Notice all bytes below are converted to integeres using the following system:
  // int i = (int)(byte & 0xFF) 
  // This properly convertes an unsigned byte (MIDI uses unsigned bytes) to a signed int
  // Because java only supports signed bytes, you will get incorrect values if you don't do so

  void rawMidi(byte[] data) { // You can also use rawMidi(byte[] data, String bus_name)
    // Receive some raw data
    // data[0] will be the status byte
    // data[1] and data[2] will contain the parameter of the message (e.g. pitch and volume for noteOn noteOff)
    println("Raw Midi Data:");
    println("Status Byte/MIDI Command:"+(int)(data[0] & 0xFF));
    // N.B. In some cases (noteOn, noteOff, controllerChange, etc) the first half of the status byte is the command and the second half if the channel
    // In these cases (data[0] & 0xF0) gives you the command and (data[0] & 0x0F) gives you the channel
    for (int i = 1;i < data.length;i++) {
      println("Param "+(i+1)+": "+(int)(data[i] & 0xFF));

but when I try translating this into python it doesn't like taking byte[] as a variable in rawMidi. This is how I tried to do it in python (excluding the superfluous stuff):


def setup():
    global myBus
    myBus = MidiBus(this, 0, 0)

def rawMidi(byte[] data):
    println("Raw Midi Data:")
    println("Status Byte/MIDI Command:"+ int(data[0] & 0xFF))

I apologise if my question is a bit jumbled - not an experienced programmer at all.

Sign In or Register to comment.