Creating an array to store Midi Control Messages - ofxMidi

Hi everyone, First this forum is an amazing resource.

I’m trying to use ofxMidi to grab any Midi controller information from a Que Neo and store it in an array. This seems to be working but also drags down the frame rate. What is a more efficient way to do this?

This code is in my Update function:

if( midiMessage.status == MIDI_CONTROL_CHANGE){
switch (midiMessage.control){
case 68: ctrrls[8] = ofMap(midiMessage.value,0,127,0,30); break;
case 50: ctrrls[30] = ofMap(midiMessage.value,0,127,0,30); break;
}
}

Thanks in advance,
Casey


this code doesn’t look slow offhand – if you comment it out does the app get fast again?

Thanks for looking at that Zach. 'preciate it.
So it works much much better if I put this code in the newMidiMessage function. The array updates very very smoothly. When it was in the update function it would start to hang when I was sending many midi controller changes simultaneously.

void testApp::newMidiMessage(ofxMidiMessage& msg) {

switch (midiMessage.control){
    case 23: ctrrls[1] = ofMap(midiMessage.value,0,127,0,30);break;
    case 26: ctrrls[2] = ofMap(midiMessage.value,0,127,0,30);break;
    case 29: ctrrls[3] = ofMap(midiMessage.value,0,127,0,30);break;
    case 32: ctrrls[4] = ofMap(midiMessage.value,0,127,0,30);break;
    case 35: ctrrls[5] = ofMap(midiMessage.value,0,127,0,30);break;
    case 38: ctrrls[6] = ofMap(midiMessage.value,0,127,0,30);break;
    case 41: ctrrls[7] = ofMap(midiMessage.value,0,127,0,30);break;
    case 44: ctrrls[8] = ofMap(midiMessage.value,0,127,0,30);break;
    case 47: ctrrls[9] = ofMap(midiMessage.value,0,127,0,30);break;
    case 50: ctrrls[10] = ofMap(midiMessage.value,0,127,0,30);break;
    case 53: ctrrls[11] = ofMap(midiMessage.value,0,127,0,30);break;
    case 56: ctrrls[12] = ofMap(midiMessage.value,0,127,0,30);break;
    case 59: ctrrls[13] = ofMap(midiMessage.value,0,127,0,30);break;
    case 62: ctrrls[14] = ofMap(midiMessage.value,0,127,0,30);break;
    case 65: ctrrls[15] = ofMap(midiMessage.value,0,127,0,30);break;
    case 68: ctrrls[16] = ofMap(midiMessage.value,0,127,0,30);break;
}

On a related note. If I wanted to further smooth the data coming in from ofxMidi which sounds like the better idea.

  1. Put each midi controller stream in a vector or array and then average that array in the update function?

  2. Use a tweening library like ofxtween to tween the incoming values over a longer period of time.

I would like to do some substantial smoothing. For instance if I instantaneously change a value at the controller it would slowly interpolate over three seconds.

Thanks again,
Casey