From 4407c8805a5d653e3ca7f0a830de9b71df38a00c Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 27 Sep 2019 18:15:22 +0200 Subject: [PATCH] parse MIDI even if not connected --- linux/sound.cpp | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/linux/sound.cpp b/linux/sound.cpp index 6087e548..f4036604 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -254,35 +254,6 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) } } - // akt on MIDI data if MIDI is enabled - if ( pSound->input_port_midi != NULL ) - { - void* in_midi = jack_port_get_buffer ( - pSound->input_port_midi, nframes ); - - if ( in_midi != 0 ) - { - jack_nframes_t event_count = jack_midi_get_event_count ( in_midi ); - - for ( jack_nframes_t j = 0; j < event_count; j++ ) - { - jack_midi_event_t in_event; - - jack_midi_event_get ( &in_event, in_midi, j ); - - // copy packet and send it to the MIDI parser -// TODO do not call malloc in real-time callback - CVector vMIDIPaketBytes ( in_event.size ); - - for ( i = 0; i < static_cast ( in_event.size ); i++ ) - { - vMIDIPaketBytes[i] = static_cast ( in_event.buffer[i] ); - } - pSound->ParseMIDIMessage ( vMIDIPaketBytes ); - } - } - } - // call processing callback function pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo ); @@ -332,6 +303,34 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) } } + // akt on MIDI data if MIDI is enabled + if ( pSound->input_port_midi != NULL ) + { + void* in_midi = jack_port_get_buffer ( pSound->input_port_midi, nframes ); + + if ( in_midi != 0 ) + { + jack_nframes_t event_count = jack_midi_get_event_count ( in_midi ); + + for ( jack_nframes_t j = 0; j < event_count; j++ ) + { + jack_midi_event_t in_event; + + jack_midi_event_get ( &in_event, in_midi, j ); + + // copy packet and send it to the MIDI parser +// TODO do not call malloc in real-time callback + CVector vMIDIPaketBytes ( in_event.size ); + + for ( i = 0; i < static_cast ( in_event.size ); i++ ) + { + vMIDIPaketBytes[i] = static_cast ( in_event.buffer[i] ); + } + pSound->ParseMIDIMessage ( vMIDIPaketBytes ); + } + } + } + return 0; // zero on success, non-zero on error }