-
how do i read an incoming midi clock and turn it to a BPM I can display? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 23 replies
-
Midi clock is basically 1/96 th notes. |
Beta Was this translation helpful? Give feedback.
-
this prints bpm to serial monitor byte midi_clock = 0xf8; MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); void setup() { void loop() { if (MIDI.read()) { // Is there a MIDI message incoming ? |
Beta Was this translation helpful? Give feedback.
-
Please keep in mind that Serial.println is incredibly slow. Even if you are on a mega and use Serial1 for midi , if you are measuring permanently, the println will tamper the measuring. We are not on a multiprocessor machine here. |
Beta Was this translation helpful? Give feedback.
-
Additionally there is always jitter on any device distributing midi clock. If there is a PC using a cheap usb midi interface, it is rather unreliable to put out any measuring. (And just forget about blutooth midi) |
Beta Was this translation helpful? Give feedback.
this prints bpm to serial monitor
thanks for the suggestions, solved.
`#include <MIDI.h>
byte midi_clock = 0xf8;
unsigned long int startTime;
int beatCount;
bool counting = false;
long int bpm;
long int noteTime;
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(57600);
Serial.println("MIDI Input Test");
}
void loop() {
if (MIDI.read()) { // Is there a MIDI message incoming ?
byte type = MIDI.getType();
if (type == midi_clock) {
if ( not counting) { // first time you have seen a clock message in this batch
startTime = millis();
counting = true;
beatCount = 1;
}
else {
beatCount += 1;
if (beatCount >= 96) {
noteTime = millis() -…