Code: Select all
void MuStudio::MIDI::OutputExported::messageWritePrepare(size_t n_frames)
{
buffer=jack_port_get_buffer((jack_port_t*)port,n_frames);
jack_midi_clear_buffer(buffer);
}
void MuStudio::MIDI::OutputExported::messageWrite(const Event& e)
{
jack_midi_data_t* outbuff = jack_midi_event_reserve( buffer, 0, 3);
outbuff[0]=e.data.bytes[0];
outbuff[1]=e.data.bytes[1];
outbuff[2]=e.data.bytes[2];
}
Code: Select all
int onProcess(size_t n_frames)
{
MuStudio::MIDI::Event event_in;
bool event_has=midi_in.eventFirstGet(event_in,n_frames);
midi_out.messageWritePrepare(n_frames);
size_t now=0;
while(n_frames)
{
if(event_has && event_in.time>=now)
{
if((event_in.data.bytes[0]&0xf0)==0x80
|| (event_in.data.bytes[0]&0xf0)==0x90)
{
int key=event_in.data.bytes[1];
key+=m_amount;
event_in.data.bytes[1]=std::max(0,std::min(key,127));
}
midi_out.messageWrite(event_in);
event_has=midi_in.eventNextGet(event_in);
}
--n_frames;
++now;
}
return 0;
}
1. Should I pass "now" to MuStudio::MIDI::OutputExported::messageWrite in order to get perfect timing? Not really a problem since in my case the buffer is small anyway.
2. The Program change consists of two bytes only. Does this mean that I need special treatments for shorter messages to avoid problems. I have one device that seems to interpret a trailing zero byte as changing the program back to "Grand piano".