![]() |
Mixxx
|
00001 // loopingcontrol.h 00002 // Created on Sep 23, 2008 00003 // Author: asantoni, rryan 00004 00005 #ifndef LOOPINGCONTROL_H 00006 #define LOOPINGCONTROL_H 00007 00008 #include <QObject> 00009 00010 #include "configobject.h" 00011 #include "engine/enginecontrol.h" 00012 #include "trackinfoobject.h" 00013 #include "track/beats.h" 00014 00015 #define MINIMUM_AUDIBLE_LOOP_SIZE 30 // In samples 00016 00017 class ControlPushButton; 00018 class ControlObject; 00019 00020 class BeatLoopingControl; 00021 00022 class LoopingControl : public EngineControl { 00023 Q_OBJECT 00024 public: 00025 LoopingControl(const char * _group, ConfigObject<ConfigValue> * _config); 00026 virtual ~LoopingControl(); 00027 00028 // process() updates the internal state of the LoopingControl to reflect the 00029 // correct current sample. If a loop should be taken LoopingControl returns 00030 // the sample that should be seeked to. Otherwise it returns currentSample. 00031 double process(const double dRate, 00032 const double currentSample, 00033 const double totalSamples, 00034 const int iBufferSize); 00035 00036 // nextTrigger returns the sample at which the engine will be triggered to 00037 // take a loop, given the value of currentSample and dRate. 00038 double nextTrigger(const double dRate, 00039 const double currentSample, 00040 const double totalSamples, 00041 const int iBufferSize); 00042 00043 // getTrigger returns the sample that the engine will next be triggered to 00044 // loop to, given the value of currentSample and dRate. 00045 double getTrigger(const double dRate, 00046 const double currentSample, 00047 const double totalSamples, 00048 const int iBufferSize); 00049 00050 // hintReader will add to hintList hints both the loop in and loop out 00051 // sample, if set. 00052 void hintReader(QList<Hint>& hintList); 00053 00054 void notifySeek(double dNewPlaypos); 00055 00056 public slots: 00057 void slotLoopIn(double); 00058 void slotLoopOut(double); 00059 void slotReloopExit(double); 00060 void slotLoopStartPos(double); 00061 void slotLoopEndPos(double); 00062 virtual void trackLoaded(TrackPointer pTrack); 00063 virtual void trackUnloaded(TrackPointer pTrack); 00064 void slotUpdatedTrackBeats(); 00065 00066 // Generate a loop of 'beats' length. It can also do fractions for a 00067 // beatslicing effect. 00068 void slotBeatLoop(double loopSize, bool keepStartPoint=false); 00069 void slotBeatLoopActivate(BeatLoopingControl* pBeatLoopControl); 00070 void slotBeatLoopDeactivate(BeatLoopingControl* pBeatLoopControl); 00071 00072 void slotLoopScale(double); 00073 void slotLoopDouble(double); 00074 void slotLoopHalve(double); 00075 00076 private: 00077 void setLoopingEnabled(bool enabled); 00078 void clearActiveBeatLoop(); 00079 00080 ControlObject* m_pCOLoopStartPosition; 00081 ControlObject* m_pCOLoopEndPosition; 00082 ControlObject* m_pCOLoopEnabled; 00083 ControlPushButton* m_pLoopInButton; 00084 ControlPushButton* m_pLoopOutButton; 00085 ControlPushButton* m_pReloopExitButton; 00086 ControlObject* m_pCOLoopScale; 00087 ControlPushButton* m_pLoopHalveButton; 00088 ControlPushButton* m_pLoopDoubleButton; 00089 00090 bool m_bLoopingEnabled; 00091 int m_iLoopEndSample; 00092 int m_iLoopStartSample; 00093 int m_iCurrentSample; 00094 ControlObject* m_pQuantizeEnabled; 00095 ControlObject* m_pNextBeat; 00096 ControlObject* m_pClosestBeat; 00097 ControlObject* m_pTrackSamples; 00098 BeatLoopingControl* m_pActiveBeatLoop; 00099 00100 // Base BeatLoop Control Object. 00101 ControlObject* m_pCOBeatLoop; 00102 // Different sizes for Beat Loops/Seeks. 00103 static double s_dBeatSizes[]; 00104 // Array of BeatLoopingControls, one for each size. 00105 QList<BeatLoopingControl*> m_beatLoops; 00106 00107 TrackPointer m_pTrack; 00108 BeatsPointer m_pBeats; 00109 }; 00110 00111 // Class for handling beat loops of a set size. This allows easy access from 00112 // skins. 00113 class BeatLoopingControl : public QObject { 00114 Q_OBJECT 00115 public: 00116 BeatLoopingControl(const char* pGroup, double size); 00117 virtual ~BeatLoopingControl(); 00118 00119 void activate(); 00120 void deactivate(); 00121 inline double getSize() { 00122 return m_dBeatLoopSize; 00123 } 00124 public slots: 00125 void slotLegacy(double value); 00126 void slotActivate(double value); 00127 void slotToggle(double value); 00128 00129 signals: 00130 void activateBeatLoop(BeatLoopingControl*); 00131 void deactivateBeatLoop(BeatLoopingControl*); 00132 00133 private: 00134 // Used simply to generate the beatloop_%SIZE and beatseek_%SIZE CO 00135 // ConfigKeys. 00136 ConfigKey keyForControl(const char * _group, QString ctrlName, double num); 00137 double m_dBeatLoopSize; 00138 bool m_bActive; 00139 ControlPushButton* m_pLegacy; 00140 ControlPushButton* m_pActivate; 00141 ControlPushButton* m_pToggle; 00142 ControlObject* m_pEnabled; 00143 }; 00144 00145 #endif /* LOOPINGCONTROL_H */