XMidiEvent.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003  The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef XMIDIEVENT_H_INCLUDED
00020 #define XMIDIEVENT_H_INCLUDED
00021 
00022 // Midi Status Bytes
00023 #define MIDI_STATUS_NOTE_OFF    0x8
00024 #define MIDI_STATUS_NOTE_ON             0x9
00025 #define MIDI_STATUS_AFTERTOUCH  0xA
00026 #define MIDI_STATUS_CONTROLLER  0xB
00027 #define MIDI_STATUS_PROG_CHANGE 0xC
00028 #define MIDI_STATUS_PRESSURE    0xD
00029 #define MIDI_STATUS_PITCH_WHEEL 0xE
00030 #define MIDI_STATUS_SYSEX               0xF
00031 
00032 //
00033 // XMidiFile Controllers
00034 //
00035 
00036 //
00037 // Channel Lock (110)
00038 //  < 64 : Release Lock
00039 // >= 64 : Lock an unlocked unprotected physical channel to be used exclusively
00040 //         by this logical channel. Traditionally the physical channel would be
00041 //         bettween 1 and 9, and the logical channel between 11 and 16
00042 //
00043 // When a channel is locked, any notes already playing on it are turned off. 
00044 // When the lock is released, the previous state of the channel is restored.
00045 // Locks are automatically released when the sequences finishes playing
00046 //
00047 #define XMIDI_CONTROLLER_CHAN_LOCK                      0x6e    
00048 
00049 #define XMIDI_CONTROLLER_CHAN_LOCK_PROT         0x6f    // Channel Lock Protect
00050 #define XMIDI_CONTROLLER_VOICE_PROT                     0x70    // Voice Protect
00051 #define XMIDI_CONTROLLER_TIMBRE_PROT            0x71    // Timbre Protect
00052 #define XMIDI_CONTROLLER_BANK_CHANGE            0x72    // Bank Change
00053 #define XMIDI_CONTROLLER_IND_CTRL_PREFIX        0x73    // Indirect Controller Prefix
00054 #define XMIDI_CONTROLLER_FOR_LOOP                       0x74    // For Loop
00055 #define XMIDI_CONTROLLER_NEXT_BREAK                     0x75    // Next/Break
00056 #define XMIDI_CONTROLLER_CLEAR_BB_COUNT         0x76    // Clear Beat/Bar Count
00057 #define XMIDI_CONTROLLER_CALLBACK_TRIG          0x77    // Callback Trigger
00058 #define XMIDI_CONTROLLER_SEQ_BRANCH_INDEX       0x78    // Sequence Branch Index
00059 
00060 
00061 // Maximum number of for loops we'll allow (used by LowLevelMidiDriver)
00062 // The specs say 4, so that is what we;ll use
00063 #define XMIDI_MAX_FOR_LOOP_COUNT        4
00064 
00065 struct XMidiEvent
00066 {
00067         int                             time;
00068         unsigned char   status;
00069 
00070         unsigned char   data[2];
00071 
00072         union 
00073         {
00074                 struct {
00075                         uint32                  len;                    // Length of SysEx Data
00076                         unsigned char   *buffer;                // SysEx Data
00077                 } sysex_data;
00078 
00079                 struct {
00080                         int                             duration;               // Duration of note (120 Hz)
00081                         XMidiEvent              *next_note;             // The next note on the stack
00082                         uint32                  note_time;              // Time note stops playing (6000th of second)
00083                         uint8                   actualvel;              // Actual velocity of playing note
00084                 } note_on;
00085 
00086                 struct {
00087                         XMidiEvent              *next_branch;   // Next branch index contoller
00088                 } branch_index;
00089 
00090         } ex;
00091 
00092         XMidiEvent              *next;
00093 
00094 
00095         // Here's a bit of joy: WIN32 isn't SMP safe if we use operator new and 
00096         // delete. On the other hand, nothing else is thread-safe if we use 
00097         // malloc()/free(). So, we wrap the implementations and use 
00098         // malloc()/calloc()/free() for WIN32, and the C++ thread-safe allocator 
00099         // for other platforms.
00100 
00101         template<class T>
00102         static inline T* Malloc(size_t num=1)
00103         {
00104         #ifdef WIN32
00105                 return static_cast<T*>(std::malloc(num));
00106         #else
00107                 return static_cast<T*>(::operator new(num));
00108         #endif
00109         }
00110 
00111         template<class T>
00112         static inline T* Calloc(size_t num=1,size_t sz=0)
00113         {
00114                 if(!sz)
00115                         sz=sizeof(T);
00116         #ifdef WIN32
00117                 return static_cast<T*>(std::calloc(num,sz));
00118         #else
00119                 size_t  total=sz*num;
00120                 T *tmp=Malloc<T>(total);
00121                 std::memset(tmp,0,total);
00122                 return tmp;
00123         #endif
00124         }
00125 
00126         static inline void      Free(void *ptr)
00127         {
00128         #ifdef WIN32
00129                 std::free(ptr);
00130         #else
00131                 ::operator delete(ptr);
00132         #endif
00133         }
00134 };
00135 
00136 #endif //XMIDIEVENT_H_INCLUDED

Generated on Fri Jul 27 22:27:54 2007 for pentagram by  doxygen 1.4.7