Sending just one midi message with ofxMidi



I am trying to create a generative audio piece where when objects collide, midi information if sent from OF to Ableton Live. I have everything connected and making sound but currently I can’t figure out how to stop the midi messages from bring sent - I just want one note played as if playing a keyboard.

This is my midi out code currently:

void ofApp::sendMidi(vectorboids, RedMouse _rm) {
for(int i = 0; i < boids.size(); i++) {
float distance = ofDist(_rm.location.x, _rm.location.y, boids[i].position.x, boids[i].position.y);
if (distance < 20 && distance > 0) {
noteVelocity = 80;
midiOut.sendNoteOn(channel, note, noteVelocity);
midiOut.sendNoteOff(channel, note, noteVelocity);

RedMouse is just a circle around my mouse’s x and y location and boids are for playing with flocking down the line. Both have a radius of 20, hence the amount of distance I am calculating. so the whole time that the objects are overlapping, midi messages are continually sent, making a horrible noise. I have tried making the distance just 1 but it then means the likelihood of midi messages being sent is very slim.

Any thoughts, code pointers would be greatly appreciated.



The thing is, that when you send
midiOut.sendNoteOn(channel, note, noteVelocity);
Ableton will process that osc message. Assuming that note will take at least 0.1 second, if you have more than one boid with distance distance < 20 && distance > 0 you already have a lot of sounds to process. The duration of your note has to be fast.

I would suggest you to test your code with just one boid at center of the screen and a short sound. Then try to add more boid.

Could you post the code of “sendNoteOn” ?