1 | /* $Id: mpu401.cpp 147 2000-04-24 19:45:21Z sandervl $ */
|
---|
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\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 |
|
---|
43 |
|
---|
44 | /* Constructor. */
|
---|
45 |
|
---|
46 | MPU_401::MPU_401(TIMER* pTimer ) :
|
---|
47 | MIDIAUDIO ( AUDIOHW_MPU401_PLAY, pTimer )
|
---|
48 | {
|
---|
49 | static char szName[] = "SBLive #"; // Instance name for RTMIDI. A number will be appended.
|
---|
50 | static char szSuffix[] = "0"; // Printable char that is appended to szName.
|
---|
51 |
|
---|
52 | // RTMIDI (MIDI.SYS) related stuff
|
---|
53 | ++szSuffix[0]; // Bump number in instance name.
|
---|
54 | strcpy( szRTMIDI_Name, szName ); // Setup instance name.
|
---|
55 | strcat( szRTMIDI_Name, szSuffix ); // Append ASCII number to instance name.
|
---|
56 | ulRTMIDI_Caps = MIDICAPSA_INPUT; // Set RTMIDI caps.
|
---|
57 | // When we have an IRQ and a send capability, add next line.
|
---|
58 | // ulCapabilities |= MIDICAPSA_OUTPUT;
|
---|
59 |
|
---|
60 | midiOutStreamId = 0;
|
---|
61 | midiInStreamId = 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | virtual void MPU_401::noteOff( BYTE mchan, BYTE note, BYTE velocity )
|
---|
65 | {
|
---|
66 | writeByte( (BYTE) 0x80 | mchan );
|
---|
67 | writeByte( note );
|
---|
68 | writeByte( velocity );
|
---|
69 | }
|
---|
70 |
|
---|
71 | virtual void MPU_401::noteOn( BYTE mchan, BYTE note, BYTE velocity )
|
---|
72 | {
|
---|
73 | writeByte( (BYTE) 0x90 | mchan );
|
---|
74 | writeByte( note );
|
---|
75 | writeByte( velocity );
|
---|
76 | }
|
---|
77 |
|
---|
78 | virtual void MPU_401::polyphonicPressure( BYTE mchan, BYTE note, BYTE value )
|
---|
79 | {
|
---|
80 | writeByte( (BYTE) 0xA0 | mchan );
|
---|
81 | writeByte( note );
|
---|
82 | writeByte( value );
|
---|
83 | }
|
---|
84 |
|
---|
85 | virtual void MPU_401::controlChange( BYTE mchan, BYTE control_number, BYTE value )
|
---|
86 | {
|
---|
87 | writeByte( (BYTE) 0xB0 | mchan );
|
---|
88 | writeByte( control_number );
|
---|
89 | writeByte( value );
|
---|
90 | }
|
---|
91 |
|
---|
92 | virtual void MPU_401::programChange( BYTE mchan, BYTE program_number )
|
---|
93 | {
|
---|
94 | writeByte( (BYTE) 0xC0 | mchan );
|
---|
95 | writeByte( program_number );
|
---|
96 | }
|
---|
97 |
|
---|
98 | virtual void MPU_401::channelPressure( BYTE mchan, BYTE value )
|
---|
99 | {
|
---|
100 | writeByte( (BYTE) 0xD0 | mchan );
|
---|
101 | writeByte( value );
|
---|
102 | }
|
---|
103 |
|
---|
104 | virtual void MPU_401::pitchBend( BYTE mchan, BYTE value_lsb, BYTE value_msb )
|
---|
105 | {
|
---|
106 | writeByte( (BYTE) 0xE0 | mchan );
|
---|
107 | writeByte( value_lsb );
|
---|
108 | writeByte( value_msb );
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | int MPU_401::_iAllNotesOff(void)
|
---|
113 | {
|
---|
114 | for (int iChannel=0; iChannel<16; iChannel++) {
|
---|
115 | writeByte((BYTE) (0xB0 + iChannel)); // channel mode
|
---|
116 | writeByte(123); // all notes off
|
---|
117 | writeByte(0);
|
---|
118 | }
|
---|
119 |
|
---|
120 | return TRUE;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | int MPU_401::writeByte(BYTE b)
|
---|
125 | {
|
---|
126 | //TODO:
|
---|
127 | return 0;
|
---|
128 | }
|
---|
129 |
|
---|
130 | int MPU_401::readByte(void)
|
---|
131 | {
|
---|
132 | //TODO:
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | #pragma off (unreferenced)
|
---|
137 |
|
---|
138 | int MPU_401::Reset(STREAM *stream)
|
---|
139 | {
|
---|
140 | return 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | int MPU_401::Start( STREAM *stream )
|
---|
144 | {
|
---|
145 | BOOL rc;
|
---|
146 |
|
---|
147 | // Start timer on 4 mSec interval.
|
---|
148 | rc = getTimer()->Start();
|
---|
149 | return rc;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | int MPU_401::Stop(STREAM *stream)
|
---|
154 | {
|
---|
155 | getTimer()->Stop();
|
---|
156 | _iAllNotesOff();
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | int MPU_401::Pause(STREAM *stream)
|
---|
162 | {
|
---|
163 | getTimer()->Pause();
|
---|
164 | _iAllNotesOff();
|
---|
165 | return 0;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | int MPU_401::Resume(STREAM *stream)
|
---|
170 | {
|
---|
171 | getTimer()->Resume();
|
---|
172 | return 0;
|
---|
173 | }
|
---|
174 |
|
---|
175 | USHORT MPU_401::RTMIDI_OpenReceive(void)
|
---|
176 | {
|
---|
177 | if(midiInStreamId == 0) {
|
---|
178 | midiInStreamId = OSS16_OpenMidiStream(MIDI_RECEIVE);
|
---|
179 | }
|
---|
180 | return (midiInStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
---|
181 | }
|
---|
182 |
|
---|
183 | USHORT MPU_401::RTMIDI_OpenSend(void)
|
---|
184 | {
|
---|
185 | if(midiOutStreamId == 0) {
|
---|
186 | midiOutStreamId = OSS16_OpenMidiStream(MIDI_SEND);
|
---|
187 | }
|
---|
188 | return (midiOutStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
---|
189 | }
|
---|
190 |
|
---|
191 | USHORT MPU_401::RTMIDI_CloseReceive(void)
|
---|
192 | {
|
---|
193 | OSS16_CloseMidiStream(MIDI_RECEIVE, midiInStreamId);
|
---|
194 | return 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 | USHORT MPU_401::RTMIDI_CloseSend(void)
|
---|
198 | {
|
---|
199 | OSS16_CloseMidiStream(MIDI_SEND, midiOutStreamId);
|
---|
200 | return 0;
|
---|
201 | }
|
---|
202 |
|
---|