1 | /* $Id: mpu401.cpp 561 2011-07-28 09:16:56Z rudi $ */
|
---|
2 |
|
---|
3 | /* SCCSID = %W% %E% */
|
---|
4 | /****************************************************************************
|
---|
5 | * *
|
---|
6 | * Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
7 | * *
|
---|
8 | * The following IBM OS/2 source code is provided to you solely for the *
|
---|
9 | * the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
10 | * You may use this code in accordance with the IBM License Agreement *
|
---|
11 | * provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
12 | * *
|
---|
13 | ****************************************************************************/
|
---|
14 | /**@internal %W%
|
---|
15 | * MPU_401 object implementation.
|
---|
16 | * @version %I%
|
---|
17 | * @context
|
---|
18 | * Unless otherwise noted, all interfaces are Ring-0, 16-bit, kernel stack.
|
---|
19 | * @notes
|
---|
20 | * @history
|
---|
21 | */
|
---|
22 |
|
---|
23 | extern "C" { // 16-bit header files are not C++ aware
|
---|
24 | #define INCL_NOPMAPI
|
---|
25 | #define INCL_DOSMISC
|
---|
26 | #include <os2.h>
|
---|
27 | }
|
---|
28 | #include <os2medef.h> // DATATYPE_MIDI
|
---|
29 | #include <include.h> // cli, sti, inp, outp
|
---|
30 | #include <string.h> // strcpy(), strcat()
|
---|
31 | #include "sizedefs.h" //### NUM_DEVICES, MAX_MPU401
|
---|
32 | #include "midi_idc.h" // RTMIDI i/f
|
---|
33 | #include "iodelay.h"
|
---|
34 | #include "malloc.h"
|
---|
35 | #include "mpu401.hpp" // Object definition.
|
---|
36 | #include "timer.hpp" // Object definition.
|
---|
37 | #include "stream.hpp" // Prereq to includeing midistrm.h
|
---|
38 | #include "midistrm.hpp" // Object definition.
|
---|
39 |
|
---|
40 | #include "parse.h"
|
---|
41 | #include "ossidc.h"
|
---|
42 | #include <dbgos2.h>
|
---|
43 |
|
---|
44 | #define TIMEOUT 60000
|
---|
45 |
|
---|
46 |
|
---|
47 | /* Constructor. */
|
---|
48 |
|
---|
49 | MPU_401::MPU_401(TIMER* pTimer ) :
|
---|
50 | MIDIAUDIO ( AUDIOHW_MPU401_PLAY, pTimer )
|
---|
51 | {
|
---|
52 | static char szName[] = "SBLive RTMIDI #"; // Instance name for RTMIDI. A number will be appended.
|
---|
53 | static char szSuffix[] = "0"; // Printable char that is appended to szName.
|
---|
54 |
|
---|
55 | // RTMIDI (MIDI.SYS) related stuff
|
---|
56 | //// ++szSuffix[0]; // Bump number in instance name.
|
---|
57 | strcpy( szRTMIDI_Name, szName ); // Setup instance name.
|
---|
58 | strcat( szRTMIDI_Name, szSuffix ); // Append ASCII number to instance name.
|
---|
59 | ulRTMIDI_Caps = MIDICAPSA_INPUT | MIDICAPSA_OUTPUT; // Set RTMIDI caps.
|
---|
60 |
|
---|
61 | midiOutStreamId = 0;
|
---|
62 | midiInStreamId = 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void MPU_401::noteOff( BYTE mchan, BYTE note, BYTE velocity )
|
---|
66 | {
|
---|
67 | writeByte( (BYTE) 0x80 | mchan );
|
---|
68 | writeByte( note );
|
---|
69 | writeByte( velocity );
|
---|
70 | }
|
---|
71 |
|
---|
72 | void MPU_401::noteOn( BYTE mchan, BYTE note, BYTE velocity )
|
---|
73 | {
|
---|
74 | writeByte( (BYTE) 0x90 | mchan );
|
---|
75 | writeByte( note );
|
---|
76 | writeByte( velocity );
|
---|
77 | }
|
---|
78 |
|
---|
79 | void MPU_401::polyphonicPressure( BYTE mchan, BYTE note, BYTE value )
|
---|
80 | {
|
---|
81 | writeByte( (BYTE) 0xA0 | mchan );
|
---|
82 | writeByte( note );
|
---|
83 | writeByte( value );
|
---|
84 | }
|
---|
85 |
|
---|
86 | void MPU_401::controlChange( BYTE mchan, BYTE control_number, BYTE value )
|
---|
87 | {
|
---|
88 | writeByte( (BYTE) 0xB0 | mchan );
|
---|
89 | writeByte( control_number );
|
---|
90 | writeByte( value );
|
---|
91 | }
|
---|
92 |
|
---|
93 | void MPU_401::programChange( BYTE mchan, BYTE program_number )
|
---|
94 | {
|
---|
95 | writeByte( (BYTE) 0xC0 | mchan );
|
---|
96 | writeByte( program_number );
|
---|
97 | }
|
---|
98 |
|
---|
99 | void MPU_401::channelPressure( BYTE mchan, BYTE value )
|
---|
100 | {
|
---|
101 | writeByte( (BYTE) 0xD0 | mchan );
|
---|
102 | writeByte( value );
|
---|
103 | }
|
---|
104 |
|
---|
105 | void MPU_401::pitchBend( BYTE mchan, BYTE value_lsb, BYTE value_msb )
|
---|
106 | {
|
---|
107 | writeByte( (BYTE) 0xE0 | mchan );
|
---|
108 | writeByte( value_lsb );
|
---|
109 | writeByte( value_msb );
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | int MPU_401::_iAllNotesOff(void)
|
---|
114 | {
|
---|
115 | for (int iChannel=0; iChannel<16; iChannel++) {
|
---|
116 | writeByte((BYTE) (0xB0 + iChannel)); // channel mode
|
---|
117 | writeByte(123); // all notes off
|
---|
118 | writeByte(0);
|
---|
119 | }
|
---|
120 |
|
---|
121 | return TRUE;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | int MPU_401::writeByte(BYTE b)
|
---|
126 | {
|
---|
127 | if(!midiOutStreamId) {
|
---|
128 | DebugInt3();
|
---|
129 | return 0;
|
---|
130 | }
|
---|
131 | unsigned int i;
|
---|
132 |
|
---|
133 | for (i=0; i<TIMEOUT; i++) {
|
---|
134 | if(OSS16_WriteMidiByte(midiOutStreamId, b)) {
|
---|
135 | return 1;
|
---|
136 | }
|
---|
137 | iodelay(1);
|
---|
138 | }
|
---|
139 | return 0;
|
---|
140 | }
|
---|
141 |
|
---|
142 | int MPU_401::readByte(void)
|
---|
143 | {
|
---|
144 | //TODO:
|
---|
145 | return -1;
|
---|
146 | }
|
---|
147 |
|
---|
148 | void MPU_401::processIrq(unsigned long streamid)
|
---|
149 | {
|
---|
150 | char buffer[64];
|
---|
151 | int bufsize;
|
---|
152 |
|
---|
153 | MIDIAUDIO* pma = (MIDIAUDIO *) pAudioHWList->Head();
|
---|
154 | while (pma) {
|
---|
155 | if((pma->ulDeviceType == AUDIOHW_MPU401_CAPTURE) ||
|
---|
156 | (pma->ulDeviceType == AUDIOHW_MPU401_PLAY)) {
|
---|
157 | break;
|
---|
158 | }
|
---|
159 | pma = (MIDIAUDIO *) pma->pNext;
|
---|
160 | }
|
---|
161 | if(pma == NULL) {
|
---|
162 | dprintf(("MPU_401::processIrq: mpu device found!!"));
|
---|
163 | return;
|
---|
164 | }
|
---|
165 |
|
---|
166 | while(TRUE) {
|
---|
167 | bufsize = OSS16_ReadMidiBytes(streamid, &buffer[0], sizeof(buffer));
|
---|
168 | for(int i=0;i<bufsize;i++) {
|
---|
169 | pma->pfnSendByte(pma->ulRTMIDI_Handle, buffer[i]);
|
---|
170 | }
|
---|
171 | if(bufsize != sizeof(buffer)) {
|
---|
172 | break;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | #pragma off (unreferenced)
|
---|
178 |
|
---|
179 | int MPU_401::Reset(STREAM *stream)
|
---|
180 | {
|
---|
181 | return 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | int MPU_401::Start( STREAM *stream )
|
---|
185 | {
|
---|
186 | BOOL rc;
|
---|
187 |
|
---|
188 | // Start timer on 4 mSec interval.
|
---|
189 | rc = getTimer()->Start();
|
---|
190 | return rc;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | int MPU_401::Stop(STREAM *stream)
|
---|
195 | {
|
---|
196 | getTimer()->Stop();
|
---|
197 | _iAllNotesOff();
|
---|
198 | return 0;
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | int MPU_401::Pause(STREAM *stream)
|
---|
203 | {
|
---|
204 | getTimer()->Pause();
|
---|
205 | _iAllNotesOff();
|
---|
206 | return 0;
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | int MPU_401::Resume(STREAM *stream)
|
---|
211 | {
|
---|
212 | getTimer()->Resume();
|
---|
213 | return 0;
|
---|
214 | }
|
---|
215 |
|
---|
216 | USHORT MPU_401::RTMIDI_OpenReceive(void)
|
---|
217 | {
|
---|
218 | if(midiOutStreamId == 0) {
|
---|
219 | midiOutStreamId = OSS16_OpenMidiStream(MIDI_RECEIVE);
|
---|
220 | }
|
---|
221 | return (midiOutStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
---|
222 | }
|
---|
223 |
|
---|
224 | USHORT MPU_401::RTMIDI_OpenSend(void)
|
---|
225 | {
|
---|
226 | if(midiInStreamId == 0) {
|
---|
227 | midiInStreamId = OSS16_OpenMidiStream(MIDI_SEND);
|
---|
228 | }
|
---|
229 | return (midiInStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
---|
230 | }
|
---|
231 |
|
---|
232 | USHORT MPU_401::RTMIDI_CloseReceive(void)
|
---|
233 | {
|
---|
234 | if(midiOutStreamId) {
|
---|
235 | OSS16_CloseMidiStream(MIDI_RECEIVE, midiOutStreamId);
|
---|
236 | midiOutStreamId = 0;
|
---|
237 | }
|
---|
238 | return 0;
|
---|
239 | }
|
---|
240 |
|
---|
241 | USHORT MPU_401::RTMIDI_CloseSend(void)
|
---|
242 | {
|
---|
243 | if(midiInStreamId) {
|
---|
244 | OSS16_CloseMidiStream(MIDI_SEND, midiInStreamId);
|
---|
245 | midiInStreamId = 0;
|
---|
246 | }
|
---|
247 | return 0;
|
---|
248 | }
|
---|
249 |
|
---|