1 #pragma once
2 
3 #include <QObject>
4 
5 #include "preferences/usersettings.h"
6 #include "engine/controls/enginecontrol.h"
7 #include "engine/sync/syncable.h"
8 
9 class BpmControl;
10 class Rotary;
11 class ControlTTRotary;
12 class ControlObject;
13 class ControlPotmeter;
14 class ControlPushButton;
15 class ControlProxy;
16 class EngineChannel;
17 class PositionScratchController;
18 
19 // RateControl is an EngineControl that is in charge of managing the rate of
20 // playback of a given channel of audio in the Mixxx engine. Using input from
21 // various controls, RateControl will calculate the current rate.
22 class RateControl : public EngineControl {
23     Q_OBJECT
24 public:
25   RateControl(const QString& group, UserSettingsPointer pConfig);
26   ~RateControl() override;
27 
28   // Enumerations which hold the state of the pitchbend buttons.
29   // These enumerations can be used like a bitmask.
30   enum class RampDirection {
31       None,      // No buttons are held down
32       Down,      // Down button is being held
33       Up,        // Up button is being held
34       DownSmall, // DownSmall button is being held
35       UpSmall,   // UpSmall button is being held
36   };
37 
38   enum class RampMode {
39       Stepping = 0, // pitch takes a temporary step up/down a certain amount
40       Linear = 1    // pitch moves up/down in a progressively linear fashion
41   };
42 
43   void setBpmControl(BpmControl* bpmcontrol);
44 
45   // Returns the current engine rate.  "reportScratching" is used to tell
46   // the caller that the user is currently scratching, and this is used to
47   // disable keylock.
48   double calculateSpeed(
49           double baserate,
50           double speed,
51           bool paused,
52           int iSamplesPerBuffer,
53           bool* pReportScratching,
54           bool* pReportReverse);
55 
56   // Set rate change when temp rate button is pressed
57   static void setTemporaryRateChangeCoarseAmount(double v);
58   static double getTemporaryRateChangeCoarseAmount();
59   // Set rate change when temp rate small button is pressed
60   static void setTemporaryRateChangeFineAmount(double v);
61   static double getTemporaryRateChangeFineAmount();
62   // Set rate change when perm rate button is pressed
63   static void setPermanentRateChangeCoarseAmount(double v);
64   static double getPermanentRateChangeCoarseAmount();
65   // Set rate change when perm rate small button is pressed
66   static void setPermanentRateChangeFineAmount(double v);
67   static double getPermanentRateChangeFineAmount();
68   // Set Rate Ramp Mode
69   static void setRateRampMode(RampMode mode);
70   static RampMode getRateRampMode();
71   // Set Rate Ramp Sensitivity
72   static void setRateRampSensitivity(int);
73   static int getRateRampSensitivity();
74   void notifySeek(double dNewPlaypos) override;
75   bool isReverseButtonPressed();
76 
77 public slots:
78   void slotRateRangeChanged(double);
79   void slotRateSliderChanged(double);
80   void slotRateRatioChanged(double);
81   void slotReverseRollActivate(double);
82   void slotControlRatePermDown(double);
83   void slotControlRatePermDownSmall(double);
84   void slotControlRatePermUp(double);
85   void slotControlRatePermUpSmall(double);
86   void slotControlFastForward(double);
87   void slotControlFastBack(double);
88 
89 private:
90   void processTempRate(const int bufferSamples);
91   double getJogFactor() const;
92   double getWheelFactor() const;
93   SyncMode getSyncMode() const;
94 
95   // Set rate change of the temporary pitch rate
96   void setRateTemp(double v);
97   // Add a value to the temporary pitch rate
98   void addRateTemp(double v);
99   // Subtract a value from the temporary pitch rate
100   void subRateTemp(double v);
101   // Reset the temporary pitch rate
102   void resetRateTemp(void);
103   // Get the 'Raw' Temp Rate
104   double getTempRate(void);
105 
106   // Values used when temp and perm rate buttons are pressed
107   static ControlValueAtomic<double> m_dTemporaryRateChangeCoarse;
108   static ControlValueAtomic<double> m_dTemporaryRateChangeFine;
109   static ControlValueAtomic<double> m_dPermanentRateChangeCoarse;
110   static ControlValueAtomic<double> m_dPermanentRateChangeFine;
111 
112   ControlPushButton* m_pButtonRateTempDown;
113   ControlPushButton* m_pButtonRateTempDownSmall;
114   ControlPushButton* m_pButtonRateTempUp;
115   ControlPushButton* m_pButtonRateTempUpSmall;
116 
117   ControlPushButton* m_pButtonRatePermDown;
118   ControlPushButton* m_pButtonRatePermDownSmall;
119   ControlPushButton* m_pButtonRatePermUp;
120   ControlPushButton* m_pButtonRatePermUpSmall;
121 
122   ControlObject* m_pRateRatio;
123   ControlObject* m_pRateDir;
124   ControlObject* m_pRateRange;
125   ControlPotmeter* m_pRateSlider;
126   ControlPotmeter* m_pRateSearch;
127   ControlPushButton* m_pReverseButton;
128   ControlPushButton* m_pReverseRollButton;
129   ControlObject* m_pBackButton;
130   ControlObject* m_pForwardButton;
131 
132   ControlTTRotary* m_pWheel;
133   ControlObject* m_pScratch2;
134   PositionScratchController* m_pScratchController;
135 
136   ControlPushButton* m_pScratch2Enable;
137   ControlObject* m_pJog;
138   ControlObject* m_pVCEnabled;
139   ControlObject* m_pVCScratching;
140   ControlObject* m_pVCMode;
141   ControlObject* m_pScratch2Scratching;
142   Rotary* m_pJogFilter;
143 
144   ControlObject* m_pSampleRate;
145 
146   // For Master Sync
147   BpmControl* m_pBpmControl;
148 
149   ControlProxy* m_pSyncMode;
150   ControlProxy* m_pSlipEnabled;
151 
152   // This is true if we've already started to ramp the rate
153   bool m_bTempStarted;
154   // Set the Temporary Rate Change Mode
155   static RampMode m_eRateRampMode;
156   // The Rate Temp Sensitivity, the higher it is the slower it gets
157   static int m_iRateRampSensitivity;
158   // Factor applied to the deprecated "wheel" rate value.
159   static const double kWheelMultiplier;
160   // Factor applied to jogwheels when the track is paused to speed up seeking.
161   static const double kPausedJogMultiplier;
162   // Temporary pitchrate, added to the permanent rate for calculateRate
163   double m_tempRateRatio;
164   // Speed for temporary rate change
165   double m_dRateTempRampChange;
166 };
167