We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, today I had this idea and tried to write some code but then got stucked.
I'm thinking about syncing Processing's frameRate/draw function with an incoming MIDI signal because I would love to create a visualization in sync with music coming from Ableton.
With the MidiBus Library and through the IAC Driver on my Mac I got the Sync/Clock MIDI Message from Ableton into Processing but then I wasn't able to link those two things together.
This is my code so far but I'm not sure it's working properly. Any help would be greatly appreciated.
import themidibus.*; //Import the library
import javax.sound.midi.MidiMessage; //Import the MidiMessage classes http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/midi/MidiMessage.html
import javax.sound.midi.SysexMessage;
import javax.sound.midi.ShortMessage;
MidiBus myBus; // The MidiBus
int i = 1;
void setup() {
size(400, 400);
background(0);
frameRate(60);
MidiBus.list();
myBus = new MidiBus(this, 0, 1);
}
void draw() {
if(frameCount % 60 == 0) {
println("min");
i = 1;
}
}
void midiMessage(MidiMessage message) {
print(i + " ");
i++;
}
Answers
https://Processing.org/reference/redraw_.html
This will be a good starting point but is it possible to sync different threads?
For example: having the draw() function doing its thing and having another function checking the sync with the MIDI input?
AFAIK, midiMessage() should be called back by MidiBus's own Thread. :-B
In order to be sure midiMessage() is indeed called back by another Thread, place this code line there:
println(Thread.currentThread());
*-:)If it isn't displayed as
Thread[Animation Thread,5,main]
, it isn't sketch's "Animation Thread" like I guess. ;;)Sorry for this late update but yesterday I found this: https://github.com/luiscript/NSYNC/blob/master/Processing/Processing_MIDI_clock/Processing_MIDI_clock.pde which is an easier approach to what I was looking for and it's working flawlessly.