Audacity  3.0.3
Scrubbing.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 Scrubbing.h
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_SCRUBBING__
12 #define __AUDACITY_SCRUBBING__
13 
14 
15 
16 #include <vector>
17 #include <wx/longlong.h>
18 
19 #include "../../ScrubState.h" // for ScrubbingOptions
20 #include "ClientData.h" // to inherit
21 #include "Prefs.h" // to inherit
22 #include "../../widgets/Overlay.h" // to inherit
23 #include "../../commands/CommandContext.h"
24 #include "../../commands/CommandManager.h" // for MenuTable
25 #include "Identifier.h"
26 
27 class AudacityProject;
28 class TranslatableString;
29 
30 // Conditionally compile either a separate thead, or else use a timer in the main
31 // thread, to poll the mouse and update scrubbing speed and direction. The advantage of
32 // a thread may be immunity to choppy scrubbing in case redrawing takes too much time.
33 #ifdef __WXGTK__
34 // Unfortunately some things the thread needs to do are not thread safe
35 #else
36 #define USE_SCRUB_THREAD
37 #endif
38 
39 // Scrub state object
40 class AUDACITY_DLL_API Scrubber final
41  : public wxEvtHandler
42  , public ClientData::Base
43  , private PrefsListener
44  , public std::enable_shared_from_this< Scrubber >
45 {
46 public:
47  static Scrubber &Get( AudacityProject &project );
48  static const Scrubber &Get( const AudacityProject &project );
49 
50  explicit
51  Scrubber(AudacityProject *project);
52  Scrubber( const Scrubber & ) PROHIBITED;
53  Scrubber &operator=( const Scrubber & ) PROHIBITED;
54  ~Scrubber();
55 
56  static bool ShouldScrubPinned();
57 
58  // Assume xx is relative to the left edge of TrackPanel!
59  void MarkScrubStart(wxCoord xx, bool smoothScrolling, bool seek);
60 
61  // Returns true iff the event should be considered consumed by this:
62  // Assume xx is relative to the left edge of TrackPanel!
63  bool MaybeStartScrubbing(wxCoord xx);
64  bool StartSpeedPlay(double speed, double time0, double time1);
65  bool StartKeyboardScrubbing(double time0, bool backwards);
67 
70 
71  // This is meant to be called only from ProjectAudioManager
72  void StopScrubbing();
73 
74  wxCoord GetScrubStartPosition() const
75  { return mScrubStartPosition; }
76 
77  bool WasSpeedPlaying() const
78  { return mSpeedPlaying;}
79  bool IsSpeedPlaying() const
80  { return IsScrubbing() && mSpeedPlaying; }
81  bool WasKeyboardScrubbing() const
82  { return mKeyboardScrubbing; }
83  bool IsKeyboardScrubbing() const
84  { return IsScrubbing() && mKeyboardScrubbing; }
85  void SetBackwards(bool backwards)
86  { mBackwards = backwards;}
87  bool IsBackwards() const
88  { return mBackwards;}
89  // True iff the user has clicked to start scrub and not yet stopped,
90  // but IsScrubbing() may yet be false
91  bool HasMark() const
92  { return GetScrubStartPosition() >= 0; }
93  bool IsScrubbing() const;
94 
95  bool IsScrollScrubbing() const // If true, implies HasMark()
96  { return mSmoothScrollingScrub; }
97  void SetScrollScrubbing(bool value)
98  { mSmoothScrollingScrub = value; }
99 
100  bool ChoseSeeking() const;
101  void SetMayDragToSeek( bool value ) { mMayDragToSeek = value; }
102  bool MayDragToSeek() const { return mMayDragToSeek; }
103  bool TemporarilySeeks() const;
104  bool Seeks() const;
105  bool Scrubs() const;
106  bool ShowsBar() const;
107 
108  void Cancel()
109  { mCancelled = true; }
110 
112  double FindScrubSpeed(bool seeking, double time) const;
113  double GetMaxScrubSpeed() const { return mOptions.maxSpeed; }
114 
115  void HandleScrollWheel(int steps);
116 
117  // This returns the same as the enabled state of the menu items:
118  bool CanScrub() const;
119 
120  // For popup
121  void PopulatePopupMenu(wxMenu &menu);
122 
123  void OnScrubOrSeek(bool seek);
124  void OnScrub(const CommandContext&);
125  void OnSeek(const CommandContext&);
127 
130  void DoKeyboardScrub(bool backwards, bool keyUp);
131 
132  // Convenience wrapper for the above
133  template<void (Scrubber::*pfn)(const CommandContext&)>
134  void Thunk(wxCommandEvent &)
135  { (this->*pfn)(*mProject); }
136 
137  // A string to put in the leftmost part of the status bar
138  // when scrub or seek is in progress, or else empty.
140  wxString StatusMessageForWave() const;
141 
142  void Pause(bool paused);
143  bool IsPaused() const;
145 
146  bool IsTransportingPinned() const;
147 
148  void SetSeekPress( bool value ) { mScrubSeekPress = value; }
149 
150 private:
151  void UpdatePrefs() override;
152 
153  void StartPolling();
154  void StopPolling();
155  void DoScrub(bool seek);
156  void OnActivateOrDeactivateApp(wxActivateEvent & event);
157 
158 private:
162  wxCoord mLastScrubPosition {};
163  bool mScrubSeekPress {};
165 
166  bool mPaused{};
167  bool mSeeking {};
168  bool mSpeedPlaying{true};
169  bool mKeyboardScrubbing{};
170  bool mBackwards{};
171  bool mDragging {};
172 
173  bool mCancelled {};
174 
175 #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
176  int mLogMaxScrubSpeed;
177 #endif
178 
180 
181  DECLARE_EVENT_TABLE()
182 
183 #ifdef USE_SCRUB_THREAD
184  // Course corrections in playback are done in a helper thread, unhindered by
185  // the complications of the main event dispatch loop
186  class ScrubPollerThread;
187  ScrubPollerThread *mpThread {};
188 #endif
189 
190  // Other periodic update of the UI must be done in the main thread,
191  // by this object which is driven by timer events.
192  class ScrubPoller;
193  std::unique_ptr<ScrubPoller> mPoller;
194 
196  double mMaxSpeed { 1.0 };
197 
198  bool mShowScrubbing { false };
199  bool mMayDragToSeek{ false };
200 };
201 
202 #endif
Scrubber::DoKeyboardScrub
void DoKeyboardScrub(bool backwards, bool keyUp)
Scrubber::StartSpeedPlay
bool StartSpeedPlay(double speed, double time0, double time1)
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
Scrubber::OnScrub
void OnScrub(const CommandContext &)
Scrubber::IsTransportingPinned
bool IsTransportingPinned() const
ScrubbingOptions
Definition: ScrubState.h:18
Scrubber::Thunk
void Thunk(wxCommandEvent &)
Definition: Scrubbing.h:134
Scrubber::Cancel
void Cancel()
Definition: Scrubbing.h:108
Scrubber::DoScrub
void DoScrub(bool seek)
Scrubber::MaybeStartScrubbing
bool MaybeStartScrubbing(wxCoord xx)
Scrubber::OnToggleScrubRuler
void OnToggleScrubRuler(const CommandContext &)
Scrubber::mProject
AudacityProject * mProject
Definition: Scrubbing.h:179
Scrubber::StartKeyboardScrubbing
bool StartKeyboardScrubbing(double time0, bool backwards)
Scrubber::Scrubs
bool Scrubs() const
Scrubber::MayDragToSeek
bool MayDragToSeek() const
Definition: Scrubbing.h:102
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
Scrubber::Seeks
bool Seeks() const
Scrubber::mOptions
ScrubbingOptions mOptions
Definition: Scrubbing.h:195
Scrubber::mScrubSpeedDisplayCountdown
int mScrubSpeedDisplayCountdown
Definition: Scrubbing.h:160
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
Scrubber::StatusMessageForWave
wxString StatusMessageForWave() const
Scrubber
Definition: Scrubbing.h:45
Scrubber::HasMark
bool HasMark() const
Definition: Scrubbing.h:91
Scrubber::GetUntranslatedStateString
const TranslatableString & GetUntranslatedStateString() const
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
Scrubber::UpdatePrefs
void UpdatePrefs() override
Scrubber::ContinueScrubbingPoll
void ContinueScrubbingPoll()
Scrubber::WasSpeedPlaying
bool WasSpeedPlaying() const
Definition: Scrubbing.h:77
Scrubber::Scrubber
Scrubber(const Scrubber &) PROHIBITED
Scrubber::CheckMenuItems
void CheckMenuItems()
Scrubber::CanScrub
bool CanScrub() const
Scrubber::operator=
Scrubber & operator=(const Scrubber &) PROHIBITED
Scrubber::IsScrollScrubbing
bool IsScrollScrubbing() const
Definition: Scrubbing.h:95
Scrubber::SetMayDragToSeek
void SetMayDragToSeek(bool value)
Definition: Scrubbing.h:101
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
Scrubber::IsBackwards
bool IsBackwards() const
Definition: Scrubbing.h:87
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
Scrubber::IsSpeedPlaying
bool IsSpeedPlaying() const
Definition: Scrubbing.h:79
Scrubber::mScrubStartPosition
wxCoord mScrubStartPosition
Definition: Scrubbing.h:161
Scrubber::IsKeyboardScrubbing
bool IsKeyboardScrubbing() const
Definition: Scrubbing.h:83
Scrubber::OnKeyboardScrubBackwards
void OnKeyboardScrubBackwards(const CommandContext &)
Identifier.h
Scrubber::mScrubToken
int mScrubToken
Definition: Scrubbing.h:159
Scrubber::WasKeyboardScrubbing
bool WasKeyboardScrubbing() const
Definition: Scrubbing.h:81
Scrubber::ChoseSeeking
bool ChoseSeeking() const
Scrubber::TemporarilySeeks
bool TemporarilySeeks() const
Scrubber::SetScrollScrubbing
void SetScrollScrubbing(bool value)
Definition: Scrubbing.h:97
Scrubber::GetMaxScrubSpeed
double GetMaxScrubSpeed() const
Definition: Scrubbing.h:113
Scrubber::ScrubPollerThread
Definition: Scrubbing.cpp:140
Scrubber::HandleScrollWheel
void HandleScrollWheel(int steps)
Scrubber::PopulatePopupMenu
void PopulatePopupMenu(wxMenu &menu)
Scrubber::ShouldDrawScrubSpeed
bool ShouldDrawScrubSpeed()
Scrubber::SetBackwards
void SetBackwards(bool backwards)
Definition: Scrubbing.h:85
Scrubber::StopScrubbing
void StopScrubbing()
Scrubber::FindScrubSpeed
double FindScrubSpeed(bool seeking, double time) const
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
Scrubber::IsScrubbing
bool IsScrubbing() const
Scrubber::GetKeyboardScrubbingSpeed
double GetKeyboardScrubbingSpeed()
Scrubber::ContinueScrubbingUI
void ContinueScrubbingUI()
Scrubber::StopPolling
void StopPolling()
Prefs.h
Scrubber::OnScrubOrSeek
void OnScrubOrSeek(bool seek)
Scrubber::mPoller
std::unique_ptr< ScrubPoller > mPoller
Definition: Scrubbing.h:192
Scrubber::ShowsBar
bool ShowsBar() const
Scrubber::OnActivateOrDeactivateApp
void OnActivateOrDeactivateApp(wxActivateEvent &event)
Scrubber::StartPolling
void StartPolling()
Scrubber::SetSeekPress
void SetSeekPress(bool value)
Definition: Scrubbing.h:148
Scrubber::IsPaused
bool IsPaused() const
Scrubber::OnSeek
void OnSeek(const CommandContext &)
Scrubber::GetScrubStartPosition
wxCoord GetScrubStartPosition() const
Definition: Scrubbing.h:74
Scrubber::mSmoothScrollingScrub
bool mSmoothScrollingScrub
Definition: Scrubbing.h:164
Scrubber::Pause
void Pause(bool paused)
Scrubber::OnKeyboardScrubForwards
void OnKeyboardScrubForwards(const CommandContext &)