Have envelope control ADSR of MIDI

pull/170/head
James Ball 2023-11-25 17:57:35 +00:00
rodzic a7169bd8d1
commit 00edb70a75
6 zmienionych plików z 42 dodań i 20 usunięć

Wyświetl plik

@ -62,6 +62,11 @@ void MidiComponent::handleAsyncUpdate() {
2
);
{
juce::SpinLock::ScopedLockType lock(audioProcessor.effectsLock);
audioProcessor.adsrEnv = newEnv;
}
envelope.setEnv(newEnv);
}

Wyświetl plik

@ -716,7 +716,10 @@ void OscirenderAudioProcessor::envelopeChanged(EnvelopeComponent* changedEnvelop
EnvCurveList curves = env.getCurves();
if (levels.size() == 4 && times.size() == 3 && curves.size() == 3) {
{
juce::SpinLock::ScopedLockType lock(effectsLock);
this->adsrEnv = env;
}
updateIfApproxEqual(attackTime, times[0]);
updateIfApproxEqual(attackLevel, levels[1]);
updateIfApproxEqual(attackShape, curves[0].getCurve());

Wyświetl plik

@ -221,9 +221,10 @@ float Env::lookup(float time) const throw()
float level0 = levels_[stageIndex-1];
float level1 = levels_[stageIndex];
EnvCurve curve = getCurves()[stageIndex-1];
EnvCurve::CurveType type = curve.getType();
float curveValue = curve.getCurve();
int curveIndex = (stageIndex - 1) % curves_.size();
EnvCurve::CurveType type = curves_.data[curveIndex].getType();
float curveValue = curves_.data[curveIndex].getCurve();
if((lastTime - stageTime)==0.f)
{

Wyświetl plik

@ -140,7 +140,6 @@ public:
/// @} <!-- end Array access and manipulation ----------------------------------------------- -->
private:
static EnvCurve empty;
std::vector<EnvCurve> data;
};

Wyświetl plik

@ -21,7 +21,18 @@ void ShapeVoice::startNote(int midiNoteNumber, float velocity, juce::Synthesiser
frameLength = shapeSound->updateFrame(frame);
tries++;
}
tailOff = 0.0;
adsr = audioProcessor.adsrEnv;
time = 0.0;
releaseTime = 0.0;
endTime = 0.0;
waitingForRelease = true;
std::vector<double> times = adsr.getTimes();
for (int i = 0; i < times.size(); i++) {
if (i < adsr.getReleaseNode()) {
releaseTime += times[i];
}
endTime += times[i];
}
if (audioProcessor.midiEnabled->getBoolValue()) {
frequency = juce::MidiMessage::getMidiNoteInHertz(midiNoteNumber);
}
@ -104,17 +115,17 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
x = channels.x;
y = channels.y;
if (tailOff > 0.0) {
tailOff *= 0.99999;
time += 1.0 / audioProcessor.currentSampleRate;
if (tailOff < 0.005) {
if (waitingForRelease) {
time = juce::jmin(time, releaseTime);
} else if (time >= endTime) {
clearCurrentNote();
sound = nullptr;
break;
}
}
double gain = tailOff == 0.0 ? 1.0 : tailOff;
double gain = audioProcessor.midiEnabled->getBoolValue() ? adsr.lookup(time) : 1.0;
if (numChannels >= 2) {
outputBuffer.addSample(0, sample, x * gain);
@ -154,11 +165,8 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
void ShapeVoice::stopNote(float velocity, bool allowTailOff) {
currentlyPlaying = false;
if (allowTailOff) {
if (tailOff == 0.0) {
tailOff = 1.0;
}
} else {
waitingForRelease = false;
if (!allowTailOff) {
clearCurrentNote();
sound = nullptr;
}

Wyświetl plik

@ -1,6 +1,7 @@
#pragma once
#include <JuceHeader.h>
#include "ShapeSound.h"
#include "../UGen/Env.h"
class OscirenderAudioProcessor;
class ShapeVoice : public juce::SynthesiserVoice {
@ -34,6 +35,11 @@ private:
double lengthIncrement = 0.0;
bool currentlyPlaying = false;
double tailOff = 0.0;
double frequency = 1.0;
Env adsr;
double time = 0.0;
double releaseTime = 0.0;
double endTime = 99999999;
bool waitingForRelease = false;
};