Browse Source

Hopefully make it ABI compatible

@x42 Will this work? I am not confident about this
pull/514/head
piegames 6 years ago
parent
commit
8d9c141136
5 changed files with 205 additions and 25 deletions
  1. +4
    -0
      common/JackEventPort.h
  2. +160
    -0
      common/JackMidiAPI.cpp
  3. +11
    -9
      common/jack/eventport.h
  4. +29
    -16
      common/jack/midiport.h
  5. +1
    -0
      common/wscript

+ 4
- 0
common/JackEventPort.h View File

@@ -37,6 +37,10 @@ struct jack_event_t
jack_event_data_t *buffer; /**< Raw event data */ 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. */ /** A Jack MIDI port type. */
#define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi" #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
/** A Jack OSC port type. */ /** A Jack OSC port type. */


+ 160
- 0
common/JackMidiAPI.cpp View File

@@ -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 <errno.h>
#include <string.h>

#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;
}

+ 11
- 9
common/jack/eventport.h View File

@@ -29,19 +29,21 @@ extern "C" {
#include <jack/types.h> #include <jack/types.h>
#include <stdlib.h> #include <stdlib.h>



/** 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. */ /** 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 * @defgroup EVENTAPI Reading and writing event data


+ 29
- 16
common/jack/midiport.h View File

@@ -1,16 +1,20 @@
/* /*
Copyright (C) 2004 Ian Esten Copyright (C) 2004 Ian Esten

This program is free software; you can redistribute it and/or modify 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 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 the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.

This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/ */




@@ -26,14 +30,6 @@ extern "C" {
#include <jack/eventport.h> #include <jack/eventport.h>
#include <stdlib.h> #include <stdlib.h>



/** 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 * @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. * @param port_buffer Port buffer from which to retrieve event.
* @return number of events inside @a port_buffer * @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. /** 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. * @param event_index Index of event to retrieve.
* @return 0 on success, ENODATA if buffer is empty. * @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. /** 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). * @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). /** 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. * @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. /** 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. * @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. /** 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 * @return Pointer to the beginning of the reserved event's data buffer, or
* NULL on error (ie not enough space). * 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. /** 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. * @param data_size Length of @a data in bytes.
* @return 0 on success, ENOBUFS if there's not enough space in buffer for event. * @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. /** 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. * @param port_buffer Port to receive count for.
* @returns Number of events that could not be written to @a port_buffer. * @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 */ #endif /* __JACK_MIDIPORT_H */


+ 1
- 0
common/wscript View File

@@ -58,6 +58,7 @@ def build(bld):
'JackAudioPort.cpp', 'JackAudioPort.cpp',
'JackEventPort.cpp', 'JackEventPort.cpp',
'JackEventAPI.cpp', 'JackEventAPI.cpp',
'JackMidiAPI.cpp',
'JackEngineControl.cpp', 'JackEngineControl.cpp',
'JackShmMem.cpp', 'JackShmMem.cpp',
'JackGenericClientChannel.cpp', 'JackGenericClientChannel.cpp',


Loading…
Cancel
Save