We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all.
So my code is now advancing but it's still laggy. It receives the data in Ableton but it's very temperamental. I've avoided using delay functions as it delays the entire thing. If anyone has any suggestions or can see any anomalies it would be much appreciated! Thank you :)
import gab.opencv.*;
import processing.video.*;
import ipcapture.*;
import org.opencv.core.Rect;
import themidibus.*; //Import the library
OpenCV opencv;
IPCapture cam;
MidiBus midi;
int lastMillis;
int [] timestamps = new int [128];
void setup() {
size(640, 480);
//video = new Movie(this, "street.mov"); MUTED
cam = new IPCapture(this, "http://153.201.66.43:60001/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, "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);
strokeWeight(1);
int rx = 300;
int ry = 150;
int rw = 30;
int rh = 15;
rect(rx, ry, rx+rw, ry+rh);
int rx2 = 10;
int ry2 = 10;
int rw2 = 15;
int rh2 = 15;
rect(rx2, ry2, rx2+rw2, ry2+rh2);
stroke(255, 0, 0);
strokeWeight(10);
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();
{
int [] numbers = new int [128];
if (( x > rx && x < rx + rw) && (y > ry && y < ry + rh))
for (int i = -1; i < timestamps.length; i++)
midi.sendNoteOn(0, 62, 127);
timestamps[62] = millis();
if (millis()>lastMillis+40)
midi.sendNoteOff(0, 62, 127);
println(timestamps);
}
}
}
}
Answers
Tip: Also check your latency setting on your Computer.
https://help.ableton.com/hc/en-us/articles/209072249-Understanding-Reduced-Latency-when-Monitoring
https://www.soundonsound.com/techniques/optimising-latency-pc-audio-interface
All drivers up-to-date ?
https://sound.stackexchange.com/questions/22397/asio4all-couldnt-get-beneath-24-ms-latency
Might help
http://www.asio4all.com/
So you don't think this has anything to do with the code? Does it all look a-okay?
Also, I don't think it's a problem with Ableton, I think it's a problem with the code. I'm not sure if it stops sending midi from Processing or if Ableton stops receiving midi but in normal circumstances, Ableton runs perfect for me. My mac is pretty well spec'd up and is only a month old.