Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/engine/ratecontrol.h

Go to the documentation of this file.
00001 // ratecontrol.h
00002 // Created 7/4/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #ifndef RATECONTROL_H
00005 #define RATECONTROL_H
00006 
00007 #include <QObject>
00008 
00009 #include "configobject.h"
00010 #include "engine/enginecontrol.h"
00011 
00012 const int RATE_TEMP_STEP = 500;
00013 const int RATE_TEMP_STEP_SMALL = RATE_TEMP_STEP * 10.;
00014 const int RATE_SENSITIVITY_MIN = 100;
00015 const int RATE_SENSITIVITY_MAX = 2500;
00016 
00017 class Rotary;
00018 class ControlTTRotary;
00019 class ControlObject;
00020 class ControlPotmeter;
00021 class ControlPushButton;
00022 class PositionScratchController;
00023 
00024 // RateControl is an EngineControl that is in charge of managing the rate of
00025 // playback of a given channel of audio in the Mixxx engine. Using input from
00026 // various controls, RateControl will calculate the current rate.
00027 class RateControl : public EngineControl {
00028     Q_OBJECT
00029 public:
00030     RateControl(const char* _group, ConfigObject<ConfigValue>* _config);
00031     virtual ~RateControl();
00032 
00033     // Must be called during each callback of the audio thread so that
00034     // RateControl has a chance to update itself.
00035     double process(const double dRate,
00036                    const double currentSample,
00037                    const double totalSamples,
00038                    const int bufferSamples);
00039     // Returns the current engine rate.
00040     double calculateRate(double baserate, bool paused, int iSamplesPerBuffer, bool* isScratching);
00041     double getRawRate();
00042 
00043     // Set rate change when temp rate button is pressed
00044     static void setTemp(double v);
00045     // Set rate change when temp rate small button is pressed
00046     static void setTempSmall(double v);
00047     // Set rate change when perm rate button is pressed
00048     static void setPerm(double v);
00049     // Set rate change when perm rate small button is pressed
00050     static void setPermSmall(double v);
00052     static void setRateRamp(bool);
00054     static void setRateRampSensitivity(int);
00055     virtual void notifySeek(double dNewPlaypos);
00056 
00057   public slots:
00058     void slotControlRatePermDown(double);
00059     void slotControlRatePermDownSmall(double);
00060     void slotControlRatePermUp(double);
00061     void slotControlRatePermUpSmall(double);
00062     void slotControlRateTempDown(double);
00063     void slotControlRateTempDownSmall(double);
00064     void slotControlRateTempUp(double);
00065     void slotControlRateTempUpSmall(double);
00066     void slotControlFastForward(double);
00067     void slotControlFastBack(double);
00068     void slotControlVinyl(double);
00069 
00070   private:
00071     double getJogFactor();
00072     double getWheelFactor();
00073 
00075     void setRateTemp(double v);
00077     void addRateTemp(double v);
00079     void subRateTemp(double v);
00081     void resetRateTemp(void);
00083     double getTempRate(void);
00085     bool m_bVinylControlEnabled;
00086 
00088     static double m_dTemp, m_dTempSmall, m_dPerm, m_dPermSmall;
00089 
00090     ControlPushButton *buttonRateTempDown, *buttonRateTempDownSmall,
00091         *buttonRateTempUp, *buttonRateTempUpSmall;
00092     ControlPushButton *buttonRatePermDown, *buttonRatePermDownSmall,
00093         *buttonRatePermUp, *buttonRatePermUpSmall;
00094     ControlObject *m_pRateDir, *m_pRateRange;
00095     ControlPotmeter* m_pRateSlider;
00096     ControlPotmeter* m_pRateSearch;
00097     ControlPushButton* m_pReverseButton;
00098     ControlObject* m_pBackButton;
00099     ControlObject* m_pForwardButton;
00100 
00101     ControlTTRotary* m_pWheel;
00102     ControlTTRotary* m_pScratch;
00103     ControlTTRotary* m_pOldScratch;
00104     PositionScratchController* m_pScratchController;
00105 
00106     ControlPushButton* m_pScratchToggle;
00107     ControlObject* m_pJog;
00108     Rotary* m_pJogFilter;
00109 
00110     ControlObject *m_pSampleRate;
00111 
00112     // Enumerations which hold the state of the pitchbend buttons.
00113     // These enumerations can be used like a bitmask.
00114     enum RATERAMP_DIRECTION {
00115         RATERAMP_NONE = 0,      // No buttons are held down
00116         RATERAMP_DOWN = 1,      // Down button is being held
00117         RATERAMP_UP = 2,        // Up button is being held
00118         RATERAMP_BOTH = 3       // Both buttons are being held down
00119     };
00120 
00121     // Rate ramping mode:
00122     //  RATERAMP_STEP: pitch takes a temporary step up/down a certain amount.
00123     //  RATERAMP_LINEAR: pitch moves up/down in a progresively linear fashion.
00124     enum RATERAMP_MODE {
00125         RATERAMP_STEP = 0,
00126         RATERAMP_LINEAR = 1
00127     };
00128 
00129     // This defines how the rate returns to normal. Currently unused.
00130     // Rate ramp back mode:
00131     //  RATERAMP_RAMPBACK_NONE: returns back to normal all at once.
00132     //  RATERAMP_RAMPBACK_SPEED: moves back in a linearly progresive manner.
00133     //  RATERAMP_RAMPBACK_PERIOD: returns to normal within a period of time.
00134     enum RATERAMP_RAMPBACK_MODE {
00135         RATERAMP_RAMPBACK_NONE,
00136         RATERAMP_RAMPBACK_SPEED,
00137         RATERAMP_RAMPBACK_PERIOD
00138     };
00139 
00140     // The current rate ramping direction. Only holds the last button pressed.
00141     int m_ePbCurrent;
00142     //  The rate ramping buttons which are currently being pressed.
00143     int m_ePbPressed;
00144 
00146     int m_bTempStarted;
00148     double m_dTempRateChange;
00150     static enum RATERAMP_MODE m_eRateRampMode;
00152     static int m_iRateRampSensitivity;
00154     double m_dRateTemp;
00156     enum RATERAMP_RAMPBACK_MODE m_eRampBackMode;
00158     double m_dRateTempRampbackChange;
00159 
00165     double m_dOldRate;
00166 
00167 
00169     ConfigObject<ConfigValue>* m_pConfig;
00170 };
00171 
00172 #endif /* RATECONTROL_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines