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 XMIDISEQUENCE_H_INCLUDED 00020 #define XMIDISEQUENCE_H_INCLUDED 00021 00022 #include "XMidiSequenceHandler.h" 00023 #include "XMidiEvent.h" 00024 #include "XMidiEventList.h" 00025 #include "XMidiNoteStack.h" 00026 00027 class XMidiSequence 00028 { 00029 public: 00030 00038 XMidiSequence(XMidiSequenceHandler *handler, uint16 sequence_id, XMidiEventList *events, 00039 bool repeat, int volume, int branch); 00040 00042 ~XMidiSequence(); 00043 00048 int playEvent(); 00049 00052 sint32 timeTillNext(); 00053 00056 void setVolume(int new_vol); 00057 00060 int getVolume() { return vol_multi; } 00061 00064 void setSpeed(int new_speed) { speed = new_speed; } 00065 00069 void loseChannel(int c); 00070 00074 void gainChannel(int c); 00075 00078 void applyShadow(int c); 00079 00082 uint16 getChanMask() { return evntlist->chan_mask; } 00083 00085 void pause(); 00086 00088 void unpause(); 00089 00091 bool isPaused() { return paused; } 00092 00096 int countNotesOn(int chan); 00097 00098 private: 00099 00100 XMidiSequenceHandler *handler; 00101 uint16 sequence_id; 00102 XMidiEventList *evntlist; 00103 XMidiEvent *event; 00104 bool repeat; 00105 XMidiNoteStack notes_on; 00106 uint32 last_tick; 00107 uint32 start; 00108 int loop_num; 00109 int vol_multi; 00110 bool paused; 00111 int speed; 00112 00114 XMidiEvent * loop_event[XMIDI_MAX_FOR_LOOP_COUNT]; 00115 00117 int loop_count[XMIDI_MAX_FOR_LOOP_COUNT]; 00118 00119 struct ChannelShadow { 00120 static const uint16 centre_value; 00121 static const uint8 fine_value; 00122 static const uint8 coarse_value; 00123 static const uint16 combined_value; 00124 00125 int pitchWheel; 00126 int program; 00127 00128 // Controllers 00129 int bank[2]; // 0 00130 int modWheel[2]; // 1 00131 int footpedal[2]; // 4 00132 int volumes[2]; // 7 00133 int pan[2]; // 9 00134 int balance[2]; // 10 00135 int expression[2]; // 11 00136 int sustain; // 64 00137 int effects; // 91 00138 int chorus; // 93 00139 00140 int xbank; 00141 void reset(); 00142 } shadows[16]; 00143 00145 void sendEvent(); 00146 00148 void updateShadowForEvent(XMidiEvent *event); 00149 00151 inline void initClock () 00152 { start = handler->getTickCount(sequence_id)+24; } 00153 00155 inline void addOffset (uint32 offset) 00156 { start += offset; } 00157 00159 inline uint32 getTime () 00160 { return handler->getTickCount(sequence_id) - start; } 00161 00163 inline uint32 getStart () 00164 { return start; } 00165 00167 inline uint32 getRealTime () 00168 { return handler->getTickCount(sequence_id); } 00169 }; 00170 00171 #endif //XMIDISEQUENCE_H_INCLUDED