00001 /* 00002 * @(#)util/PowerQuantise.h 3.00 2 April 2000 00003 * 00004 * Copyright (c) 2000 Pete Goodliffe (pete@cthree.org) 00005 * 00006 * This file is part of TSE3 - the Trax Sequencer Engine version 3.00. 00007 * 00008 * This library is modifiable/redistributable under the terms of the GNU 00009 * General Public License. 00010 * 00011 * You should have received a copy of the GNU General Public License along 00012 * with this program; see the file COPYING. If not, write to the Free Software 00013 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00014 * 00015 */ 00016 00017 #ifndef TSE3_UTIL_POWERQUANTISE_H 00018 #define TSE3_UTIL_POWERQUANTISE_H 00019 00020 #include "tse3/Midi.h" 00021 00022 #include <vector> 00023 #include <cstddef> 00024 00025 namespace TSE3 00026 { 00027 class PhraseEdit; 00028 00029 namespace Util 00030 { 00064 class PowerQuantise 00065 { 00066 public: 00067 00072 PowerQuantise(); 00073 00081 class Pattern 00082 { 00083 public: 00084 00088 Pattern(); 00089 00098 TSE3::Clock length() const { return _length; } 00099 00105 void setLength(TSE3::Clock length); 00106 00110 size_t size() const { return points.size(); } 00111 00115 TSE3::Clock const &operator[](size_t n) const 00116 { 00117 return points[n]; 00118 } 00119 00123 void insert(TSE3::Clock point); 00124 00128 void erase(size_t n); 00129 00133 void erase(TSE3::Clock point); 00134 00135 private: 00136 00137 std::vector<TSE3::Clock> points; 00138 TSE3::Clock _length; 00139 }; 00140 00141 Pattern &pattern() { return _pattern; } 00142 00154 int by() const { return _by; } 00155 00161 void setBy(int by); 00162 00172 int window() const { return _window; } 00173 00179 void setWindow(int window); 00180 00189 bool onlySelected() const { return _onlySelected; } 00190 00196 void setOnlySelected(bool s); 00197 00205 bool onlyNotes() const { return _onlyNotes; } 00206 00212 void setOnlyNotes(bool n); 00213 00230 bool spreadCtrl() const { return _spreadCtrl; } 00231 00237 void setSpreadCtrl(bool s); 00238 00239 enum Direction 00240 { 00241 nearest, 00242 backwards, 00243 forwards 00244 }; 00245 00253 Direction direction() const { return _direction; } 00254 00260 void setDirection(Direction d); 00261 00262 enum Length 00263 { 00264 quantiseOffTime, 00265 quantiseLength 00266 }; 00267 00280 Length length() const { return _length; } 00281 00287 void setLength(Length l); 00288 00296 int lengthBy() const { return _lengthBy; } 00297 00303 void setLengthBy(int by); 00304 00319 TSE3::Clock humanise() const { return _humanise; } 00320 00326 void setHumanise(TSE3::Clock h); 00327 00335 TSE3::Clock lengthHumanise() const { return _lengthHumanise; } 00336 00342 void setLengthHumanise(TSE3::Clock h); 00343 00347 void go(TSE3::PhraseEdit *phraseEdit); 00348 00349 private: 00350 00355 bool shouldBeQuantised(TSE3::MidiEvent e) 00356 { 00357 using namespace TSE3; 00358 return (!_onlyNotes || e.data.status == MidiCommand_NoteOn) 00359 && (!_onlySelected || e.data.selected) 00360 && !shouldBeSpread(e); 00361 } 00362 00367 bool shouldBeSpread(TSE3::MidiEvent e) 00368 { 00369 return (_spreadCtrl && isContinuous(e)) 00370 && (!_onlySelected || e.data.selected); 00371 } 00372 00377 bool isContinuous(TSE3::MidiEvent e) 00378 { 00379 using namespace TSE3; 00380 bool b = false; 00381 switch (e.data.status) 00382 { 00383 case MidiCommand_KeyPressure: 00384 case MidiCommand_ControlChange: 00385 case MidiCommand_ChannelPressure: 00386 case MidiCommand_PitchBend: 00387 b = true; 00388 } 00389 return b; 00390 } 00391 00396 TSE3::Clock quantise(TSE3::Clock time, int percentage); 00397 00402 TSE3::Clock humanise(TSE3::Clock time, 00403 TSE3::Clock maxVal); 00404 00413 TSE3::Clock spreadContinuous( 00414 TSE3::PhraseEdit *phraseEdit, 00415 size_t pos, 00416 TSE3::Clock lastNonCont_Original, 00417 TSE3::Clock lastNonCont_Quantised); 00418 00419 Pattern _pattern; 00420 int _by; 00421 int _window; 00422 bool _onlySelected; 00423 bool _onlyNotes; 00424 bool _spreadCtrl; 00425 Direction _direction; 00426 Length _length; 00427 int _lengthBy; 00428 TSE3::Clock _humanise; 00429 TSE3::Clock _lengthHumanise; 00430 }; 00431 } 00432 } 00433 00434 #endif