cyclpsrock
Member
Hey all, thanks for taking the time to read. I'm trying to add external clock sync from a DAW to my project and I'm a little lost. The best documentation I've been able to find on how to implement the beat clock is from here but I'm still foggy. This is also my first time programming in a C language and I've been trying to pick up the syntax as I go, so it's very possible there may be conventions in here I would have picked up on if I had more previous experience or fundamentals I just have no idea about so I apologize my issues seem obvious.
As a test to get clock sync working in my program, I'm trying to generate a midi note send for every quarter note synced to my DAW. My rationale based off the above link is that every time the counter reaches 0 a note should play. If the DAW sends the START or CONTINUE byte the counter should start back at 0. If the DAW sends STOP I tried setting the counter to 1 so that the for loop condition would not be met and a midi note would not trigger. My understanding is that there are 24 ticks per quarter note from the midi clock so the counter should loop back to 0 when it hits 24 to keep track of quarter notes at any bpm.
I have my DAW set to only send clock when the track is rolling. The way the program behaves currently is that the usb note will repeatedly trigger in my DAW regardless of whether the track is playing or not. BPM changes do not seem to affect the rate. The start of the note pattern does not seem to reset when I hit play, though when I hit stop it does stop but only for a brief moment. The delay I inserted as a test between NoteOn and NoteOff seems to be the only thing that affects the rate of the note.
I'm on Teensy 2.0. Any help or hints very appreciated!!
As a test to get clock sync working in my program, I'm trying to generate a midi note send for every quarter note synced to my DAW. My rationale based off the above link is that every time the counter reaches 0 a note should play. If the DAW sends the START or CONTINUE byte the counter should start back at 0. If the DAW sends STOP I tried setting the counter to 1 so that the for loop condition would not be met and a midi note would not trigger. My understanding is that there are 24 ticks per quarter note from the midi clock so the counter should loop back to 0 when it hits 24 to keep track of quarter notes at any bpm.
I have my DAW set to only send clock when the track is rolling. The way the program behaves currently is that the usb note will repeatedly trigger in my DAW regardless of whether the track is playing or not. BPM changes do not seem to affect the rate. The start of the note pattern does not seem to reset when I hit play, though when I hit stop it does stop but only for a brief moment. The delay I inserted as a test between NoteOn and NoteOff seems to be the only thing that affects the rate of the note.
I'm on Teensy 2.0. Any help or hints very appreciated!!
Code:
byte counter;
byte CLOCK = 248;
byte START = 250;
byte CONTINUE = 251;
byte STOP = 252;
const int note = 60;
const int velocityOn = 99;
const int velocityOff = 0;
const int channel = 1;
void setup() {
usbMIDI.setHandleRealTimeSystem(myRealTimeSystem);
}
void loop() {
usbMIDI.read();
//////////clock test begin//////////
for (counter==0; counter==0; ) {
usbMIDI.sendNoteOn(note , velocityOn, channel);
delay(500);
usbMIDI.sendNoteOff(note, velocityOff, channel);
}
//////////clock test end//////////
}
//////////beat clock begin//////////
void myRealTimeSystem(byte realtimebyte) {
if (realtimebyte == 248) {
counter++;
if (counter == 24) {
counter = 0;
}
if (realtimebyte == START || realtimebyte == CONTINUE) {
counter = 0;
}
if(realtimebyte == STOP) {
counter = 1;
}
}
}
//////////beat clock end//////////