hello,
i am going back to a project that i abandonned a few months ago, because it involved counting every incoming F8 (clock) from a MIDI stream ( coming out of an Electribe mkII ) in a very precise way, even at high BPM.
the problem was that the sketch was too slow and the buffer must be filled with F8, so occasionnaly missing some and getting wrong tempo indications.
now i am rewriting the sketch for teensy 3.5 and would like to get a better method for dealing with F8 messages
i put the main structure of my program hereunder ;
my questions are :
- would it be better to use interrupts to count F8 ? using setHandleClock ?
- i had chosen not to use the MIDI library, because i had trouble recognizing the NRPN messages from Electribe. does any of you have positive experience with properly recognizing NRPN messages with the library ?
- generally speaking, any tip on dealing precisely with F8 messages ?
i am going back to a project that i abandonned a few months ago, because it involved counting every incoming F8 (clock) from a MIDI stream ( coming out of an Electribe mkII ) in a very precise way, even at high BPM.
the problem was that the sketch was too slow and the buffer must be filled with F8, so occasionnaly missing some and getting wrong tempo indications.
now i am rewriting the sketch for teensy 3.5 and would like to get a better method for dealing with F8 messages
i put the main structure of my program hereunder ;
my questions are :
- would it be better to use interrupts to count F8 ? using setHandleClock ?
- i had chosen not to use the MIDI library, because i had trouble recognizing the NRPN messages from Electribe. does any of you have positive experience with properly recognizing NRPN messages with the library ?
- generally speaking, any tip on dealing precisely with F8 messages ?
Code:
#include <Arduino.h>
#include <Encoder.h>
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
int compteurF8 ;
long moment, oldtimeF8, dureeF8 ;
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 18, /* data=*/ 19, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the
void setup() {
u8x8.begin();
u8x8.setFont(u8x8_font_amstrad_cpc_extended_r);
Serial1.begin(31250); // pour la lecture de Rx3 Tx3
}
void loop()
{
boolean keepAnalyzing ;
if (Serial1.available() > 0)
{
byte Buff = 0 ;
Buff = Serial1.read();
keepAnalyzing = true ;
if ( Buff == 0xF8 )
{
do
{
compteurF8++ ;
if ( compteurF8 >= 24 ) {
moment = millis();
dureeF8 = (moment - oldtimeF8 ) / 24 ;
oldtimeF8 = moment;
compteurF8 = 0;
}
if ( Serial1.available() )
{
Buff = Serial1.read();
keepAnalyzing = true ;
}
else
{ keepAnalyzing = false ; }
} while ( Buff == 0xF8 && keepAnalyzing ) ;
}
if ( keepAnalyzing )
{
switch (Buff & B11110000)
{
case (0xB0):
{
}
break;
case (0x90) :
{
}
break ;
case (0x80) :
{
}
break;
default :
{
}
break ;
}
}
}
}