Files
serumalt/Source/Synth/Envelope.h
T
biggy 4b0db50271 refactor(source): move every implementation into its module directory
- 36 files move into the module whose AGENTS.md already claimed them:
  Engine/, Synth/, Modulation/, Params/, Plugin/, GUI/, EffectUnits/, Resources/
- Source/engine, modulation, params, plugin and synth become Engine,
  Modulation, Params, Plugin and Synth, matching the directories that already
  hold code
- ExactCompare.h stays at the Source/ root as the one shared header
- SERUMALT_INCLUDE_DIRS adds one include directory per module, so the 31
  parent-relative includes become plain names with no path prefix
- the module AGENTS.md files list owned files instead of describing a move
  that had not happened, and README.md and AGENTS.md describe the real tree

Verified: the harness passes CTest, the Linux VST3 and Standalone link, the
Windows cross-build passes its module checks, each configure exposes only its
own targets, no first-party warning line appears, and the generated Windows
manifest is unchanged.
2026-10-06 09:17:49 +02:00

54 lines
1.7 KiB
C++

#pragma once
#include <JuceHeader.h>
namespace serum
{
// Curve-to-shape mapping shared by the envelope DSP and the GUI preview, so the
// two cannot drift apart.
inline float attackShapeFor (float curve) noexcept { return 0.3f + curve * 2.7f; } // 0.3 .. 3.0
inline float decayShapeFor (float curve) noexcept { return 3.0f - curve * 2.7f; } // 3.0 .. 0.3
// ===========================================================================
// ADSR envelope with curve tension. Durations are in seconds; the sustain
// level is 0..1. Retriggering (noteOn while active) starts from the current
// value for click-free legato behaviour.
// ===========================================================================
class Envelope
{
public:
void prepare (double sampleRate) { sr = sampleRate; reset(); }
void reset();
void noteOn();
void noteOff();
void setParams (float attackSec, float decaySec, float sustain, float releaseSec, float curve);
float process() noexcept; // advance one sample and return the value
float getValue() const noexcept { return value; }
bool isActive() const noexcept { return stage != Stage::Idle; }
// Snapshot for GUI rendering.
struct Shape { float attack = 0, decay = 0, sustain = 0, release = 0, curve = 0.5f; };
Shape getShape() const noexcept { return shape; }
private:
enum class Stage { Idle, Attack, Decay, Sustain, Release };
Stage stage = Stage::Idle;
double sr = 44100.0;
float value = 0.0f;
float startValue = 0.0f, endValue = 0.0f;
double elapsed = 0.0, duration = 0.0;
double attackShape = 1.0, decayShape = 1.0;
float sustain = 0.7f;
double attackSamples = 0.0, decaySamples = 0.0, releaseSamples = 0.0;
Shape shape;
};
} // namespace serum