Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem Class Referencefinal
Inheritance diagram for anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem:
[legend]
Collaboration diagram for anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem:
[legend]

Public Member Functions

 ProjectDependentMultiplierSnapItem (const Identifier &internalName, const TranslatableString &label, MultiplierFunctor functor)
 
SnapResult Snap (const AudacityProject &project, double time, bool nearest) const override
 
SnapResult SingleStep (const AudacityProject &project, double time, bool upwards) const override
 
- Public Member Functions inherited from SnapRegistryItem
 SnapRegistryItem (const Identifier &internalName, const TranslatableString &label)
 
 ~SnapRegistryItem () override
 
virtual SnapResult Snap (const AudacityProject &project, double time, bool nearest) const =0
 
virtual SnapResult SingleStep (const AudacityProject &project, double time, bool upwards) const =0
 
- Public Member Functions inherited from Registry::SingleItem
 ~SingleItem () override=0
 
- Public Member Functions inherited from Registry::detail::BaseItem
 BaseItem (const Identifier &internalName)
 
virtual ~BaseItem ()
 

Private Attributes

const MultiplierFunctor mMultiplierFunctor
 

Additional Inherited Members

- Public Attributes inherited from SnapRegistryItem
const TranslatableString label
 
- Public Attributes inherited from Registry::detail::BaseItem
const Identifier name
 
OrderingHint orderingHint
 

Detailed Description

Definition at line 232 of file SnapUtils.cpp.

Constructor & Destructor Documentation

◆ ProjectDependentMultiplierSnapItem()

anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem::ProjectDependentMultiplierSnapItem ( const Identifier internalName,
const TranslatableString label,
MultiplierFunctor  functor 
)
inline

Definition at line 235 of file SnapUtils.cpp.

238 : SnapRegistryItem { internalName, label }
239 , mMultiplierFunctor { std::move(functor) }
240 {
241 assert(mMultiplierFunctor);
242 }
const TranslatableString label
Definition: SnapUtils.h:82

Member Function Documentation

◆ SingleStep()

SnapResult anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem::SingleStep ( const AudacityProject project,
double  time,
bool  upwards 
) const
inlineoverridevirtual

Implements SnapRegistryItem.

Definition at line 252 of file SnapUtils.cpp.

254 {
256 return { time, false };
257
258 const auto multiplier = mMultiplierFunctor(project);
259
260 const auto eps =
261 std::max(1.0, time) * std::numeric_limits<double>::epsilon();
262
263 const auto current = static_cast<int>(std::floor(time * (1.0 + eps) * multiplier));
264 const auto next = upwards ? current + 1 : current - 1;
265
266 double result = next / multiplier;
267
268 if (result < 0.0)
269 return { 0.0, false };
270
271 while (static_cast<int>(std::floor(result * multiplier)) < next)
272 result += eps;
273
274 while (static_cast<int>(std::floor(result * multiplier)) > next)
275 result -= eps;
276
277 return { result, true };
278 }
const auto project

References project.

◆ Snap()

SnapResult anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem::Snap ( const AudacityProject project,
double  time,
bool  nearest 
) const
inlineoverridevirtual

Implements SnapRegistryItem.

Definition at line 245 of file SnapUtils.cpp.

246 {
248 return { time, false };
249 return SnapWithMultiplier(time, mMultiplierFunctor(project), nearest);
250 }
SnapResult SnapWithMultiplier(double value, double multiplier, bool nearest)
Definition: SnapUtils.cpp:187

References project, and anonymous_namespace{SnapUtils.cpp}::SnapWithMultiplier().

Here is the call graph for this function:

Member Data Documentation

◆ mMultiplierFunctor

const MultiplierFunctor anonymous_namespace{SnapUtils.cpp}::ProjectDependentMultiplierSnapItem::mMultiplierFunctor
private

Definition at line 281 of file SnapUtils.cpp.


The documentation for this class was generated from the following file: