Audacity 3.2.0
SnapUtils.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 SnapUtils.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include "Callable.h"
14#include "Prefs.h"
15#include "Registry.h"
16
17#include <functional>
18#include <string_view>
19
20enum class SnapMode
21{
25};
26
27extern SNAPPING_API StringSetting SnapToSetting;
28extern SNAPPING_API EnumSetting<SnapMode> SnapModeSetting;
29
30SNAPPING_API SnapMode ReadSnapMode();
31SNAPPING_API Identifier ReadSnapTo();
32
34struct SnapRegistryItem;
36
37class AudacityProject;
38
39struct SNAPPING_API SnapResult final
40{
42
47 double time {};
49 bool snapped {};
50};
51
55};
57
60 const bool inlined;
61};
62
63struct SNAPPING_API SnapRegistryGroup final
65 Registry::GroupItem<SnapRegistryTraits>,
66 SnapRegistryGroupData,
67 const Identifier &
68 >
69{
70 using Extension::Extension;
71 ~SnapRegistryGroup() override;
72 bool Inlined() const { return inlined; }
73 const TranslatableString &Label() const { return label; }
74};
75
76struct SNAPPING_API SnapRegistryItem : public Registry::SingleItem
77{
79 const Identifier& internalName, const TranslatableString& label);
80 ~SnapRegistryItem() override;
81
83
84 virtual SnapResult Snap(const AudacityProject& project, double time, bool nearest) const = 0;
85 virtual SnapResult SingleStep(const AudacityProject& project, double time, bool upwards) const = 0;
86};
87
88std::unique_ptr<SnapRegistryItem> TimeInvariantSnapFunction(
89 const Identifier& functionId, const TranslatableString& label,
90 double multiplier);
91
92using MultiplierFunctor = std::function<double(const AudacityProject&)>;
93
94std::unique_ptr<SnapRegistryItem> TimeInvariantSnapFunction(
95 const Identifier& functionId, const TranslatableString& label,
96 MultiplierFunctor functor);
97
100
101struct SNAPPING_API SnapFunctionsRegistry final {
103
104 static void Visit(const SnapRegistryVisitor& visitor);
105
106 static const SnapRegistryItem* Find(const Identifier& id);
107
108 static SnapResult Snap(const Identifier& id, const AudacityProject& project, double time, bool nearest);
109 static SnapResult SingleStep(
110 const Identifier& id, const AudacityProject& project, double time,
111 bool upwards);
112};
113
116
118 Registry::GroupItem<SnapRegistryTraits>, void, const Identifier&
119> {
120 using Extension::Extension;
121};
122
123constexpr auto SnapFunctionItems =
124 Callable::UniqueMaker<SnapFunctionSuperGroup>();
Functions and classes that generate callable objects.
constexpr auto SnapFunctionGroup
Definition: SnapUtils.h:98
SNAPPING_API SnapMode ReadSnapMode()
Definition: SnapUtils.cpp:38
std::unique_ptr< SnapRegistryItem > TimeInvariantSnapFunction(const Identifier &functionId, const TranslatableString &label, double multiplier)
Definition: SnapUtils.cpp:294
constexpr auto SnapFunctionItems
Definition: SnapUtils.h:123
SNAPPING_API StringSetting SnapToSetting
Definition: SnapUtils.cpp:29
SNAPPING_API EnumSetting< SnapMode > SnapModeSetting
Definition: SnapUtils.cpp:31
std::function< double(const AudacityProject &)> MultiplierFunctor
Definition: SnapUtils.h:92
SnapMode
Definition: SnapUtils.h:21
SNAPPING_API Identifier ReadSnapTo()
Definition: SnapUtils.cpp:90
TranslatableString label
Definition: TagsEditor.cpp:165
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
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:514
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Specialization of Setting for strings.
Definition: Prefs.h:370
Holds a msgid for the translation catalog; may also bind format arguments.
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
constexpr auto UniqueMaker()
Generate variadic factory functions.
Definition: Callable.h:122
MENUS_API void Visit(Visitor< Traits > &visitor, AudacityProject &project)
Extend Base with extra fields, in a second, protected base class.
Definition: Composite.h:177
Common abstract base class for items that are not groups.
Definition: Registry.h:224
const bool inlined
Definition: SnapUtils.h:60
const TranslatableString label
Definition: SnapUtils.h:59
const TranslatableString & Label() const
Definition: SnapUtils.h:73
bool Inlined() const
Definition: SnapUtils.h:72
virtual SnapResult SingleStep(const AudacityProject &project, double time, bool upwards) const =0
const TranslatableString label
Definition: SnapUtils.h:82
virtual SnapResult Snap(const AudacityProject &project, double time, bool nearest) const =0
Empty specialization.
Definition: TypeList.h:63
Primary template for a list of arbitrary types.
Definition: TypeList.h:61