Plaquette
 
Loading...
Searching...
No Matches
PivotField.h
1/*
2 * PivotField.h
3 *
4 * (c) 2025 Sofian Audry :: info(@)sofianaudry(.)com
5 * (c) 2018 Thomas O Fredericks :: tof(@)t-o-f(.)info
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20#ifndef PIVOT_FIELD_H_
21#define PIVOT_FIELD_H_
22
23#include "AbstractField.h"
24#include "pq_easing.h"
25
26namespace pq {
27
28enum PivotFieldMode {
29 PIVOT_RISING,
30 PIVOT_FALLING,
31 PIVOT_BUMP,
32 PIVOT_NOTCH
33};
34
36{
37public:
39 PivotField();
40 virtual ~PivotField() {}
41
47 virtual float at(float proportion) override;
48
50 virtual float get() override { return _value; }
51
57 virtual float put(float value) override {
58 return (_value = constrain01(value));
59 }
60
65 void mode(PivotFieldMode mode) { _mode = mode; }
66
68 PivotFieldMode mode() const { return _mode; }
69
74 void easing(easing_function easing) { _easing = easing; }
75
77 void noEasing() { easing(easeNone); }
78
83 void rampWidth(float rampWidth);
84
86 void noRampWidth() { rampWidth(0); }
87
89 float rampWidth() const { return _rampWidth; }
90
95 void rampShift(float rampShift);
96
98 float rampShift() const { return _rampShift; }
99
104 void bumpWidth(float bumpWidth);
105
107 float bumpWidth() const { return 2*_halfBumpWidth; }
108
113 void center(float center) { _center = constrain01(center); }
114
116 float center() const { return _center; }
117
118protected:
119 // Internal use: return ramp value based on proportion compared to value.
120 float _ramp(float proportion, float value) {
121 return
122#if PQ_OPTIMIZE_FOR_CPU
123 constrain01( (proportion - value) * _invRampWidth + _rampShiftFactor );
124#else
125 constrain01( (proportion - value) / _rampWidth - 2*_rampShift + 1.5f );
126#endif
127 }
128
129protected:
130 // The current mode.
131 PivotFieldMode _mode;
132
133 // The current value.
134 float _value;
135
136 // The ramp width as %.
137 float _rampWidth;
138
139 // The ramp shift in [0, 1].
140 float _rampShift;
141
142 // The bump width as %.
143 float _halfBumpWidth;
144
145 // The center of the ramp in [0, 1].
146 float _center;
147
148 // Optional easing function.
149 easing_function _easing;
150
151#if PQ_OPTIMIZE_FOR_CPU
152 // Precompiled values.
153 float _invRampWidth;
154 float _rampShiftFactor;
155#endif
156};
157
158}
159#endif
Definition AbstractField.h:28
Definition PivotField.h:36
void easing(easing_function easing)
Sets easing function to apply to ramp.
Definition PivotField.h:74
float rampShift() const
Returns ramp shift.
Definition PivotField.h:98
PivotFieldMode mode() const
Returns mode.
Definition PivotField.h:68
PivotField()
Constructor.
Definition PivotField.cpp:24
float bumpWidth() const
Returns bump width.
Definition PivotField.h:107
virtual float put(float value) override
Pushes value into the unit.
Definition PivotField.h:57
void center(float center)
Sets center of the ramp in [0, 1].
Definition PivotField.h:113
void noEasing()
Remove easing function (linear/no easing).
Definition PivotField.h:77
void noRampWidth()
Removes ramp width.
Definition PivotField.h:86
float rampWidth() const
Returns ramp width.
Definition PivotField.h:89
void mode(PivotFieldMode mode)
Sets mode to use.
Definition PivotField.h:65
float center() const
Returns center of the ramp.
Definition PivotField.h:116
virtual float get() override
Returns value.
Definition PivotField.h:50
virtual float at(float proportion) override
Returns value at given proportion in [0, 1].
Definition PivotField.cpp:57