No more recieved midi events on Daisy Seed

Hey guys.I m working on a project where a arduino send midi to the daisy seed to modify the parameters of a drum machine (kick, snare, hh, cymbal).
The midi work only when the kick is process alone, when i add the other instrument to the audio processing no more midi is received.
Anyone can help?

Here is the code:


#define LENGTH 16 //longeur des séquence max 64;
#include "daisy_seed.h"
#include "daisysp.h"
#include "Sequence.h"
#include "sequences.h"


using namespace daisy;
using namespace daisysp;


DaisySeed      hw;
//MidiUsbHandler midi;
MidiUartHandler midi;
bool play=true;
bool kickBend;
//instruments
AnalogBassDrum kick808;
AnalogSnareDrum snare;
HiHat< SquareNoise, LinearVCA, false > hh;
HiHat< RingModNoise, LinearVCA, true > cymbal;
//Effets
Overdrive drive;
//Séquences
static Metro      clock;
float tempo=120; //tempo à 120 bpm
int position=0;
int sequence_choisie=0;
Sequence sequence[LENGTH];

float volumeKick=1.;
float volumeSnare=1.;
float volumeHh=1.;
float volumeCymbal=1.;
float volumeTom=1.;
float velocityKick=0;
float velocitySnare=0;
float velocityHh=0;
float velocityCymbal=0;
float velocityTom=0;
bool retrigKick=false;
bool retrigSnare=false;
bool retrigHh=false;
bool retrigCymbal=false;
bool retrigTom=false;

void initSequences(){
//charge toutes les séquences

sequence[0].init(seq0,5);/*
sequence[1].init(seq0,5);
sequence[2].init(seq0,5);
sequence[3].init(seq0,5);
sequence[4].init(seq0,5);
sequence[5].init(seq0,5);
sequence[6].init(seq0,5);
sequence[7].init(seq0,5);*/


}
void AudioCallback(AudioHandle::InputBuffer  in,
                   AudioHandle::OutputBuffer out,
                   size_t                    size)
{
     uint8_t tic;
     if(kickBend) {kick808.SetFreq(80);} else {kick808.SetFreq(40);}
     if(play){tic = clock.Process();}
        if(tic)
        {
             
            if (sequence[sequence_choisie].seqKick[position]>0)
            {
                kick808.Trig();
                //hw.Print("%d",position); 
                velocityKick=sequence[sequence_choisie].seqKick[position];
            }
            if (sequence[sequence_choisie].seqSnare[position]>0)
            {
                snare.Trig();
                //hw.Print("%d",position); 
                velocitySnare=sequence[sequence_choisie].seqSnare[position];
            }
            if (sequence[sequence_choisie].seqHH[position]>0)
            {
                hh.Trig();
                //hw.Print("%d",position); 
                velocityHh=sequence[sequence_choisie].seqHH[position];
            }
            if (sequence[sequence_choisie].seqCymbal[position]>0)
            {
                cymbal.Trig();
                //hw.Print("%d",position); 
                velocityCymbal=sequence[sequence_choisie].seqCymbal[position];
            }
               
            position++;
            if (position == sequence[sequence_choisie].lenght)
            {
                position=0;
                //hw.PrintLine("  ");
            }
        }
   
    for(size_t i = 0; i < size; i++)
        out[0][i] = out[1][i] = 
        volumeKick * kick808.Process() * 30. * (velocityKick/127.0f) + 
        volumeSnare * snare.Process()* 0.4  * (velocitySnare/127.0f) ; 
        //+ volumeHh * hh.Process()  * 0.1 * (velocityHh/127.0f) +
        //volumeCymbal * cymbal.Process()  * 0.05 * (velocityCymbal/127.0f);
       /* drive.Process(in[0][i]) ; */

}
// Typical Switch case for Message Type.
void HandleMidiMessage(MidiEvent m)
{
    bool hasBeenCleared = false;
    switch(m.type)
    {
        case NoteOn:
        {
            
            
            NoteOnEvent p = m.AsNoteOn();
            // This is to avoid Max/MSP Note outs for now..
            
            //hw.PrintLine("note");
            if(m.data[1] != 0)
            {
                //p.note, p.velocity
                
            }
        }
        break;
        case NoteOff:
        {
            if(!hasBeenCleared)
                

            NoteOffEvent p = m.AsNoteOff();
            // This is to avoid Max/MSP Note outs for now..

            
        }
        break;
        case ControlChange:
        {
            ControlChangeEvent p = m.AsControlChange();
           /* hw.Print("ControlChange message du controlleur ");
            hw.Print("%d",p.control_number);
            hw.PrintLine(" value ","%d",p.value);*/
            switch(p.control_number)
            {
                case 1:
                    // CC 1 for cutoff.
                    //filt.SetFreq(mtof((float)p.value));
                    break;
                case 100:
                    if ((int)p.value > 0)
                    {
                        kickBend=true;
                    } else { kickBend=false;}
                    
                   
                    // CC 2 for res.
                    //filt.SetRes(((float)p.value / 127.0f));
                    break;
                default: break;
            }
            break;
        }
        default: break;
    }
     
}
int main(void)
{
    /** Basic initialization of Daisy hardware */
    hw.Configure();
    hw.Init();
    //hw.StartLog(false);
    //System::Delay(2000);
    //hw.PrintLine("Ca commence");
    hw.SetAudioBlockSize(4);

    
    MidiUartHandler::Config midi_config;
    midi.Init(midi_config);

 
    /** Initialize our instruments */
    float samplerate = hw.AudioSampleRate();
    // initialize Metro object at 120 Bpm
    clock.Init(tempo * 16 / 60, samplerate); // click à 1/16
    initSequences(); //initialisation des séquences
    
   
    //initialisation du kick 808
    kick808.Init(samplerate);
    kick808.SetFreq(40);
    kick808.SetDecay(.9);
    kick808.SetTone(0.0);
    kick808.SetAccent(1.);
    kick808.SetAttackFmAmount(0.5);
    kick808.SetSelfFmAmount(0.5);
    //initialisation du snare 808
    snare.Init(samplerate);
    snare.SetFreq(150);
    snare.SetSustain(false);
    snare.SetTone(0.5);
    snare.SetSnappy(1.);
    //initialisation du HH
    hh.Init(samplerate);
    hh.SetFreq(7000);
    hh.SetSustain(false);
    hh.SetTone(0.1);
    hh.SetDecay(.9);
    //initialisation du cymbal
    cymbal.Init(samplerate);
    cymbal.SetFreq(10000);
    cymbal.SetSustain(false);
    cymbal.SetTone(1.);
    cymbal.SetDecay(.9);
    cymbal.SetAccent(1.);
    /** Initialize our effects */
    drive.Init();
    drive.SetDrive(0.5);
    /** And start the audio callback */
    hw.StartAudio(AudioCallback);
    midi.StartReceive();

    while(1)
    {
        /** Listen to MIDI for new changes */
        midi.Listen();

        /** When there are messages waiting in the queue... */
        while(midi.HasEvents())
        { 
            
            HandleMidiMessage(midi.PopEvent());
            
            
        }
    }
}

Hello loya!
I’m sorry for the delay in response.

My initial guess would be that those audio functions you’re uncommenting (so those processes for other instruments that you are trying to add) are taking up lots of time. Therefore, the main loop may not have the time to read the midi. Basically, the audio callback is eating all of the time up.
That said, it would be helpful to do some debugging to confirm that. Maybe just with the printlns or a debugger.
Those AnalogDrum and HiHat models are really heavy, so that’s where my guess is.

1 Like

Hello Takumi, thank for your response!
You"re right, i’ve reduced the samplerate to 32Khz and the midi come again.

1 Like

Awesome! I’m glad to hear that it’s working for you now.

1 Like