diff --git a/linux/sound.cpp b/linux/sound.cpp index 7f51315a..d88a3cb4 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -79,10 +79,14 @@ void CSound::OpenJack() output_port_right = jack_port_register ( pJackClient, "output right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); + input_port_midi = jack_port_register ( pJackClient, "input midi", + JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0 ); + if ( ( input_port_left == NULL ) || ( input_port_right == NULL ) || ( output_port_left == NULL ) || - ( output_port_right == NULL ) ) + ( output_port_right == NULL ) || + ( input_port_midi == NULL ) ) { throw CGenErr ( tr ( "The Jack port registering failed." ) ); } @@ -225,7 +229,10 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) (jack_default_audio_sample_t*) jack_port_get_buffer ( pSound->input_port_right, nframes ); - // copy input data + void* in_midi = jack_port_get_buffer ( + pSound->input_port_midi, nframes ); + + // copy input audio data if ( in_left != 0 && in_right != 0 ) { for ( i = 0; i < pSound->iJACKBufferSizeMono; i++ ) @@ -238,6 +245,28 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) } } + // akt on MIDI data + 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 + 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 ); diff --git a/linux/sound.h b/linux/sound.h index cb1940fe..0510f551 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -40,6 +40,7 @@ #if WITH_SOUND # include +# include #endif @@ -81,6 +82,7 @@ public: jack_port_t* input_port_right; jack_port_t* output_port_left; jack_port_t* output_port_right; + jack_port_t* input_port_midi; protected: void OpenJack();