Plaquette
 
Loading...
Searching...
No Matches
AbstractWave.h
1/*
2 * AbstractWave.h
3 *
4 * (c) 2022 Sofian Audry :: info(@)sofianaudry(.)com
5 * (c) 2015 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
21#ifndef ABSTRACT_WAVE_H_
22#define ABSTRACT_WAVE_H_
23
24#include "PqCore.h"
25#include "AbstractOscillator.h"
26#include "pq_phase_utils.h"
27
28namespace pq {
29
34public:
36
42
49
57
58 virtual ~AbstractWave() {}
59
61 virtual float get();
62
70 virtual float shiftBy(float phaseShift) const;
71
77 virtual float shiftByTime(float timeShift) const;
78
87 virtual float atPhase(float phase) const;
88
93 [[deprecated("Use wave.mapTo(min,max) instead.")]]
94 virtual void amplitude(float amplitude);
95
97 [[deprecated("Use wave.mapTo(min,max) instead.")]]
98 virtual float amplitude() const { return fixed32ToFloat(_amplitude); }
99
104 virtual void skew(float skew);
105
107 virtual float skew() const { return fixed32ToFloat(_skew32); }
108
111
117 [[deprecated("Use skew(float) instead.")]]
118 virtual void width(float width) { skew(width); }
119
122 [[deprecated("Use skew() instead.")]]
123 virtual float width() const { return skew(); }
124
126 virtual bool passedPeriod() const { return _overflowed; }
127
129 virtual bool passedSkew() const { return _passedSkew; }
130
132 virtual void onPassPeriod(EventCallback callback);
133
135 virtual void onPassSkew(EventCallback callback);
136
137protected:
138 // Core Plaquette methods.
139 virtual void begin();
140 virtual void step();
141
142 // Returns true if event is triggered.
143 virtual bool eventTriggered(EventType eventType);
144
145 // Returns value in [0, 1] as fixed32-point value (to be defined by subclasses).
146 virtual q0_32u_t _getFixed32(q0_32u_t t) const = 0;
147
148 // Returns amplified version of _get(t).
149 virtual float _getAmplified(q0_32u_t t) const;
150
151 bool _isPreSkew() const {
152 return (_phase32 <= _skew32);
153 }
154
155 // Call after a change.
156 void _updatePassedSkew();
157
158 // Amplitude (in %).
159 q0_32u_t _amplitude;
160
161 // Skew of the signal.
162 q0_32u_t _skew32;
163};
164
165}
166
167#endif
Triangle/sawtooth oscillator.
Definition AbstractOscillator.h:33
virtual float period() const
Returns the period (in seconds).
Definition AbstractOscillator.h:55
virtual float phaseShift() const
Returns the phase shift (ie.
Definition AbstractOscillator.cpp:158
virtual float phase() const
Returns the phase (in % of period).
Definition AbstractOscillator.h:97
Triangle/sawtooth oscillator.
Definition AbstractWave.h:33
virtual void onPassSkew(EventCallback callback)
Registers event callback on wave pass skew point event.
Definition AbstractWave.cpp:108
virtual void width(float width)
Definition AbstractWave.h:118
virtual bool passedSkew() const
Returns true on the step where the wave passed the skew point.
Definition AbstractWave.h:129
virtual Parameter Skew()
Returns the skew as a parameter.
Definition AbstractWave.h:110
virtual float get()
Returns value in [0, 1].
Definition AbstractWave.cpp:35
virtual float shiftByTime(float timeShift) const
Returns oscillator's value with given phase shift expressed in time (in seconds).
Definition AbstractWave.cpp:85
virtual float skew() const
Returns the skew of the signal.
Definition AbstractWave.h:107
virtual float shiftBy(float phaseShift) const
Returns oscillator's value with given phase shift (in % of period).
Definition AbstractWave.cpp:81
virtual float amplitude() const
Returns the amplitude of the wave.
Definition AbstractWave.h:98
virtual bool passedPeriod() const
Returns true on the step where the wave passed the period (end cycle).
Definition AbstractWave.h:126
virtual float width() const
Definition AbstractWave.h:123
virtual float atPhase(float phase) const
Returns the oscillator's value at a given absolute phase (in % of period).
Definition AbstractWave.cpp:89
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition AbstractWave.cpp:112
virtual void onPassPeriod(EventCallback callback)
Registers event callback on wave pass period event.
Definition AbstractWave.cpp:104
An analog analog source that contains a value constrained to a finite range (typically in [0,...
Definition PqCore.h:482
The main Plaquette static class containing all the units.
Definition PqCore.h:63
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:30
Definition PqCore.h:343
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:420