Cleanup wscripts.
[jack2.git] / common / JackMidiPort.h
blob0dbfcb9a23ac8a0e3321304319f1d69add53e3ad
1 /*
2 Copyright (C) 2007 Dmitry Baikov
3 Original JACK MIDI API implementation Copyright (C) 2004 Ian Esten
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef __JackMidiPort__
22 #define __JackMidiPort__
24 #include "types.h"
25 #include "JackConstants.h"
26 #include "JackPlatformPlug.h"
27 #include <stddef.h>
29 /** Type for raw event data contained in @ref jack_midi_event_t. */
30 typedef unsigned char jack_midi_data_t;
32 /** A Jack MIDI event. */
33 struct jack_midi_event_t
35 jack_nframes_t time; /**< Sample index at which event is valid */
36 size_t size; /**< Number of bytes of data in \a buffer */
37 jack_midi_data_t *buffer; /**< Raw MIDI data */
40 /** A Jack MIDI port type. */
41 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
43 namespace Jack
46 struct SERVER_EXPORT JackMidiEvent
48 // Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
49 enum { INLINE_SIZE_MAX = sizeof(jack_shmsize_t) };
51 uint32_t time;
52 jack_shmsize_t size;
53 union {
54 jack_shmsize_t offset;
55 jack_midi_data_t data[INLINE_SIZE_MAX];
58 jack_midi_data_t* GetData(void* buffer)
60 if (size <= INLINE_SIZE_MAX)
61 return data;
62 else
63 return (jack_midi_data_t*)buffer + offset;
68 * To store events with arbitrarily sized payload, but still have O(1) indexed access
69 * we use a trick here:
70 * Events are stored in an linear array from the beginning of the buffer,
71 * but their data (if not inlined) is stored from the end of the same buffer.
74 struct JackMidiBuffer
76 enum { MAGIC = 0x900df00d };
78 uint32_t magic;
79 jack_shmsize_t buffer_size;
80 jack_nframes_t nframes;
81 jack_shmsize_t write_pos; //!< data write position from the end of the buffer.
82 uint32_t event_count;
83 uint32_t lost_events;
84 uint32_t mix_index;
86 JackMidiEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here.
88 int IsValid() const
90 return magic == MAGIC;
92 void Reset(jack_nframes_t nframes);
93 jack_shmsize_t MaxEventSize() const;
95 // checks only size constraints.
96 jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
99 } // namespace Jack
101 #endif