Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: counting F8 without missing one

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    2

    counting F8 without missing one

    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 ?

    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 ;
                }
                
            }
        }    
    }

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,134
    You've left out the important bits. What is the code doing when it gets Note on/off or Control Change? Post ALL the code.
    But why not handle the 0xF8 in the switch statement? You're handling a serial stream of data. Looking for 0xF8 first, doesn't speed things up if it has Control Change and/or Note On messages in front of it.

    Pete

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    2
    i left the 0xF8 out of the switch in order to quickly eliminate them from the buffer ;
    as an Electribe sends 6 0xF8 by step, they are usually much more present in the stream than notes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •