Jack2  1.9.9
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 
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  * 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.
72  */
73 
74 struct SERVER_EXPORT JackMidiBuffer
75 {
76  enum { MAGIC = 0x900df00d };
77 
78  uint32_t magic;
79  jack_shmsize_t buffer_size;
80  jack_nframes_t nframes;
81  jack_shmsize_t write_pos;
82  uint32_t event_count;
83  uint32_t lost_events;
84  uint32_t mix_index;
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 } // namespace Jack
100 
101 #endif
jack_midi_data_t * buffer
Definition: JackMidiPort.h:37
jack_shmsize_t write_pos
data write position from the end of the buffer.
Definition: JackMidiPort.h:81
jack_nframes_t time
Definition: JackMidiPort.h:35