xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/CMidiInQ.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
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.
11 //
12 //		Set editor tabs to 3 for your viewing pleasure.
13 //
14 // ----------------------------------------------------------------------------
15 //
16 //		Copyright Echo Digital Audio Corporation (c) 1998 - 2002
17 //		All rights reserved
18 //		www.echoaudio.com
19 //
20 //		Permission is hereby granted, free of charge, to any person obtaining a
21 //		copy of this software and associated documentation files (the
22 //		"Software"), to deal with the Software without restriction, including
23 //		without limitation the rights to use, copy, modify, merge, publish,
24 //		distribute, sublicense, and/or sell copies of the Software, and to
25 //		permit persons to whom the Software is furnished to do so, subject to
26 //		the following conditions:
27 //
28 //		- Redistributions of source code must retain the above copyright
29 //		notice, this list of conditions and the following disclaimers.
30 //
31 //		- Redistributions in binary form must reproduce the above copyright
32 //		notice, this list of conditions and the following disclaimers in the
33 //		documentation and/or other materials provided with the distribution.
34 //
35 //		- Neither the name of Echo Digital Audio, nor the names of its
36 //		contributors may be used to endorse or promote products derived from
37 //		this Software without specific prior written permission.
38 //
39 //		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
40 //		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41 //		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42 //		IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
43 //		ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
44 //		TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45 //		SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
46 //
47 // ****************************************************************************
48 
49 //	Prevent problems with multiple includes
50 #ifndef _MIDIQUEUEOBJECT_
51 #define _MIDIQUEUEOBJECT_
52 
53 typedef BYTE MIDI_DATA;
54 typedef MIDI_DATA *PMIDI_DATA;
55 
56 //
57 //	Class used for simple MIDI byte queue
58 //
59 class CMidiInQ
60 {
61 public:
62 	//
63 	//	Construction/destruction
64 	//
65 	CMidiInQ();
66 	~CMidiInQ();
67 
68 	//
69 	// Init
70 	//
71 	ECHOSTATUS Init(CEchoGals *pEG);
72 
73 	//
74 	//	Get the oldest byte from the circular buffer
75 	//
76 	ECHOSTATUS GetMidi
77 	(
78 		MIDI_DATA &Midi
79 	);
80 
81 	//
82 	// Enable and disable MIDI input
83 	//
84 	ECHOSTATUS Arm();
85 	void Disarm();
86 
87 	//
88 	// See if there has been any recent MIDI input activity
89 	//
90 	BOOL IsActive();
91 
92 	//
93 	//	Reset the in/out ptrs
94 	//
95 	void Reset();
96 
97 	//
98 	// Service a MIDI input interrupt
99 	//
100 	ECHOSTATUS ServiceIrq();
101 
102 
103 protected:
104 
105 	//
106 	//	Find the next offset into the circular buffer
107 	//
108 	PMIDI_DATA ComputeNext( PMIDI_DATA pCur );
109 
110 	//
111 	// Add a MIDI byte to the circular buffer
112 	//
113 	inline ECHOSTATUS AddMidi
114 	(
115 		MIDI_DATA Midi
116 	);
117 
118 	//
119 	// Parse MIDI time code data
120 	//
121 	DWORD MtcProcessData( DWORD dwMidiData );
122 
123 	//
124 	// Cleanup
125 	//
126 	void Cleanup();
127 
128 	//
129 	//	Midi buffer management
130 	//
131 	PMIDI_DATA 	m_pBuffer;
132 	PMIDI_DATA	m_pEnd;
133 	PMIDI_DATA	m_pFill;
134 	PMIDI_DATA	m_pDrain;
135 
136 	BOOL			m_fArmed;
137 
138 	//
139 	// Most recent MIDI input time - used for activity detector
140 	//
141 	ULONGLONG	m_ullLastActivityTime;
142 
143 	//
144 	// MIDI time code
145 	//
146 	WORD			m_wMtcState;
147 
148 	//
149 	// Other objects
150 	//
151 	CEchoGals		*m_pEG;
152 
153 };		// class CMidiInQ
154 
155 typedef CMidiInQ * PCMidiInQ;
156 
157 #endif
158 
159 // *** CMidiInQ.H ***
160