ofxPDSP
AHR.h
1 
2 // AHR.h
3 // ofxPDSP
4 // Nicola Pisanti, MIT License, 2016
5 
6 #ifndef PDSP_ENV_AHR_H_INCLUDED
7 #define PDSP_ENV_AHR_H_INCLUDED
8 
9 
10 #include "../pdspCore.h"
11 #include "stages/EnvelopeStage.h"
12 #include "stages/AttackStage.h"
13 #include "stages/HoldStage.h"
14 #include "stages/ReleaseStage.h"
15 
16 namespace pdsp{
17 
24 class AHR : public Unit,
25  public virtual EnvelopeStage,
26  public virtual AttackStage,
27  public virtual HoldStage,
28  public virtual ReleaseStage
29 {
30 
31 public:
32  AHR();
33 
41  Patchable& set(float attackTimeMs, float holdTimeMs, float releaseTimeMs, float velocity = 1.0f );
42 
43 
48  void setAttackCurve(float hardness);
49 
54  void setReleaseCurve(float hardness);
55 
60  void setCurve(float hardness);
61 
62 
68  void enableDBTriggering(float dBmin, float dBmax=0.0f);
69 
73  void disableDBTriggering();
74 
75 
76 
80  Patchable& in_trig();
81 
86 
90  Patchable& in_hold();
91 
96 
101 
106 
110  float meter_output() const;
111 
115  int meter_triggers() const;
116 private:
117  void process(int bufferSize) noexcept override;
118  void prepareUnit( int expectedBufferSize, double sampleRate) override;
119  void releaseResources() override;
120 
121  inline_f void doEnvelope() {
122  switch (stageSwitch){
123  case off : envelopeOutput = 0.0; break;
124  case attackStage : Attack(stageSwitch, holdStage); break;
125  case holdStage : Hold(stageSwitch, releaseStage); break;
126  case releaseStage : Release(stageSwitch, off); break;
127  }
128  };
129 
130  void onRetrigger(float triggerValue, int n);
131 
132  void process_run(int bufferSize);
133  void process_T( const float* &trigBuffer, const int &bufferSize);
134 
135  InputNode input_trig;
136  OutputNode output;
137  InputNode input_attack;
138  InputNode input_hold;
139  InputNode input_release;
140  InputNode input_velocity;
141 
142  std::atomic<bool> dBtrig;
143  float dBmin;
144  float dBmax;
145 
146 
147  int stageSwitch;
148 
149  static const int off = 0;
150  static const int attackStage = 1;
151  static const int holdStage = 2;
152  static const int releaseStage = 3;
153 
154  std::atomic<float> meter;
155  std::atomic<int> trigcount;
156 };
157 
158 } // pdsp end namespace
159 
160 
161 #endif // PDSP_ENV_AHR_H_INCLUDED
Patchable & in_velocity()
Sets "velocity" as selected input and returns this Unit ready to be patched. This input rapresent the...
Definition: AHR.cpp:99
void setReleaseCurve(float hardness)
sets the curve of the release stage of the envelope, from a smoother linear in dB curve to an harder ...
Definition: AHR.cpp:51
void setAttackCurve(float hardness)
sets the curve of the attack stage the envelope, from a smoother linear in dB curve to an harder anal...
Definition: AHR.cpp:43
Patchable & in_trig()
Sets "trig" as selected input and returns this Unit ready to be patched. This is the default input...
Definition: AHR.cpp:83
void enableDBTriggering(float dBmin, float dBmax=0.0f)
enable an alternate mode for the trigger dynamics, trigger will output linear value that are the equi...
Definition: AHR.cpp:64
Abstract class for implementing Units.
Definition: BasicNodes.h:223
Patchable & in_attack()
Sets "attack" as selected input and returns this Unit ready to be patched. This input sets the attack...
Definition: AHR.cpp:87
Abstract class for implementing Units and Modules.
Definition: BasicNodes.h:82
Input of a Unit, process all the connected Outputs and sum them. Has an internal variable state...
Definition: BasicNodes.h:536
int meter_triggers() const
returns number of received triggers since the start of the program, as int. Can overflow. This method is thread-safe.
Definition: AHR.cpp:79
Patchable & out_signal()
Sets "signal" as selected output and returns this Unit ready to be patched. This is the default outpu...
Definition: AHR.cpp:103
Thread-safe value control with smoothing.
Definition: SequencerBridge.h:11
Attack-Hold-Release envelope.
Definition: AHR.h:24
Output of a Unit, contains a buffer of rendered floats and has a variable state flag.
Definition: BasicNodes.h:354
void disableDBTriggering()
disable the alternate mode for the trigger dynamics.
Definition: AHR.cpp:70
Patchable & in_release()
Sets "release" as selected input and returns this Unit ready to be patched. This input sets the relea...
Definition: AHR.cpp:95
Patchable & in_hold()
Sets "hold" as selected input and returns this Unit ready to be patched. This input sets the hold tim...
Definition: AHR.cpp:91
void setCurve(float hardness)
sets the curve of the envelope, from a smoother linear in dB curve to an harder analog-like curve...
Definition: AHR.cpp:60
float meter_output() const
returns the first value of the last processed output buffer. This method is thread-safe.
Definition: AHR.cpp:75