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__
25 #include "JackConstants.h"
28 /** Type for raw event data contained in @ref jack_midi_event_t. */
29 typedef unsigned char jack_midi_data_t
;
31 /** A Jack MIDI event. */
32 struct jack_midi_event_t
34 jack_nframes_t time
; /**< Sample index at which event is valid */
35 size_t size
; /**< Number of bytes of data in \a buffer */
36 jack_midi_data_t
*buffer
; /**< Raw MIDI data */
39 /** A Jack MIDI port type. */
40 #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
47 // Most MIDI events are < 4 bytes in size, so we can save a lot, storing them inplace.
48 enum { INLINE_SIZE_MAX
= sizeof(jack_shmsize_t
) };
53 jack_shmsize_t offset
;
54 jack_midi_data_t data
[INLINE_SIZE_MAX
];
57 jack_midi_data_t
* GetData(void* buffer
)
59 if (size
<= INLINE_SIZE_MAX
)
62 return (jack_midi_data_t
*)buffer
+ offset
;
67 * To store events with arbitrarily sized payload, but still have O(1) indexed access
68 * we use a trick here:
69 * Events are stored in an linear array from the beginning of the buffer,
70 * but their data (if not inlined) is stored from the end of the same buffer.
75 enum { MAGIC
= 0x900df00d };
78 jack_shmsize_t buffer_size
;
79 jack_nframes_t nframes
;
80 jack_shmsize_t write_pos
; //!< data write position from the end of the buffer.
85 JackMidiEvent events
[0];
89 return magic
== MAGIC
;
91 void Reset(jack_nframes_t nframes
);
92 jack_shmsize_t
MaxEventSize() const;
94 // checks only size constraints.
95 jack_midi_data_t
* ReserveEvent(jack_nframes_t time
, jack_shmsize_t size
);