From f6939c64b43a5abb996ad74c8b9ecbe02cf8ee90 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 14:32:46 +0200 Subject: [PATCH 01/20] Rename all JackMidi* files to JackEvent --- common/{JackMidiAPI.cpp => JackEventAPI.cpp} | 0 common/{JackMidiAsyncQueue.cpp => JackEventAsyncQueue.cpp} | 0 common/{JackMidiAsyncQueue.h => JackEventAsyncQueue.h} | 0 .../{JackMidiAsyncWaitQueue.cpp => JackEventAsyncWaitQueue.cpp} | 0 common/{JackMidiAsyncWaitQueue.h => JackEventAsyncWaitQueue.h} | 0 .../{JackMidiBufferReadQueue.cpp => JackEventBufferReadQueue.cpp} | 0 common/{JackMidiBufferReadQueue.h => JackEventBufferReadQueue.h} | 0 ...JackMidiBufferWriteQueue.cpp => JackEventBufferWriteQueue.cpp} | 0 .../{JackMidiBufferWriteQueue.h => JackEventBufferWriteQueue.h} | 0 common/{JackMidiDriver.cpp => JackEventDriver.cpp} | 0 common/{JackMidiDriver.h => JackEventDriver.h} | 0 common/{JackMidiPort.cpp => JackEventPort.cpp} | 0 common/{JackMidiPort.h => JackEventPort.h} | 0 ...MidiRawInputWriteQueue.cpp => JackEventRawInputWriteQueue.cpp} | 0 ...JackMidiRawInputWriteQueue.h => JackEventRawInputWriteQueue.h} | 0 ...diRawOutputWriteQueue.cpp => JackEventRawOutputWriteQueue.cpp} | 0 ...ckMidiRawOutputWriteQueue.h => JackEventRawOutputWriteQueue.h} | 0 common/{JackMidiReadQueue.cpp => JackEventReadQueue.cpp} | 0 common/{JackMidiReadQueue.h => JackEventReadQueue.h} | 0 common/{JackMidiReceiveQueue.cpp => JackEventReceiveQueue.cpp} | 0 common/{JackMidiReceiveQueue.h => JackEventReceiveQueue.h} | 0 common/{JackMidiSendQueue.cpp => JackEventSendQueue.cpp} | 0 common/{JackMidiSendQueue.h => JackEventSendQueue.h} | 0 common/{JackMidiWriteQueue.cpp => JackEventWriteQueue.cpp} | 0 common/{JackMidiWriteQueue.h => JackEventWriteQueue.h} | 0 common/jack/{midiport.h => eventport.h} | 0 26 files changed, 0 insertions(+), 0 deletions(-) rename common/{JackMidiAPI.cpp => JackEventAPI.cpp} (100%) rename common/{JackMidiAsyncQueue.cpp => JackEventAsyncQueue.cpp} (100%) rename common/{JackMidiAsyncQueue.h => JackEventAsyncQueue.h} (100%) rename common/{JackMidiAsyncWaitQueue.cpp => JackEventAsyncWaitQueue.cpp} (100%) rename common/{JackMidiAsyncWaitQueue.h => JackEventAsyncWaitQueue.h} (100%) rename common/{JackMidiBufferReadQueue.cpp => JackEventBufferReadQueue.cpp} (100%) rename common/{JackMidiBufferReadQueue.h => JackEventBufferReadQueue.h} (100%) rename common/{JackMidiBufferWriteQueue.cpp => JackEventBufferWriteQueue.cpp} (100%) rename common/{JackMidiBufferWriteQueue.h => JackEventBufferWriteQueue.h} (100%) rename common/{JackMidiDriver.cpp => JackEventDriver.cpp} (100%) rename common/{JackMidiDriver.h => JackEventDriver.h} (100%) rename common/{JackMidiPort.cpp => JackEventPort.cpp} (100%) rename common/{JackMidiPort.h => JackEventPort.h} (100%) rename common/{JackMidiRawInputWriteQueue.cpp => JackEventRawInputWriteQueue.cpp} (100%) rename common/{JackMidiRawInputWriteQueue.h => JackEventRawInputWriteQueue.h} (100%) rename common/{JackMidiRawOutputWriteQueue.cpp => JackEventRawOutputWriteQueue.cpp} (100%) rename common/{JackMidiRawOutputWriteQueue.h => JackEventRawOutputWriteQueue.h} (100%) rename common/{JackMidiReadQueue.cpp => JackEventReadQueue.cpp} (100%) rename common/{JackMidiReadQueue.h => JackEventReadQueue.h} (100%) rename common/{JackMidiReceiveQueue.cpp => JackEventReceiveQueue.cpp} (100%) rename common/{JackMidiReceiveQueue.h => JackEventReceiveQueue.h} (100%) rename common/{JackMidiSendQueue.cpp => JackEventSendQueue.cpp} (100%) rename common/{JackMidiSendQueue.h => JackEventSendQueue.h} (100%) rename common/{JackMidiWriteQueue.cpp => JackEventWriteQueue.cpp} (100%) rename common/{JackMidiWriteQueue.h => JackEventWriteQueue.h} (100%) rename common/jack/{midiport.h => eventport.h} (100%) diff --git a/common/JackMidiAPI.cpp b/common/JackEventAPI.cpp similarity index 100% rename from common/JackMidiAPI.cpp rename to common/JackEventAPI.cpp diff --git a/common/JackMidiAsyncQueue.cpp b/common/JackEventAsyncQueue.cpp similarity index 100% rename from common/JackMidiAsyncQueue.cpp rename to common/JackEventAsyncQueue.cpp diff --git a/common/JackMidiAsyncQueue.h b/common/JackEventAsyncQueue.h similarity index 100% rename from common/JackMidiAsyncQueue.h rename to common/JackEventAsyncQueue.h diff --git a/common/JackMidiAsyncWaitQueue.cpp b/common/JackEventAsyncWaitQueue.cpp similarity index 100% rename from common/JackMidiAsyncWaitQueue.cpp rename to common/JackEventAsyncWaitQueue.cpp diff --git a/common/JackMidiAsyncWaitQueue.h b/common/JackEventAsyncWaitQueue.h similarity index 100% rename from common/JackMidiAsyncWaitQueue.h rename to common/JackEventAsyncWaitQueue.h diff --git a/common/JackMidiBufferReadQueue.cpp b/common/JackEventBufferReadQueue.cpp similarity index 100% rename from common/JackMidiBufferReadQueue.cpp rename to common/JackEventBufferReadQueue.cpp diff --git a/common/JackMidiBufferReadQueue.h b/common/JackEventBufferReadQueue.h similarity index 100% rename from common/JackMidiBufferReadQueue.h rename to common/JackEventBufferReadQueue.h diff --git a/common/JackMidiBufferWriteQueue.cpp b/common/JackEventBufferWriteQueue.cpp similarity index 100% rename from common/JackMidiBufferWriteQueue.cpp rename to common/JackEventBufferWriteQueue.cpp diff --git a/common/JackMidiBufferWriteQueue.h b/common/JackEventBufferWriteQueue.h similarity index 100% rename from common/JackMidiBufferWriteQueue.h rename to common/JackEventBufferWriteQueue.h diff --git a/common/JackMidiDriver.cpp b/common/JackEventDriver.cpp similarity index 100% rename from common/JackMidiDriver.cpp rename to common/JackEventDriver.cpp diff --git a/common/JackMidiDriver.h b/common/JackEventDriver.h similarity index 100% rename from common/JackMidiDriver.h rename to common/JackEventDriver.h diff --git a/common/JackMidiPort.cpp b/common/JackEventPort.cpp similarity index 100% rename from common/JackMidiPort.cpp rename to common/JackEventPort.cpp diff --git a/common/JackMidiPort.h b/common/JackEventPort.h similarity index 100% rename from common/JackMidiPort.h rename to common/JackEventPort.h diff --git a/common/JackMidiRawInputWriteQueue.cpp b/common/JackEventRawInputWriteQueue.cpp similarity index 100% rename from common/JackMidiRawInputWriteQueue.cpp rename to common/JackEventRawInputWriteQueue.cpp diff --git a/common/JackMidiRawInputWriteQueue.h b/common/JackEventRawInputWriteQueue.h similarity index 100% rename from common/JackMidiRawInputWriteQueue.h rename to common/JackEventRawInputWriteQueue.h diff --git a/common/JackMidiRawOutputWriteQueue.cpp b/common/JackEventRawOutputWriteQueue.cpp similarity index 100% rename from common/JackMidiRawOutputWriteQueue.cpp rename to common/JackEventRawOutputWriteQueue.cpp diff --git a/common/JackMidiRawOutputWriteQueue.h b/common/JackEventRawOutputWriteQueue.h similarity index 100% rename from common/JackMidiRawOutputWriteQueue.h rename to common/JackEventRawOutputWriteQueue.h diff --git a/common/JackMidiReadQueue.cpp b/common/JackEventReadQueue.cpp similarity index 100% rename from common/JackMidiReadQueue.cpp rename to common/JackEventReadQueue.cpp diff --git a/common/JackMidiReadQueue.h b/common/JackEventReadQueue.h similarity index 100% rename from common/JackMidiReadQueue.h rename to common/JackEventReadQueue.h diff --git a/common/JackMidiReceiveQueue.cpp b/common/JackEventReceiveQueue.cpp similarity index 100% rename from common/JackMidiReceiveQueue.cpp rename to common/JackEventReceiveQueue.cpp diff --git a/common/JackMidiReceiveQueue.h b/common/JackEventReceiveQueue.h similarity index 100% rename from common/JackMidiReceiveQueue.h rename to common/JackEventReceiveQueue.h diff --git a/common/JackMidiSendQueue.cpp b/common/JackEventSendQueue.cpp similarity index 100% rename from common/JackMidiSendQueue.cpp rename to common/JackEventSendQueue.cpp diff --git a/common/JackMidiSendQueue.h b/common/JackEventSendQueue.h similarity index 100% rename from common/JackMidiSendQueue.h rename to common/JackEventSendQueue.h diff --git a/common/JackMidiWriteQueue.cpp b/common/JackEventWriteQueue.cpp similarity index 100% rename from common/JackMidiWriteQueue.cpp rename to common/JackEventWriteQueue.cpp diff --git a/common/JackMidiWriteQueue.h b/common/JackEventWriteQueue.h similarity index 100% rename from common/JackMidiWriteQueue.h rename to common/JackEventWriteQueue.h diff --git a/common/jack/midiport.h b/common/jack/eventport.h similarity index 100% rename from common/jack/midiport.h rename to common/jack/eventport.h From e2c5a09a23dc311fa816179ec7db56b672e621d9 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 14:57:03 +0200 Subject: [PATCH 02/20] Rename Midi API to Event API --- common/JackEventAPI.cpp | 64 ++++++++++++++++++++--------------------- common/jack/eventport.h | 64 ++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/common/JackEventAPI.cpp b/common/JackEventAPI.cpp index 61d77e12..638c621b 100644 --- a/common/JackEventAPI.cpp +++ b/common/JackEventAPI.cpp @@ -28,24 +28,24 @@ extern "C" { #endif - LIB_EXPORT uint32_t jack_midi_get_event_count(void* port_buffer); + LIB_EXPORT uint32_t jack_event_get_count(void* port_buffer); - LIB_EXPORT int jack_midi_event_get(jack_midi_event_t* event, + LIB_EXPORT int jack_event_get(jack_event_t* event, void* port_buffer, uint32_t event_index); - LIB_EXPORT void jack_midi_clear_buffer(void* port_buffer); + LIB_EXPORT void jack_event_clear_buffer(void* port_buffer); - LIB_EXPORT void jack_midi_reset_buffer(void* port_buffer); + LIB_EXPORT void jack_event_reset_buffer(void* port_buffer); - LIB_EXPORT size_t jack_midi_max_event_size(void* port_buffer); + LIB_EXPORT size_t jack_event_max_size(void* port_buffer); - LIB_EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, + LIB_EXPORT jack_event_data_t* jack_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size); - LIB_EXPORT int jack_midi_event_write(void* port_buffer, - jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); + LIB_EXPORT int jack_event_write(void* port_buffer, + jack_nframes_t time, const jack_event_data_t* data, size_t data_size); - LIB_EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer); + LIB_EXPORT jack_nframes_t jack_event_get_lost_count(void* port_buffer); #ifdef __cplusplus } @@ -54,9 +54,9 @@ extern "C" using namespace Jack; LIB_EXPORT -uint32_t jack_midi_get_event_count(void* port_buffer) +uint32_t jack_event_get_count(void* port_buffer) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (!buf || !buf->IsValid()) { return 0; } @@ -64,16 +64,16 @@ uint32_t jack_midi_get_event_count(void* port_buffer) } LIB_EXPORT -int jack_midi_event_get(jack_midi_event_t *event, void* port_buffer, uint32_t event_index) +int jack_event_get(jack_event_t *event, void* port_buffer, uint32_t event_index) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (!buf || !buf->IsValid()) { return -EINVAL; } if (event_index >= buf->event_count) { return -ENOBUFS; } - JackMidiEvent* ev = &buf->events[event_index]; + JackEvent* ev = &buf->events[event_index]; event->time = ev->time; event->size = ev->size; event->buffer = ev->GetData(buf); @@ -81,24 +81,24 @@ int jack_midi_event_get(jack_midi_event_t *event, void* port_buffer, uint32_t ev } LIB_EXPORT -void jack_midi_clear_buffer(void* port_buffer) +void jack_event_clear_buffer(void* port_buffer) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (buf && buf->IsValid()) { buf->Reset(buf->nframes); } } LIB_EXPORT -void jack_midi_reset_buffer(void* port_buffer) +void jack_event_reset_buffer(void* port_buffer) { - MidiBufferInit(port_buffer, BUFFER_SIZE_MAX, BUFFER_SIZE_MAX); + EventBufferInit(port_buffer, BUFFER_SIZE_MAX, BUFFER_SIZE_MAX); } LIB_EXPORT -size_t jack_midi_max_event_size(void* port_buffer) +size_t jack_event_max_size(void* port_buffer) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (buf && buf->IsValid()) { return buf->MaxEventSize(); } @@ -106,24 +106,24 @@ size_t jack_midi_max_event_size(void* port_buffer) } LIB_EXPORT -jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size) +jack_event_data_t* jack_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (! buf) { - jack_error("jack_midi_event_reserve: port buffer is set to NULL"); + jack_error("jack_event_reserve: port buffer is set to NULL"); return 0; } if (! buf->IsValid()) { - jack_error("jack_midi_event_reserve: port buffer is invalid"); + jack_error("jack_event_reserve: port buffer is invalid"); return 0; } if (time >= buf->nframes) { - jack_error("jack_midi_event_reserve: time parameter is out of range " + jack_error("jack_event_reserve: time parameter is out of range " "(%lu >= %lu)", time, buf->nframes); return 0; } if (buf->event_count && (buf->events[buf->event_count - 1].time > time)) { - jack_error("jack_midi_event_reserve: time parameter is earlier than " + jack_error("jack_event_reserve: time parameter is earlier than " "last reserved event"); return 0; } @@ -131,17 +131,17 @@ jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time } LIB_EXPORT -int jack_midi_event_write(void* port_buffer, - jack_nframes_t time, const jack_midi_data_t* data, size_t data_size) +int jack_event_write(void* port_buffer, + jack_nframes_t time, const jack_event_data_t* data, size_t data_size) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (!buf || !buf->IsValid()) { return -EINVAL; } if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time)) { return -EINVAL; } - jack_midi_data_t* dest = buf->ReserveEvent(time, data_size); + jack_event_data_t* dest = buf->ReserveEvent(time, data_size); if (!dest) { return -ENOBUFS; } @@ -150,9 +150,9 @@ int jack_midi_event_write(void* port_buffer, } LIB_EXPORT -uint32_t jack_midi_get_lost_event_count(void* port_buffer) +uint32_t jack_event_get_lost_count(void* port_buffer) { - JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; if (buf && buf->IsValid()) { return buf->lost_events; } diff --git a/common/jack/eventport.h b/common/jack/eventport.h index 3fbf2126..8e0c8ca1 100644 --- a/common/jack/eventport.h +++ b/common/jack/eventport.h @@ -30,21 +30,21 @@ extern "C" { #include -/** Type for raw event data contained in @ref jack_midi_event_t. */ -typedef unsigned char jack_midi_data_t; +/** Type for raw event data contained in @ref jack_event_event_t. */ +typedef unsigned char jack_event_data_t; -/** A Jack MIDI event. */ -typedef struct _jack_midi_event +/** A Jack event. */ +typedef struct _jack_event { - jack_nframes_t time; /**< Sample index at which event is valid */ - size_t size; /**< Number of bytes of data in \a buffer */ - jack_midi_data_t *buffer; /**< Raw MIDI data */ -} jack_midi_event_t; + jack_nframes_t time; /**< Sample index at which event is valid */ + size_t size; /**< Number of bytes of data in \a buffer */ + jack_event_data_t *buffer; /**< Raw event data */ +} jack_event_t; /** - * @defgroup MIDIAPI Reading and writing MIDI data + * @defgroup EVENTAPI Reading and writing event data * @{ */ @@ -54,10 +54,14 @@ typedef struct _jack_midi_event * @return number of events inside @a port_buffer */ uint32_t -jack_midi_get_event_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; +jack_event_get_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; -/** Get a MIDI event from an event port buffer. +/** Get an event from an event port buffer. It is up to the caller to determine + * which protocol to interpret the data with. The port's type and the metadata + * API should suffice to do so. + * + * If the event represents MIDI data: * * Jack MIDI is normalised, the MIDI event returned by this function is * guaranteed to be a complete MIDI event (the status byte will always be @@ -80,7 +84,7 @@ jack_midi_get_event_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; * @return 0 on success, ENODATA if buffer is empty. */ int -jack_midi_event_get(jack_midi_event_t *event, +jack_event_get(jack_event_t *event, void *port_buffer, uint32_t event_index) JACK_OPTIONAL_WEAK_EXPORT; @@ -88,26 +92,26 @@ jack_midi_event_get(jack_midi_event_t *event, /** Clear an event buffer. * * This should be called at the beginning of each process cycle before calling - * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This + * @ref jack_event_reserve or @ref jack_event_write. This * function may not be called on an input port's buffer. * * @param port_buffer Port buffer to clear (must be an output port buffer). */ void -jack_midi_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; +jack_event_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /** Reset an event buffer (from data allocated outside of JACK). * * This should be called at the beginning of each process cycle before calling - * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This + * @ref jack_event_reserve or @ref jack_event_write. This * function may not be called on an input port's buffer. * - * @deprecated Please use jack_midi_clear_buffer(). + * @deprecated Please use jack_event_clear_buffer(). * * @param port_buffer Port buffer to reset. */ void -jack_midi_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT; +jack_event_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT; /** Get the size of the largest event that can be stored by the port. @@ -118,14 +122,17 @@ jack_midi_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT; * @param port_buffer Port buffer to check size of. */ size_t -jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; +jack_event_max_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /** Allocate space for an event to be written to an event port buffer. * * Clients are to write the actual event data to be written starting at the * pointer returned by this function. Clients must not write more than - * @a data_size bytes into this buffer. Clients must write normalised + * @a data_size bytes into this buffer. Clients may write arbitrary binary data, + * but should only write events using the protocol associated with the port. + * + * If this is a MIDI port, clients must write normalised * MIDI data to the port - no running status and no (1-byte) realtime * messages interspersed with other messages (realtime messages are fine * when they occur on their own, like other messages). @@ -140,19 +147,21 @@ jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; * @return Pointer to the beginning of the reserved event's data buffer, or * NULL on error (ie not enough space). */ -jack_midi_data_t* -jack_midi_event_reserve(void *port_buffer, +jack_event_data_t* +jack_event_reserve(void *port_buffer, jack_nframes_t time, size_t data_size) JACK_OPTIONAL_WEAK_EXPORT; /** Write an event into an event port buffer. * - * This function is simply a wrapper for @ref jack_midi_event_reserve + * This function is simply a wrapper for @ref jack_event_reserve * which writes the event data into the space reserved in the buffer. * * Clients must not write more than - * @a data_size bytes into this buffer. Clients must write normalised + * @a data_size bytes into this buffer. Clients may write arbitrary binary data, + * but should only write events using the protocol associated with the port. + * If this is a MIDI port, clients must write normalised * MIDI data to the port - no running status and no (1-byte) realtime * messages interspersed with other messages (realtime messages are fine * when they occur on their own, like other messages). @@ -168,22 +177,23 @@ jack_midi_event_reserve(void *port_buffer, * @return 0 on success, ENOBUFS if there's not enough space in buffer for event. */ int -jack_midi_event_write(void *port_buffer, +jack_event_write(void *port_buffer, jack_nframes_t time, - const jack_midi_data_t *data, + const jack_event_data_t *data, size_t data_size) JACK_OPTIONAL_WEAK_EXPORT; /** Get the number of events that could not be written to @a port_buffer. * * This function returning a non-zero value implies @a port_buffer is full. - * Currently the only way this can happen is if events are lost on port mixdown. + * Currently the only way this can happen is if events are lost on port mixdown + * (when multiple event output ports are connected to one input port). * * @param port_buffer Port to receive count for. * @returns Number of events that could not be written to @a port_buffer. */ uint32_t -jack_midi_get_lost_event_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; +jack_event_get_lost_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /*@}*/ From c325c975fccab951c44d785e8169bc1b20ecc2f1 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 15:16:10 +0200 Subject: [PATCH 03/20] Rename JackMidiPort to JackEventPort --- common/JackEventPort.cpp | 72 ++++++++++++++++++++++------------------ common/JackEventPort.h | 42 +++++++++++++---------- 2 files changed, 64 insertions(+), 50 deletions(-) diff --git a/common/JackEventPort.cpp b/common/JackEventPort.cpp index 8731f1e1..7357df68 100644 --- a/common/JackEventPort.cpp +++ b/common/JackEventPort.cpp @@ -20,15 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "JackError.h" -#include "JackPortType.h" -#include "JackMidiPort.h" +#include "JackEventType.h" +#include "JackEventPort.h" #include #include namespace Jack { -SERVER_EXPORT void JackMidiBuffer::Reset(jack_nframes_t nframes) +SERVER_EXPORT void JackEventBuffer::Reset(jack_nframes_t nframes) { /* This line ate 1 hour of my life... dsbaikov */ this->nframes = nframes; @@ -37,48 +37,48 @@ SERVER_EXPORT void JackMidiBuffer::Reset(jack_nframes_t nframes) lost_events = 0; } -SERVER_EXPORT jack_shmsize_t JackMidiBuffer::MaxEventSize() const +SERVER_EXPORT jack_shmsize_t JackEventBuffer::MaxEventSize() const { assert (((jack_shmsize_t) - 1) < 0); // jack_shmsize_t should be signed - jack_shmsize_t left = buffer_size - (sizeof(JackMidiBuffer) + sizeof(JackMidiEvent) * (event_count + 1) + write_pos); + jack_shmsize_t left = buffer_size - (sizeof(JackEventBuffer) + sizeof(JackEvent) * (event_count + 1) + write_pos); if (left < 0) { return 0; } - if (left <= JackMidiEvent::INLINE_SIZE_MAX) { - return JackMidiEvent::INLINE_SIZE_MAX; + if (left <= JackEvent::INLINE_SIZE_MAX) { + return JackEvent::INLINE_SIZE_MAX; } return left; } -SERVER_EXPORT jack_midi_data_t* JackMidiBuffer::ReserveEvent(jack_nframes_t time, jack_shmsize_t size) +SERVER_EXPORT jack_event_data_t* JackEventBuffer::ReserveEvent(jack_nframes_t time, jack_shmsize_t size) { jack_shmsize_t space = MaxEventSize(); if (space == 0 || size > space) { - jack_error("JackMidiBuffer::ReserveEvent - the buffer does not have " + jack_error("JackEventBuffer::ReserveEvent - the buffer does not have " "enough room to enqueue a %lu byte event", size); lost_events++; return 0; } - JackMidiEvent* event = &events[event_count++]; + JackEvent* event = &events[event_count++]; event->time = time; event->size = size; - if (size <= JackMidiEvent::INLINE_SIZE_MAX) { + if (size <= JackEvent::INLINE_SIZE_MAX) { return event->data; } write_pos += size; event->offset = buffer_size - write_pos; - return (jack_midi_data_t*)this + event->offset; + return (jack_event_data_t*)this + event->offset; } -void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes) +void EventBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes) { - JackMidiBuffer* midi = (JackMidiBuffer*)buffer; - midi->magic = JackMidiBuffer::MAGIC; + JackEventBuffer* buffer = (JackEventBuffer*)buffer; + buffer->magic = JackEventBuffer::MAGIC; /* Since port buffer has actually always BUFFER_SIZE_MAX frames, we can safely use all the size */ - midi->buffer_size = BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); - midi->Reset(nframes); + buffer->buffer_size = BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); + buffer->Reset(nframes); } /* @@ -91,11 +91,11 @@ void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes) * implementation as is, until it is proved to be a bottleneck. * Dmitry Baikov. */ -static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes) +static void EventBufferMixdown(void* mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes) { - JackMidiBuffer* mix = static_cast(mixbuffer); + JackEventBuffer* mix = static_cast(mixbuffer); if (!mix->IsValid()) { - jack_error("Jack::MidiBufferMixdown - invalid mix buffer"); + jack_error("Jack::EventBufferMixdown - invalid mix buffer"); return; } mix->Reset(nframes); @@ -103,9 +103,9 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count uint32_t mix_index[src_count]; int event_count = 0; for (int i = 0; i < src_count; ++i) { - JackMidiBuffer* buf = static_cast(src_buffers[i]); + JackEventBuffer* buf = static_cast(src_buffers[i]); if (!buf->IsValid()) { - jack_error("Jack::MidiBufferMixdown - invalid source buffer"); + jack_error("Jack::EventBufferMixdown - invalid source buffer"); return; } mix_index[i] = 0; @@ -115,16 +115,16 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count int events_done; for (events_done = 0; events_done < event_count; ++events_done) { - JackMidiBuffer* next_buf = 0; - JackMidiEvent* next_event = 0; + JackEventBuffer* next_buf = 0; + JackEvent* next_event = 0; uint32_t next_buf_index = 0; // find the earliest event for (int i = 0; i < src_count; ++i) { - JackMidiBuffer* buf = static_cast(src_buffers[i]); + JackEventBuffer* buf = static_cast(src_buffers[i]); if (mix_index[i] >= buf->event_count) continue; - JackMidiEvent* e = &buf->events[mix_index[i]]; + JackEvent* e = &buf->events[mix_index[i]]; if (!next_event || e->time < next_event->time) { next_event = e; next_buf = buf; @@ -132,12 +132,12 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count } } if (next_event == 0) { - jack_error("Jack::MidiBufferMixdown - got invalid next event"); + jack_error("Jack::EventBufferMixdown - got invalid next event"); break; } // write the event - jack_midi_data_t* dest = mix->ReserveEvent(next_event->time, next_event->size); + jack_event_data_t* dest = mix->ReserveEvent(next_event->time, next_event->size); if (!dest) break; memcpy(dest, next_event->GetData(next_buf), next_event->size); @@ -146,7 +146,7 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count mix->lost_events += event_count - events_done; } -static size_t MidiBufferSize() +static size_t EventBufferSize() { return BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); } @@ -154,9 +154,17 @@ static size_t MidiBufferSize() const JackPortType gMidiPortType = { JACK_DEFAULT_MIDI_TYPE, - MidiBufferSize, - MidiBufferInit, - MidiBufferMixdown + EventBufferSize, + EventBufferInit, + EventBufferMixdown +}; + +const JackPortType gOscPortType = +{ + JACK_DEFAULT_OSC_TYPE, + EventBufferSize, + EventBufferInit, + EventBufferMixdown }; } // namespace Jack diff --git a/common/JackEventPort.h b/common/JackEventPort.h index d43c95ae..007e2332 100644 --- a/common/JackEventPort.h +++ b/common/JackEventPort.h @@ -18,49 +18,55 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiPort__ -#define __JackMidiPort__ +#ifndef __JackEventPort__ +#define __JackEventPort__ #include "types.h" #include "JackConstants.h" #include "JackPlatformPlug.h" #include -/** Type for raw event data contained in @ref jack_midi_event_t. */ -typedef unsigned char jack_midi_data_t; +/** Type for raw event data contained in @ref jack_event_t. */ +typedef unsigned char jack_event_data_t; -/** A Jack MIDI event. */ -struct jack_midi_event_t +/** A Jack event. */ +struct jack_event_t { - jack_nframes_t time; /**< Sample index at which event is valid */ - size_t size; /**< Number of bytes of data in \a buffer */ - jack_midi_data_t *buffer; /**< Raw MIDI data */ + jack_nframes_t time; /**< Sample index at which event is valid */ + size_t size; /**< Number of bytes of data in \a buffer */ + jack_event_data_t *buffer; /**< Raw event data */ }; /** A Jack MIDI port type. */ #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" +/** A Jack OSC port type. */ +#define JACK_DEFAULT_OSC_TYPE "32 bit OSC" namespace Jack { -struct SERVER_EXPORT JackMidiEvent +struct SERVER_EXPORT JackEvent { - // Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace. + /** Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace. + * "inplace" means that instead of storing an offset to the actual data we store 4 bytes in that + * pointer. This is not relevant for OSC data (and other newer protocols) since most packets are a + * lot larger. + */ enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) }; uint32_t time; jack_shmsize_t size; union { jack_shmsize_t offset; - jack_midi_data_t data[INLINE_SIZE_MAX]; + jack_event_data_t data[INLINE_SIZE_MAX]; }; - jack_midi_data_t* GetData(void* buffer) + jack_event_data_t* GetData(void* buffer) { if (size <= INLINE_SIZE_MAX) { return data; } else { - return (jack_midi_data_t*)buffer + offset; + return (jack_event_data_t*)buffer + offset; } } }; @@ -72,7 +78,7 @@ struct SERVER_EXPORT JackMidiEvent * but their data (if not inlined) is stored from the end of the same buffer. */ -struct SERVER_EXPORT JackMidiBuffer +struct SERVER_EXPORT JackEventBuffer { enum { MAGIC = 0x900df00d }; @@ -83,7 +89,7 @@ struct SERVER_EXPORT JackMidiBuffer uint32_t event_count; uint32_t lost_events; - JackMidiEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here. + JackEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here. int IsValid() const { @@ -93,10 +99,10 @@ struct SERVER_EXPORT JackMidiBuffer jack_shmsize_t MaxEventSize() const; // checks only size constraints. - jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size); + jack_event_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size); }; -void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes); +void EventBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes); } // namespace Jack From fb648d2cb3311dbae0fd10d03d6bd94410f8dd84 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 15:26:11 +0200 Subject: [PATCH 04/20] Update type names in JackMidiUtil --- common/JackMidiUtil.cpp | 16 ++++++++-------- common/JackMidiUtil.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/JackMidiUtil.cpp b/common/JackMidiUtil.cpp index a0dc0bae..282e0eb1 100644 --- a/common/JackMidiUtil.cpp +++ b/common/JackMidiUtil.cpp @@ -23,14 +23,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackMidiUtil.h" #include "JackTime.h" -jack_midi_data_t -Jack::ApplyRunningStatus(size_t *size, jack_midi_data_t **buffer, - jack_midi_data_t running_status) +jack_event_data_t +Jack::ApplyRunningStatus(size_t *size, jack_event_data_t **buffer, + jack_event_data_t running_status) { // Stolen and modified from alsa/midi_pack.h - jack_midi_data_t status = **buffer; + jack_event_data_t status = **buffer; if ((status >= 0x80) && (status < 0xf0)) { if (status == running_status) { (*buffer)++; @@ -44,9 +44,9 @@ Jack::ApplyRunningStatus(size_t *size, jack_midi_data_t **buffer, return running_status; } -jack_midi_data_t -Jack::ApplyRunningStatus(jack_midi_event_t *event, - jack_midi_data_t running_status) +jack_event_data_t +Jack::ApplyRunningStatus(jack_event_t *event, + jack_event_data_t running_status) { return ApplyRunningStatus(&(event->size), &(event->buffer), running_status); @@ -78,7 +78,7 @@ Jack::GetLastFrame() } int -Jack::GetMessageLength(jack_midi_data_t status_byte) +Jack::GetMessageLength(jack_event_data_t status_byte) { switch (status_byte & 0xf0) { case 0x80: diff --git a/common/JackMidiUtil.h b/common/JackMidiUtil.h index 52db64c8..0b02c51e 100644 --- a/common/JackMidiUtil.h +++ b/common/JackMidiUtil.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __JackMidiUtil__ #define __JackMidiUtil__ -#include "JackMidiPort.h" +#include "JackEventPort.h" namespace Jack { @@ -41,17 +41,17 @@ namespace Jack { * message for each message that can be optimized. */ - SERVER_EXPORT jack_midi_data_t - ApplyRunningStatus(size_t *size, jack_midi_data_t **buffer, - jack_midi_data_t running_status=0); + SERVER_EXPORT jack_event_data_t + ApplyRunningStatus(size_t *size, jack_event_data_t **buffer, + jack_event_data_t running_status=0); /** * A wrapper function for the above `ApplyRunningStatus` function. */ - SERVER_EXPORT jack_midi_data_t - ApplyRunningStatus(jack_midi_event_t *event, - jack_midi_data_t running_status); + SERVER_EXPORT jack_event_data_t + ApplyRunningStatus(jack_event_t *event, + jack_event_data_t running_status); /** * Gets the estimated current time in frames. This function has the same @@ -86,7 +86,7 @@ namespace Jack { */ SERVER_EXPORT int - GetMessageLength(jack_midi_data_t status_byte); + GetMessageLength(jack_event_data_t status_byte); /** * Gets the estimated time at which the given frame will occur. This From d0119179fc838f51d081331cdd558d697bd2b864 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 15:27:35 +0200 Subject: [PATCH 05/20] Add OSC port type --- common/JackPortType.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/common/JackPortType.cpp b/common/JackPortType.cpp index 092b4c6b..3be1c4d2 100644 --- a/common/JackPortType.cpp +++ b/common/JackPortType.cpp @@ -28,6 +28,7 @@ static const JackPortType* gPortTypes[] = { &gAudioPortType, &gMidiPortType, + &gOscPortType, }; jack_port_type_id_t PORT_TYPES_MAX = sizeof(gPortTypes) / sizeof(gPortTypes[0]); From 90b8043b4db23c7b6f458d838dacffbc38402e73 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 15:42:52 +0200 Subject: [PATCH 06/20] Add OSC namespace property --- common/JackMetadata.cpp | 21 +++++++++++---------- common/jack/metadata.h | 8 ++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/JackMetadata.cpp b/common/JackMetadata.cpp index 0136b25b..925176f6 100644 --- a/common/JackMetadata.cpp +++ b/common/JackMetadata.cpp @@ -28,16 +28,17 @@ #define JACK_METADATA_PREFIX "http://jackaudio.org/metadata/" -LIB_EXPORT const char* JACK_METADATA_CONNECTED = JACK_METADATA_PREFIX "connected"; -LIB_EXPORT const char* JACK_METADATA_EVENT_TYPES = JACK_METADATA_PREFIX "event-types"; -LIB_EXPORT const char* JACK_METADATA_HARDWARE = JACK_METADATA_PREFIX "hardware"; -LIB_EXPORT const char* JACK_METADATA_ICON_LARGE = JACK_METADATA_PREFIX "icon-large"; -LIB_EXPORT const char* JACK_METADATA_ICON_NAME = JACK_METADATA_PREFIX "icon-name"; -LIB_EXPORT const char* JACK_METADATA_ICON_SMALL = JACK_METADATA_PREFIX "icon-small"; -LIB_EXPORT const char* JACK_METADATA_ORDER = JACK_METADATA_PREFIX "order"; -LIB_EXPORT const char* JACK_METADATA_PORT_GROUP = JACK_METADATA_PREFIX "port-group"; -LIB_EXPORT const char* JACK_METADATA_PRETTY_NAME = JACK_METADATA_PREFIX "pretty-name"; -LIB_EXPORT const char* JACK_METADATA_SIGNAL_TYPE = JACK_METADATA_PREFIX "signal-type"; +LIB_EXPORT const char* JACK_METADATA_CONNECTED = JACK_METADATA_PREFIX "connected"; +LIB_EXPORT const char* JACK_METADATA_EVENT_TYPES = JACK_METADATA_PREFIX "event-types"; +LIB_EXPORT const char* JACK_METADATA_EVENT_OSC_NAMESPACE = JACK_METADATA_PREFIX "event-osc-namespace"; +LIB_EXPORT const char* JACK_METADATA_HARDWARE = JACK_METADATA_PREFIX "hardware"; +LIB_EXPORT const char* JACK_METADATA_ICON_LARGE = JACK_METADATA_PREFIX "icon-large"; +LIB_EXPORT const char* JACK_METADATA_ICON_NAME = JACK_METADATA_PREFIX "icon-name"; +LIB_EXPORT const char* JACK_METADATA_ICON_SMALL = JACK_METADATA_PREFIX "icon-small"; +LIB_EXPORT const char* JACK_METADATA_ORDER = JACK_METADATA_PREFIX "order"; +LIB_EXPORT const char* JACK_METADATA_PORT_GROUP = JACK_METADATA_PREFIX "port-group"; +LIB_EXPORT const char* JACK_METADATA_PRETTY_NAME = JACK_METADATA_PREFIX "pretty-name"; +LIB_EXPORT const char* JACK_METADATA_SIGNAL_TYPE = JACK_METADATA_PREFIX "signal-type"; #undef JACK_METADATA_PREFIX namespace Jack diff --git a/common/jack/metadata.h b/common/jack/metadata.h index 9e026161..5c948cfd 100644 --- a/common/jack/metadata.h +++ b/common/jack/metadata.h @@ -244,6 +244,14 @@ extern const char* JACK_METADATA_CONNECTED; */ extern const char* JACK_METADATA_EVENT_TYPES; +/** + * OSC allows for arbitrary paths and function names. A namespace is an interface + * that gives certain paths and functions a semantic meaning. Currently, the only + * standardized interface is "SYN" (). + * Multiple namespaces (if supported) are specified as comma separated list. + */ +extern const char* JACK_METADATA_EVENT_OSC_NAMESPACE; + /** * A value that should be shown when attempting to identify the * specific hardware outputs of a client. Typical values might be From 8aa1e1ad3e8d0a30d14cd88e3be7dfa7639d57af Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 16:36:47 +0200 Subject: [PATCH 07/20] Rename all the queues Except the raw MIDI queues, since they're MIDI specific --- common/JackEventAsyncQueue.cpp | 32 ++++++------- common/JackEventAsyncQueue.h | 46 +++++++++---------- common/JackEventAsyncWaitQueue.cpp | 34 +++++++------- common/JackEventAsyncWaitQueue.h | 46 +++++++++---------- common/JackEventBufferReadQueue.cpp | 30 ++++++------ common/JackEventBufferReadQueue.h | 22 ++++----- common/JackEventBufferWriteQueue.cpp | 20 ++++---- common/JackEventBufferWriteQueue.h | 22 ++++----- common/JackEventReadQueue.cpp | 6 +-- common/JackEventReadQueue.h | 14 +++--- common/JackEventReceiveQueue.cpp | 6 +-- common/JackEventReceiveQueue.h | 10 ++-- common/JackEventSendQueue.cpp | 8 ++-- common/JackEventSendQueue.h | 16 +++---- common/JackEventWriteQueue.cpp | 4 +- common/JackEventWriteQueue.h | 16 +++---- ...eue.cpp => JackMidiRawInputWriteQueue.cpp} | 24 +++++----- ...teQueue.h => JackMidiRawInputWriteQueue.h} | 32 ++++++------- ...ue.cpp => JackMidiRawOutputWriteQueue.cpp} | 20 ++++---- ...eQueue.h => JackMidiRawOutputWriteQueue.h} | 28 +++++------ 20 files changed, 218 insertions(+), 218 deletions(-) rename common/{JackEventRawInputWriteQueue.cpp => JackMidiRawInputWriteQueue.cpp} (90%) rename common/{JackEventRawInputWriteQueue.h => JackMidiRawInputWriteQueue.h} (86%) rename common/{JackEventRawOutputWriteQueue.cpp => JackMidiRawOutputWriteQueue.cpp} (86%) rename common/{JackEventRawOutputWriteQueue.h => JackMidiRawOutputWriteQueue.h} (87%) diff --git a/common/JackEventAsyncQueue.cpp b/common/JackEventAsyncQueue.cpp index ab64db3f..f5a4164b 100644 --- a/common/JackEventAsyncQueue.cpp +++ b/common/JackEventAsyncQueue.cpp @@ -19,14 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -#include "JackMidiAsyncQueue.h" +#include "JackEventAsyncQueue.h" -using Jack::JackMidiAsyncQueue; +using Jack::JackEventAsyncQueue; -JackMidiAsyncQueue::JackMidiAsyncQueue(size_t max_bytes, size_t max_messages) +JackEventAsyncQueue::JackEventAsyncQueue(size_t max_bytes, size_t max_messages) { - data_buffer = new jack_midi_data_t[max_bytes]; - byte_ring = jack_ringbuffer_create((max_bytes * sizeof(jack_midi_data_t)) + + data_buffer = new jack_event_data_t[max_bytes]; + byte_ring = jack_ringbuffer_create((max_bytes * sizeof(jack_event_data_t)) + 1); if (byte_ring) { info_ring = jack_ringbuffer_create((max_messages * INFO_SIZE) + 1); @@ -42,17 +42,17 @@ JackMidiAsyncQueue::JackMidiAsyncQueue(size_t max_bytes, size_t max_messages) throw std::bad_alloc(); } -JackMidiAsyncQueue::~JackMidiAsyncQueue() +JackEventAsyncQueue::~JackEventAsyncQueue() { jack_ringbuffer_free(byte_ring); jack_ringbuffer_free(info_ring); delete[] data_buffer; } -jack_midi_event_t * -JackMidiAsyncQueue::DequeueEvent() +jack_event_t * +JackEventAsyncQueue::DequeueEvent() { - jack_midi_event_t *event = 0; + jack_event_t *event = 0; if (jack_ringbuffer_read_space(info_ring) >= INFO_SIZE) { size_t size; event = &dequeue_event; @@ -61,27 +61,27 @@ JackMidiAsyncQueue::DequeueEvent() jack_ringbuffer_read(info_ring, (char *) &size, sizeof(size_t)); jack_ringbuffer_read(byte_ring, (char *) data_buffer, - size * sizeof(jack_midi_data_t)); + size * sizeof(jack_event_data_t)); event->buffer = data_buffer; event->size = size; } return event; } -Jack::JackMidiWriteQueue::EnqueueResult -JackMidiAsyncQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) +Jack::JackEventWriteQueue::EnqueueResult +JackEventAsyncQueue::EnqueueEvent(jack_nframes_t time, size_t size, + jack_event_data_t *buffer) { if (size > max_bytes) { return BUFFER_TOO_SMALL; } if (! ((jack_ringbuffer_write_space(info_ring) >= INFO_SIZE) && (jack_ringbuffer_write_space(byte_ring) >= - (size * sizeof(jack_midi_data_t))))) { + (size * sizeof(jack_event_data_t))))) { return BUFFER_FULL; } jack_ringbuffer_write(byte_ring, (const char *) buffer, - size * sizeof(jack_midi_data_t)); + size * sizeof(jack_event_data_t)); jack_ringbuffer_write(info_ring, (const char *) (&time), sizeof(jack_nframes_t)); jack_ringbuffer_write(info_ring, (const char *) (&size), sizeof(size_t)); @@ -89,7 +89,7 @@ JackMidiAsyncQueue::EnqueueEvent(jack_nframes_t time, size_t size, } size_t -JackMidiAsyncQueue::GetAvailableSpace() +JackEventAsyncQueue::GetAvailableSpace() { return jack_ringbuffer_write_space(info_ring) < INFO_SIZE ? 0 : max_bytes - jack_ringbuffer_read_space(byte_ring); diff --git a/common/JackEventAsyncQueue.h b/common/JackEventAsyncQueue.h index 0bf23cbb..3e8341a1 100644 --- a/common/JackEventAsyncQueue.h +++ b/common/JackEventAsyncQueue.h @@ -17,28 +17,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiAsyncQueue__ -#define __JackMidiAsyncQueue__ +#ifndef __JackEventAsyncQueue__ +#define __JackEventAsyncQueue__ -#include "JackMidiPort.h" -#include "JackMidiReadQueue.h" -#include "JackMidiWriteQueue.h" +#include "JackEventPort.h" +#include "JackEventReadQueue.h" +#include "JackEventWriteQueue.h" #include "ringbuffer.h" namespace Jack { /** - * This is a MIDI message queue designed to allow one thread to pass MIDI + * This is a event message queue designed to allow one thread to pass event * messages to another thread (though it can also be used to buffer events - * internally). This is especially useful if the MIDI API you're + * internally). This is especially useful if the event API you're * attempting to interface with doesn't provide the ability to schedule - * MIDI events ahead of time and/or has blocking send/receive calls, as it + * events ahead of time and/or has blocking send/receive calls, as it * allows a separate thread to handle input/output while the JACK process - * thread copies events from a MIDI buffer to this queue, or vice versa. + * thread copies events from a buffer to this queue, or vice versa. */ - class SERVER_EXPORT JackMidiAsyncQueue: - public JackMidiReadQueue, public JackMidiWriteQueue { + class SERVER_EXPORT JackEventAsyncQueue: + public JackEventReadQueue, public JackEventWriteQueue { private: @@ -46,43 +46,43 @@ namespace Jack { sizeof(jack_nframes_t) + sizeof(size_t); jack_ringbuffer_t *byte_ring; - jack_midi_data_t *data_buffer; - jack_midi_event_t dequeue_event; + jack_event_data_t *data_buffer; + jack_event_t dequeue_event; jack_ringbuffer_t *info_ring; size_t max_bytes; public: - using JackMidiWriteQueue::EnqueueEvent; + using JackEventWriteQueue::EnqueueEvent; /** - * Creates a new asynchronous MIDI message queue. The queue can store - * up to `max_messages` MIDI messages and up to `max_bytes` of MIDI + * Creates a new asynchronous event message queue. The queue can store + * up to `max_messages` messages and up to `max_bytes` of * data before it starts rejecting messages. */ - JackMidiAsyncQueue(size_t max_bytes=4096, size_t max_messages=1024); + JackEventAsyncQueue(size_t max_bytes=4096, size_t max_messages=1024); virtual - ~JackMidiAsyncQueue(); + ~JackEventAsyncQueue(); /** - * Dequeues and returns a MIDI event. Returns '0' if there are no MIDI - * events available. This method may be overridden. + * Dequeues and returns an event. Returns '0' if there are none + * available. This method may be overridden. */ - virtual jack_midi_event_t * + virtual jack_event_t * DequeueEvent(); /** - * Enqueues the MIDI event specified by the arguments. The return + * Enqueues the event specified by the arguments. The return * value indicates whether or not the event was successfully enqueued. * This method may be overridden. */ virtual EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); /** * Returns the maximum size event that can be enqueued right *now*. diff --git a/common/JackEventAsyncWaitQueue.cpp b/common/JackEventAsyncWaitQueue.cpp index 016737cb..53b74b41 100644 --- a/common/JackEventAsyncWaitQueue.cpp +++ b/common/JackEventAsyncWaitQueue.cpp @@ -19,34 +19,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -#include "JackMidiAsyncWaitQueue.h" +#include "JackEventAsyncWaitQueue.h" #include "JackMidiUtil.h" #include "JackTime.h" -using Jack::JackMidiAsyncWaitQueue; +using Jack::JackEventAsyncWaitQueue; -JackMidiAsyncWaitQueue::JackMidiAsyncWaitQueue(size_t max_bytes, +JackEventAsyncWaitQueue::JackEventAsyncWaitQueue(size_t max_bytes, size_t max_messages): - JackMidiAsyncQueue(max_bytes, max_messages) + JackEventAsyncQueue(max_bytes, max_messages) { - if (semaphore.Allocate("JackMidiAsyncWaitQueue", "midi-thread", 0)) { + if (semaphore.Allocate("JackEventAsyncWaitQueue", "event-thread", 0)) { throw std::bad_alloc(); } } -JackMidiAsyncWaitQueue::~JackMidiAsyncWaitQueue() +JackEventAsyncWaitQueue::~JackEventAsyncWaitQueue() { semaphore.Destroy(); } -jack_midi_event_t * -JackMidiAsyncWaitQueue::DequeueEvent() +jack_event_t * +JackEventAsyncWaitQueue::DequeueEvent() { return DequeueEvent((long) 0); } -jack_midi_event_t * -JackMidiAsyncWaitQueue::DequeueEvent(jack_nframes_t frame) +jack_event_t * +JackEventAsyncWaitQueue::DequeueEvent(jack_nframes_t frame) { // XXX: I worry about timer resolution on Solaris and Windows. When the @@ -65,18 +65,18 @@ JackMidiAsyncWaitQueue::DequeueEvent(jack_nframes_t frame) (long) (frame_time - current_time)); } -jack_midi_event_t * -JackMidiAsyncWaitQueue::DequeueEvent(long usec) +jack_event_t * +JackEventAsyncWaitQueue::DequeueEvent(long usec) { return ((usec < 0) ? semaphore.Wait() : semaphore.TimedWait(usec)) ? - JackMidiAsyncQueue::DequeueEvent() : 0; + JackEventAsyncQueue::DequeueEvent() : 0; } -Jack::JackMidiWriteQueue::EnqueueResult -JackMidiAsyncWaitQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) +Jack::JackEventWriteQueue::EnqueueResult +JackEventAsyncWaitQueue::EnqueueEvent(jack_nframes_t time, size_t size, + jack_event_data_t *buffer) { - EnqueueResult result = JackMidiAsyncQueue::EnqueueEvent(time, size, + EnqueueResult result = JackEventAsyncQueue::EnqueueEvent(time, size, buffer); if (result == OK) { semaphore.Signal(); diff --git a/common/JackEventAsyncWaitQueue.h b/common/JackEventAsyncWaitQueue.h index 72df48c5..bbb4d683 100644 --- a/common/JackEventAsyncWaitQueue.h +++ b/common/JackEventAsyncWaitQueue.h @@ -17,26 +17,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiAsyncWaitQueue__ -#define __JackMidiAsyncWaitQueue__ +#ifndef __JackEventAsyncWaitQueue__ +#define __JackEventAsyncWaitQueue__ -#include "JackMidiAsyncQueue.h" +#include "JackEventAsyncQueue.h" namespace Jack { /** * This is an asynchronous wait queue that allows a thread to wait for a * message, either indefinitely or for a specified time. This is one - * example of a way that the `JackMidiAsyncQueue` class can be extended so - * that process threads can interact with non-process threads to send MIDI + * example of a way that the `JackEventAsyncQueue` class can be extended so + * that process threads can interact with non-process threads to send * events. * * XXX: As of right now, this code hasn't been tested. Also, note the - * warning in the JackMidiAsyncWaitQueue.cpp about semaphore wait + * warning in the JackEventAsyncWaitQueue.cpp about semaphore wait * resolution. */ - class SERVER_EXPORT JackMidiAsyncWaitQueue: public JackMidiAsyncQueue { + class SERVER_EXPORT JackEventAsyncWaitQueue: public JackEventAsyncQueue { private: @@ -44,53 +44,53 @@ namespace Jack { public: - using JackMidiAsyncQueue::EnqueueEvent; + using JackEventAsyncQueue::EnqueueEvent; /** - * Creates a new asynchronous MIDI wait message queue. The queue can - * store up to `max_messages` MIDI messages and up to `max_bytes` of - * MIDI data before it starts rejecting messages. + * Creates a new asynchronous wait message queue. The queue can + * store up to `max_messages` messages and up to `max_bytes` of + * messagea data before it starts rejecting messages. */ - JackMidiAsyncWaitQueue(size_t max_bytes=4096, + JackEventAsyncWaitQueue(size_t max_bytes=4096, size_t max_messages=1024); - ~JackMidiAsyncWaitQueue(); + ~JackEventAsyncWaitQueue(); /** * Dequeues and returns a MIDI event. Returns '0' if there are no MIDI * events available right now. */ - jack_midi_event_t * + jack_event_t * DequeueEvent(); /** - * Waits a specified time for a MIDI event to be available, or - * indefinitely if the time is negative. Returns the MIDI event, or - * '0' if time runs out and no MIDI event is available. + * Waits a specified time for an event to be available, or + * indefinitely if the time is negative. Returns the event, or + * '0' if time runs out and no event is available. */ - jack_midi_event_t * + jack_event_t * DequeueEvent(long usecs); /** - * Waits until the specified frame for a MIDI event to be available. - * Returns the MIDI event, or '0' if time runs out and no MIDI event is + * Waits until the specified frame for an event to be available. + * Returns the event, or '0' if time runs out and no event is * available. */ - jack_midi_event_t * + jack_event_t * DequeueEvent(jack_nframes_t frame); /** - * Enqueues the MIDI event specified by the arguments. The return + * Enqueues the event specified by the arguments. The return * value indicates whether or not the event was successfully enqueued. */ EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); }; diff --git a/common/JackEventBufferReadQueue.cpp b/common/JackEventBufferReadQueue.cpp index 67d79b1f..c1720b81 100644 --- a/common/JackEventBufferReadQueue.cpp +++ b/common/JackEventBufferReadQueue.cpp @@ -17,48 +17,48 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiBufferReadQueue.h" +#include "JackEventBufferReadQueue.h" #include "JackMidiUtil.h" #include "JackError.h" -using Jack::JackMidiBufferReadQueue; +using Jack::JackEventBufferReadQueue; -JackMidiBufferReadQueue::JackMidiBufferReadQueue() +JackEventBufferReadQueue::JackEventBufferReadQueue() { event_count = 0; index = 0; } -jack_midi_event_t * -JackMidiBufferReadQueue::DequeueEvent() +jack_event_t * +JackEventBufferReadQueue::DequeueEvent() { - jack_midi_event_t *e = 0; + jack_event_t *e = 0; if (index < event_count) { - JackMidiEvent *event = &(buffer->events[index]); - midi_event.buffer = event->GetData(buffer); - midi_event.size = event->size; - midi_event.time = last_frame_time + event->time; - e = &midi_event; + JackEvent *event = &(buffer->events[index]); + event.buffer = event->GetData(buffer); + event.size = event->size; + event.time = last_frame_time + event->time; + e = &event; index++; } return e; } void -JackMidiBufferReadQueue::ResetMidiBuffer(JackMidiBuffer *buffer) +JackEventBufferReadQueue::ResetEventBuffer(JackEventBuffer *buffer) { event_count = 0; index = 0; if (! buffer) { - jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - buffer reset " + jack_error("JackEventBufferReadQueue::ResetEventBuffer - buffer reset " "to NULL"); } else if (! buffer->IsValid()) { - jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - buffer reset " + jack_error("JackEventBufferReadQueue::ResetEventBuffer - buffer reset " "to invalid buffer"); } else { uint32_t lost_events = buffer->lost_events; if (lost_events) { - jack_error("JackMidiBufferReadQueue::ResetMidiBuffer - %d events " + jack_error("JackEventBufferReadQueue::ResetEventBuffer - %d events " "lost during mixdown", lost_events); } this->buffer = buffer; diff --git a/common/JackEventBufferReadQueue.h b/common/JackEventBufferReadQueue.h index 84337e42..55393d94 100644 --- a/common/JackEventBufferReadQueue.h +++ b/common/JackEventBufferReadQueue.h @@ -17,41 +17,41 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiBufferReadQueue__ -#define __JackMidiBufferReadQueue__ +#ifndef __JackEventBufferReadQueue__ +#define __JackEventBufferReadQueue__ -#include "JackMidiReadQueue.h" +#include "JackEventReadQueue.h" namespace Jack { /** - * Wrapper class to present a JackMidiBuffer in a read queue interface. + * Wrapper class to present a JackEventBuffer in a read queue interface. */ - class SERVER_EXPORT JackMidiBufferReadQueue: public JackMidiReadQueue { + class SERVER_EXPORT JackEventBufferReadQueue: public JackEventReadQueue { private: - JackMidiBuffer *buffer; + JackEventBuffer *buffer; jack_nframes_t event_count; jack_nframes_t index; jack_nframes_t last_frame_time; - jack_midi_event_t midi_event; + jack_event_t midi_event; public: - JackMidiBufferReadQueue(); + JackEventBufferReadQueue(); - jack_midi_event_t * + jack_event_t * DequeueEvent(); /** - * This method must be called each period to reset the MIDI buffer for + * This method must be called each period to reset the buffer for * processing. */ void - ResetMidiBuffer(JackMidiBuffer *buffer); + ResetEventBuffer(JackEventBuffer *buffer); }; diff --git a/common/JackEventBufferWriteQueue.cpp b/common/JackEventBufferWriteQueue.cpp index 82788155..5b11b55f 100644 --- a/common/JackEventBufferWriteQueue.cpp +++ b/common/JackEventBufferWriteQueue.cpp @@ -17,20 +17,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiBufferWriteQueue.h" +#include "JackEventBufferWriteQueue.h" #include "JackMidiUtil.h" #include "JackError.h" -using Jack::JackMidiBufferWriteQueue; +using Jack::JackEventBufferWriteQueue; -JackMidiBufferWriteQueue::JackMidiBufferWriteQueue() +JackEventBufferWriteQueue::JackEventBufferWriteQueue() { // Empty } -Jack::JackMidiWriteQueue::EnqueueResult -JackMidiBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *data) +Jack::JackEventWriteQueue::EnqueueResult +JackEventBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, + jack_evemt_data_t *data) { if (time >= next_frame_time) { return EVENT_EARLY; @@ -38,7 +38,7 @@ JackMidiBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, if (time < last_frame_time) { time = last_frame_time; } - jack_midi_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size); + jack_evemt_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size); if (! dst) { return size > max_bytes ? BUFFER_TOO_SMALL : BUFFER_FULL; } @@ -47,14 +47,14 @@ JackMidiBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, } void -JackMidiBufferWriteQueue::ResetMidiBuffer(JackMidiBuffer *buffer, +JackEventBufferWriteQueue::ResetEventBuffer(JackEventBuffer *buffer, jack_nframes_t frames) { if (! buffer) { - jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset " + jack_error("JackEventBufferWriteQueue::ResetEventBuffer - buffer reset " "to NULL"); } else if (! buffer->IsValid()) { - jack_error("JackMidiBufferWriteQueue::ResetMidiBuffer - buffer reset " + jack_error("JackEventBufferWriteQueue::ResetEventBuffer - buffer reset " "to invalid buffer"); } else { this->buffer = buffer; diff --git a/common/JackEventBufferWriteQueue.h b/common/JackEventBufferWriteQueue.h index 90d5cbf1..fd9cd12d 100644 --- a/common/JackEventBufferWriteQueue.h +++ b/common/JackEventBufferWriteQueue.h @@ -17,43 +17,43 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiBufferWriteQueue__ -#define __JackMidiBufferWriteQueue__ +#ifndef __JackEventBufferWriteQueue__ +#define __JackEventBufferWriteQueue__ -#include "JackMidiWriteQueue.h" +#include "JackEventWriteQueue.h" namespace Jack { /** - * Wrapper class to present a JackMidiBuffer in a write queue interface. + * Wrapper class to present a JackEventBuffer in a write queue interface. */ - class SERVER_EXPORT JackMidiBufferWriteQueue: public JackMidiWriteQueue { + class SERVER_EXPORT JackEventBufferWriteQueue: public JackEventWriteQueue { private: - JackMidiBuffer *buffer; + JackEventBuffer *buffer; jack_nframes_t last_frame_time; size_t max_bytes; jack_nframes_t next_frame_time; public: - using JackMidiWriteQueue::EnqueueEvent; + using JackEventWriteQueue::EnqueueEvent; - JackMidiBufferWriteQueue(); + JackEventBufferWriteQueue(); EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); /** - * This method must be called each period to reset the MIDI buffer for + * This method must be called each period to reset the buffer for * processing. */ void - ResetMidiBuffer(JackMidiBuffer *buffer, jack_nframes_t frames); + ResetEventBuffer(JackEventBuffer *buffer, jack_nframes_t frames); }; diff --git a/common/JackEventReadQueue.cpp b/common/JackEventReadQueue.cpp index a6869691..4d54af71 100644 --- a/common/JackEventReadQueue.cpp +++ b/common/JackEventReadQueue.cpp @@ -17,11 +17,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiReadQueue.h" +#include "JackEventReadQueue.h" -using Jack::JackMidiReadQueue; +using Jack::JackEventReadQueue; -JackMidiReadQueue::~JackMidiReadQueue() +JackEventReadQueue::~JackEventReadQueue() { // Empty } diff --git a/common/JackEventReadQueue.h b/common/JackEventReadQueue.h index 0f4ca692..823a1933 100644 --- a/common/JackEventReadQueue.h +++ b/common/JackEventReadQueue.h @@ -17,23 +17,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiReadQueue__ -#define __JackMidiReadQueue__ +#ifndef __JackEventReadQueue__ +#define __JackEventReadQueue__ -#include "JackMidiPort.h" +#include "JackEventPort.h" namespace Jack { /** - * Interface for objects that MIDI events can be read from. + * Interface for objects that events can be read from. */ - class SERVER_EXPORT JackMidiReadQueue { + class SERVER_EXPORT JackEventReadQueue { public: virtual - ~JackMidiReadQueue(); + ~JackEventReadQueue(); /** * Dequeues an event from the queue. Returns the event, or 0 if no @@ -45,7 +45,7 @@ namespace Jack { * next event. */ - virtual jack_midi_event_t * + virtual jack_event_t * DequeueEvent() = 0; }; diff --git a/common/JackEventReceiveQueue.cpp b/common/JackEventReceiveQueue.cpp index 3eb3573e..fb081dfc 100644 --- a/common/JackEventReceiveQueue.cpp +++ b/common/JackEventReceiveQueue.cpp @@ -17,11 +17,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiReceiveQueue.h" +#include "JackEventReceiveQueue.h" -using Jack::JackMidiReceiveQueue; +using Jack::JackEventReceiveQueue; -JackMidiReceiveQueue::~JackMidiReceiveQueue() +JackEventReceiveQueue::~JackEventReceiveQueue() { // Empty } diff --git a/common/JackEventReceiveQueue.h b/common/JackEventReceiveQueue.h index 1d19c3c1..8bde2707 100644 --- a/common/JackEventReceiveQueue.h +++ b/common/JackEventReceiveQueue.h @@ -17,10 +17,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiReceiveQueue__ -#define __JackMidiReceiveQueue__ +#ifndef __JackEventReceiveQueue__ +#define __JackEventReceiveQueue__ -#include "JackMidiReadQueue.h" +#include "JackEventReadQueue.h" namespace Jack { @@ -28,12 +28,12 @@ namespace Jack { * Implemented by MIDI input connections. */ - class SERVER_EXPORT JackMidiReceiveQueue: public JackMidiReadQueue { + class SERVER_EXPORT JackEventReceiveQueue: public JackEventReadQueue { public: virtual - ~JackMidiReceiveQueue(); + ~JackEventReceiveQueue(); }; diff --git a/common/JackEventSendQueue.cpp b/common/JackEventSendQueue.cpp index ac66d812..e7fff5b6 100644 --- a/common/JackEventSendQueue.cpp +++ b/common/JackEventSendQueue.cpp @@ -17,18 +17,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiSendQueue.h" +#include "JackEventSendQueue.h" #include "JackMidiUtil.h" -using Jack::JackMidiSendQueue; +using Jack::JackEventSendQueue; -JackMidiSendQueue::~JackMidiSendQueue() +JackEventSendQueue::~JackEventSendQueue() { // Empty } jack_nframes_t -JackMidiSendQueue::GetNextScheduleFrame() +JackEventSendQueue::GetNextScheduleFrame() { return GetCurrentFrame(); } diff --git a/common/JackEventSendQueue.h b/common/JackEventSendQueue.h index 0cb8df44..25d59046 100644 --- a/common/JackEventSendQueue.h +++ b/common/JackEventSendQueue.h @@ -17,28 +17,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiSendQueue__ -#define __JackMidiSendQueue__ +#ifndef __JackEventSendQueue__ +#define __JackEventSendQueue__ -#include "JackMidiWriteQueue.h" +#include "JackEventWriteQueue.h" namespace Jack { /** - * Implemented by MIDI output connections. + * Implemented by event output connections. */ - class SERVER_EXPORT JackMidiSendQueue: public JackMidiWriteQueue { + class SERVER_EXPORT JackEventSendQueue: public JackEventWriteQueue { public: - using JackMidiWriteQueue::EnqueueEvent; + using JackEventWriteQueue::EnqueueEvent; virtual - ~JackMidiSendQueue(); + ~JackEventSendQueue(); /** - * Returns the next frame that a MIDI message can be sent at. The + * Returns the next frame that a message can be sent at. The * default method returns the current frame. */ diff --git a/common/JackEventWriteQueue.cpp b/common/JackEventWriteQueue.cpp index 37fd9067..6ca82df7 100644 --- a/common/JackEventWriteQueue.cpp +++ b/common/JackEventWriteQueue.cpp @@ -19,9 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackMidiWriteQueue.h" -using Jack::JackMidiWriteQueue; +using Jack::JackEventWriteQueue; -JackMidiWriteQueue::~JackMidiWriteQueue() +JackEventWriteQueue::~JackEventWriteQueue() { // Empty } diff --git a/common/JackEventWriteQueue.h b/common/JackEventWriteQueue.h index f21a58ff..7a0f90bf 100644 --- a/common/JackEventWriteQueue.h +++ b/common/JackEventWriteQueue.h @@ -17,19 +17,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __JackMidiWriteQueue__ -#define __JackMidiWriteQueue__ +#ifndef __JackEventWriteQueue__ +#define __JackEventWriteQueue__ -#include "JackMidiPort.h" +#include "JackEventPort.h" namespace Jack { /** - * Interface for classes that act as write queues for MIDI messages. Write + * Interface for classes that act as write queues for event messages. Write * queues are used by processors to transfer data to the next processor. */ - class SERVER_EXPORT JackMidiWriteQueue { + class SERVER_EXPORT JackEventWriteQueue { public: @@ -41,7 +41,7 @@ namespace Jack { OK }; - virtual ~JackMidiWriteQueue(); + virtual ~JackEventWriteQueue(); /** * Enqueues a data packet in the write queue of `size` bytes contained @@ -60,7 +60,7 @@ namespace Jack { virtual EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) = 0; + jack_event_data_t *buffer) = 0; /** * A wrapper method for the `EnqueueEvent` method above. The optional @@ -69,7 +69,7 @@ namespace Jack { */ inline EnqueueResult - EnqueueEvent(jack_midi_event_t *event, jack_nframes_t frame_offset=0) + EnqueueEvent(jack_event_t *event, jack_nframes_t frame_offset=0) { return EnqueueEvent(event->time + frame_offset, event->size, event->buffer); diff --git a/common/JackEventRawInputWriteQueue.cpp b/common/JackMidiRawInputWriteQueue.cpp similarity index 90% rename from common/JackEventRawInputWriteQueue.cpp rename to common/JackMidiRawInputWriteQueue.cpp index f753c4f8..5463c06b 100644 --- a/common/JackEventRawInputWriteQueue.cpp +++ b/common/JackMidiRawInputWriteQueue.cpp @@ -27,12 +27,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. using Jack::JackMidiRawInputWriteQueue; JackMidiRawInputWriteQueue:: -JackMidiRawInputWriteQueue(JackMidiWriteQueue *write_queue, +JackMidiRawInputWriteQueue(JackEventWriteQueue *write_queue, size_t max_packet_data, size_t max_packets) { - packet_queue = new JackMidiAsyncQueue(max_packet_data, max_packets); - std::unique_ptr packet_queue_ptr(packet_queue); - input_buffer = new jack_midi_data_t[max_packet_data]; + packet_queue = new JackEventAsyncQueue(max_packet_data, max_packets); + std::unique_ptr packet_queue_ptr(packet_queue); + input_buffer = new jack_event_data_t[max_packet_data]; Clear(); expected_bytes = 0; event_pending = false; @@ -56,9 +56,9 @@ JackMidiRawInputWriteQueue::Clear() unbuffered_bytes = 0; } -Jack::JackMidiWriteQueue::EnqueueResult +Jack::JackEventWriteQueue::EnqueueResult JackMidiRawInputWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) + jack_event_data_t *buffer) { return packet_queue->EnqueueEvent(time, size, buffer); } @@ -79,7 +79,7 @@ JackMidiRawInputWriteQueue::HandleBufferFailure(size_t unbuffered_bytes, } void -JackMidiRawInputWriteQueue::HandleEventLoss(jack_midi_event_t *event) +JackMidiRawInputWriteQueue::HandleEventLoss(jack_event_t *event) { jack_error("JackMidiRawInputWriteQueue::HandleEventLoss - A %d byte MIDI " "event scheduled for frame '%d' could not be processed because " @@ -96,7 +96,7 @@ JackMidiRawInputWriteQueue::HandleIncompleteMessage(size_t total_bytes) } void -JackMidiRawInputWriteQueue::HandleInvalidStatusByte(jack_midi_data_t byte) +JackMidiRawInputWriteQueue::HandleInvalidStatusByte(jack_event_data_t byte) { jack_error("JackMidiRawInputWriteQueue::HandleInvalidStatusByte - " "Dropping invalid MIDI status byte '%x'.", (unsigned int) byte); @@ -130,7 +130,7 @@ JackMidiRawInputWriteQueue::PrepareBufferedEvent(jack_nframes_t time) bool JackMidiRawInputWriteQueue::PrepareByteEvent(jack_nframes_t time, - jack_midi_data_t byte) + jack_event_data_t byte) { event_byte = byte; PrepareEvent(time, 1, &event_byte); @@ -139,7 +139,7 @@ JackMidiRawInputWriteQueue::PrepareByteEvent(jack_nframes_t time, void JackMidiRawInputWriteQueue::PrepareEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) + jack_event_data_t *buffer) { event.buffer = buffer; event.size = size; @@ -174,7 +174,7 @@ JackMidiRawInputWriteQueue::Process(jack_nframes_t boundary_frame) bool JackMidiRawInputWriteQueue::ProcessByte(jack_nframes_t time, - jack_midi_data_t byte) + jack_event_data_t byte) { if (byte >= 0xf8) { // Realtime @@ -269,7 +269,7 @@ JackMidiRawInputWriteQueue::ProcessByte(jack_nframes_t time, } void -JackMidiRawInputWriteQueue::RecordByte(jack_midi_data_t byte) +JackMidiRawInputWriteQueue::RecordByte(jack_event_data_t byte) { if (total_bytes < input_buffer_size) { input_buffer[total_bytes] = byte; diff --git a/common/JackEventRawInputWriteQueue.h b/common/JackMidiRawInputWriteQueue.h similarity index 86% rename from common/JackEventRawInputWriteQueue.h rename to common/JackMidiRawInputWriteQueue.h index 32573d0f..40f6c6cd 100644 --- a/common/JackEventRawInputWriteQueue.h +++ b/common/JackMidiRawInputWriteQueue.h @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __JackMidiRawInputWriteQueue__ #define __JackMidiRawInputWriteQueue__ -#include "JackMidiAsyncQueue.h" -#include "JackMidiWriteQueue.h" +#include "JackEventAsyncQueue.h" +#include "JackEventWriteQueue.h" namespace Jack { @@ -33,22 +33,22 @@ namespace Jack { * MIDI bytes that must be parsed. */ - class SERVER_EXPORT JackMidiRawInputWriteQueue: public JackMidiWriteQueue { + class SERVER_EXPORT JackMidiRawInputWriteQueue: public JackEventWriteQueue { private: - jack_midi_event_t event; - jack_midi_data_t event_byte; + jack_event_t event; + jack_event_data_t event_byte; bool event_pending; size_t expected_bytes; - jack_midi_data_t *input_buffer; + jack_event_data_t *input_buffer; size_t input_buffer_size; - jack_midi_event_t *packet; + jack_event_t *packet; JackMidiAsyncQueue *packet_queue; - jack_midi_data_t status_byte; + jack_event_data_t status_byte; size_t total_bytes; size_t unbuffered_bytes; - JackMidiWriteQueue *write_queue; + JackEventWriteQueue *write_queue; void Clear(); @@ -57,17 +57,17 @@ namespace Jack { PrepareBufferedEvent(jack_nframes_t time); bool - PrepareByteEvent(jack_nframes_t time, jack_midi_data_t byte); + PrepareByteEvent(jack_nframes_t time, jack_event_data_t byte); void PrepareEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); bool - ProcessByte(jack_nframes_t time, jack_midi_data_t byte); + ProcessByte(jack_nframes_t time, jack_event_data_t byte); void - RecordByte(jack_midi_data_t byte); + RecordByte(jack_event_data_t byte); bool WriteEvent(jack_nframes_t boundary_frame); @@ -120,7 +120,7 @@ namespace Jack { public: - using JackMidiWriteQueue::EnqueueEvent; + using JackEventWriteQueue::EnqueueEvent; /** * Called to create a new raw input write queue. The `write_queue` @@ -132,7 +132,7 @@ namespace Jack { * written to the write queue. */ - JackMidiRawInputWriteQueue(JackMidiWriteQueue *write_queue, + JackMidiRawInputWriteQueue(JackEventWriteQueue *write_queue, size_t max_packet_data=4096, size_t max_packets=1024); @@ -140,7 +140,7 @@ namespace Jack { EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); /** * Returns the maximum size event that can be enqueued right *now*. diff --git a/common/JackEventRawOutputWriteQueue.cpp b/common/JackMidiRawOutputWriteQueue.cpp similarity index 86% rename from common/JackEventRawOutputWriteQueue.cpp rename to common/JackMidiRawOutputWriteQueue.cpp index b81ea0c0..0da04b7e 100644 --- a/common/JackEventRawOutputWriteQueue.cpp +++ b/common/JackMidiRawOutputWriteQueue.cpp @@ -29,13 +29,13 @@ using Jack::JackMidiRawOutputWriteQueue; #define STILL_TIME(c, b) ((! (b)) || ((c) < (b))) JackMidiRawOutputWriteQueue:: -JackMidiRawOutputWriteQueue(JackMidiSendQueue *send_queue, size_t non_rt_size, +JackMidiRawOutputWriteQueue(JackEventSendQueue *send_queue, size_t non_rt_size, size_t max_non_rt_messages, size_t max_rt_messages) { - non_rt_queue = new JackMidiAsyncQueue(non_rt_size, max_non_rt_messages); - std::unique_ptr non_rt_ptr(non_rt_queue); - rt_queue = new JackMidiAsyncQueue(max_rt_messages, max_rt_messages); - std::unique_ptr rt_ptr(rt_queue); + non_rt_queue = new JackEventAsyncQueue(non_rt_size, max_non_rt_messages); + std::unique_ptr non_rt_ptr(non_rt_queue); + rt_queue = new JackEventAsyncQueue(max_rt_messages, max_rt_messages); + std::unique_ptr rt_ptr(rt_queue); non_rt_event = 0; rt_event = 0; running_status = 0; @@ -69,18 +69,18 @@ JackMidiRawOutputWriteQueue::DequeueRealtimeEvent() } } -Jack::JackMidiWriteQueue::EnqueueResult +Jack::JackEventWriteQueue::EnqueueResult JackMidiRawOutputWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer) + jack_event_data_t *buffer) { - JackMidiAsyncQueue *queue = (size == 1) && (*buffer >= 0xf8) ? rt_queue : + JackEventAsyncQueue *queue = (size == 1) && (*buffer >= 0xf8) ? rt_queue : non_rt_queue; return queue->EnqueueEvent(time, size, buffer); } void JackMidiRawOutputWriteQueue::HandleWriteQueueBug(jack_nframes_t time, - jack_midi_data_t byte) + jack_event_data_t byte) { jack_error("JackMidiRawOutputWriteQueue::HandleWriteQueueBug - **BUG** " "The write queue told us that it couldn't enqueue a 1-byte " @@ -123,7 +123,7 @@ JackMidiRawOutputWriteQueue::Process(jack_nframes_t boundary_frame) bool JackMidiRawOutputWriteQueue::SendByte(jack_nframes_t time, - jack_midi_data_t byte) + jack_event_data_t byte) { switch (send_queue->EnqueueEvent(time, 1, &byte)) { case BUFFER_TOO_SMALL: diff --git a/common/JackEventRawOutputWriteQueue.h b/common/JackMidiRawOutputWriteQueue.h similarity index 87% rename from common/JackEventRawOutputWriteQueue.h rename to common/JackMidiRawOutputWriteQueue.h index 967591bf..acb8c8e8 100644 --- a/common/JackEventRawOutputWriteQueue.h +++ b/common/JackMidiRawOutputWriteQueue.h @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __JackMidiRawOutputWriteQueue__ #define __JackMidiRawOutputWriteQueue__ -#include "JackMidiAsyncQueue.h" -#include "JackMidiSendQueue.h" +#include "JackEventAsyncQueue.h" +#include "JackEventSendQueue.h" namespace Jack { @@ -44,18 +44,18 @@ namespace Jack { */ class SERVER_EXPORT JackMidiRawOutputWriteQueue: - public JackMidiWriteQueue { + public JackEventWriteQueue { private: - jack_midi_event_t *non_rt_event; + jack_event_t *non_rt_event; jack_nframes_t non_rt_event_time; - JackMidiAsyncQueue *non_rt_queue; - jack_midi_event_t *rt_event; + JackEventAsyncQueue *non_rt_queue; + jack_event_t *rt_event; jack_nframes_t rt_event_time; - JackMidiAsyncQueue *rt_queue; - jack_midi_data_t running_status; - JackMidiSendQueue *send_queue; + JackEventAsyncQueue *rt_queue; + jack_event_data_t running_status; + JackEventSendQueue *send_queue; void DequeueNonRealtimeEvent(); @@ -64,7 +64,7 @@ namespace Jack { DequeueRealtimeEvent(); bool - SendByte(jack_nframes_t time, jack_midi_data_t byte); + SendByte(jack_nframes_t time, jack_event_data_t byte); bool SendNonRTBytes(jack_nframes_t boundary_frame); @@ -78,11 +78,11 @@ namespace Jack { */ virtual void - HandleWriteQueueBug(jack_nframes_t time, jack_midi_data_t byte); + HandleWriteQueueBug(jack_nframes_t time, jack_event_data_t byte); public: - using JackMidiWriteQueue::EnqueueEvent; + using JackEventWriteQueue::EnqueueEvent; /** * Called to create a new raw write queue. The `send_queue` argument @@ -95,7 +95,7 @@ namespace Jack { * the non-realtime queue. */ - JackMidiRawOutputWriteQueue(JackMidiSendQueue *send_queue, + JackMidiRawOutputWriteQueue(JackEventSendQueue *send_queue, size_t non_rt_size=4096, size_t max_non_rt_messages=1024, size_t max_rt_messages=128); @@ -104,7 +104,7 @@ namespace Jack { EnqueueResult EnqueueEvent(jack_nframes_t time, size_t size, - jack_midi_data_t *buffer); + jack_event_data_t *buffer); /** * The `Process()` method should be called each time the From b695770a8db7289c6b616596ce03ad3ba1077526 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 16:37:30 +0200 Subject: [PATCH 08/20] Update JackMidiDriver --- common/{JackEventDriver.cpp => JackMidiDriver.cpp} | 8 ++++---- common/{JackEventDriver.h => JackMidiDriver.h} | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename common/{JackEventDriver.cpp => JackMidiDriver.cpp} (95%) rename common/{JackEventDriver.h => JackMidiDriver.h} (90%) diff --git a/common/JackEventDriver.cpp b/common/JackMidiDriver.cpp similarity index 95% rename from common/JackEventDriver.cpp rename to common/JackMidiDriver.cpp index 22060076..27cde208 100644 --- a/common/JackEventDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -198,16 +198,16 @@ int JackMidiDriver::ProcessWriteAsync() return 0; } -JackMidiBuffer* JackMidiDriver::GetInputBuffer(int port_index) +JackEventBuffer* JackMidiDriver::GetInputBuffer(int port_index) { assert(fCapturePortList[port_index]); - return (JackMidiBuffer*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize); + return (JackEventBuffer*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize); } -JackMidiBuffer* JackMidiDriver::GetOutputBuffer(int port_index) +JackEventBuffer* JackMidiDriver::GetOutputBuffer(int port_index) { assert(fPlaybackPortList[port_index]); - return (JackMidiBuffer*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize); + return (JackEventBuffer*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize); } } // end of namespace diff --git a/common/JackEventDriver.h b/common/JackMidiDriver.h similarity index 90% rename from common/JackEventDriver.h rename to common/JackMidiDriver.h index 76f187db..88df9f67 100644 --- a/common/JackEventDriver.h +++ b/common/JackMidiDriver.h @@ -21,7 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JackMidiDriver__ #include "JackDriver.h" -#include "JackMidiPort.h" +#include "JackEventPort.h" #include "JackLockedEngine.h" #include "ringbuffer.h" @@ -29,7 +29,7 @@ namespace Jack { /*! -\brief The base class for MIDI drivers: drivers with MIDI ports. +\brief The base class for event drivers: drivers with MIDI ports. A concrete derived class will have to be defined with a real MIDI driver API, either callback based one (like CoreMIDI..) ones or blocking ones (like ALSA MIDI). @@ -41,8 +41,8 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver protected: - JackMidiBuffer* GetInputBuffer(int port_index); - JackMidiBuffer* GetOutputBuffer(int port_index); + JackEventBuffer* GetInputBuffer(int port_index); + JackEventBuffer* GetOutputBuffer(int port_index); virtual int ProcessReadSync(); virtual int ProcessWriteSync(); From 0c1c32d47c0e12b47aa109359552999f80707053 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 17:24:17 +0200 Subject: [PATCH 09/20] Update JackNet --- common/JackNetAPI.cpp | 20 ++++++++++---------- common/JackNetDriver.cpp | 8 ++++---- common/JackNetDriver.h | 4 ++-- common/JackNetManager.cpp | 4 ++-- common/JackNetTool.cpp | 18 +++++++++--------- common/JackNetTool.h | 14 +++++++------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/common/JackNetAPI.cpp b/common/JackNetAPI.cpp index 09962ca7..08ccc18d 100644 --- a/common/JackNetAPI.cpp +++ b/common/JackNetAPI.cpp @@ -390,8 +390,8 @@ struct JackNetExtMaster : public JackNetMasterInterface { } for (int midi_port_index = 0; midi_port_index < midi_input; midi_port_index++) { - assert(((JackMidiBuffer**)midi_input_buffer)[midi_port_index]); - fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, ((JackMidiBuffer**)midi_input_buffer)[midi_port_index]); + assert(((JackEventBuffer**)midi_input_buffer)[midi_port_index]); + fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, ((JackEventBuffer**)midi_input_buffer)[midi_port_index]); } int res1 = SyncRecv(); @@ -443,8 +443,8 @@ struct JackNetExtMaster : public JackNetMasterInterface { } for (int midi_port_index = 0; midi_port_index < midi_output; midi_port_index++) { - assert(((JackMidiBuffer**)midi_output_buffer)[midi_port_index]); - fNetMidiCaptureBuffer->SetBuffer(midi_port_index, ((JackMidiBuffer**)midi_output_buffer)[midi_port_index]); + assert(((JackEventBuffer**)midi_output_buffer)[midi_port_index]); + fNetMidiCaptureBuffer->SetBuffer(midi_port_index, ((JackEventBuffer**)midi_output_buffer)[midi_port_index]); } EncodeSyncPacket(frames); @@ -481,8 +481,8 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf float** fAudioCaptureBuffer; float** fAudioPlaybackBuffer; - JackMidiBuffer** fMidiCaptureBuffer; - JackMidiBuffer** fMidiPlaybackBuffer; + JackEventBuffer** fMidiCaptureBuffer; + JackEventBuffer** fMidiPlaybackBuffer; JackThread fThread; @@ -567,9 +567,9 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf } if (fParams.fSendMidiChannels > 0) { - fMidiCaptureBuffer = new JackMidiBuffer*[fParams.fSendMidiChannels]; + fMidiCaptureBuffer = new JackEventBuffer*[fParams.fSendMidiChannels]; for (int midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++) { - fMidiCaptureBuffer[midi_port_index] = (JackMidiBuffer*)new float[fParams.fPeriodSize]; + fMidiCaptureBuffer[midi_port_index] = (JackEventBuffer*)new float[fParams.fPeriodSize]; memset(fMidiCaptureBuffer[midi_port_index], 0, sizeof(float) * fParams.fPeriodSize); fNetMidiCaptureBuffer->SetBuffer(midi_port_index, fMidiCaptureBuffer[midi_port_index]); } @@ -585,9 +585,9 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf } if (fParams.fReturnMidiChannels > 0) { - fMidiPlaybackBuffer = new JackMidiBuffer*[fParams.fReturnMidiChannels]; + fMidiPlaybackBuffer = new JackEventBuffer*[fParams.fReturnMidiChannels]; for (int midi_port_index = 0; midi_port_index < fParams.fReturnMidiChannels; midi_port_index++) { - fMidiPlaybackBuffer[midi_port_index] = (JackMidiBuffer*)new float[fParams.fPeriodSize]; + fMidiPlaybackBuffer[midi_port_index] = (JackEventBuffer*)new float[fParams.fPeriodSize]; memset(fMidiPlaybackBuffer[midi_port_index], 0, sizeof(float) * fParams.fPeriodSize); fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, fMidiPlaybackBuffer[midi_port_index]); } diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index af5e8097..4af21c98 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -453,14 +453,14 @@ namespace Jack } } - JackMidiBuffer* JackNetDriver::GetMidiInputBuffer(int port_index) + JackEventBuffer* JackNetDriver::GetMidiInputBuffer(int port_index) { - return static_cast(fGraphManager->GetBuffer(fMidiCapturePortList[port_index], fEngineControl->fBufferSize)); + return static_cast(fGraphManager->GetBuffer(fMidiCapturePortList[port_index], fEngineControl->fBufferSize)); } - JackMidiBuffer* JackNetDriver::GetMidiOutputBuffer(int port_index) + JackEventBuffer* JackNetDriver::GetMidiOutputBuffer(int port_index) { - return static_cast(fGraphManager->GetBuffer(fMidiPlaybackPortList[port_index], fEngineControl->fBufferSize)); + return static_cast(fGraphManager->GetBuffer(fMidiPlaybackPortList[port_index], fEngineControl->fBufferSize)); } //transport--------------------------------------------------------------------------- diff --git a/common/JackNetDriver.h b/common/JackNetDriver.h index da65a13b..8d721463 100644 --- a/common/JackNetDriver.h +++ b/common/JackNetDriver.h @@ -69,8 +69,8 @@ namespace Jack void EncodeTransportData(); void DecodeTransportData(); - JackMidiBuffer* GetMidiInputBuffer(int port_index); - JackMidiBuffer* GetMidiOutputBuffer(int port_index); + JackEventBuffer* GetMidiInputBuffer(int port_index); + JackEventBuffer* GetMidiOutputBuffer(int port_index); void SaveConnections(int alias); diff --git a/common/JackNetManager.cpp b/common/JackNetManager.cpp index 250c1237..ab5436c9 100644 --- a/common/JackNetManager.cpp +++ b/common/JackNetManager.cpp @@ -462,7 +462,7 @@ namespace Jack //buffers for (int midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++) { fNetMidiCaptureBuffer->SetBuffer(midi_port_index, - static_cast(jack_port_get_buffer(fMidiCapturePorts[midi_port_index], + static_cast(jack_port_get_buffer(fMidiCapturePorts[midi_port_index], fParams.fPeriodSize))); } for (int audio_port_index = 0; audio_port_index < fParams.fSendAudioChannels; audio_port_index++) { @@ -487,7 +487,7 @@ namespace Jack for (int midi_port_index = 0; midi_port_index < fParams.fReturnMidiChannels; midi_port_index++) { fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, - static_cast(jack_port_get_buffer(fMidiPlaybackPorts[midi_port_index], + static_cast(jack_port_get_buffer(fMidiPlaybackPorts[midi_port_index], fParams.fPeriodSize))); } for (int audio_port_index = 0; audio_port_index < fParams.fReturnAudioChannels; audio_port_index++) { diff --git a/common/JackNetTool.cpp b/common/JackNetTool.cpp index 8e83db6c..85752b1a 100644 --- a/common/JackNetTool.cpp +++ b/common/JackNetTool.cpp @@ -97,7 +97,7 @@ namespace Jack fMaxBufsize = fNPorts * sizeof(sample_t) * params->fPeriodSize; fMaxPcktSize = params->fMtu - sizeof(packet_header_t); fBuffer = new char[fMaxBufsize]; - fPortBuffer = new JackMidiBuffer* [fNPorts]; + fPortBuffer = new JackEventBuffer* [fNPorts]; for (int port_index = 0; port_index < fNPorts; port_index++) { fPortBuffer[port_index] = NULL; } @@ -125,12 +125,12 @@ namespace Jack return (res1) ? res2 + 1 : res2; } - void NetMidiBuffer::SetBuffer(int index, JackMidiBuffer* buffer) + void NetMidiBuffer::SetBuffer(int index, JackEventBuffer* buffer) { fPortBuffer[index] = buffer; } - JackMidiBuffer* NetMidiBuffer::GetBuffer(int index) + JackEventBuffer* NetMidiBuffer::GetBuffer(int index) { return fPortBuffer[index]; } @@ -155,14 +155,14 @@ namespace Jack for (int port_index = 0; port_index < fNPorts; port_index++) { char* write_pos = fBuffer + pos; - copy_size = sizeof(JackMidiBuffer) + fPortBuffer[port_index]->event_count * sizeof(JackMidiEvent); + copy_size = sizeof(JackEventBuffer) + fPortBuffer[port_index]->event_count * sizeof(JackEvent); memcpy(fBuffer + pos, fPortBuffer[port_index], copy_size); pos += copy_size; memcpy(fBuffer + pos, fPortBuffer[port_index] + (fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos), fPortBuffer[port_index]->write_pos); pos += fPortBuffer[port_index]->write_pos; - JackMidiBuffer* midi_buffer = reinterpret_cast(write_pos); + JackEventBuffer* midi_buffer = reinterpret_cast(write_pos); MidiBufferHToN(midi_buffer, midi_buffer); } return pos; @@ -174,9 +174,9 @@ namespace Jack size_t copy_size; for (int port_index = 0; port_index < fNPorts; port_index++) { - JackMidiBuffer* midi_buffer = reinterpret_cast(fBuffer + pos); + JackEventBuffer* midi_buffer = reinterpret_cast(fBuffer + pos); MidiBufferNToH(midi_buffer, midi_buffer); - copy_size = sizeof(JackMidiBuffer) + reinterpret_cast(fBuffer + pos)->event_count * sizeof(JackMidiEvent); + copy_size = sizeof(JackEventBuffer) + reinterpret_cast(fBuffer + pos)->event_count * sizeof(JackEvent); memcpy(fPortBuffer[port_index], fBuffer + pos, copy_size); pos += copy_size; memcpy(fPortBuffer[port_index] + (fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos), @@ -1270,7 +1270,7 @@ namespace Jack jack_info("**********************************************"); } - SERVER_EXPORT void MidiBufferHToN(JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer) + SERVER_EXPORT void MidiBufferHToN(JackEventBuffer* src_buffer, JackEventBuffer* dst_buffer) { dst_buffer->magic = htonl(src_buffer->magic); dst_buffer->buffer_size = htonl(src_buffer->buffer_size); @@ -1280,7 +1280,7 @@ namespace Jack dst_buffer->lost_events = htonl(src_buffer->lost_events); } - SERVER_EXPORT void MidiBufferNToH(JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer) + SERVER_EXPORT void MidiBufferNToH(JackEventBuffer* src_buffer, JackEventBuffer* dst_buffer) { dst_buffer->magic = ntohl(src_buffer->magic); dst_buffer->buffer_size = ntohl(src_buffer->buffer_size); diff --git a/common/JackNetTool.h b/common/JackNetTool.h index e664f9fe..1013c4d3 100644 --- a/common/JackNetTool.h +++ b/common/JackNetTool.h @@ -17,7 +17,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "JackMidiPort.h" +#include "JackEventPort.h" #include "JackTools.h" #include "types.h" #include "transport.h" @@ -224,7 +224,7 @@ namespace Jack \Brief Midi buffer and operations class This class is a toolset to manipulate Midi buffers. - A JackMidiBuffer has a fixed size, which is the same than an audio buffer size. + A JackEventBuffer has a fixed size, which is the same than an audio buffer size. An intermediate fixed size buffer allows to uninterleave midi data (from jack ports). But for a big majority of the process cycles, this buffer is filled less than 1%, Sending over a network 99% of useless data seems completely unappropriate. @@ -245,7 +245,7 @@ namespace Jack char* fBuffer; char* fNetBuffer; - JackMidiBuffer** fPortBuffer; + JackEventBuffer** fPortBuffer; size_t fCycleBytesSize; // needed size in bytes ofr an entire cycle @@ -260,8 +260,8 @@ namespace Jack size_t GetCycleSize(); int GetNumPackets(int data_sizen, int max_size); - void SetBuffer(int index, JackMidiBuffer* buffer); - JackMidiBuffer* GetBuffer(int index); + void SetBuffer(int index, JackEventBuffer* buffer); + JackEventBuffer* GetBuffer(int index); //utility void DisplayEvents(); @@ -492,8 +492,8 @@ namespace Jack SERVER_EXPORT void SessionParamsNToH(session_params_t* src_params, session_params_t* dst_params); SERVER_EXPORT void PacketHeaderHToN(packet_header_t* src_header, packet_header_t* dst_header); SERVER_EXPORT void PacketHeaderNToH(packet_header_t* src_header, packet_header_t* dst_header); - SERVER_EXPORT void MidiBufferHToN(JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer); - SERVER_EXPORT void MidiBufferNToH(JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer); + SERVER_EXPORT void MidiBufferHToN(JackEventBuffer* src_buffer, JackEventBuffer* dst_buffer); + SERVER_EXPORT void MidiBufferNToH(JackEventBuffer* src_buffer, JackEventBuffer* dst_buffer); SERVER_EXPORT void TransportDataHToN(net_transport_data_t* src_params, net_transport_data_t* dst_params); SERVER_EXPORT void TransportDataNToH(net_transport_data_t* src_params, net_transport_data_t* dst_params); //display session parameters From e39a37d35981870a9b51f914affc56e9f6a9025d Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 17:24:29 +0200 Subject: [PATCH 10/20] Update build script --- common/wscript | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/wscript b/common/wscript index afc251a2..35216ff8 100644 --- a/common/wscript +++ b/common/wscript @@ -56,8 +56,8 @@ def build(bld): 'JackPort.cpp', 'JackPortType.cpp', 'JackAudioPort.cpp', - 'JackMidiPort.cpp', - 'JackMidiAPI.cpp', + 'JackEventPort.cpp', + 'JackEventAPI.cpp', 'JackEngineControl.cpp', 'JackShmMem.cpp', 'JackGenericClientChannel.cpp', @@ -239,17 +239,17 @@ def build(bld): 'JackNetInterface.cpp', 'JackArgParser.cpp', 'JackRequestDecoder.cpp', - 'JackMidiAsyncQueue.cpp', - 'JackMidiAsyncWaitQueue.cpp', - 'JackMidiBufferReadQueue.cpp', - 'JackMidiBufferWriteQueue.cpp', + 'JackEventAsyncQueue.cpp', + 'JackEventAsyncWaitQueue.cpp', + 'JackEventBufferReadQueue.cpp', + 'JackEventBufferWriteQueue.cpp', 'JackMidiRawInputWriteQueue.cpp', 'JackMidiRawOutputWriteQueue.cpp', - 'JackMidiReadQueue.cpp', - 'JackMidiReceiveQueue.cpp', - 'JackMidiSendQueue.cpp', + 'JackEventReadQueue.cpp', + 'JackEventReceiveQueue.cpp', + 'JackEventSendQueue.cpp', 'JackMidiUtil.cpp', - 'JackMidiWriteQueue.cpp', + 'JackEventWriteQueue.cpp', 'JackMetadata.cpp', ] From e949f54ef3844233649adbbc92f057e09423e095 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 17:24:47 +0200 Subject: [PATCH 11/20] Fix remaining compile errors --- common/JackEventAPI.cpp | 2 +- common/JackEventBufferReadQueue.cpp | 8 ++++---- common/JackEventBufferReadQueue.h | 2 +- common/JackEventBufferWriteQueue.cpp | 4 ++-- common/JackEventPort.cpp | 10 +++++----- common/JackEventWriteQueue.cpp | 2 +- common/JackMidiRawInputWriteQueue.h | 6 +++--- common/JackPortType.h | 1 + common/jack/eventport.h | 4 ++-- common/jack/types.h | 1 + 10 files changed, 21 insertions(+), 19 deletions(-) diff --git a/common/JackEventAPI.cpp b/common/JackEventAPI.cpp index 638c621b..a67c2fab 100644 --- a/common/JackEventAPI.cpp +++ b/common/JackEventAPI.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "JackError.h" -#include "JackMidiPort.h" +#include "JackEventPort.h" #include #include diff --git a/common/JackEventBufferReadQueue.cpp b/common/JackEventBufferReadQueue.cpp index c1720b81..33e4473f 100644 --- a/common/JackEventBufferReadQueue.cpp +++ b/common/JackEventBufferReadQueue.cpp @@ -34,10 +34,10 @@ JackEventBufferReadQueue::DequeueEvent() { jack_event_t *e = 0; if (index < event_count) { - JackEvent *event = &(buffer->events[index]); - event.buffer = event->GetData(buffer); - event.size = event->size; - event.time = last_frame_time + event->time; + JackEvent *jack_event = &(buffer->events[index]); + event.buffer = jack_event->GetData(buffer); + event.size = jack_event->size; + event.time = last_frame_time + jack_event->time; e = &event; index++; } diff --git a/common/JackEventBufferReadQueue.h b/common/JackEventBufferReadQueue.h index 55393d94..89cb4025 100644 --- a/common/JackEventBufferReadQueue.h +++ b/common/JackEventBufferReadQueue.h @@ -36,7 +36,7 @@ namespace Jack { jack_nframes_t event_count; jack_nframes_t index; jack_nframes_t last_frame_time; - jack_event_t midi_event; + jack_event_t event; public: diff --git a/common/JackEventBufferWriteQueue.cpp b/common/JackEventBufferWriteQueue.cpp index 5b11b55f..4b0e6288 100644 --- a/common/JackEventBufferWriteQueue.cpp +++ b/common/JackEventBufferWriteQueue.cpp @@ -30,7 +30,7 @@ JackEventBufferWriteQueue::JackEventBufferWriteQueue() Jack::JackEventWriteQueue::EnqueueResult JackEventBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, - jack_evemt_data_t *data) + jack_event_data_t *data) { if (time >= next_frame_time) { return EVENT_EARLY; @@ -38,7 +38,7 @@ JackEventBufferWriteQueue::EnqueueEvent(jack_nframes_t time, size_t size, if (time < last_frame_time) { time = last_frame_time; } - jack_evemt_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size); + jack_event_data_t *dst = buffer->ReserveEvent(time - last_frame_time, size); if (! dst) { return size > max_bytes ? BUFFER_TOO_SMALL : BUFFER_FULL; } diff --git a/common/JackEventPort.cpp b/common/JackEventPort.cpp index 7357df68..84d0cfa9 100644 --- a/common/JackEventPort.cpp +++ b/common/JackEventPort.cpp @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "JackError.h" -#include "JackEventType.h" +#include "JackPortType.h" #include "JackEventPort.h" #include #include @@ -74,11 +74,11 @@ SERVER_EXPORT jack_event_data_t* JackEventBuffer::ReserveEvent(jack_nframes_t ti void EventBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes) { - JackEventBuffer* buffer = (JackEventBuffer*)buffer; - buffer->magic = JackEventBuffer::MAGIC; + JackEventBuffer* event_buffer = (JackEventBuffer*)buffer; + event_buffer->magic = JackEventBuffer::MAGIC; /* Since port buffer has actually always BUFFER_SIZE_MAX frames, we can safely use all the size */ - buffer->buffer_size = BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); - buffer->Reset(nframes); + event_buffer->buffer_size = BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); + event_buffer->Reset(nframes); } /* diff --git a/common/JackEventWriteQueue.cpp b/common/JackEventWriteQueue.cpp index 6ca82df7..9ab3f19a 100644 --- a/common/JackEventWriteQueue.cpp +++ b/common/JackEventWriteQueue.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "JackMidiWriteQueue.h" +#include "JackEventWriteQueue.h" using Jack::JackEventWriteQueue; diff --git a/common/JackMidiRawInputWriteQueue.h b/common/JackMidiRawInputWriteQueue.h index 40f6c6cd..62caabcf 100644 --- a/common/JackMidiRawInputWriteQueue.h +++ b/common/JackMidiRawInputWriteQueue.h @@ -44,7 +44,7 @@ namespace Jack { jack_event_data_t *input_buffer; size_t input_buffer_size; jack_event_t *packet; - JackMidiAsyncQueue *packet_queue; + JackEventAsyncQueue *packet_queue; jack_event_data_t status_byte; size_t total_bytes; size_t unbuffered_bytes; @@ -91,7 +91,7 @@ namespace Jack { */ virtual void - HandleEventLoss(jack_midi_event_t *event); + HandleEventLoss(jack_event_t *event); /** * Override this method to specify what happens when an incomplete MIDI @@ -107,7 +107,7 @@ namespace Jack { */ virtual void - HandleInvalidStatusByte(jack_midi_data_t byte); + HandleInvalidStatusByte(jack_event_data_t byte); /** * Override this method to specify what happens when a sysex end byte diff --git a/common/JackPortType.h b/common/JackPortType.h index efb8ca2f..ad4b58d2 100644 --- a/common/JackPortType.h +++ b/common/JackPortType.h @@ -42,6 +42,7 @@ extern const struct JackPortType* GetPortType(jack_port_type_id_t port_type_id); extern const struct JackPortType gAudioPortType; extern const struct JackPortType gMidiPortType; +extern const struct JackPortType gOscPortType; } // namespace Jack diff --git a/common/jack/eventport.h b/common/jack/eventport.h index 8e0c8ca1..da56f309 100644 --- a/common/jack/eventport.h +++ b/common/jack/eventport.h @@ -18,8 +18,8 @@ */ -#ifndef __JACK_MIDIPORT_H -#define __JACK_MIDIPORT_H +#ifndef __JACK_EVENTPORT_H +#define __JACK_EVENTPORT_H #ifdef __cplusplus extern "C" { diff --git a/common/jack/types.h b/common/jack/types.h index b62af964..6288868e 100644 --- a/common/jack/types.h +++ b/common/jack/types.h @@ -450,6 +450,7 @@ typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, */ #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio" #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" +#define JACK_DEFAULT_OSC_TYPE "32 bit OSC" /** * For convenience, use this typedef if you want to be able to change From 125b3ce9a292faa884a45d1e9be4b5412f453b63 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 19:32:36 +0200 Subject: [PATCH 12/20] Add typedefs for backwards compability Documentation saying that they are deprecated is missing --- common/JackEventBufferReadQueue.h | 5 + common/JackEventBufferWriteQueue.h | 5 + common/JackMidi.h | 46 ++++++++ common/jack/midiport.h | 170 +++++++++++++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 common/JackMidi.h create mode 100644 common/jack/midiport.h diff --git a/common/JackEventBufferReadQueue.h b/common/JackEventBufferReadQueue.h index 89cb4025..374f39c7 100644 --- a/common/JackEventBufferReadQueue.h +++ b/common/JackEventBufferReadQueue.h @@ -53,6 +53,11 @@ namespace Jack { void ResetEventBuffer(JackEventBuffer *buffer); + void + ResetMidiBuffer(JackEventBuffer *buffer) { + ResetEventBuffer(buffer); + } + }; } diff --git a/common/JackEventBufferWriteQueue.h b/common/JackEventBufferWriteQueue.h index fd9cd12d..e3df8ed9 100644 --- a/common/JackEventBufferWriteQueue.h +++ b/common/JackEventBufferWriteQueue.h @@ -55,6 +55,11 @@ namespace Jack { void ResetEventBuffer(JackEventBuffer *buffer, jack_nframes_t frames); + void + ResetMidiBuffer(JackEventBuffer *buffer, jack_nframes_t frames) { + ResetEventBuffer(buffer, frames); + } + }; } diff --git a/common/JackMidi.h b/common/JackMidi.h new file mode 100644 index 00000000..15f183f3 --- /dev/null +++ b/common/JackMidi.h @@ -0,0 +1,46 @@ +/* +Copyright (C) 2010 Devin Anderson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifndef __JackMidi__ +#define __JackMidi__ + +#include "JackEventPort.h" +#include "JackEventReceiveQueue.h" +#include "JackEventSendQueue.h" +#include "JackEventWriteQueue.h" +#include "JackEventAsyncQueue.h" +#include "JackEventBufferReadQueue.h" +#include "JackEventBufferWriteQueue.h" + +namespace Jack { + + typedef jack_event_data_t jack_midi_data_t; + typedef jack_event_t jack_midi_event_t; + + typedef JackEventBuffer JackMidiBuffer; + typedef JackEventReceiveQueue JackMidiReceiveQueue; + typedef JackEventSendQueue JackMidiSendQueue; + typedef JackEventWriteQueue JackMidiWriteQueue; + typedef JackEventAsyncQueue JackMidiAsyncQueue; + typedef JackEventBufferReadQueue JackMidiBufferReadQueue; + typedef JackEventBufferWriteQueue JackMidiBufferWriteQueue; + +} + +#endif diff --git a/common/jack/midiport.h b/common/jack/midiport.h new file mode 100644 index 00000000..97e646e1 --- /dev/null +++ b/common/jack/midiport.h @@ -0,0 +1,170 @@ +/* + Copyright (C) 2004 Ian Esten + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef __JACK_MIDIPORT_H +#define __JACK_MIDIPORT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + + +/** Type for raw event data contained in @ref jack_midi_event_t. */ +typedef jack_event_data_t jack_midi_data_t; + + +/** A Jack MIDI event. */ +typedef jack_event_t jack_midi_event_t; + +/** + * @defgroup MIDIAPI Reading and writing MIDI data + * @{ + */ + +/** Get number of events in a port buffer. + * + * @param port_buffer Port buffer from which to retrieve event. + * @return number of events inside @a port_buffer + */ +#define jack_midi_get_event_count jack_event_get_count + +/** Get a MIDI event from an event port buffer. + * + * Jack MIDI is normalised, the MIDI event returned by this function is + * guaranteed to be a complete MIDI event (the status byte will always be + * present, and no realtime events will interspered with the event). + * + * This rule does not apply to System Exclusive MIDI messages + * since they can be of arbitrary length. + * To maintain smooth realtime operation such events CAN be deliverd + * as multiple, non-normalised events. + * The maximum size of one event "chunk" depends on the MIDI backend in use. + * For example the midiseq driver will create chunks of 256 bytes. + * The first SysEx "chunked" event starts with 0xF0 and the last + * delivered chunk ends with 0xF7. + * To receive the full SysEx message, a caller of jack_midi_event_get() + * must concatenate chunks until a chunk ends with 0xF7. + * + * @param event Event structure to store retrieved event in. + * @param port_buffer Port buffer from which to retrieve event. + * @param event_index Index of event to retrieve. + * @return 0 on success, ENODATA if buffer is empty. + */ +#define jack_midi_event_get jack_event_get + + +/** Clear an event buffer. + * + * This should be called at the beginning of each process cycle before calling + * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This + * function may not be called on an input port's buffer. + * + * @param port_buffer Port buffer to clear (must be an output port buffer). + */ +#define jack_midi_clear_buffer jack_event_clear_buffer + +/** Reset an event buffer (from data allocated outside of JACK). + * + * This should be called at the beginning of each process cycle before calling + * @ref jack_midi_event_reserve or @ref jack_midi_event_write. This + * function may not be called on an input port's buffer. + * + * @deprecated Please use jack_midi_clear_buffer(). + * + * @param port_buffer Port buffer to reset. + */ +#define jack_midi_reset_buffer jack_event_reset_buffer + + +/** Get the size of the largest event that can be stored by the port. + * + * This function returns the current space available, taking into account + * events already stored in the port. + * + * @param port_buffer Port buffer to check size of. + */ +#define jack_midi_max_event_size jack_event_max_size + + +/** Allocate space for an event to be written to an event port buffer. + * + * Clients are to write the actual event data to be written starting at the + * pointer returned by this function. Clients must not write more than + * @a data_size bytes into this buffer. Clients must write normalised + * MIDI data to the port - no running status and no (1-byte) realtime + * messages interspersed with other messages (realtime messages are fine + * when they occur on their own, like other messages). + * + * Events must be written in order, sorted by their sample offsets. + * JACK will not sort the events for you, and will refuse to store + * out-of-order events. + * + * @param port_buffer Buffer to write event to. + * @param time Sample offset of event. + * @param data_size Length of event's raw data in bytes. + * @return Pointer to the beginning of the reserved event's data buffer, or + * NULL on error (ie not enough space). + */ +#define jack_midi_event_reserve jack_event_reserve + + +/** Write an event into an event port buffer. + * + * This function is simply a wrapper for @ref jack_midi_event_reserve + * which writes the event data into the space reserved in the buffer. + * + * Clients must not write more than + * @a data_size bytes into this buffer. Clients must write normalised + * MIDI data to the port - no running status and no (1-byte) realtime + * messages interspersed with other messages (realtime messages are fine + * when they occur on their own, like other messages). + * + * Events must be written in order, sorted by their sample offsets. + * JACK will not sort the events for you, and will refuse to store + * out-of-order events. + * + * @param port_buffer Buffer to write event to. + * @param time Sample offset of event. + * @param data Message data to be written. + * @param data_size Length of @a data in bytes. + * @return 0 on success, ENOBUFS if there's not enough space in buffer for event. + */ +#define jack_midi_event_write jack_event_write + + +/** Get the number of events that could not be written to @a port_buffer. + * + * This function returning a non-zero value implies @a port_buffer is full. + * Currently the only way this can happen is if events are lost on port mixdown. + * + * @param port_buffer Port to receive count for. + * @returns Number of events that could not be written to @a port_buffer. + */ +#define jack_midi_get_lost_event_count jack_event_get_lost_count + +/*@}*/ + +#ifdef __cplusplus +} +#endif + + +#endif /* __JACK_MIDIPORT_H */ From 1e18408f9a00b4e177dda07c07ecdf506d378dc6 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 19:33:19 +0200 Subject: [PATCH 13/20] Make linux modules compile --- linux/alsarawmidi/JackALSARawMidiInputPort.h | 3 +-- linux/alsarawmidi/JackALSARawMidiOutputPort.h | 3 +-- linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp | 4 ++++ linux/alsarawmidi/JackALSARawMidiReceiveQueue.h | 2 +- linux/alsarawmidi/JackALSARawMidiSendQueue.h | 2 +- linux/firewire/JackFFADOMidiInputPort.h | 2 +- linux/firewire/JackFFADOMidiOutputPort.h | 2 +- linux/firewire/JackFFADOMidiReceiveQueue.cpp | 4 ++++ linux/firewire/JackFFADOMidiReceiveQueue.h | 2 +- linux/firewire/JackFFADOMidiSendQueue.h | 2 +- 10 files changed, 16 insertions(+), 10 deletions(-) diff --git a/linux/alsarawmidi/JackALSARawMidiInputPort.h b/linux/alsarawmidi/JackALSARawMidiInputPort.h index fc261ed1..2423363d 100644 --- a/linux/alsarawmidi/JackALSARawMidiInputPort.h +++ b/linux/alsarawmidi/JackALSARawMidiInputPort.h @@ -22,8 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackALSARawMidiPort.h" #include "JackALSARawMidiReceiveQueue.h" -#include "JackMidiAsyncQueue.h" -#include "JackMidiBufferWriteQueue.h" +#include "JackMidi.h" #include "JackMidiRawInputWriteQueue.h" namespace Jack { diff --git a/linux/alsarawmidi/JackALSARawMidiOutputPort.h b/linux/alsarawmidi/JackALSARawMidiOutputPort.h index 31a20213..230e83c4 100644 --- a/linux/alsarawmidi/JackALSARawMidiOutputPort.h +++ b/linux/alsarawmidi/JackALSARawMidiOutputPort.h @@ -22,8 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackALSARawMidiPort.h" #include "JackALSARawMidiSendQueue.h" -#include "JackMidiAsyncQueue.h" -#include "JackMidiBufferReadQueue.h" +#include "JackMidi.h" #include "JackMidiRawOutputWriteQueue.h" namespace Jack { diff --git a/linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp b/linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp index 61af8e91..ccced69b 100644 --- a/linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp +++ b/linux/alsarawmidi/JackALSARawMidiReceiveQueue.cpp @@ -21,6 +21,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackError.h" #include "JackMidiUtil.h" +/* Somehow the compiler doesn't accept my typedef in JackMidi.h */ +typedef jack_event_data_t jack_midi_data_t; +typedef jack_event_t jack_midi_event_t; + using Jack::JackALSARawMidiReceiveQueue; JackALSARawMidiReceiveQueue:: diff --git a/linux/alsarawmidi/JackALSARawMidiReceiveQueue.h b/linux/alsarawmidi/JackALSARawMidiReceiveQueue.h index ffe4ea5f..62d216ba 100644 --- a/linux/alsarawmidi/JackALSARawMidiReceiveQueue.h +++ b/linux/alsarawmidi/JackALSARawMidiReceiveQueue.h @@ -22,7 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include -#include "JackMidiReceiveQueue.h" +#include "JackMidi.h" namespace Jack { diff --git a/linux/alsarawmidi/JackALSARawMidiSendQueue.h b/linux/alsarawmidi/JackALSARawMidiSendQueue.h index a420e96c..0670beb7 100644 --- a/linux/alsarawmidi/JackALSARawMidiSendQueue.h +++ b/linux/alsarawmidi/JackALSARawMidiSendQueue.h @@ -22,7 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include -#include "JackMidiSendQueue.h" +#include "JackMidi.h" namespace Jack { diff --git a/linux/firewire/JackFFADOMidiInputPort.h b/linux/firewire/JackFFADOMidiInputPort.h index f4c70a80..56eeeb26 100644 --- a/linux/firewire/JackFFADOMidiInputPort.h +++ b/linux/firewire/JackFFADOMidiInputPort.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __JackFFADOMidiInputPort__ #include "JackFFADOMidiReceiveQueue.h" -#include "JackMidiBufferWriteQueue.h" +#include "JackMidi.h" #include "JackMidiRawInputWriteQueue.h" namespace Jack { diff --git a/linux/firewire/JackFFADOMidiOutputPort.h b/linux/firewire/JackFFADOMidiOutputPort.h index 4ca309bb..106f1115 100644 --- a/linux/firewire/JackFFADOMidiOutputPort.h +++ b/linux/firewire/JackFFADOMidiOutputPort.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __JackFFADOMidiOutputPort__ #include "JackFFADOMidiSendQueue.h" -#include "JackMidiBufferReadQueue.h" +#include "JackMidi.h" #include "JackMidiRawOutputWriteQueue.h" namespace Jack { diff --git a/linux/firewire/JackFFADOMidiReceiveQueue.cpp b/linux/firewire/JackFFADOMidiReceiveQueue.cpp index 4b67f329..e1802ad1 100644 --- a/linux/firewire/JackFFADOMidiReceiveQueue.cpp +++ b/linux/firewire/JackFFADOMidiReceiveQueue.cpp @@ -20,6 +20,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JackFFADOMidiReceiveQueue.h" #include "JackMidiUtil.h" +/* Somehow the compiler doesn't accept my typedef in JackMidi.h */ +typedef jack_event_data_t jack_midi_data_t; +typedef jack_event_t jack_midi_event_t; + using Jack::JackFFADOMidiReceiveQueue; JackFFADOMidiReceiveQueue::JackFFADOMidiReceiveQueue() diff --git a/linux/firewire/JackFFADOMidiReceiveQueue.h b/linux/firewire/JackFFADOMidiReceiveQueue.h index 7647869d..d4e49dc9 100644 --- a/linux/firewire/JackFFADOMidiReceiveQueue.h +++ b/linux/firewire/JackFFADOMidiReceiveQueue.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __JackFFADOMidiReceiveQueue__ #define __JackFFADOMidiReceiveQueue__ -#include "JackMidiReceiveQueue.h" +#include "JackMidi.h" namespace Jack { diff --git a/linux/firewire/JackFFADOMidiSendQueue.h b/linux/firewire/JackFFADOMidiSendQueue.h index f395f13d..49d54777 100644 --- a/linux/firewire/JackFFADOMidiSendQueue.h +++ b/linux/firewire/JackFFADOMidiSendQueue.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __JackFFADOMidiSendQueue__ #define __JackFFADOMidiSendQueue__ -#include "JackMidiSendQueue.h" +#include "JackMidi.h" namespace Jack { From eb1ad872023c0afa98e195f8a3ead32b8b9749be Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 22:32:45 +0200 Subject: [PATCH 14/20] Fix more compile errors I cannot test this locally due to lack of hardware --- macosx/coremidi/JackCoreMidiInputPort.h | 3 +-- macosx/coremidi/JackCoreMidiOutputPort.h | 3 +-- windows/winmme/JackWinMMEOutputPort.h | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/macosx/coremidi/JackCoreMidiInputPort.h b/macosx/coremidi/JackCoreMidiInputPort.h index 95c45781..00cc82d5 100644 --- a/macosx/coremidi/JackCoreMidiInputPort.h +++ b/macosx/coremidi/JackCoreMidiInputPort.h @@ -21,8 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JackCoreMidiInputPort__ #include "JackCoreMidiPort.h" -#include "JackMidiAsyncQueue.h" -#include "JackMidiBufferWriteQueue.h" +#include "JackMidi.h" namespace Jack { diff --git a/macosx/coremidi/JackCoreMidiOutputPort.h b/macosx/coremidi/JackCoreMidiOutputPort.h index a04d98b3..e962fb26 100644 --- a/macosx/coremidi/JackCoreMidiOutputPort.h +++ b/macosx/coremidi/JackCoreMidiOutputPort.h @@ -23,8 +23,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include #include "JackCoreMidiPort.h" -#include "JackMidiAsyncQueue.h" -#include "JackMidiBufferReadQueue.h" +#include "JackMidi.h" #include "JackThread.h" namespace Jack { diff --git a/windows/winmme/JackWinMMEOutputPort.h b/windows/winmme/JackWinMMEOutputPort.h index fc18becf..aef7f367 100644 --- a/windows/winmme/JackWinMMEOutputPort.h +++ b/windows/winmme/JackWinMMEOutputPort.h @@ -20,8 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #ifndef __JackWinMMEOutputPort__ #define __JackWinMMEOutputPort__ -#include "JackMidiAsyncQueue.h" -#include "JackMidiBufferReadQueue.h" +#include "JackMidi.h" #include "JackThread.h" #include "JackWinMMEPort.h" From 52ab82d802b8c227bc623e25e07d1f30c8231c00 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 11 Oct 2019 22:51:54 +0200 Subject: [PATCH 15/20] Add generic event port type I don't know how useful it is yet, maybe I'll remove it later on (tell me if you don't like it) --- common/JackEventPort.cpp | 8 ++++++++ common/JackEventPort.h | 5 +++++ common/JackPortType.cpp | 3 ++- common/JackPortType.h | 1 + common/jack/types.h | 3 ++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/JackEventPort.cpp b/common/JackEventPort.cpp index 84d0cfa9..7409af51 100644 --- a/common/JackEventPort.cpp +++ b/common/JackEventPort.cpp @@ -167,4 +167,12 @@ const JackPortType gOscPortType = EventBufferMixdown }; +const JackPortType gEventPortType = +{ + JACK_DEFAULT_EVENT_TYPE, + EventBufferSize, + EventBufferInit, + EventBufferMixdown +}; + } // namespace Jack diff --git a/common/JackEventPort.h b/common/JackEventPort.h index 007e2332..2b2ff678 100644 --- a/common/JackEventPort.h +++ b/common/JackEventPort.h @@ -41,6 +41,11 @@ struct jack_event_t #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" /** A Jack OSC port type. */ #define JACK_DEFAULT_OSC_TYPE "32 bit OSC" +/** If you want to toy around with a custom + * event protocol (maybe MIDI 3.0?). Please put details + * about it into the metadata. + */ +#define JACK_DEFAULT_EVENT_TYPE "generic binary data" namespace Jack { diff --git a/common/JackPortType.cpp b/common/JackPortType.cpp index 3be1c4d2..e41fcf7c 100644 --- a/common/JackPortType.cpp +++ b/common/JackPortType.cpp @@ -28,7 +28,8 @@ static const JackPortType* gPortTypes[] = { &gAudioPortType, &gMidiPortType, - &gOscPortType, + &gOscPortType, + &gEventPortType, }; jack_port_type_id_t PORT_TYPES_MAX = sizeof(gPortTypes) / sizeof(gPortTypes[0]); diff --git a/common/JackPortType.h b/common/JackPortType.h index ad4b58d2..c980333b 100644 --- a/common/JackPortType.h +++ b/common/JackPortType.h @@ -43,6 +43,7 @@ extern const struct JackPortType* GetPortType(jack_port_type_id_t port_type_id); extern const struct JackPortType gAudioPortType; extern const struct JackPortType gMidiPortType; extern const struct JackPortType gOscPortType; +extern const struct JackPortType gEventPortType; } // namespace Jack diff --git a/common/jack/types.h b/common/jack/types.h index 6288868e..45c947c1 100644 --- a/common/jack/types.h +++ b/common/jack/types.h @@ -446,11 +446,12 @@ typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, /** * Used for the type argument of jack_port_register() for default - * audio ports and midi ports. + * audio ports and event ports. */ #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio" #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" #define JACK_DEFAULT_OSC_TYPE "32 bit OSC" +#define JACK_DEFAULT_EVENT_TYPE "generic binary data" /** * For convenience, use this typedef if you want to be able to change From 8d9c1411368deb5d1a9670f55c55b2a98ce2d50b Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 12 Oct 2019 11:49:27 +0200 Subject: [PATCH 16/20] Hopefully make it ABI compatible @x42 Will this work? I am not confident about this --- common/JackEventPort.h | 4 + common/JackMidiAPI.cpp | 160 ++++++++++++++++++++++++++++++++++++++++ common/jack/eventport.h | 20 ++--- common/jack/midiport.h | 45 +++++++---- common/wscript | 1 + 5 files changed, 205 insertions(+), 25 deletions(-) create mode 100644 common/JackMidiAPI.cpp diff --git a/common/JackEventPort.h b/common/JackEventPort.h index 2b2ff678..b159e21d 100644 --- a/common/JackEventPort.h +++ b/common/JackEventPort.h @@ -37,6 +37,10 @@ struct jack_event_t jack_event_data_t *buffer; /**< Raw event data */ }; +/** Backwards compability */ +typedef jack_event_data_t jack_midi_data_t; +typedef jack_event_t jack_midi_event_t; + /** A Jack MIDI port type. */ #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" /** A Jack OSC port type. */ diff --git a/common/JackMidiAPI.cpp b/common/JackMidiAPI.cpp new file mode 100644 index 00000000..15d8a04a --- /dev/null +++ b/common/JackMidiAPI.cpp @@ -0,0 +1,160 @@ +/* +Copyright (C) 2007 Dmitry Baikov +Original JACK MIDI implementation Copyright (C) 2004 Ian Esten + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "JackError.h" +#include "JackEventPort.h" +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + LIB_EXPORT uint32_t jack_midi_get_event_count(void* port_buffer); + + LIB_EXPORT int jack_midi_event_get(jack_midi_event_t* event, + void* port_buffer, uint32_t event_index); + + LIB_EXPORT void jack_midi_clear_buffer(void* port_buffer); + + LIB_EXPORT void jack_midi_reset_buffer(void* port_buffer); + + LIB_EXPORT size_t jack_midi_max_event_size(void* port_buffer); + + LIB_EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, + jack_nframes_t time, size_t data_size); + + LIB_EXPORT int jack_midi_event_write(void* port_buffer, + jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); + + LIB_EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer); + +#ifdef __cplusplus +} +#endif + +using namespace Jack; + +LIB_EXPORT +uint32_t jack_midi_get_event_count(void* port_buffer) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (!buf || !buf->IsValid()) { + return 0; + } + return buf->event_count; +} + +LIB_EXPORT +int jack_midi_event_get(jack_event_t *event, void* port_buffer, uint32_t event_index) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (!buf || !buf->IsValid()) { + return -EINVAL; + } + if (event_index >= buf->event_count) { + return -ENOBUFS; + } + JackEvent* ev = &buf->events[event_index]; + event->time = ev->time; + event->size = ev->size; + event->buffer = ev->GetData(buf); + return 0; +} + +LIB_EXPORT +void jack_midi_clear_buffer(void* port_buffer) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (buf && buf->IsValid()) { + buf->Reset(buf->nframes); + } +} + +LIB_EXPORT +void jack_midi_reset_buffer(void* port_buffer) +{ + EventBufferInit(port_buffer, BUFFER_SIZE_MAX, BUFFER_SIZE_MAX); +} + +LIB_EXPORT +size_t jack_midi_max_event_size(void* port_buffer) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (buf && buf->IsValid()) { + return buf->MaxEventSize(); + } + return 0; +} + +LIB_EXPORT +jack_event_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (! buf) { + jack_error("jack_event_reserve: port buffer is set to NULL"); + return 0; + } + if (! buf->IsValid()) { + jack_error("jack_event_reserve: port buffer is invalid"); + return 0; + } + if (time >= buf->nframes) { + jack_error("jack_event_reserve: time parameter is out of range " + "(%lu >= %lu)", time, buf->nframes); + return 0; + } + if (buf->event_count && (buf->events[buf->event_count - 1].time > time)) { + jack_error("jack_event_reserve: time parameter is earlier than " + "last reserved event"); + return 0; + } + return buf->ReserveEvent(time, data_size); +} + +LIB_EXPORT +int jack_midi_event_write(void* port_buffer, + jack_nframes_t time, const jack_event_data_t* data, size_t data_size) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (!buf || !buf->IsValid()) { + return -EINVAL; + } + if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time)) { + return -EINVAL; + } + jack_event_data_t* dest = buf->ReserveEvent(time, data_size); + if (!dest) { + return -ENOBUFS; + } + memcpy(dest, data, data_size); + return 0; +} + +LIB_EXPORT +uint32_t jack_midi_get_lost_event_count(void* port_buffer) +{ + JackEventBuffer *buf = (JackEventBuffer*)port_buffer; + if (buf && buf->IsValid()) { + return buf->lost_events; + } + return 0; +} diff --git a/common/jack/eventport.h b/common/jack/eventport.h index da56f309..877eb21d 100644 --- a/common/jack/eventport.h +++ b/common/jack/eventport.h @@ -29,19 +29,21 @@ extern "C" { #include #include - -/** Type for raw event data contained in @ref jack_event_event_t. */ -typedef unsigned char jack_event_data_t; - +/** Type for raw event data contained in @ref jack_midi_event_t. */ +typedef unsigned char jack_midi_data_t; /** A Jack event. */ -typedef struct _jack_event +typedef struct _jack_midi_event { - jack_nframes_t time; /**< Sample index at which event is valid */ - size_t size; /**< Number of bytes of data in \a buffer */ - jack_event_data_t *buffer; /**< Raw event data */ -} jack_event_t; + jack_nframes_t time; /**< Sample index at which event is valid */ + size_t size; /**< Number of bytes of data in \a buffer */ + jack_midi_data_t *buffer; /**< Raw event data */ +} jack_midi_event_t; + +/** Type for raw event data contained in @ref jack_event_t. */ +typedef jack_midi_data_t jack_event_data_t; +typedef jack_midi_event_t jack_event_t; /** * @defgroup EVENTAPI Reading and writing event data diff --git a/common/jack/midiport.h b/common/jack/midiport.h index 97e646e1..170df504 100644 --- a/common/jack/midiport.h +++ b/common/jack/midiport.h @@ -1,16 +1,20 @@ /* Copyright (C) 2004 Ian Esten + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ @@ -26,14 +30,6 @@ extern "C" { #include #include - -/** Type for raw event data contained in @ref jack_midi_event_t. */ -typedef jack_event_data_t jack_midi_data_t; - - -/** A Jack MIDI event. */ -typedef jack_event_t jack_midi_event_t; - /** * @defgroup MIDIAPI Reading and writing MIDI data * @{ @@ -44,7 +40,9 @@ typedef jack_event_t jack_midi_event_t; * @param port_buffer Port buffer from which to retrieve event. * @return number of events inside @a port_buffer */ -#define jack_midi_get_event_count jack_event_get_count +uint32_t +jack_midi_get_event_count(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; + /** Get a MIDI event from an event port buffer. * @@ -68,7 +66,10 @@ typedef jack_event_t jack_midi_event_t; * @param event_index Index of event to retrieve. * @return 0 on success, ENODATA if buffer is empty. */ -#define jack_midi_event_get jack_event_get +int +jack_midi_event_get(jack_midi_event_t *event, + void *port_buffer, + uint32_t event_index) JACK_OPTIONAL_WEAK_EXPORT; /** Clear an event buffer. @@ -79,7 +80,8 @@ typedef jack_event_t jack_midi_event_t; * * @param port_buffer Port buffer to clear (must be an output port buffer). */ -#define jack_midi_clear_buffer jack_event_clear_buffer +void +jack_midi_clear_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /** Reset an event buffer (from data allocated outside of JACK). * @@ -91,7 +93,8 @@ typedef jack_event_t jack_midi_event_t; * * @param port_buffer Port buffer to reset. */ -#define jack_midi_reset_buffer jack_event_reset_buffer +void +jack_midi_reset_buffer(void *port_buffer) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT; /** Get the size of the largest event that can be stored by the port. @@ -101,7 +104,8 @@ typedef jack_event_t jack_midi_event_t; * * @param port_buffer Port buffer to check size of. */ -#define jack_midi_max_event_size jack_event_max_size +size_t +jack_midi_max_event_size(void* port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /** Allocate space for an event to be written to an event port buffer. @@ -123,7 +127,10 @@ typedef jack_event_t jack_midi_event_t; * @return Pointer to the beginning of the reserved event's data buffer, or * NULL on error (ie not enough space). */ -#define jack_midi_event_reserve jack_event_reserve +jack_midi_data_t* +jack_midi_event_reserve(void *port_buffer, + jack_nframes_t time, + size_t data_size) JACK_OPTIONAL_WEAK_EXPORT; /** Write an event into an event port buffer. @@ -147,7 +154,11 @@ typedef jack_event_t jack_midi_event_t; * @param data_size Length of @a data in bytes. * @return 0 on success, ENOBUFS if there's not enough space in buffer for event. */ -#define jack_midi_event_write jack_event_write +int +jack_midi_event_write(void *port_buffer, + jack_nframes_t time, + const jack_midi_data_t *data, + size_t data_size) JACK_OPTIONAL_WEAK_EXPORT; /** Get the number of events that could not be written to @a port_buffer. @@ -158,7 +169,8 @@ typedef jack_event_t jack_midi_event_t; * @param port_buffer Port to receive count for. * @returns Number of events that could not be written to @a port_buffer. */ -#define jack_midi_get_lost_event_count jack_event_get_lost_count +uint32_t +jack_midi_get_lost_event_count(void *port_buffer) JACK_OPTIONAL_WEAK_EXPORT; /*@}*/ @@ -168,3 +180,4 @@ typedef jack_event_t jack_midi_event_t; #endif /* __JACK_MIDIPORT_H */ + diff --git a/common/wscript b/common/wscript index 35216ff8..1400b5d8 100644 --- a/common/wscript +++ b/common/wscript @@ -58,6 +58,7 @@ def build(bld): 'JackAudioPort.cpp', 'JackEventPort.cpp', 'JackEventAPI.cpp', + 'JackMidiAPI.cpp', 'JackEngineControl.cpp', 'JackShmMem.cpp', 'JackGenericClientChannel.cpp', From c4904f187b447f39af9086b08fc079974af90d74 Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 12 Oct 2019 11:56:50 +0200 Subject: [PATCH 17/20] Fixed another Mac compile error --- macosx/coremidi/JackCoreMidiOutputPort.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/macosx/coremidi/JackCoreMidiOutputPort.mm b/macosx/coremidi/JackCoreMidiOutputPort.mm index f62ebaff..f986cf15 100644 --- a/macosx/coremidi/JackCoreMidiOutputPort.mm +++ b/macosx/coremidi/JackCoreMidiOutputPort.mm @@ -28,6 +28,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackTime.h" #include "JackError.h" +/* Somehow the compiler doesn't accept my typedef in JackMidi.h */ +typedef jack_event_data_t jack_midi_data_t; +typedef jack_event_t jack_midi_event_t; + using Jack::JackCoreMidiOutputPort; JackCoreMidiOutputPort::JackCoreMidiOutputPort(double time_ratio, From 1c3f811f7bc5961b1e69af8adfef6f4d9b552a68 Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 12 Oct 2019 12:19:16 +0200 Subject: [PATCH 18/20] Remove previously added port types There are only two now, `gAudioPortType` and `gMessagePortType`. There is a string constant for `JACK_DEFAULT_MIDI_TYPE` which will be handled separately. --- common/JackEventPort.cpp | 20 +++----------------- common/JackEventPort.h | 10 ++-------- common/JackPortType.cpp | 4 +--- common/JackPortType.h | 4 +--- common/jack/types.h | 3 +-- 5 files changed, 8 insertions(+), 33 deletions(-) diff --git a/common/JackEventPort.cpp b/common/JackEventPort.cpp index 7409af51..a70b26d9 100644 --- a/common/JackEventPort.cpp +++ b/common/JackEventPort.cpp @@ -151,28 +151,14 @@ static size_t EventBufferSize() return BUFFER_SIZE_MAX * sizeof(jack_default_audio_sample_t); } -const JackPortType gMidiPortType = +const JackPortType gMessagePortType = { - JACK_DEFAULT_MIDI_TYPE, + JACK_DEFAULT_MESSAGE_TYPE, EventBufferSize, EventBufferInit, EventBufferMixdown }; -const JackPortType gOscPortType = -{ - JACK_DEFAULT_OSC_TYPE, - EventBufferSize, - EventBufferInit, - EventBufferMixdown -}; - -const JackPortType gEventPortType = -{ - JACK_DEFAULT_EVENT_TYPE, - EventBufferSize, - EventBufferInit, - EventBufferMixdown -}; +const JackPortType gMidiPortType = gMessagePortType; } // namespace Jack diff --git a/common/JackEventPort.h b/common/JackEventPort.h index b159e21d..9112bcf0 100644 --- a/common/JackEventPort.h +++ b/common/JackEventPort.h @@ -41,15 +41,9 @@ struct jack_event_t typedef jack_event_data_t jack_midi_data_t; typedef jack_event_t jack_midi_event_t; -/** A Jack MIDI port type. */ +/** A Jack MIDI port type. Use @ref JACK_DEFAULT_MESSAGE_TYPE instead if possible */ #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" -/** A Jack OSC port type. */ -#define JACK_DEFAULT_OSC_TYPE "32 bit OSC" -/** If you want to toy around with a custom - * event protocol (maybe MIDI 3.0?). Please put details - * about it into the metadata. - */ -#define JACK_DEFAULT_EVENT_TYPE "generic binary data" +#define JACK_DEFAULT_MESSAGE_TYPE "binary message data" namespace Jack { diff --git a/common/JackPortType.cpp b/common/JackPortType.cpp index e41fcf7c..1f5d88bb 100644 --- a/common/JackPortType.cpp +++ b/common/JackPortType.cpp @@ -27,9 +27,7 @@ namespace Jack static const JackPortType* gPortTypes[] = { &gAudioPortType, - &gMidiPortType, - &gOscPortType, - &gEventPortType, + &gMessagePortType, }; jack_port_type_id_t PORT_TYPES_MAX = sizeof(gPortTypes) / sizeof(gPortTypes[0]); diff --git a/common/JackPortType.h b/common/JackPortType.h index c980333b..cce7ebac 100644 --- a/common/JackPortType.h +++ b/common/JackPortType.h @@ -41,9 +41,7 @@ extern jack_port_type_id_t GetPortTypeId(const char* port_type); extern const struct JackPortType* GetPortType(jack_port_type_id_t port_type_id); extern const struct JackPortType gAudioPortType; -extern const struct JackPortType gMidiPortType; -extern const struct JackPortType gOscPortType; -extern const struct JackPortType gEventPortType; +extern const struct JackPortType gMessagePortType; } // namespace Jack diff --git a/common/jack/types.h b/common/jack/types.h index 45c947c1..a6af7a82 100644 --- a/common/jack/types.h +++ b/common/jack/types.h @@ -450,8 +450,7 @@ typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, */ #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio" #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" -#define JACK_DEFAULT_OSC_TYPE "32 bit OSC" -#define JACK_DEFAULT_EVENT_TYPE "generic binary data" +#define JACK_DEFAULT_MESSAGE_TYPE "binary message data" /** * For convenience, use this typedef if you want to be able to change From cf6523f0f2c49268d5b0f55d0e60c74888f7f508 Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 12 Oct 2019 13:49:03 +0200 Subject: [PATCH 19/20] Better port type handling - Added inline helper methods to create ports of the correct type - Had to move `jack_port_uuid` to the top because we still can't use methods declared below in 2019 - I'd like to add helper methods that automatically set the metadata but C has no method overloading?! - Improved metadata documentation - Registering a port with the `JACK_DEFAULT_MIDI_TYPE` will automatically change it to `JACK_DEFAULT_MESSAGE_TYPE` for forward compatibility. --- common/JackAPI.cpp | 13 +++++++++- common/jack/jack.h | 57 ++++++++++++++++++++++++++++++++++-------- common/jack/metadata.h | 12 ++++++--- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index 6789d987..8e450e32 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -1094,9 +1094,20 @@ LIB_EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char } else if ((port_name == NULL) || (port_type == NULL)) { jack_error("jack_port_register called with a NULL port name or a NULL port_type"); return NULL; + } + + if (strcmp(port_type, JACK_DEFAULT_AUDIO_TYPE) == 0) { + // Don't change anything + } else if (strcmp(port_type, JACK_DEFAULT_MESSAGE_TYPE) == 0) { + // Don't change anything + } else if (strcmp(port_type, JACK_DEFAULT_MIDI_TYPE) == 0) { + // Rename the old port type + port_type = JACK_DEFAULT_MESSAGE_TYPE; } else { - return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size)); + jack_info("jack_port_register called with a non-default port_type: '%s'.", port_type); } + + return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size)); } LIB_EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port) diff --git a/common/jack/jack.h b/common/jack/jack.h index e982b6df..bbe02634 100644 --- a/common/jack/jack.h +++ b/common/jack/jack.h @@ -709,6 +709,13 @@ float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; * @{ */ +/** + * @return the UUID of the jack_port_t + * + * @see jack_uuid_to_string() to convert into a string representation + */ +jack_uuid_t jack_port_uuid (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT; + /** * Create a new port for the client. This is an object used for moving * data of any type in or out of the client. Ports may be connected @@ -723,9 +730,9 @@ float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; * The @a port_name must be unique among all ports owned by this client. * If the name is not unique, the registration will fail. * - * All ports have a type, which may be any non-NULL and non-zero - * length string, passed as an argument. Some port types are built - * into the JACK API, currently only JACK_DEFAULT_AUDIO_TYPE. + * All ports have a type. It is strongly encouraged to use @ref jack_port_register_audio + * for signal channels and @ref jack_port_register_message for message (MIDI, OSC, …) + * channels instead of this method. * * @param client pointer to JACK client structure. * @param port_name non-empty short name for the new port (not @@ -744,6 +751,43 @@ jack_port_t * jack_port_register (jack_client_t *client, unsigned long flags, unsigned long buffer_size) JACK_OPTIONAL_WEAK_EXPORT; + +/** + * Create a new message port as documented in @ref jack_port_register. Use the metadata API + * to specify what type of data this port is sending/receiving. The default is "PCM" for plain + * audio. To create a port containing voltage control instead of audio, you need to call + * @code + * jack_uuid_t uuid = jack_port_uuid(port); + * jack_set_property(client, uuid, JACK_METADATA_EVENT_TYPE, "VC", "text/plain"); + * @endcode + */ +inline jack_port_t * jack_port_register_audio (jack_client_t *client, + const char *port_name, + unsigned long flags, + unsigned long buffer_size) JACK_OPTIONAL_WEAK_EXPORT +{ + return jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, flags, buffer_size); +} + + +/** + * Create a new message port as documented in @ref jack_port_register. Use the metadata API + * to specify which communication protocols this port understands. The default is "MIDI". To + * create an OSC port for example, you need to call + * @code + * jack_uuid_t uuid = jack_port_uuid(port); + * jack_set_property(client, uuid, JACK_METADATA_EVENT_TYPE, "OSC", "text/plain"); + * @endcode + */ +inline jack_port_t * jack_port_register_message (jack_client_t *client, + const char *port_name, + unsigned long flags, + unsigned long buffer_size) JACK_OPTIONAL_WEAK_EXPORT +{ + return jack_port_register(client, port_name, JACK_DEFAULT_MESSAGE_TYPE, flags, buffer_size); +} + + /** * Remove the port from the client, disconnecting any existing * connections. @@ -773,13 +817,6 @@ int jack_port_unregister (jack_client_t *client, jack_port_t *port) JACK_OPTIONA */ void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT; -/** - * @return the UUID of the jack_port_t - * - * @see jack_uuid_to_string() to convert into a string representation - */ -jack_uuid_t jack_port_uuid (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT; - /** * @return the full name of the jack_port_t (including the @a * "client_name:" prefix). diff --git a/common/jack/metadata.h b/common/jack/metadata.h index 5c948cfd..531eca35 100644 --- a/common/jack/metadata.h +++ b/common/jack/metadata.h @@ -241,6 +241,9 @@ extern const char* JACK_METADATA_CONNECTED; * OSC events is not a valid MIDI status byte, so MIDI clients that check the * status byte will gracefully ignore OSC messages if the user makes an * inappropriate connection. + * + * This property may contain values other than "MIDI" and "OSC" for custom (or + * newer) protocols. If it is not set, the contained data should be treated as "MIDI". */ extern const char* JACK_METADATA_EVENT_TYPES; @@ -312,10 +315,11 @@ extern const char* JACK_METADATA_PORT_GROUP; * The type of an audio signal. * * This property allows audio ports to be tagged with a "meaning". The value - * is a simple string. Currently, the only type is "CV", for "control voltage" - * ports. Hosts SHOULD be take care to not treat CV ports as audibile and send - * their output directly to speakers. In particular, CV ports are not - * necessarily periodic at all and may have very high DC. + * is a simple string. Currently, the only types are "PCM" for normal audio and + * "CV", for "control voltage" ports. Hosts SHOULD be take care to not treat CV ports + * as audibile and send their output directly to speakers. In particular, CV ports + * are not necessarily periodic at all and may have very high DC. Not setting this property + * implies the default value "PCM". */ extern const char* JACK_METADATA_SIGNAL_TYPE; From 613174ddeadf678f4e5725528b5a35b4f4c8c023 Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 12 Oct 2019 14:38:44 +0200 Subject: [PATCH 20/20] Update jack_connect client --- example-clients/connect.c | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/example-clients/connect.c b/example-clients/connect.c index b302ce67..5f88e103 100644 --- a/example-clients/connect.c +++ b/example-clients/connect.c @@ -26,7 +26,9 @@ #include #include +#include #include +#include #define TRUE 1 #define FALSE 0 @@ -51,6 +53,8 @@ show_usage (char *my_name) fprintf (stderr, "\nusage: %s [options] port1 port2\n", my_name); fprintf (stderr, "Connects two JACK ports together.\n\n"); fprintf (stderr, " -s, --server Connect to the jack server named \n"); + fprintf (stderr, " -u, --uuid Reference ports by their UUID instead of their name\n"); + fprintf (stderr, " -f, --force Force connect even if the ports may not be compatible\n"); fprintf (stderr, " -v, --version Output version information and exit\n"); fprintf (stderr, " -h, --help Display this help message\n\n"); fprintf (stderr, "For more information see http://jackaudio.org/\n"); @@ -73,6 +77,7 @@ main (int argc, char *argv[]) char portA[300]; char portB[300]; int use_uuid=0; + int force_connect=0; int connecting, disconnecting; int port1_flags, port2_flags; int rc = 1; @@ -82,10 +87,11 @@ main (int argc, char *argv[]) { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "uuid", 0, 0, 'u' }, + { "force", 0, 0, 'f' }, { 0, 0, 0, 0 } }; - while ((c = getopt_long (argc, argv, "s:hvu", long_options, &option_index)) >= 0) { + while ((c = getopt_long (argc, argv, "s:fhvu", long_options, &option_index)) >= 0) { switch (c) { case 's': server_name = (char *) malloc (sizeof (char) * strlen(optarg)); @@ -95,6 +101,9 @@ main (int argc, char *argv[]) case 'u': use_uuid = 1; break; + case 'f': + force_connect = 1; + break; case 'h': show_usage (my_name); return 1; @@ -218,6 +227,45 @@ main (int argc, char *argv[]) */ if (connecting) { + if (!force_connect) { + int fail = 0; + + /* Get the port type to know which proprty to query. */ + const char* src_port_type = jack_port_type(src_port); + const char* dst_port_type = jack_port_type(dst_port); + + /* Get src's port content */ + char* src_type; + if (strcmp(src_port_type, JACK_DEFAULT_AUDIO_TYPE) == 0) + jack_get_property(jack_port_uuid(src_port), JACK_METADATA_SIGNAL_TYPE, &src_type, NULL); + else if (strcmp(src_port_type, JACK_DEFAULT_MESSAGE_TYPE) == 0) + jack_get_property(jack_port_uuid(src_port), JACK_METADATA_EVENT_TYPES, &src_type, NULL); + else + fail = 1; + + /* Get src's port content */ + char* dst_type; + if (strcmp(dst_port_type, JACK_DEFAULT_AUDIO_TYPE) == 0) + jack_get_property(jack_port_uuid(dst_port), JACK_METADATA_SIGNAL_TYPE, &dst_type, NULL); + else if (strcmp(dst_port_type, JACK_DEFAULT_MESSAGE_TYPE) == 0) + jack_get_property(jack_port_uuid(dst_port), JACK_METADATA_EVENT_TYPES, &dst_type, NULL); + else + fail = 1; + + /* Finally compare the ports */ + if (!fail) + // TODO this does not handle if multiple content types are supported. + fail = strcmp(src_type, dst_type); + + jack_free(src_type); + jack_free(dst_type); + + if (fail) { + fprintf (stderr, "cannot connect ports, since they may have different kinds of data. Run with --force to connect them anyways.\n"); + goto exit; + } + } + if (jack_connect(client, jack_port_name(src_port), jack_port_name(dst_port))) { fprintf (stderr, "cannot connect client, already connected?\n"); goto exit;