1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id: midstuff.h 1035 2013-08-14 00:38:40Z wesleyjohnson $ 5 // 6 // Copyright (C) 1998-2000 by DooM Legacy Team. 7 // 8 // This program is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU General Public License 10 // as published by the Free Software Foundation; either version 2 11 // of the License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // 18 // 19 // $Log: midstuff.h,v $ 20 // Revision 1.2 2000/02/27 00:42:12 hurdler 21 // Revision 1.1.1.1 2000/02/22 20:32:33 hurdler 22 // Initial import into CVS (v1.29 pr3) 23 // 24 // 25 // DESCRIPTION: 26 // MIDI structures and definitions used by the MSTREAM sample 27 // application in converting a MID file to a MIDI stream for 28 // playback using the midiStream API. 29 // Inpired by DirectX5 SDK examples 30 // 31 //----------------------------------------------------------------------------- 32 33 #ifndef MIDSTUFF_H 34 #define MIDSTUFF_H 35 36 // MIDI file constants 37 // 38 #define MThd 0x6468544D // Start of file 39 #define MTrk 0x6B72544D // Start of track 40 41 #define MIDI_SYSEX ((BYTE)0xF0) // SysEx begin 42 #define MIDI_SYSEXEND ((BYTE)0xF7) // SysEx begin 43 #define MIDI_META ((BYTE)0xFF) // Meta event begin 44 #define MIDI_META_TEMPO ((BYTE)0x51) // Tempo change 45 #define MIDI_META_EOT ((BYTE)0x2F) // End-of-track 46 47 #define MIDI_NOTEOFF ((BYTE)0x80) // + note + velocity 48 #define MIDI_NOTEON ((BYTE)0x90) // + note + velocity 49 #define MIDI_POLYPRESS ((BYTE)0xA0) // + pressure (2 bytes) 50 #define MIDI_CTRLCHANGE ((BYTE)0xB0) // + ctrlr + value 51 #define MIDI_PRGMCHANGE ((BYTE)0xC0) // + new patch 52 #define MIDI_CHANPRESS ((BYTE)0xD0) // + pressure (1 byte) 53 #define MIDI_PITCHBEND ((BYTE)0xE0) // + pitch bend (2 bytes) 54 55 #define NUM_CHANNELS 16 56 57 #define MIDICTRL_VOLUME ((BYTE)0x07) 58 #define MIDICTRL_VOLUME_LSB ((BYTE)0x27) 59 #define MIDICTRL_PAN ((BYTE)0x0A) 60 61 #define MIDIEVENT_CHANNEL(dw) (dw & 0x0000000F) 62 #define MIDIEVENT_TYPE(dw) (dw & 0x000000F0) 63 #define MIDIEVENT_DATA1(dw) ((dw & 0x0000FF00) >> 8) 64 #define MIDIEVENT_VOLUME(dw) ((dw & 0x007F0000) >> 16) 65 66 // Macros for swapping hi/lo-endian data 67 // 68 #define WORDSWAP(w) (((w) >> 8) | \ 69 (((w) << 8) & 0xFF00)) 70 71 #define DWORDSWAP(dw) (((dw) >> 24) | \ 72 (((dw) >> 8) & 0x0000FF00) | \ 73 (((dw) << 8) & 0x00FF0000) | \ 74 (((dw) << 24) & 0xFF000000)) 75 76 // In debug builds, TRACKERR will show us where the parser died 77 // 78 //#define TRACKERR(p,sz) ShowTrackError(p,sz); 79 #define TRACKERR(p,sz) 80 81 82 // Make a little distinction here so the various structure members are a bit 83 // more clearly labelled -- we have offsets and byte counts to keep track of 84 // that deal with both in-memory buffers and the file on disk 85 86 #define FILEOFF DWORD 87 88 89 // These structures are stored in MIDI files; they need to be byte aligned. 90 // 91 #pragma pack(1) 92 93 // Chunk header. dwTag is either MTrk or MThd. 94 // 95 typedef struct 96 { 97 DWORD dwTag; // Type 98 DWORD dwChunkLength; // Length (hi-lo) 99 } MIDICHUNK; 100 101 // Contents of MThd chunk. 102 typedef struct 103 { 104 WORD wFormat; // Format (hi-lo) 105 WORD wTrackCount; // # tracks (hi-lo) 106 WORD wTimeDivision; // Time division (hi-lo) 107 } MIDIFILEHDR; 108 109 #pragma pack() // End of need for byte-aligned structures 110 111 112 // Temporary event structure which stores event data until we're ready to 113 // dump it into a stream buffer 114 // 115 typedef struct 116 { 117 DWORD tkEvent; // Absolute time of event 118 BYTE byShortData[4]; // Event type and parameters if channel msg 119 DWORD dwEventLength; // Length of data which follows if meta or sysex 120 LPBYTE pLongData; // -> Event data if applicable 121 } TEMPEVENT, *PTEMPEVENT; 122 123 #define ITS_F_ENDOFTRK 0x00000001 124 125 // Description of a track open for read 126 // 127 typedef struct 128 { 129 DWORD fdwTrack; // Track status 130 DWORD dwTrackLength; // Total bytes in track 131 DWORD dwLeftInBuffer; // Bytes left unread in track buffer 132 LPBYTE pTrackStart; // -> start of track data buffer 133 LPBYTE pTrackCurrent; // -> next byte to read in buffer 134 DWORD tkNextEventDue; // Absolute time of next event in track 135 BYTE byRunningStatus;// Running status from last channel msg 136 137 FILEOFF foTrackStart; // Start of track -- used for walking the file 138 FILEOFF foNextReadStart;// File offset of next read from disk 139 DWORD dwLeftOnDisk; // Bytes left unread on disk 140 #ifdef DEBUG 141 DWORD nTrack; // # of this track for debugging 142 #endif 143 } INTRACKSTATE, *PINTRACKSTATE; 144 145 // Description of the input MIDI file 146 // 147 typedef struct 148 { 149 DWORD cbFileLength; // Total bytes in file 150 DWORD dwTimeDivision; // Original time division 151 DWORD dwFormat; // Original format 152 DWORD dwTrackCount; // Track count (specifies pitsTracks size) 153 INTRACKSTATE *pitsTracks; // -> array of tracks in this file 154 } INFILESTATE, *PINFILESTATE; 155 156 #endif // MIDSTUFF_H 157