www.pudn.com > tetris_new.rar > MIDI.H
///////////////////////////////////////////////////////////////////////////// // Copyright (C) 1998 by Jörg König // All rights reserved // // This file is part of the completely free tetris clone "CGTetris". // // This is free software. // You may redistribute it by any means providing it is not sold for profit // without the authors written consent. // // No warrantee of any kind, expressed or implied, is included with this // software; use at your own risk, responsibility for damages (if any) to // anyone resulting from the use of this software rests entirely with the // user. // // Send bug reports, bug fixes, enhancements, requests, flames, etc., and // I'll try to keep a version up to date. I can be reached as follows: // J.Koenig@adg.de (company site) // Joerg.Koenig@rhein-neckar.de (private site) ///////////////////////////////////////////////////////////////////////////// // Midi.h : main header file for the MIDI application // // This class is based on the DirectX sample "mstream". #ifndef MIDI_h #define MIDI_h #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include#pragma message("linking with multimedia library") #pragma comment(lib, "winmm.lib") #include using namespace std; // This message is sent to the controlling window, if the volume changes in // another way than explicitly set by the owner of the CMIDI object. // WPARAM the pointer to the MIDI object // LPARAM lo-word: the number of the channel that changed volume // hi-word: the new volume in percent #define WM_MIDI_VOLUMECHANGED WM_USER+23 #define MIDI_CTRLCHANGE ((BYTE)0xB0) // + ctrlr + value #define MIDI_PRGMCHANGE ((BYTE)0xC0) // + new patch #define MIDI_CHANPRESS ((BYTE)0xD0) // + pressure (1 byte) #define MIDICTRL_VOLUME ((BYTE)0x07) #define MIDIEVENT_CHANNEL(dw) (dw & 0x0000000F) #define MIDIEVENT_TYPE(dw) (dw & 0x000000F0) #define MIDIEVENT_DATA1(dw) ((dw & 0x0000FF00) >> 8) #define MIDIEVENT_VOLUME(dw) ((dw & 0x007F0000) >> 16) #define MIDI_SYSEX ((BYTE)0xF0) // SysEx begin #define MIDI_SYSEXEND ((BYTE)0xF7) // SysEx end #define MIDI_META ((BYTE)0xFF) // Meta event begin #define MIDI_META_TEMPO ((BYTE)0x51) // Tempo change #define MIDI_META_EOT ((BYTE)0x2F) // End-of-track // flags for the ConvertToBuffer() method #define CONVERTF_RESET 0x00000001 #define CONVERTF_STATUS_DONE 0x00000001 #define CONVERTF_STATUS_STUCK 0x00000002 #define CONVERTF_STATUS_GOTEVENT 0x00000004 // Return values from the ConvertToBuffer() method #define CONVERTERR_NOERROR 0 // No error occured #define CONVERTERR_CORRUPT -101 // The input file is corrupt // The converter has already encountered a corrupt file and cannot convert any // more of this file -- must reset the converter #define CONVERTERR_STUCK -102 #define CONVERTERR_DONE -103 // Converter is done #define CONVERTERR_BUFFERFULL -104 // The buffer is full #define CONVERTERR_METASKIP -105 // Skipping unknown meta event #define STATUS_KILLCALLBACK 100 // Signals that the callback should die #define STATUS_CALLBACKDEAD 200 // Signals callback is done processing #define STATUS_WAITINGFOREND 300 // Callback's waiting for buffers to play // Description of a track // struct TRACK { DWORD fdwTrack; // Track's flags DWORD dwTrackLength; // Total bytes in track LPBYTE pTrackStart; // -> start of track data buffer LPBYTE pTrackCurrent; // -> next byte to read in buffer DWORD tkNextEventDue; // Absolute time of next event in track BYTE byRunningStatus;// Running status from last channel msg TRACK() : fdwTrack(0) , dwTrackLength(0) , pTrackStart(0) , pTrackCurrent(0) , tkNextEventDue(0) , byRunningStatus(0) { } }; #define ITS_F_ENDOFTRK 0x00000001 // This structure is used to pass information to the ConvertToBuffer() // system and then internally by that function to send information about the // target stream buffer and current state of the conversion process to internal // lower level conversion routines. struct CONVERTINFO { MIDIHDR mhBuffer; // Standard Windows stream buffer header DWORD dwStartOffset; // Start offset from mhStreamBuffer.lpStart DWORD dwMaxLength; // Max length to convert on this pass DWORD dwBytesRecorded; DWORD tkStart; BOOL bTimesUp; CONVERTINFO() : dwStartOffset(0) , dwMaxLength(0) , dwBytesRecorded(0) , tkStart(0) , bTimesUp(FALSE) { memset(&mhBuffer, 0, sizeof(MIDIHDR)); } }; // Temporary event structure which stores event data until we're ready to // dump it into a stream buffer struct TEMPEVENT { DWORD tkEvent; // Absolute time of event BYTE byShortData[4]; // Event type and parameters if channel msg DWORD dwEventLength; // Length of data which follows if meta or sysex LPBYTE pLongData; // -> Event data if applicable }; class CMIDI { protected: typedef vector