23 #include "JackCoreMidiInputPort.h"
24 #include "JackMidiUtil.h"
25 #include "JackError.h"
29 JackCoreMidiInputPort::JackCoreMidiInputPort(
double time_ratio,
32 JackCoreMidiPort(time_ratio)
34 thread_queue =
new JackMidiAsyncQueue(max_bytes, max_messages);
35 std::auto_ptr<JackMidiAsyncQueue> thread_queue_ptr(thread_queue);
36 write_queue =
new JackMidiBufferWriteQueue();
37 std::auto_ptr<JackMidiBufferWriteQueue> write_queue_ptr(write_queue);
38 sysex_buffer =
new jack_midi_data_t[max_bytes];
39 write_queue_ptr.release();
40 thread_queue_ptr.release();
44 JackCoreMidiInputPort::~JackCoreMidiInputPort()
48 delete[] sysex_buffer;
52 JackCoreMidiInputPort::GetFramesFromTimeStamp(MIDITimeStamp timestamp)
54 return GetFramesFromTime((jack_time_t) (timestamp * time_ratio));
58 JackCoreMidiInputPort::Initialize(
const char *alias_name,
59 const char *client_name,
60 const char *driver_name,
int index,
61 MIDIEndpointRef endpoint)
63 JackCoreMidiPort::Initialize(alias_name, client_name, driver_name, index, endpoint,
false);
67 JackCoreMidiInputPort::ProcessCoreMidi(
const MIDIPacketList *packet_list)
69 set_threaded_log_function();
71 unsigned int packet_count = packet_list->numPackets;
73 MIDIPacket *packet = (MIDIPacket *) packet_list->packet;
74 for (
unsigned int i = 0; i < packet_count; i++) {
75 jack_midi_data_t *data = packet->data;
76 size_t size = packet->length;
83 if (sysex_bytes_sent) {
85 jack_error(
"JackCoreMidiInputPort::ProcessCoreMidi - System "
86 "exclusive message aborted.");
91 if ((sysex_bytes_sent + size) <=
sizeof(sysex_buffer)) {
92 memcpy(sysex_buffer + sysex_bytes_sent, packet,
93 size *
sizeof(jack_midi_data_t));
95 sysex_bytes_sent += size;
96 if (data[size - 1] == 0xf7) {
97 if (sysex_bytes_sent >
sizeof(sysex_buffer)) {
98 jack_error(
"JackCoreMidiInputPort::ProcessCoreMidi - "
99 "Could not buffer a %d-byte system exclusive "
100 "message. Discarding message.",
102 sysex_bytes_sent = 0;
103 goto get_next_packet;
105 event.buffer = sysex_buffer;
106 event.size = sysex_bytes_sent;
107 sysex_bytes_sent = 0;
110 goto get_next_packet;
114 if (data[0] == 0xf0) {
115 if (data[size - 1] != 0xf7) {
116 goto buffer_sysex_bytes;
123 event.time = GetFramesFromTimeStamp(packet->timeStamp);
125 case JackMidiWriteQueue::BUFFER_FULL:
126 jack_error(
"JackCoreMidiInputPort::ProcessCoreMidi - The thread "
127 "queue buffer is full. Dropping event.");
129 case JackMidiWriteQueue::BUFFER_TOO_SMALL:
130 jack_error(
"JackCoreMidiInputPort::ProcessCoreMidi - The thread "
131 "queue couldn't enqueue a %d-byte packet. Dropping "
132 "event.", event.
size);
139 packet = MIDIPacketNext(packet);
145 JackCoreMidiInputPort::ProcessJack(JackMidiBuffer *port_buffer,
146 jack_nframes_t frames)
153 for (; jack_event; jack_event = thread_queue->
DequeueEvent()) {
155 switch (write_queue->
EnqueueEvent(jack_event, frames)) {
156 case JackMidiWriteQueue::BUFFER_TOO_SMALL:
157 jack_error(
"JackCoreMidiInputPort::ProcessJack - The write queue "
158 "couldn't enqueue a %d-byte event. Dropping event.",
161 case JackMidiWriteQueue::OK:
171 JackCoreMidiInputPort::Start()
176 sysex_bytes_sent = 0;
181 JackCoreMidiInputPort::Stop()
EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, jack_midi_data_t *buffer)
SERVER_EXPORT void jack_error(const char *fmt,...)
void ResetMidiBuffer(JackMidiBuffer *buffer, jack_nframes_t frames)
virtual jack_midi_event_t * DequeueEvent()
virtual EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, jack_midi_data_t *buffer)