Audacity 3.2.0
Classes | Namespaces | Functions | Variables
SnapUtils.cpp File Reference
#include "SnapUtils.h"
#include <algorithm>
#include <cmath>
#include <unordered_map>
Include dependency graph for SnapUtils.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{SnapUtils.cpp}::ConstantMultiplierSnapItem
 
class  anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem
 

Namespaces

namespace  anonymous_namespace{SnapUtils.cpp}
 

Functions

SnapMode ReadSnapMode ()
 
wxString DeduceSnapTo ()
 
Identifier ReadSnapTo ()
 
SnapResult anonymous_namespace{SnapUtils.cpp}::SnapWithMultiplier (double value, double multiplier, bool nearest)
 
std::unique_ptr< SnapRegistryItemTimeInvariantSnapFunction (const Identifier &functionId, const TranslatableString &label, MultiplierFunctor functor)
 
std::unique_ptr< SnapRegistryItemTimeInvariantSnapFunction (const Identifier &functionId, const TranslatableString &label, double multiplier)
 

Variables

const wxString anonymous_namespace{SnapUtils.cpp}::SnapModeKey = L"/Snap/Mode"
 
const wxString anonymous_namespace{SnapUtils.cpp}::SnapToKey = L"/Snap/To"
 
const wxString anonymous_namespace{SnapUtils.cpp}::OldSnapToKey = L"/SnapTo"
 
const wxString anonymous_namespace{SnapUtils.cpp}::SelectionFormatKey = L"/SelectionFormat"
 
const auto anonymous_namespace{SnapUtils.cpp}::PathStart = L"SnapFunctions"
 
StringSetting SnapToSetting { SnapToKey, "bar_1_8" }
 
EnumSetting< SnapModeSnapModeSetting
 

Function Documentation

◆ DeduceSnapTo()

wxString DeduceSnapTo ( )

Definition at line 46 of file SnapUtils.cpp.

47{
48 const auto& defaultSnapTo = SnapToSetting.GetDefault();
49
51 return defaultSnapTo;
52
53 // It appears that we are migrating from an older version of Audacity
54 // where snapping was controlled by the "/SelectionFormat".
55 // We are only trying to match the known values from the
56 // config to the appropriate snapping function, this matching
57 // does not introduce any kind of dependency to the lib-numeric-format.
58
59 const auto selectionFormat = gPrefs->Read(SelectionFormatKey);
60
61 static const std::unordered_map<wxString, wxString> selectionFormatLookup = {
62 { L"seconds", L"seconds" },
63 { L"seconds + milliseconds", L"milliseconds" },
64 { L"hh:mm:ss", L"seconds" },
65 { L"dd:hh:mm:ss", L"seconds" },
66 { L"hh:mm:ss + hundredths", L"centiseconds" },
67 { L"hh:mm:ss + milliseconds", L"milliseconds" },
68 { L"hh:mm:ss + samples", L"samples" },
69 { L"samples", L"samples" },
70 { L"hh:mm:ss + film frames (24 fps)", L"film_24_fps" },
71 { L"film frames (24 fps)", L"film_24_fps" },
72 { L"hh:mm:ss + NTSC drop frames", L"ntsc_29.97_fps" },
73 // Well, not really. Snapping with the "bent" time sounds funny anyway.
74 { L"hh:mm:ss + NTSC non-drop frames", L"ntsc_30_fps" },
75 { L"NTSC frames", L"ntsc_29.97_fps" },
76 { L"hh:mm:ss + PAL frames (25 fps)", L"film_25_fps" },
77 { L"PAL frames (25 fps)", L"film_25_fps" },
78 { L"hh:mm:ss + CDDA frames (75 fps)", L"cd_75_fps" },
79 { L"CDDA frames (75 fps)", L"cd_75_fps" },
80 };
81
82 auto it = selectionFormatLookup.find(selectionFormat);
83
84 if (it != selectionFormatLookup.end())
85 return it->second;
86
87 return defaultSnapTo;
88}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
StringSetting SnapToSetting
Definition: SnapUtils.cpp:29
const T & GetDefault() const
Definition: Prefs.h:199
virtual bool HasEntry(const wxString &key) const =0
Checks whether specified key exists within the current group.
virtual bool Read(const wxString &key, bool *value) const =0

References Setting< T >::GetDefault(), gPrefs, audacity::BasicSettings::HasEntry(), audacity::BasicSettings::Read(), anonymous_namespace{SnapUtils.cpp}::SelectionFormatKey, and SnapToSetting.

Referenced by ReadSnapTo().

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

◆ ReadSnapMode()

SnapMode ReadSnapMode ( )

Definition at line 38 of file SnapUtils.cpp.

39{
41 return SnapModeSetting.ReadEnum();
42
43 return static_cast<SnapMode>(gPrefs->Read(OldSnapToKey, 0L));
44}
EnumSetting< SnapMode > SnapModeSetting
Definition: SnapUtils.cpp:31
SnapMode
Definition: SnapUtils.h:21

References gPrefs, audacity::BasicSettings::HasEntry(), anonymous_namespace{SnapUtils.cpp}::OldSnapToKey, audacity::BasicSettings::Read(), anonymous_namespace{SnapUtils.cpp}::SnapModeKey, and SnapModeSetting.

Here is the call graph for this function:

◆ ReadSnapTo()

Identifier ReadSnapTo ( )

Definition at line 90 of file SnapUtils.cpp.

91{
93 return SnapToSetting.Read();
94
95 // Try to perform the config migration once
96 const auto snapTo = DeduceSnapTo();
97 SnapToSetting.Write(snapTo);
98 gPrefs->Flush();
99
100
101 return snapTo;
102}
wxString DeduceSnapTo()
Definition: SnapUtils.cpp:46
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:259
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
virtual bool Flush() noexcept=0

References DeduceSnapTo(), audacity::BasicSettings::Flush(), gPrefs, audacity::BasicSettings::HasEntry(), Setting< T >::Read(), anonymous_namespace{SnapUtils.cpp}::SnapToKey, SnapToSetting, and Setting< T >::Write().

Referenced by anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::GetStringValue(), anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::Init(), and anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::OnPopup().

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

◆ TimeInvariantSnapFunction() [1/2]

std::unique_ptr< SnapRegistryItem > TimeInvariantSnapFunction ( const Identifier functionId,
const TranslatableString label,
double  multiplier 
)

Definition at line 294 of file SnapUtils.cpp.

297{
298 return std::make_unique<ConstantMultiplierSnapItem>(
299 functionId, label, multiplier);
300}
TranslatableString label
Definition: TagsEditor.cpp:165

References label.

◆ TimeInvariantSnapFunction() [2/2]

std::unique_ptr< SnapRegistryItem > TimeInvariantSnapFunction ( const Identifier functionId,
const TranslatableString label,
MultiplierFunctor  functor 
)

Definition at line 286 of file SnapUtils.cpp.

289{
290 return std::make_unique<ProjectDependentMultiplierSnapItem>(
291 functionId, label, std::move(functor));
292}

References label.

Variable Documentation

◆ SnapModeSetting

EnumSetting<SnapMode> SnapModeSetting

◆ SnapToSetting

StringSetting SnapToSetting { SnapToKey, "bar_1_8" }