Audacity 3.2.0
BeatsSnapFunctions.cpp
Go to the documentation of this file.
1
2/* SPDX-License-Identifier: GPL-2.0-or-later */
3/*!********************************************************************
4
5 Audacity: A Digital Audio Editor
6
7 BeatsSnapFunctions.cpp
8
9 Dmitry Vedenko
10
11**********************************************************************/
12
14
15#include "SnapUtils.h"
16
17namespace
18{
19/*
20bps = tempo / 60
211/lower takes 1/bps
22*/
23
25{
26 auto& timeSignature = ProjectTimeSignature::Get(project);
27
28 const auto barDuration = timeSignature.GetBarDuration();
29 const auto multiplier = 1 / barDuration;
30
31 return multiplier;
32}
33
35{
36 return [divisor](const AudacityProject& project)
37 {
38 auto& timeSignature = ProjectTimeSignature::Get(project);
39
40 const auto quarterDuration = timeSignature.GetQuarterDuration();
41 // DV: It was decided that for the time being,
42 // BPM sets the duration for quarter notes.
43 // For this reason, `cfg.timeSignature.second` is ignored
44 const auto fracDuration = quarterDuration * 4.0 / divisor;
45 const auto multiplier = 1.0 / fracDuration;
46
47 return multiplier;
48 };
49}
50
52{
53 return [divisor](const AudacityProject& project)
54 {
55 auto& timeSignature = ProjectTimeSignature::Get(project);
56
57 const auto quarterDuration = 60.0 / timeSignature.GetTempo();
58 const auto tripletDivisor = 3 * (divisor / 2);
59 const auto fracDuration = quarterDuration * 4.0 / tripletDivisor;
60 const auto multiplier = 1.0 / fracDuration;
61
62 return multiplier;
63 };
64}
65
67 SnapFunctionItems( "beats",
69 /* i18n-hint: The music theory "beat"*/
70 "beats", { XO("Beats"), true },
71 /* i18n-hint: The music theory "bar"*/
73 TimeInvariantSnapFunction("bar_1_2", XO("1/2"), SnapToBeat(2)),
74 TimeInvariantSnapFunction("bar_1_4", XO("1/4"), SnapToBeat(4)),
75 TimeInvariantSnapFunction("bar_1_8", XO("1/8"), SnapToBeat(8)),
76 TimeInvariantSnapFunction("bar_1_16", XO("1/16"), SnapToBeat(16)),
77 TimeInvariantSnapFunction("bar_1_32", XO("1/32"), SnapToBeat(32)),
78 TimeInvariantSnapFunction("bar_1_64", XO("1/64"), SnapToBeat(64)),
79 TimeInvariantSnapFunction("bar_1_128", XO("1/128"), SnapToBeat(128))),
81 /* i18n-hint: The music theory "triplet"*/
82 "triplets", { XO("Triplets"), true },
84 "triplet_1_2", XO("1/2 (triplets)"), SnapToTriplets(2)),
86 "triplet_1_4", XO("1/4 (triplets)"), SnapToTriplets(4)),
88 "triplet_1_8", XO("1/8 (triplets)"), SnapToTriplets(8)),
90 "triplet_1_16", XO("1/16 (triplets)"), SnapToTriplets(16)),
92 "triplet_1_32", XO("1/32 (triplets)"), SnapToTriplets(32)),
94 "triplet_1_64", XO("1/64 (triplets)"), SnapToTriplets(64)),
96 "triplet_1_128", XO("1/128 (triplets)"), SnapToTriplets(128)))
97 ),
99};
100
101}
XO("Cut/Copy/Paste")
std::unique_ptr< SnapRegistryItem > TimeInvariantSnapFunction(const Identifier &functionId, const TranslatableString &label, MultiplierFunctor functor)
Definition: SnapUtils.cpp:286
constexpr auto SnapFunctionGroup
Definition: SnapUtils.h:98
constexpr auto SnapFunctionItems
Definition: SnapUtils.h:123
std::function< double(const AudacityProject &)> MultiplierFunctor
Definition: SnapUtils.h:92
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
static ProjectTimeSignature & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
MultiplierFunctor SnapToTriplets(int divisor)
double SnapToBar(const AudacityProject &project)