Better isolation of server and clients system resources to allow starting the server...
[jack2.git] / common / JackMidiPort.h
blob9a332de7fff8ce7b7d4c62422737e00d6ffaf907
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 <stddef.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"
42 namespace Jack
45 struct JackMidiEvent
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) };
50 uint32_t time;
51 jack_shmsize_t size;
52 union {
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)
60 return data;
61 else
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.
73 struct JackMidiBuffer
75 enum { MAGIC = 0x900df00d };
77 uint32_t magic;
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.
81 uint32_t event_count;
82 uint32_t lost_events;
83 uint32_t mix_index;
85 JackMidiEvent events[0];
87 int IsValid() const
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);
98 } // namespace Jack
100 #endif