Krotos Modules 3
Loading...
Searching...
No Matches
KwidgetProcessor_Scaledadsr.cpp
Go to the documentation of this file.
1namespace krotos
2{
4 {
5 using P = Parameters;
6
7 addParameterAttachments({{P::Attack, [this](float x) { setAttack(x); }, 0},
8 {P::Decay, [this](float x) { setDecay(x); }, 0},
9 {P::Sustain, [this](float x) { setSustain(x); }, 2},
10 {P::Release, [this](float x) { setRelease(x); }, 0},
11 {P::Amount, [this](float x) { setAmount(x); }, 0}});
12
13 addModulator(true);
14 }
15
16 void KwidgetProcessor_Scaledadsr::prepare(double sampleRate, int samplesPerBlock)
17 {
18 m_adsr.setSampleRate(sampleRate);
20
21 m_buffer.setSize(1, samplesPerBlock);
22 getModulator(0)->setValues(m_buffer.getReadPointer(0), samplesPerBlock);
23 }
24
25 void KwidgetProcessor_Scaledadsr::process(AudioBuffer<float>& buffer)
26 {
27 auto numSamples = buffer.getNumSamples();
28 auto numChannels = buffer.getNumChannels();
29 auto bufferPtr = buffer.getArrayOfWritePointers();
30
31 auto modulatorBufferPtr = m_buffer.getWritePointer(0);
32
33 nextBlock(numSamples);
34 if (m_amount == 0.0f)
35 {
36 for (int sampleIndex = 0; sampleIndex < numSamples; sampleIndex++)
37 {
38 nextSample();
39
40 m_adsr.getNextSample();
41
42 // Output the modulation signal
43 modulatorBufferPtr[sampleIndex] = 0.0f; //* amp;
44
45 // Modulate the audio data using the
46 for (int channelIndex = 0; channelIndex < numChannels; channelIndex++)
47 bufferPtr[channelIndex][sampleIndex] *= 1.0f;
48 }
49 }
50
51 else
52 {
53 for (int sampleIndex = 0; sampleIndex < numSamples; sampleIndex++)
54 {
55 nextSample();
56
57 auto amp = m_adsr.getNextSample();
58
59 // Output the modulation signal
60 modulatorBufferPtr[sampleIndex] = amp * m_amount;
61
62 // Modulate the audio data using the
63 for (int channelIndex = 0; channelIndex < numChannels; channelIndex++)
64 bufferPtr[channelIndex][sampleIndex] *= amp * m_amount;
65 }
66 }
67
68 if (!m_adsr.isActive() && !m_hasBeenReset) // If the ADSR has finished
69 {
70 reset();
71 m_hasBeenReset = true;
72 }
73 }
74
75 void KwidgetProcessor_Scaledadsr::noteOn(int midiNoteNumber, float /*velocity*/, int)
76 {
77 m_isDrone = (midiNoteNumber & MIDI_NOTE_FLAG_DRONE) != 0; // Keep a record of the type of event
78
79 if (!m_adsr.isActive()) // If we are not already active
80 {
81 if (m_isDrone && ((midiNoteNumber & MIDI_NOTE_FLAG_DRONE_NOTEUP) != 0))
82 {
83 // Its a drone note-up event
84 m_noteIsOn = false;
85 m_adsr.noteOff();
86 }
87 else
88 {
89 // Its a note on event
90 m_noteIsOn = true;
91 m_adsr.noteOn();
92 m_hasBeenReset = false;
93 }
94 }
95 }
96
98 {
99 // If we were started as a drone, stop note can never switch us off, only startNote with stop flag
100 if (!m_isDrone &&
101 m_noteIsOn) // Checking m_noteIsOn prevents re-triggering of any already in-progress release - fix KST-1218
102 {
103 m_noteIsOn = false;
104 m_adsr.noteOff();
105 }
106 }
107
109 {
110 m_noteIsOn = false;
111 m_adsr.reset();
112 }
113
115
117 {
118 m_parameters.attack = attack;
119 updateParams();
120 }
122 {
123 m_parameters.decay = decay;
124 updateParams();
125 }
127 {
128 m_parameters.sustain = sustain;
129 updateParams();
130 }
132 {
133 m_parameters.release = release;
134 updateParams();
135 }
136 void KwidgetProcessor_Scaledadsr::setAmount(float amount) { m_amount = amount; }
137
139
140} // namespace krotos
Definition Kwidget.h:8
bool m_isDrone
Definition KwidgetProcessor_Scaledadsr.h:39
void setSustain(float sustain)
Definition KwidgetProcessor_Scaledadsr.cpp:126
juce::ADSR m_adsr
Definition KwidgetProcessor_Scaledadsr.h:34
Kwidget_Scaledadsr::Parameters Parameters
Definition KwidgetProcessor_Scaledadsr.h:6
void updateParams()
Definition KwidgetProcessor_Scaledadsr.cpp:138
void reset() override
Definition KwidgetProcessor_Scaledadsr.cpp:108
void setAttack(float attack)
Definition KwidgetProcessor_Scaledadsr.cpp:116
void noteCleared() override
Definition KwidgetProcessor_Scaledadsr.cpp:114
AudioBuffer< float > m_buffer
Definition KwidgetProcessor_Scaledadsr.h:38
void setAmount(float amount)
Definition KwidgetProcessor_Scaledadsr.cpp:136
bool m_hasBeenReset
Definition KwidgetProcessor_Scaledadsr.h:27
void prepare(double sampleRate, int samplesPerBlock) override
Definition KwidgetProcessor_Scaledadsr.cpp:16
KwidgetProcessor_Scaledadsr(Kwidget &owner)
Definition KwidgetProcessor_Scaledadsr.cpp:3
void process(AudioBuffer< float > &buffer) override
Definition KwidgetProcessor_Scaledadsr.cpp:25
void noteOn(int midiNoteNumber, float velocity, int) override
Definition KwidgetProcessor_Scaledadsr.cpp:75
float m_amount
Definition KwidgetProcessor_Scaledadsr.h:36
void setRelease(float release)
Definition KwidgetProcessor_Scaledadsr.cpp:131
bool m_noteIsOn
Definition KwidgetProcessor_Scaledadsr.h:28
juce::ADSR::Parameters m_parameters
Definition KwidgetProcessor_Scaledadsr.h:35
void setDecay(float decay)
Definition KwidgetProcessor_Scaledadsr.cpp:121
void noteOff(float velocity) override
Definition KwidgetProcessor_Scaledadsr.cpp:97
An interface for an audio processor designed for modular use.
Definition KwidgetProcessor.h:8
Modulator * getModulator(int index)
Definition KwidgetProcessor.cpp:34
void nextBlock(int numSamples)
Definition KwidgetProcessor.cpp:50
void addParameterAttachments(std::vector< AttachmentInfo >)
Definition KwidgetProcessor.cpp:65
void nextSample()
Definition KwidgetProcessor.cpp:59
void addModulator(bool useAudioRate)
Definition KwidgetProcessor.h:139
void setValues(const float *values, int numValues)
Definition ModulationSource.h:34
Definition AirAbsorptionFilter.cpp:2
static const int MIDI_NOTE_FLAG_DRONE_NOTEUP
Definition OscillatorUtils.h:23
static const int MIDI_NOTE_FLAG_DRONE
Definition OscillatorUtils.h:22