vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CMidiInQ.h
blobbdc8b69491921f475d2e839540283e3154b9361e
1 // ****************************************************************************
2 //
3 // CMidiInQ.h
4 //
5 // This class manages MIDI input.
6 //
7 // Use a simple fixed size queue for storing MIDI data.
8 //
9 // Fill & drain pointers are maintained automatically whenever
10 // an Add or Get function succeeds.
12 // Set editor tabs to 3 for your viewing pleasure.
14 // ----------------------------------------------------------------------------
16 // This file is part of Echo Digital Audio's generic driver library.
17 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
18 // All rights reserved
19 // www.echoaudio.com
21 // This library is free software; you can redistribute it and/or
22 // modify it under the terms of the GNU Lesser General Public
23 // License as published by the Free Software Foundation; either
24 // version 2.1 of the License, or (at your option) any later version.
26 // This library is distributed in the hope that it will be useful,
27 // but WITHOUT ANY WARRANTY; without even the implied warranty of
28 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 // Lesser General Public License for more details.
31 // You should have received a copy of the GNU Lesser General Public
32 // License along with this library; if not, write to the Free Software
33 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 // ****************************************************************************
37 // Prevent problems with multiple includes
38 #ifndef _MIDIQUEUEOBJECT_
39 #define _MIDIQUEUEOBJECT_
41 #include "CMtcSync.h"
43 typedef struct tMIDI_DATA
45 DWORD dwMidi;
46 LONGLONG llTimestamp;
48 MIDI_DATA;
50 typedef MIDI_DATA *PMIDI_DATA;
52 //
53 // Default to one MIDI input client
55 #ifndef MAX_MIDI_IN_CLIENTS
56 #define MAX_MIDI_IN_CLIENTS 1
57 #endif
60 // MIDI in queue size
62 // Total buffer size in bytes will be MIDI_IN_Q_SIZE * sizeof(MIDI_DATA)
64 // Buffer size must be a power of 2. This is the default size; to change it,
65 // add #define MIDI_IN_Q_SIZE to your OsSupport??.h file
67 #ifndef MIDI_IN_Q_SIZE
68 #define MIDI_IN_Q_SIZE 128
69 #endif
72 // Class used for simple MIDI byte queue
74 class CMidiInQ
76 public:
78 // Construction/destruction
80 CMidiInQ();
81 ~CMidiInQ();
84 // Init
86 ECHOSTATUS Init(CEchoGals *pEG);
89 // Get the oldest byte from the circular buffer
91 ECHOSTATUS GetMidi
93 ECHOGALS_MIDI_IN_CONTEXT *pContext,
94 DWORD &dwMidiByte,
95 LONGLONG &llTimestamp
99 // Enable and disable MIDI input and MTC sync
101 ECHOSTATUS Arm(ECHOGALS_MIDI_IN_CONTEXT *pContext);
102 ECHOSTATUS Disarm(ECHOGALS_MIDI_IN_CONTEXT *pContext);
103 ECHOSTATUS ArmMtcSync();
104 ECHOSTATUS DisarmMtcSync();
107 // Get and set MTC base rate
109 ECHOSTATUS GetMtcBaseRate(DWORD *pdwBaseRate);
110 ECHOSTATUS SetMtcBaseRate(DWORD dwBaseRate);
113 // If MTC sync is turned on, process received MTC data
114 // and update the sample rate
116 void ServiceMtcSync();
119 // See if there has been any recent MIDI input activity
121 BOOL IsActive();
124 // Reset the in/out ptrs
126 void Reset(ECHOGALS_MIDI_IN_CONTEXT *pContext);
129 // Service a MIDI input interrupt
131 ECHOSTATUS ServiceIrq();
134 protected:
137 // Add a MIDI byte to the circular buffer
139 inline ECHOSTATUS AddMidi
141 DWORD dwMidiByte,
142 LONGLONG llTimestamp
146 // Parse MIDI time code data
148 DWORD MtcProcessData( DWORD dwMidiData );
151 // Cleanup
153 void Cleanup();
156 // Midi buffer management
158 PMIDI_DATA m_pBuffer;
159 DWORD m_dwFill;
160 DWORD m_dwBufferSizeMask;
161 DWORD m_dwNumClients;
164 // Most recent MIDI input time - used for activity detector
166 ULONGLONG m_ullLastActivityTime;
169 // MIDI time code
171 WORD m_wMtcState;
172 CMtcSync *m_pMtcSync;
175 // Other objects
177 CEchoGals *m_pEG;
179 }; // class CMidiInQ
181 typedef CMidiInQ * PCMidiInQ;
183 #endif
185 // *** CMidiInQ.H ***