fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
BoundedValue.h
1/***************************************************************************************************
2 ██████ █████ █████ █████
3 ███░░███ ░░███ ░░███ ░░███
4 ░███ ░░░ █████ ░███████ ██ ██ █████ ███████ ░███ █████
5 ███████ ███░░ ░███░░███ ░░ ░░ ███░░ ░░░███░ ░███░░███
6 ░░░███░ ░░█████ ░███ ░███ ░░█████ ░███ ░██████░
7 ░███ ░░░░███ ░███ ░███ ░░░░███ ░███ ███ ░███░░███
8 █████ ██████ ████ █████ ██ ██ ██████ ░░█████ ████ █████
9 ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░░ ░░░░░
10
11 fantastic spatial holophonic synthesis tool kit
12
13 copyright (c) fabian hummel
14 www.github.com/fshstk
15 www.fshstk.com
16
17 this file is part of the fantastic spatial holophonic synthesis toolkit (fsh::stk)
18 fsh::stk is free software: it is provided under the terms of the gnu general public license v3.0
19 www.gnu.org/licenses/gpl-3.0
20***************************************************************************************************/
21
22#pragma once
23#include <spdlog/spdlog.h>
24
25namespace fsh::util
26{
33template<typename T, int MIN, int MAX>
35{
36public:
38 BoundedValue(T val = {}) { set(val); }
39
41 auto get() const -> T { return _val; }
42
44 void set(T val)
45 {
46 if (val < min)
47 {
48 spdlog::warn("BoundedValue: value {} is below minimum {}, clamping", val, min);
49 _val = min;
50 return;
51 }
52
53 if (val > max)
54 {
55 spdlog::warn("BoundedValue: value {} is above maximum {}, clamping", val, max);
56 _val = max;
57 return;
58 }
59
60 _val = val;
61 }
62
64 static constexpr auto min = static_cast<T>(MIN);
65
67 static constexpr auto max = static_cast<T>(MAX);
68
69private:
70 T _val;
71};
72
73template<int MIN, int MAX>
75
76template<int MIN, int MAX>
78} // namespace fsh::util
Represents a value that is bounded by a minimum and maximum.
Definition BoundedValue.h:35
BoundedValue(T val={})
Set the initial value.
Definition BoundedValue.h:38
static constexpr auto min
Minimum value.
Definition BoundedValue.h:64
auto get() const -> T
Get the value stored in this object.
Definition BoundedValue.h:41
void set(T val)
Set a new value, clamping to min/max if necessary.
Definition BoundedValue.h:44
static constexpr auto max
Maximum value.
Definition BoundedValue.h:67