Jack2 1.9.12

JackMidiPort.h
1 /*
2 Copyright (C) 2007 Dmitry Baikov
3 Original JACK MIDI API implementation Copyright (C) 2004 Ian Esten
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __JackMidiPort__
22 #define __JackMidiPort__
23
24 #include "types.h"
25 #include "JackConstants.h"
26 #include "JackPlatformPlug.h"
27 #include <stddef.h>
28
30 typedef unsigned char jack_midi_data_t;
31
33 struct jack_midi_event_t
34 {
35 jack_nframes_t time;
36 size_t size;
37 jack_midi_data_t *buffer;
38 };
39
41 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
42
43 namespace Jack
44 {
45
46 struct SERVER_EXPORT JackMidiEvent
47 {
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) };
50
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];
56 };
57
58 jack_midi_data_t* GetData(void* buffer)
59 {
60 if (size <= INLINE_SIZE_MAX) {
61 return data;
62 } else {
63 return (jack_midi_data_t*)buffer + offset;
64 }
65 }
66 };
67
68 /*
69 * To store events with arbitrarily sized payload, but still have O(1) indexed access
70 * we use a trick here:
71 * Events are stored in an linear array from the beginning of the buffer,
72 * but their data (if not inlined) is stored from the end of the same buffer.
73 */
74
75 struct SERVER_EXPORT JackMidiBuffer
76 {
77 enum { MAGIC = 0x900df00d };
78
79 uint32_t magic;
80 jack_shmsize_t buffer_size;
81 jack_nframes_t nframes;
82 jack_shmsize_t write_pos;
83 uint32_t event_count;
84 uint32_t lost_events;
85
86 JackMidiEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here.
87
88 int IsValid() const
89 {
90 return magic == MAGIC;
91 }
92 void Reset(jack_nframes_t nframes);
93 jack_shmsize_t MaxEventSize() const;
94
95 // checks only size constraints.
96 jack_midi_data_t* ReserveEvent(jack_nframes_t time, jack_shmsize_t size);
97 };
98
99 void MidiBufferInit(void* buffer, size_t buffer_size, jack_nframes_t nframes);
100
101 } // namespace Jack
102
103 #endif
jack_midi_event_t::buffer
jack_midi_data_t * buffer
Definition: JackMidiPort.h:37
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