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-02 03:11:23 +02:00
|
|
|
LUPPP_NOTE("MidiObserver %i",this);
|
2013-09-30 15:57:17 +02:00
|
|
|
}
|
2013-10-01 18:42:16 +02:00
|
|
|
|
|
|
|
|
2013-10-02 04:05:10 +02:00
|
|
|
void MidiObserver::writeMidi( unsigned char* data )
|
|
|
|
{
|
|
|
|
void* portBuffer = jack_port_get_buffer( jackInputPort, jack->getBuffersize() );
|
|
|
|
|
|
|
|
unsigned char* buffer = jack_midi_event_reserve( portBuffer, 0, 3);
|
|
|
|
if( buffer == 0 )
|
|
|
|
{
|
|
|
|
std::cout << "Error: APC writeMidi() write buffer == 0" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "JC::writeMidi() " << int(data[0]) << ", " << int(data[1]) << ", " << int(data[2]) << endl;
|
|
|
|
//memcpy( buffer, data, sizeof(unsigned char)*3 );
|
|
|
|
buffer[0] = data[0];
|
|
|
|
buffer[1] = data[1];
|
|
|
|
buffer[2] = data[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 18:42:16 +02:00
|
|
|
void MidiObserver::registerMidiPorts(std::string name)
|
|
|
|
{
|
|
|
|
// register the JACK MIDI ports
|
|
|
|
stringstream i;
|
2013-10-02 03:11:23 +02:00
|
|
|
i << name << " in";
|
|
|
|
jackInputPort = jack_port_register( jack->getJackClientPointer(),
|
2013-10-01 18:42:16 +02:00
|
|
|
i.str().c_str(),
|
|
|
|
JACK_DEFAULT_MIDI_TYPE,
|
|
|
|
JackPortIsInput,
|
|
|
|
0 );
|
|
|
|
stringstream o;
|
2013-10-02 03:11:23 +02:00
|
|
|
o << name << " out";
|
|
|
|
jackOutputPort = jack_port_register( jack->getJackClientPointer(),
|
2013-10-01 18:42:16 +02:00
|
|
|
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
|
2013-10-02 03:11:23 +02:00
|
|
|
void* inputBuffer = (void*) jack_port_get_buffer( jackInputPort, nframes );
|
2013-10-02 04:13:02 +02:00
|
|
|
void* outputBuffer= (void*) jack_port_get_buffer( jackOutputPort, nframes );
|
2013-10-01 18:42:16 +02:00
|
|
|
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] );
|
2013-10-02 04:13:02 +02:00
|
|
|
printf( "MIDI %i %i %i\n", int(in_event.buffer[0]), int(in_event.buffer[1]), int(in_event.buffer[2]) );
|
2013-10-01 18:42:16 +02:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|