JackMidiPort.h

00001 /*
00002 Copyright (C) 2007 Dmitry Baikov
00003 Original JACK MIDI API implementation Copyright (C) 2004 Ian Esten
00004 
00005 This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   This program is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifndef __JackMidiPort__
00022 #define __JackMidiPort__
00023 
00024 #include "types.h"
00025 #include "JackConstants.h"
00026 #include <stddef.h>
00027 
00029 typedef unsigned char jack_midi_data_t;
00030 
00032 struct jack_midi_event_t
00033 {
00034         jack_nframes_t    time;   
00035         size_t            size;   
00036         jack_midi_data_t *buffer; 
00037 };
00038 
00040 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
00041 
00042 namespace Jack
00043 {
00044 
00045 struct JackMidiEvent
00046 {
00047     // Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
00048     enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) };
00049 
00050     uint32_t time;
00051     jack_shmsize_t size;
00052     union {
00053         jack_shmsize_t   offset;
00054         jack_midi_data_t data[INLINE_SIZE_MAX];
00055     };
00056 
00057     jack_midi_data_t* GetData(void* buffer)
00058     {
00059         if (size <= INLINE_SIZE_MAX)
00060             return data;
00061         else
00062             return (jack_midi_data_t*)buffer + offset;
00063     }
00064 };
00065 
00066 /*
00067  * To store events with arbitrarily sized payload, but still have O(1) indexed access
00068  * we use a trick here:
00069  * Events are stored in an linear array from the beginning of the buffer,
00070  * but their data (if not inlined) is stored from the end of the same buffer.
00071  */
00072 
00073 struct JackMidiBuffer
00074 {
00075     enum { MAGIC = 0x900df00d };
00076 
00077     uint32_t magic;
00078     jack_shmsize_t buffer_size;
00079     jack_nframes_t nframes;
00080     jack_shmsize_t write_pos; 
00081     uint32_t event_count;
00082     uint32_t lost_events;
00083     uint32_t mix_index;
00084 
00085     JackMidiEvent events[0];
00086 
00087     int IsValid() const { return magic == MAGIC; }
00088     void Reset(jack_nframes_t nframes);
00089     jack_shmsize_t MaxEventSize() const;
00090 
00091     // checks only size constraints.
00092     jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
00093 };
00094 
00095 } // namespace Jack
00096 
00097 #endif

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1