first MIDI implementation for Jack, not yet tested

This commit is contained in:
Volker Fischer 2019-09-26 19:01:59 +02:00
parent 4be0fbf606
commit dbb6e9eb83
2 changed files with 33 additions and 2 deletions

View file

@ -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<uint8_t> vMIDIPaketBytes ( in_event.size );
for ( i = 0; i < static_cast<int> ( in_event.size ); i++ )
{
vMIDIPaketBytes[i] = static_cast<uint8_t> ( in_event.buffer[i] );
}
pSound->ParseMIDIMessage ( vMIDIPaketBytes );
}
}
// call processing callback function
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );

View file

@ -40,6 +40,7 @@
#if WITH_SOUND
# include <jack/jack.h>
# include <jack/midiport.h>
#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();