| 1 | /* $Id: mpu401.cpp,v 1.3 2000/05/28 16:50:40 sandervl Exp $ */
|
|---|
| 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 | #include <dbgos2.h>
|
|---|
| 43 | #include <sbversion.h>
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | #define TIMEOUT 60000
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | /* Constructor. */
|
|---|
| 50 |
|
|---|
| 51 | MPU_401::MPU_401(TIMER* pTimer ) :
|
|---|
| 52 | MIDIAUDIO ( AUDIOHW_MPU401_PLAY, pTimer )
|
|---|
| 53 | {
|
|---|
| 54 | static char szName[] = DRVNAME" RTMIDI #"; // Instance name for RTMIDI. A number will be appended.
|
|---|
| 55 | static char szSuffix[] = "0"; // Printable char that is appended to szName.
|
|---|
| 56 |
|
|---|
| 57 | // RTMIDI (MIDI.SYS) related stuff
|
|---|
| 58 | //// ++szSuffix[0]; // Bump number in instance name.
|
|---|
| 59 | strcpy( szRTMIDI_Name, szName ); // Setup instance name.
|
|---|
| 60 | strcat( szRTMIDI_Name, szSuffix ); // Append ASCII number to instance name.
|
|---|
| 61 | ulRTMIDI_Caps = MIDICAPSA_INPUT | MIDICAPSA_OUTPUT; // Set RTMIDI caps.
|
|---|
| 62 |
|
|---|
| 63 | midiOutStreamId = 0;
|
|---|
| 64 | midiInStreamId = 0;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void MPU_401::noteOff( BYTE mchan, BYTE note, BYTE velocity )
|
|---|
| 68 | {
|
|---|
| 69 | writeByte( (BYTE) 0x80 | mchan );
|
|---|
| 70 | writeByte( note );
|
|---|
| 71 | writeByte( velocity );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void MPU_401::noteOn( BYTE mchan, BYTE note, BYTE velocity )
|
|---|
| 75 | {
|
|---|
| 76 | writeByte( (BYTE) 0x90 | mchan );
|
|---|
| 77 | writeByte( note );
|
|---|
| 78 | writeByte( velocity );
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void MPU_401::polyphonicPressure( BYTE mchan, BYTE note, BYTE value )
|
|---|
| 82 | {
|
|---|
| 83 | writeByte( (BYTE) 0xA0 | mchan );
|
|---|
| 84 | writeByte( note );
|
|---|
| 85 | writeByte( value );
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void MPU_401::controlChange( BYTE mchan, BYTE control_number, BYTE value )
|
|---|
| 89 | {
|
|---|
| 90 | writeByte( (BYTE) 0xB0 | mchan );
|
|---|
| 91 | writeByte( control_number );
|
|---|
| 92 | writeByte( value );
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | void MPU_401::programChange( BYTE mchan, BYTE program_number )
|
|---|
| 96 | {
|
|---|
| 97 | writeByte( (BYTE) 0xC0 | mchan );
|
|---|
| 98 | writeByte( program_number );
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | void MPU_401::channelPressure( BYTE mchan, BYTE value )
|
|---|
| 102 | {
|
|---|
| 103 | writeByte( (BYTE) 0xD0 | mchan );
|
|---|
| 104 | writeByte( value );
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | void MPU_401::pitchBend( BYTE mchan, BYTE value_lsb, BYTE value_msb )
|
|---|
| 108 | {
|
|---|
| 109 | writeByte( (BYTE) 0xE0 | mchan );
|
|---|
| 110 | writeByte( value_lsb );
|
|---|
| 111 | writeByte( value_msb );
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | int MPU_401::_iAllNotesOff(void)
|
|---|
| 116 | {
|
|---|
| 117 | for (int iChannel=0; iChannel<16; iChannel++) {
|
|---|
| 118 | writeByte((BYTE) (0xB0 + iChannel)); // channel mode
|
|---|
| 119 | writeByte(123); // all notes off
|
|---|
| 120 | writeByte(0);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | return TRUE;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | int MPU_401::writeByte(BYTE b)
|
|---|
| 128 | {
|
|---|
| 129 | if(!midiOutStreamId) {
|
|---|
| 130 | DebugInt3();
|
|---|
| 131 | return 0;
|
|---|
| 132 | }
|
|---|
| 133 | unsigned int i;
|
|---|
| 134 |
|
|---|
| 135 | for (i=0; i<TIMEOUT; i++) {
|
|---|
| 136 | if(OSS16_WriteMidiByte(midiOutStreamId, b)) {
|
|---|
| 137 | return 1;
|
|---|
| 138 | }
|
|---|
| 139 | //Rudi: iodelay(1);
|
|---|
| 140 | }
|
|---|
| 141 | return 0;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | int MPU_401::readByte(void)
|
|---|
| 145 | {
|
|---|
| 146 | //TODO:
|
|---|
| 147 | return -1;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void MPU_401::processIrq(unsigned long streamid)
|
|---|
| 151 | {
|
|---|
| 152 | char buffer[64];
|
|---|
| 153 | int bufsize;
|
|---|
| 154 |
|
|---|
| 155 | MIDIAUDIO* pma = (MIDIAUDIO *) pAudioHWList->Head();
|
|---|
| 156 | while (pma) {
|
|---|
| 157 | if((pma->usDeviceType == AUDIOHW_MPU401_CAPTURE) ||
|
|---|
| 158 | (pma->usDeviceType == AUDIOHW_MPU401_PLAY)) {
|
|---|
| 159 | break;
|
|---|
| 160 | }
|
|---|
| 161 | pma = (MIDIAUDIO *) pma->pNext;
|
|---|
| 162 | }
|
|---|
| 163 | if(pma == NULL) {
|
|---|
| 164 | dprintf(("MPU_401::processIrq: mpu device found!!"));
|
|---|
| 165 | return;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | while(TRUE) {
|
|---|
| 169 | bufsize = OSS16_ReadMidiBytes(streamid, &buffer[0], sizeof(buffer));
|
|---|
| 170 | for(int i=0;i<bufsize;i++) {
|
|---|
| 171 | pma->pfnSendByte(pma->ulRTMIDI_Handle, buffer[i]);
|
|---|
| 172 | }
|
|---|
| 173 | if(bufsize != sizeof(buffer)) {
|
|---|
| 174 | break;
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | #pragma off (unreferenced)
|
|---|
| 180 |
|
|---|
| 181 | int MPU_401::Reset(STREAM *stream)
|
|---|
| 182 | {
|
|---|
| 183 | return 0;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | int MPU_401::Start( STREAM *stream )
|
|---|
| 187 | {
|
|---|
| 188 | BOOL rc;
|
|---|
| 189 |
|
|---|
| 190 | // Start timer on 4 mSec interval.
|
|---|
| 191 | rc = getTimer()->Start();
|
|---|
| 192 | return rc;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | int MPU_401::Stop(STREAM *stream)
|
|---|
| 197 | {
|
|---|
| 198 | getTimer()->Stop();
|
|---|
| 199 | _iAllNotesOff();
|
|---|
| 200 | return 0;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 | int MPU_401::Pause(STREAM *stream)
|
|---|
| 205 | {
|
|---|
| 206 | getTimer()->Pause();
|
|---|
| 207 | _iAllNotesOff();
|
|---|
| 208 | return 0;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 | int MPU_401::Resume(STREAM *stream)
|
|---|
| 213 | {
|
|---|
| 214 | getTimer()->Resume();
|
|---|
| 215 | return 0;
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | USHORT MPU_401::RTMIDI_OpenReceive(void)
|
|---|
| 219 | {
|
|---|
| 220 | if(midiOutStreamId == 0) {
|
|---|
| 221 | midiOutStreamId = OSS16_OpenMidiStream(MIDI_RECEIVE);
|
|---|
| 222 | }
|
|---|
| 223 | return (midiOutStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | USHORT MPU_401::RTMIDI_OpenSend(void)
|
|---|
| 227 | {
|
|---|
| 228 | if(midiInStreamId == 0) {
|
|---|
| 229 | midiInStreamId = OSS16_OpenMidiStream(MIDI_SEND);
|
|---|
| 230 | }
|
|---|
| 231 | return (midiInStreamId) ? 0 : MIDIERRA_HW_FAILED;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | USHORT MPU_401::RTMIDI_CloseReceive(void)
|
|---|
| 235 | {
|
|---|
| 236 | if(midiOutStreamId) {
|
|---|
| 237 | OSS16_CloseMidiStream(MIDI_RECEIVE, midiOutStreamId);
|
|---|
| 238 | midiOutStreamId = 0;
|
|---|
| 239 | }
|
|---|
| 240 | return 0;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | USHORT MPU_401::RTMIDI_CloseSend(void)
|
|---|
| 244 | {
|
|---|
| 245 | if(midiInStreamId) {
|
|---|
| 246 | OSS16_CloseMidiStream(MIDI_SEND, midiInStreamId);
|
|---|
| 247 | midiInStreamId = 0;
|
|---|
| 248 | }
|
|---|
| 249 | return 0;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|