Audacity 3.2.0
Classes | Typedefs | Functions | Variables
anonymous_namespace{Scrubbing.cpp} Namespace Reference

Classes

struct  MenuItem
 

Typedefs

using MenuItems = std::vector< MenuItem >
 

Functions

double FindScrubbingSpeed (const ViewInfo &viewInfo, double maxScrubSpeed, double screen, double timeAtMouse)
 
double FindSeekSpeed (const ViewInfo &viewInfo, double maxScrubSpeed, double screen, double timeAtMouse)
 
const MenuItemsmenuItems ()
 
const MenuItemFindMenuItem (bool seek)
 
bool ReadScrubEnabledPref ()
 
void WriteScrubEnabledPref (bool value)
 
auto ToolbarMenu ()
 
auto KeyboardScrubbingItems ()
 

Variables

static const wxChar * scrubEnabledPrefName = wxT("/QuickPlay/ScrubbingEnabled")
 
static const auto finder
 
AttachedItem sAttachment { Indirect(ToolbarMenu()), wxT("Transport/Basic") }
 
AttachedItem sAttachment2
 

Typedef Documentation

◆ MenuItems

using anonymous_namespace{Scrubbing.cpp}::MenuItems = typedef std::vector< MenuItem >

Definition at line 258 of file Scrubbing.cpp.

Function Documentation

◆ FindMenuItem()

const MenuItem & anonymous_namespace{Scrubbing.cpp}::FindMenuItem ( bool  seek)
inline

Definition at line 292 of file Scrubbing.cpp.

293 {
294 return *std::find_if(menuItems().begin(), menuItems().end(),
295 [=](const MenuItem &item) {
296 return seek == item.seek;
297 }
298 );
299 }
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), details::end(), menuItems(), and anonymous_namespace{Scrubbing.cpp}::MenuItem::seek.

Referenced by Scrubber::GetUntranslatedStateString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindScrubbingSpeed()

double anonymous_namespace{Scrubbing.cpp}::FindScrubbingSpeed ( const ViewInfo viewInfo,
double  maxScrubSpeed,
double  screen,
double  timeAtMouse 
)

Definition at line 61 of file Scrubbing.cpp.

62 {
63 // Map a time (which was mapped from a mouse position)
64 // to a speed.
65 // Map times to positive and negative speeds,
66 // with the time at the midline of the screen mapping to 0,
67 // and the extremes to the maximum scrub speed.
68
69 auto partScreen = screen * TracksPrefs::GetPinnedHeadPositionPreference();
70 const double origin = viewInfo.hpos + partScreen;
71 if (timeAtMouse >= origin)
72 partScreen = screen - partScreen;
73
74 // There are various snapping zones that are this fraction of screen:
75 const double snap = 0.05;
76
77 // By shrinking denom a bit, we make margins left and right
78 // that snap to maximum and negative maximum speeds.
79 const double factor = 1.0 - (snap * 2);
80 const double denom = factor * partScreen;
81 double fraction = (denom <= 0.0) ? 0.0 :
82 std::min(1.0, fabs(timeAtMouse - origin) / denom);
83
84 // Snap to 1.0 and -1.0
85 const double unity = 1.0 / maxScrubSpeed;
86 const double tolerance = snap / factor;
87 // Make speeds near 1 available too by remapping fractions outside
88 // this snap zone
89 if (fraction <= unity - tolerance)
90 fraction *= unity / (unity - tolerance);
91 else if (fraction < unity + tolerance)
92 fraction = unity;
93 else
94 fraction = unity + (fraction - (unity + tolerance)) *
95 (1.0 - unity) / (1.0 - (unity + tolerance));
96
97 double result = fraction * maxScrubSpeed;
98 if (timeAtMouse < origin)
99 result *= -1.0;
100 return result;
101 }
int min(int a, int b)
static double GetPinnedHeadPositionPreference()
double hpos
Leftmost visible timeline position in seconds.
Definition: ZoomInfo.h:54

References TracksPrefs::GetPinnedHeadPositionPreference(), ZoomInfo::hpos, and min().

Referenced by Scrubber::FindScrubSpeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindSeekSpeed()

double anonymous_namespace{Scrubbing.cpp}::FindSeekSpeed ( const ViewInfo viewInfo,
double  maxScrubSpeed,
double  screen,
double  timeAtMouse 
)

Definition at line 103 of file Scrubbing.cpp.

104 {
105 // Map a time (which was mapped from a mouse position)
106 // to a signed skip speed: a multiplier of the stutter duration,
107 // by which to advance the play position.
108 // (The stutter will play at unit speed.)
109
110 // Times near the midline of the screen map to skip-less play,
111 // and the extremes to a value proportional to maximum scrub speed.
112
113 // If the maximum scrubbing speed defaults to 1.0 when you begin to scroll-scrub,
114 // the extreme skipping for scroll-seek needs to be larger to be useful.
115 static const double ARBITRARY_MULTIPLIER = 10.0;
116 const double extreme = std::max(1.0, maxScrubSpeed * ARBITRARY_MULTIPLIER);
117
118 // Width of visible track area, in time terms:
119 auto partScreen = screen * TracksPrefs::GetPinnedHeadPositionPreference();
120 const double origin = viewInfo.hpos + partScreen;
121 if (timeAtMouse >= origin)
122 partScreen = screen - partScreen;
123
124 // The snapping zone is this fraction of screen, on each side of the
125 // center line:
126 const double snap = 0.05;
127 const double fraction = (partScreen <= 0.0) ? 0.0 :
128 std::max(snap, std::min(1.0, fabs(timeAtMouse - origin) / partScreen));
129
130 double result = 1.0 + ((fraction - snap) / (1.0 - snap)) * (extreme - 1.0);
131 if (timeAtMouse < origin)
132 result *= -1.0;
133 return result;
134 }

References TracksPrefs::GetPinnedHeadPositionPreference(), ZoomInfo::hpos, and min().

Referenced by Scrubber::FindScrubSpeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeyboardScrubbingItems()

auto anonymous_namespace{Scrubbing.cpp}::KeyboardScrubbingItems ( )

Definition at line 1151 of file Scrubbing.cpp.

1152{
1153 static auto items = std::shared_ptr{
1154 ( FinderScope{ finder },
1155 Items( wxT("KeyboardScrubbing"),
1156 Command(wxT("KeyboardScrubBackwards"), XXO("Scrub Bac&kwards"),
1159 Options{ wxT("U") }.WantKeyUp() ),
1160 Command(wxT("KeyboardScrubForwards"), XXO("Scrub For&wards"),
1163 Options{ wxT("I") }.WantKeyUp() )
1164 ) ) };
1165 return items;
1166}
wxT("CloseDown"))
const ReservedCommandFlag & CaptureNotBusyFlag()
XXO("&Cut/Copy/Paste Toolbar")
const ReservedCommandFlag & CanStopAudioStreamFlag()
void OnKeyboardScrubForwards(const CommandContext &)
Definition: Scrubbing.cpp:1109
void OnKeyboardScrubBackwards(const CommandContext &)
Definition: Scrubbing.cpp:1098
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456

References CanStopAudioStreamFlag(), CaptureNotBusyFlag(), MenuRegistry::Command, finder, MenuRegistry::Items, Scrubber::OnKeyboardScrubBackwards(), Scrubber::OnKeyboardScrubForwards(), wxT(), and XXO().

Here is the call graph for this function:

◆ menuItems()

const MenuItems & anonymous_namespace{Scrubbing.cpp}::menuItems ( )

Definition at line 259 of file Scrubbing.cpp.

260 {
261 static MenuItems theItems{
262 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
263 "Scrubbing" is variable-speed playback, ...
264 "Seeking" is normal speed playback but with skips, ...
265 */
266 { wxT("Scrub"), XXO("&Scrub"), XO("Scrubbing"),
269 },
270
271 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
272 "Scrubbing" is variable-speed playback, ...
273 "Seeking" is normal speed playback but with skips, ...
274 */
275 { wxT("Seek"), XXO("See&k"), XO("Seeking"),
278 },
279
280 /* i18n-hint: These commands assist the user in finding a sound by ear. ...
281 "Scrubbing" is variable-speed playback, ...
282 "Seeking" is normal speed playback but with skips, ...
283 */
284 { wxT("ToggleScrubRuler"), XXO("Scrub &Ruler"), {},
287 },
288 };
289 return theItems;
290 };
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
XO("Cut/Copy/Paste")
static const ReservedCommandFlag & HasWaveDataFlag()
Definition: Scrubbing.cpp:242
bool Seeks() const
Definition: Scrubbing.cpp:800
bool Scrubs() const
Definition: Scrubbing.cpp:805
void OnToggleScrubRuler(const CommandContext &)
Definition: Scrubbing.cpp:962
void OnSeek(const CommandContext &)
Definition: Scrubbing.cpp:932
void OnScrub(const CommandContext &)
Definition: Scrubbing.cpp:926
bool ShowsBar() const
Definition: Scrubbing.cpp:763

References AlwaysEnabledFlag, CaptureNotBusyFlag(), HasWaveDataFlag(), Scrubber::OnScrub(), Scrubber::OnSeek(), Scrubber::OnToggleScrubRuler(), Scrubber::Scrubs(), Scrubber::Seeks(), Scrubber::ShowsBar(), wxT(), XO(), and XXO().

Referenced by Scrubber::CheckMenuItems(), FindMenuItem(), MenuHelper::PopulateEffectsMenu(), Scrubber::PopulatePopupMenu(), and ToolbarMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadScrubEnabledPref()

bool anonymous_namespace{Scrubbing.cpp}::ReadScrubEnabledPref ( )

Definition at line 942 of file Scrubbing.cpp.

943 {
944 bool result {};
945 gPrefs->Read(scrubEnabledPrefName, &result, false);
946
947 return result;
948 }
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Read(const wxString &key, bool *value) const =0
static const wxChar * scrubEnabledPrefName
Definition: Scrubbing.cpp:940

References gPrefs, audacity::BasicSettings::Read(), and scrubEnabledPrefName.

Referenced by Scrubber::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToolbarMenu()

auto anonymous_namespace{Scrubbing.cpp}::ToolbarMenu ( )

Definition at line 1127 of file Scrubbing.cpp.

1128{
1129 static auto menu = []{
1131 auto menu = std::shared_ptr{ Menu("Scrubbing", XXO("Scru&bbing")) };
1132 for (const auto &item : menuItems()) {
1133 menu->push_back(Command(item.name, item.label,
1134 item.memFn,
1135 item.flags,
1136 item.StatusTest
1137 ? // a checkmark item
1139 return (Scrubber::Get(project).*(item.StatusTest))(); } )
1140 : // not a checkmark item
1141 Options{}
1142 ));
1143 }
1144 return menu;
1145 }();
1146 return menu;
1147}
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
static CommandContext::TargetFactory::SubstituteInUnique< InteractiveOutputTargets > scope
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74

References MenuRegistry::Options::CheckTest(), MenuRegistry::Command, finder, MenuRegistry::Menu, menuItems(), project, anonymous_namespace{wxCommandTargets.cpp}::scope, and XXO().

Here is the call graph for this function:

◆ WriteScrubEnabledPref()

void anonymous_namespace{Scrubbing.cpp}::WriteScrubEnabledPref ( bool  value)

Definition at line 950 of file Scrubbing.cpp.

951 {
953 }
virtual bool Write(const wxString &key, bool value)=0

References gPrefs, scrubEnabledPrefName, and audacity::BasicSettings::Write().

Referenced by Scrubber::OnToggleScrubRuler().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ finder

const auto anonymous_namespace{Scrubbing.cpp}::finder
static

◆ sAttachment

AttachedItem anonymous_namespace{Scrubbing.cpp}::sAttachment { Indirect(ToolbarMenu()), wxT("Transport/Basic") }

Definition at line 1149 of file Scrubbing.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{Scrubbing.cpp}::sAttachment2
Initial value:
wxT("Optional/Extra/Part1/Transport")
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 1168 of file Scrubbing.cpp.

◆ scrubEnabledPrefName

const wxChar* anonymous_namespace{Scrubbing.cpp}::scrubEnabledPrefName = wxT("/QuickPlay/ScrubbingEnabled")
static

Definition at line 940 of file Scrubbing.cpp.

Referenced by ReadScrubEnabledPref(), and WriteScrubEnabledPref().