1 // ****************************************************************************
5 // This class manages MIDI input.
7 // Use a simple fixed size queue for storing MIDI data.
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
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_
43 typedef struct tMIDI_DATA
50 typedef MIDI_DATA
*PMIDI_DATA
;
53 // Default to one MIDI input client
55 #ifndef MAX_MIDI_IN_CLIENTS
56 #define MAX_MIDI_IN_CLIENTS 1
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
72 // Class used for simple MIDI byte queue
78 // Construction/destruction
86 ECHOSTATUS
Init(CEchoGals
*pEG
);
89 // Get the oldest byte from the circular buffer
93 ECHOGALS_MIDI_IN_CONTEXT
*pContext
,
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
124 // Reset the in/out ptrs
126 void Reset(ECHOGALS_MIDI_IN_CONTEXT
*pContext
);
129 // Service a MIDI input interrupt
131 ECHOSTATUS
ServiceIrq();
137 // Add a MIDI byte to the circular buffer
139 inline ECHOSTATUS AddMidi
146 // Parse MIDI time code data
148 DWORD
MtcProcessData( DWORD dwMidiData
);
156 // Midi buffer management
158 PMIDI_DATA m_pBuffer
;
160 DWORD m_dwBufferSizeMask
;
161 DWORD m_dwNumClients
;
164 // Most recent MIDI input time - used for activity detector
166 ULONGLONG m_ullLastActivityTime
;
172 CMtcSync
*m_pMtcSync
;
181 typedef CMidiInQ
* PCMidiInQ
;
185 // *** CMidiInQ.H ***