JackMidiPort.h
/*
Copyright (C) 2007 Dmitry Baikov
Original JACK MIDI API 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.
*/
#ifndef __JackMidiPort__
#define __JackMidiPort__
#include "types.h"
#include "JackConstants.h"
#include "JackPlatformPlug.h"
#include <stddef.h>
typedef unsigned char jack_midi_data_t;
struct jack_midi_event_t
{
jack_nframes_t time;
size_t size;
jack_midi_data_t *buffer;
};
#define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
namespace Jack
{
struct SERVER_EXPORT JackMidiEvent
{
// Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
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_midi_data_t* GetData(void* buffer)
{
if (size <= INLINE_SIZE_MAX) {
return data;
} else {
return (jack_midi_data_t*)buffer + offset;
}
}
};
/*
* To store events with arbitrarily sized payload, but still have O(1) indexed access
* we use a trick here:
* Events are stored in an linear array from the beginning of the buffer,
* but their data (if not inlined) is stored from the end of the same buffer.
*/
struct SERVER_EXPORT JackMidiBuffer
{
enum { MAGIC = 0x900df00d };
uint32_t magic;
jack_shmsize_t buffer_size;
jack_nframes_t nframes;
jack_shmsize_t write_pos;
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.
int IsValid() const
{
return magic == MAGIC;
}
void Reset(jack_nframes_t nframes);
jack_shmsize_t MaxEventSize() const;
// checks only size constraints.
jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
};
void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes);
} // namespace Jack
#endif
jack_midi_event_t::buffer
jack_midi_data_t * buffer
Definition: JackMidiPort.h:37
Jack
Definition: JackAC3Encoder.cpp:30
jack_midi_event_t::size
size_t size
Definition: JackMidiPort.h:36
jack_midi_event_t
Definition: JackMidiPort.h:33
Jack::JackMidiBuffer::write_pos
jack_shmsize_t write_pos
data write position from the end of the buffer.
Definition: JackMidiPort.h:82
Jack::JackMidiEvent
Definition: JackMidiPort.h:46
Jack::JackMidiBuffer
Definition: JackMidiPort.h:75
jack_midi_event_t::time
jack_nframes_t time
Definition: JackMidiPort.h:35