2013-07-31 18:19:15 +02:00
|
|
|
|
|
|
|
#include "midi.hxx"
|
|
|
|
|
2013-10-01 18:42:16 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2013-07-31 18:19:15 +02:00
|
|
|
#include "../jack.hxx"
|
|
|
|
|
2013-07-31 18:31:47 +02:00
|
|
|
extern Jack* jack;
|
|
|
|
|
2013-10-01 22:41:39 +02:00
|
|
|
MidiObserver::MidiObserver() :
|
|
|
|
jackInputPort(0),
|
|
|
|
jackOutputPort(0)
|
2013-09-30 15:57:17 +02:00
|
|
|
{
|
|
|
|
}
|
2013-10-01 18:42:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
void MidiObserver::registerMidiPorts(std::string name)
|
|
|
|
{
|
|
|
|
// register the JACK MIDI ports
|
|
|
|
stringstream i;
|
|
|
|
i << name << "_in";
|
|
|
|
jackInputPort = (void*)jack_port_register( jack->getJackClientPointer(),
|
|
|
|
i.str().c_str(),
|
|
|
|
JACK_DEFAULT_MIDI_TYPE,
|
|
|
|
JackPortIsInput,
|
|
|
|
0 );
|
|
|
|
stringstream o;
|
|
|
|
o << name << "_out";
|
|
|
|
jackOutputPort = (void*)jack_port_register( jack->getJackClientPointer(),
|
|
|
|
o.str().c_str(),
|
|
|
|
JACK_DEFAULT_MIDI_TYPE,
|
|
|
|
JackPortIsOutput,
|
|
|
|
0 );
|
2013-10-01 18:51:51 +02:00
|
|
|
|
2013-10-01 22:41:39 +02:00
|
|
|
if ( jackInputPort && jackOutputPort )
|
|
|
|
{
|
|
|
|
LUPPP_NOTE("%i, %i", jackInputPort, jackOutputPort );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUPPP_ERROR("Error registering JACK ports" );
|
|
|
|
}
|
2013-10-01 18:42:16 +02:00
|
|
|
}
|
|
|
|
|
2013-10-01 22:41:39 +02:00
|
|
|
|
2013-10-01 18:42:16 +02:00
|
|
|
void MidiObserver::process(int nframes)
|
|
|
|
{
|
|
|
|
// get port buffers and setup
|
|
|
|
void* inputBuffer = (void*) jack_port_get_buffer( (jack_port_t*)jackInputPort, nframes );
|
|
|
|
void* outputBuffer= (void*) jack_port_get_buffer( (jack_port_t*)jackInputPort, nframes );
|
|
|
|
jack_midi_clear_buffer( outputBuffer );
|
|
|
|
|
|
|
|
jack_midi_event_t in_event;
|
|
|
|
int index = 0;
|
|
|
|
int event_count = (int) jack_midi_get_event_count( inputBuffer );
|
|
|
|
while ( index < event_count )
|
|
|
|
{
|
|
|
|
jack_midi_event_get(&in_event, inputBuffer, index);
|
|
|
|
midi( (unsigned char*) &in_event.buffer[0] );
|
|
|
|
//printf( "%s MIDI %i %i %i\n", midiObservers.at(i)->getName().c_str(), int(in_event.buffer[0]), int(in_event.buffer[1]), int(in_event.buffer[2]) );
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|