Deepnote Synthesizer Voice Library v1.0.0
A C++14 header-only library implementing the THX Deep Note effect
Loading...
Searching...
No Matches
range.hpp
Go to the documentation of this file.
1
34#pragma once
35
36#include "util/namedtype.hpp"
37
38namespace deepnote
39{
40
41namespace nt
42{
43using RangeLow = NamedType<float, struct RangeLowTag>;
44using RangeHigh = NamedType<float, struct RangeHighTag>;
45}; // namespace nt
46
47struct Range
48{
49 Range()
50 : low(0.f)
51 , high(0.f)
52 {
53 }
54
55 explicit Range(nt::RangeLow low, nt::RangeHigh high)
56 : low(low.get() < high.get() ? low.get() : high.get())
57 , high(high.get() > low.get() ? high.get() : low.get())
58 {
59 }
60
61 Range(const Range &other)
62 : low(other.low)
63 , high(other.high)
64 {
65 }
66
67 Range &operator=(const Range &other)
68 {
69 if(this != &other)
70 {
71 low = other.low;
72 high = other.high;
73 }
74 return *this;
75 }
76
77 nt::RangeLow get_low() const noexcept { return low; }
78
79 nt::RangeHigh get_high() const noexcept { return high; }
80
81 float length() const noexcept { return high.get() - low.get(); }
82
83 bool contains(float value) const noexcept { return value >= low.get() && value <= high.get(); }
84
85 float constrain(float value) const noexcept
86 {
87 if(value < low.get())
88 return low.get();
89 if(value > high.get())
90 return high.get();
91 return value;
92 }
93
94 private:
95 nt::RangeLow low;
96 nt::RangeHigh high;
97};
98
99} // namespace deepnote
Type-safe wrapper utilities for the Deep Note synthesizer.