1 | /* $Id: midistrm.hpp 142 2000-04-23 14:55:46Z ktk $ */
|
---|
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 | * Defines, class definations and prototypes for the MIDISTREAM class
|
---|
16 | * @version %I%
|
---|
17 | * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
|
---|
18 | * kernel stack.
|
---|
19 | * @history
|
---|
20 | */
|
---|
21 | #ifndef MIDISTREAM_INCLUDED
|
---|
22 | #define MIDISTREAM_INCLUDED
|
---|
23 |
|
---|
24 | #ifndef OS2_INCLUDED
|
---|
25 | #define INCL_NOPMAPI
|
---|
26 | #include <os2.h>
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #ifndef OS2ME_INCLUDED
|
---|
30 | #include <os2me.h> // prereq to midistrm.hpp
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #ifndef DDCMD_REG_STREAM // shdd.h can't handle being included twice
|
---|
34 | #include <shdd.h> // for PDDCMDREGISTER
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include "stream.hpp" // Object definition.
|
---|
38 | #include "midimsg.hpp" // Object definition.
|
---|
39 |
|
---|
40 | // Number of notes in the MIDI definition.
|
---|
41 | const NUM_MidiNotes = 128;
|
---|
42 |
|
---|
43 | // Number of channels in the MIDI definition.
|
---|
44 | const NUM_MidiChannels = 16;
|
---|
45 |
|
---|
46 | // The MIDI parser is always in one of the following states.
|
---|
47 | enum PARSER_STATE
|
---|
48 | {
|
---|
49 | S_Init, // Initial state.
|
---|
50 | S_ChannelMsg, // Channel message in progress.
|
---|
51 | S_SystemCommon, // System Common message in progress.
|
---|
52 | S_SysexSignature, // System Exclusive signature (1st 4 bytes).
|
---|
53 | S_SysexIBM, // IBM Sysex in progress.
|
---|
54 | S_SysexNotIBM // Non-IBM Sysex in progress.
|
---|
55 | };
|
---|
56 |
|
---|
57 |
|
---|
58 | class MIDISTREAM : public STREAM {
|
---|
59 |
|
---|
60 | public:
|
---|
61 | MIDISTREAM( ULONG streamtype, USHORT filesysnum);
|
---|
62 | virtual ~MIDISTREAM() {};
|
---|
63 | void Process ( void ); // Called by Timer when it's time to do work.
|
---|
64 | // Process() schedules its next invocation.
|
---|
65 | virtual ULONG GetCurrentTime(void);
|
---|
66 | virtual void SetCurrentTime(ULONG time);
|
---|
67 | virtual ULONG Read(PSTREAMBUF, unsigned);
|
---|
68 | virtual ULONG StartStream(void);
|
---|
69 | virtual ULONG StopStream(PCONTROL_PARM);
|
---|
70 | virtual ULONG PauseStream(PCONTROL_PARM);
|
---|
71 | virtual ULONG ResumeStream(void);
|
---|
72 |
|
---|
73 | private:
|
---|
74 | // Members that deal with timing
|
---|
75 | ULONG ulPerClock; // microseconds per 0xF8 timing pulse
|
---|
76 | ULONG _ulLastProcess; // Time on clock when we last processed MIDI messages.
|
---|
77 | long lWait; // microseconds to wait until it's time to
|
---|
78 | // process the next message
|
---|
79 | ULONG ulTempo; // 1/10 beats per minute (beats per 10 minutes)
|
---|
80 | USHORT usCPQN; // last PPQN scalar received from MMPM; is
|
---|
81 | // _not_ the current PPQN value. used by
|
---|
82 | // CalcDelay() to compute ulPerClock.
|
---|
83 | void CalcDelay(void); // calculates ulPerClock (per 0xF8 pulse)
|
---|
84 |
|
---|
85 | // Members that deal with processing the stream data
|
---|
86 | static USHORT _usBitNumber[]; // Used to map between integers & bit numbers.
|
---|
87 | USHORT _notesOn[ NUM_MidiNotes ];
|
---|
88 | // 128 x 16 bit matrix, each bit represents one
|
---|
89 | // note on one channel. Records whether each note
|
---|
90 | // is currently on or off. Used for "all notes off".
|
---|
91 |
|
---|
92 | PARSER_STATE state; // Current state of MIDI parser, as enumerated above.
|
---|
93 | MIDIMSG message; // Current message that we're assembling from the input stream.
|
---|
94 |
|
---|
95 | void _allNotesOff( void ); // Shut off all notes that are currently playing.
|
---|
96 | void parse( MIDIBYTE bInput ); // Parse the next byte of the input stream.
|
---|
97 | void dispatch( MIDIMSG& msg ); // Interpret the complete message.
|
---|
98 | };
|
---|
99 |
|
---|
100 | #endif
|
---|