MIdi signal from Processing to Ableton is very glitchy, any ideas on how to help this issue?

Hey all.

Finally cracked my new project of triggering midi in Ableton via webcam movement but the midi signal is very glitchy and intermittent, despite my console telling me is it sending out signals. I feel it might be an issue with buffer size as when I'm sending a small amount of data, it works okay. Anything bigger and it glitches.

If you need a screen recording of what is happening, let me know. Otherwise I've posted the code underneath. Thanks!

import gab.opencv.*;
import processing.video.*;
import ipcapture.*;
import org.opencv.core.Rect;
import themidibus.*; //Import the library

OpenCV opencv;
IPCapture cam;
MidiBus midi; 


void setup() {
  size(640, 480);
  //video = new Movie(this, "street.mov"); MUTED
  cam = new IPCapture(this, "http://" + "100.38.83.153:8081/mjpg/video.mjpg?resolution=640x480", "", "");
  cam.start();
  opencv = new OpenCV(this, 640, 480);

  opencv.startBackgroundSubtraction(5, 3, 0.5);
  MidiBus.list();
  midi = new MidiBus(this, -1, "IAC Bus 1");

  //video.loop();
  //video.play();
}

void draw() {
  if (cam.isAvailable()) {
    cam.read();
    image(cam, 0, 0);  
    opencv.loadImage(cam);
    opencv.updateBackground();

    opencv.dilate();
    opencv.erode();

    noFill();
    stroke(255, 0, 0);
    strokeWeight(5);
    for (Contour contour : opencv.findContours()) {


      println(contour.getBoundingBox().x);
      println(contour.getBoundingBox().y);
      int x = contour.getBoundingBox().x;
      int y = contour.getBoundingBox().y;

      contour.draw();

      if ((x < 700) && (x > 650)) 
        println("x1");
      midi.sendNoteOn(0, 60, 127);
      midi.sendNoteOff(0, 60, 127);

      if ((x < 649) && (x > 600)) 
        println("x2");
      midi.sendNoteOn(0, 61, 127);
      midi.sendNoteOff(0, 61, 127);


      if ((x < 599) && (x > 550)) 
        println("x3");
      midi.sendNoteOn(0, 62, 127);
      midi.sendNoteOff(0, 62, 127);

      if ((x < 549) && (x > 500)) 
        println("x4");
      midi.sendNoteOn(0, 63, 127);
      midi.sendNoteOff(0, 63, 127);


      if ((x < 499) && (x > 450)) 
        println("x5");
      midi.sendNoteOn(0, 64, 127);
      midi.sendNoteOff(0, 64, 127);

      if ((x < 449) && (x > 400)) 
        println("x6");
      midi.sendNoteOn(0, 65, 127);
      midi.sendNoteOff(0, 65, 127);

      if ((x < 399) && (x > 350)) 
        println("x7");
      midi.sendNoteOn(0, 66, 127);
      midi.sendNoteOff(0, 66, 127);


      if ((x < 349) && (x > 300)) 
        println("x8");
      midi.sendNoteOn(0, 67, 127);
      midi.sendNoteOff(0, 67, 127);

      if ((x < 299) && (x > 250)) 
        println("x9");
      midi.sendNoteOn(0, 68, 127);
      midi.sendNoteOff(0, 68, 127);

      if ((x < 249) && (x > 200)) 
        println("x10");
      midi.sendNoteOn(0, 69, 127);
      midi.sendNoteOff(0, 69, 127);


      if ((x < 199) && (x > 150)) 
        println("x11");
      midi.sendNoteOn(0, 69, 127);
      midi.sendNoteOff(0, 69, 127);

      if ((x < 149) && (x > 100)) 
        println("x12");
      midi.sendNoteOn(0, 69, 127);
      midi.sendNoteOff(0, 69, 127);

      if ((x < 99) && (x > 50)) 
        println("X13");
      midi.sendNoteOn(0, 69, 127);
      midi.sendNoteOff(0, 69, 127);

      if ((x < 49) && (x > 1)) 
        println("x14");
      midi.sendNoteOn(0, 69, 127);
      midi.sendNoteOff(0, 69, 127);


      if ((y < 700) && (y > 650)) 
        println("y1");
      midi.sendNoteOn(1, 60, 127);
      midi.sendNoteOff(1, 60, 127);

      if ((y < 649) && (y > 600)) 
        println("x2");
      midi.sendNoteOn(1, 61, 127);
      midi.sendNoteOff(1, 61, 127);


      if ((y < 599) && (y > 550)) 
        println("y");
      midi.sendNoteOn(1, 62, 127);
      midi.sendNoteOff(1, 62, 127);

      if ((y < 549) && (y > 500)) 
        println("x4");
      midi.sendNoteOn(1, 63, 127);
      midi.sendNoteOff(1, 63, 127);


      if ((y < 499) && (y > 450)) 
        println("y5");
      midi.sendNoteOn(1, 64, 127);
      midi.sendNoteOff(1, 64, 127);

      if ((y < 449) && (y > 400)) 
        println("y6");
      midi.sendNoteOn(1, 65, 127);
      midi.sendNoteOff(1, 65, 127);

      if ((y < 399) && (y > 350)) 
        println("y7");
      midi.sendNoteOn(1, 66, 127);
      midi.sendNoteOff(1, 66, 127);


      if ((y < 349) && (y > 300))
        println("y8");
      midi.sendNoteOn(1, 67, 127);
      midi.sendNoteOff(1, 67, 127);

      if ((y < 299) && (y > 250)) 
        println("y9");
      midi.sendNoteOn(1, 68, 127);
      midi.sendNoteOff(1, 68, 127);

      if ((y < 249) && (y > 200)) 
        println("y10");
      midi.sendNoteOn(1, 69, 127);
      midi.sendNoteOff(1, 69, 127);


      if ((y < 199) && (y > 150)) 
        println("y11");
      midi.sendNoteOn(1, 69, 127);
      midi.sendNoteOff(1, 69, 127);

      if ((y < 149) && (y > 100)) 
        println("y12");
      midi.sendNoteOn(1, 69, 127);
      midi.sendNoteOff(1, 69, 127);

      if ((y < 99) && (y > 50)) 
        println("y13");
      midi.sendNoteOn(1, 69, 127);
      midi.sendNoteOff(1, 69, 127);

      if ((y < 49) && (y > 1)) 
        println("y14");
      midi.sendNoteOn(1, 69, 127);
      midi.sendNoteOff(1, 69, 127);
    }



    // void movieEvent(Movie m) {
    //  m.read();
  }
}

EDIT. Sorry, being stupid and can't get the code quoted properly! Edit 2, Got it ;)

Answers

  • Answer ✓
      if ((x < 700) && (x > 650)) 
        println("x1");
      midi.sendNoteOn(0, 60, 127);
      midi.sendNoteOff(0, 60, 127);
    

    ok, you do realise that lines 3 and 4 here are unconditional. without a {} block defined after the condition then only the first statement is conditional. the way that code read is that everything from line 50 onwards is always executed for each contour. which is certainly not what you want (and may cause flooding)

  • Answer ✓

    also, sending noteOn and then immediately noteOff, is that going to work?

  • Yes, that's perfect! Thank you very much for your help. I wrote delay(50) after midion and it worked great. As wrll as use of {}. Thank you kindly!

Sign In or Register to comment.