kopia lustrzana https://github.com/jameshball/osci-render
Get all parameters working
rodzic
6d08a00b33
commit
a7169bd8d1
|
@ -16,18 +16,26 @@ MidiComponent::MidiComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
|
|||
envelope.setEnv(audioProcessor.adsrEnv);
|
||||
envelope.addListener(&audioProcessor);
|
||||
|
||||
audioProcessor.attack->addListener(this);
|
||||
audioProcessor.decay->addListener(this);
|
||||
audioProcessor.sustain->addListener(this);
|
||||
audioProcessor.release->addListener(this);
|
||||
audioProcessor.attackTime->addListener(this);
|
||||
audioProcessor.attackLevel->addListener(this);
|
||||
audioProcessor.attackShape->addListener(this);
|
||||
audioProcessor.decayTime->addListener(this);
|
||||
audioProcessor.decayShape->addListener(this);
|
||||
audioProcessor.sustainLevel->addListener(this);
|
||||
audioProcessor.releaseTime->addListener(this);
|
||||
audioProcessor.releaseShape->addListener(this);
|
||||
}
|
||||
|
||||
MidiComponent::~MidiComponent() {
|
||||
envelope.removeListener(&audioProcessor);
|
||||
audioProcessor.attack->removeListener(this);
|
||||
audioProcessor.decay->removeListener(this);
|
||||
audioProcessor.sustain->removeListener(this);
|
||||
audioProcessor.release->removeListener(this);
|
||||
audioProcessor.attackTime->removeListener(this);
|
||||
audioProcessor.attackLevel->removeListener(this);
|
||||
audioProcessor.attackShape->removeListener(this);
|
||||
audioProcessor.decayTime->removeListener(this);
|
||||
audioProcessor.decayShape->removeListener(this);
|
||||
audioProcessor.sustainLevel->removeListener(this);
|
||||
audioProcessor.releaseTime->removeListener(this);
|
||||
audioProcessor.releaseShape->removeListener(this);
|
||||
}
|
||||
|
||||
void MidiComponent::parameterValueChanged(int parameterIndex, float newValue) {
|
||||
|
@ -38,13 +46,20 @@ void MidiComponent::parameterGestureChanged(int parameterIndex, bool gestureIsSt
|
|||
|
||||
void MidiComponent::handleAsyncUpdate() {
|
||||
DBG("MidiComponent::handleAsyncUpdate");
|
||||
Env newEnv = Env::adsr(
|
||||
audioProcessor.attack->getValueUnnormalised(),
|
||||
audioProcessor.decay->getValueUnnormalised(),
|
||||
audioProcessor.sustain->getValueUnnormalised(),
|
||||
audioProcessor.release->getValueUnnormalised(),
|
||||
1.0,
|
||||
std::vector<EnvCurve>{ audioProcessor.attackShape->getValueUnnormalised(), audioProcessor.decayShape->getValueUnnormalised(), audioProcessor.releaseShape->getValueUnnormalised() }
|
||||
Env newEnv = Env(
|
||||
{
|
||||
0.0,
|
||||
audioProcessor.attackLevel->getValueUnnormalised(),
|
||||
audioProcessor.sustainLevel->getValueUnnormalised(),
|
||||
0.0
|
||||
},
|
||||
{
|
||||
audioProcessor.attackTime->getValueUnnormalised(),
|
||||
audioProcessor.decayTime->getValueUnnormalised(),
|
||||
audioProcessor.releaseTime->getValueUnnormalised()
|
||||
},
|
||||
std::vector<EnvCurve>{ audioProcessor.attackShape->getValueUnnormalised(), audioProcessor.decayShape->getValueUnnormalised(), audioProcessor.releaseShape->getValueUnnormalised() },
|
||||
2
|
||||
);
|
||||
|
||||
envelope.setEnv(newEnv);
|
||||
|
|
|
@ -141,10 +141,14 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
|||
addParameter(parameter);
|
||||
}
|
||||
|
||||
addParameter(attack);
|
||||
addParameter(decay);
|
||||
addParameter(sustain);
|
||||
addParameter(release);
|
||||
addParameter(attackTime);
|
||||
addParameter(attackLevel);
|
||||
addParameter(attackShape);
|
||||
addParameter(decayTime);
|
||||
addParameter(decayShape);
|
||||
addParameter(sustainLevel);
|
||||
addParameter(releaseTime);
|
||||
addParameter(releaseShape);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
synth.addVoice(new ShapeVoice(*this));
|
||||
|
@ -699,6 +703,12 @@ void OscirenderAudioProcessor::parameterValueChanged(int parameterIndex, float n
|
|||
|
||||
void OscirenderAudioProcessor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {}
|
||||
|
||||
void updateIfApproxEqual(FloatParameter* parameter, float newValue) {
|
||||
if (std::abs(parameter->getValueUnnormalised() - newValue) > 0.0001) {
|
||||
parameter->setUnnormalisedValueNotifyingHost(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessor::envelopeChanged(EnvelopeComponent* changedEnvelope) {
|
||||
Env env = changedEnvelope->getEnv();
|
||||
std::vector<double> levels = env.getLevels();
|
||||
|
@ -707,27 +717,14 @@ void OscirenderAudioProcessor::envelopeChanged(EnvelopeComponent* changedEnvelop
|
|||
|
||||
if (levels.size() == 4 && times.size() == 3 && curves.size() == 3) {
|
||||
this->adsrEnv = env;
|
||||
if (attack->getValueUnnormalised() != times[0]) {
|
||||
attack->setUnnormalisedValueNotifyingHost(times[0]);
|
||||
}
|
||||
if (decay->getValueUnnormalised() != times[1]) {
|
||||
decay->setUnnormalisedValueNotifyingHost(times[1]);
|
||||
}
|
||||
if (sustain->getValueUnnormalised() != levels[2]) {
|
||||
sustain->setUnnormalisedValueNotifyingHost(levels[2]);
|
||||
}
|
||||
if (release->getValueUnnormalised() != times[2]) {
|
||||
release->setUnnormalisedValueNotifyingHost(times[2]);
|
||||
}
|
||||
if (attackShape->getValueUnnormalised() != curves[0].getCurve()) {
|
||||
attackShape->setUnnormalisedValueNotifyingHost(curves[0].getCurve());
|
||||
}
|
||||
if (decayShape->getValueUnnormalised() != curves[1].getCurve()) {
|
||||
decayShape->setUnnormalisedValueNotifyingHost(curves[1].getCurve());
|
||||
}
|
||||
if (releaseShape->getValueUnnormalised() != curves[2].getCurve()) {
|
||||
releaseShape->setUnnormalisedValueNotifyingHost(curves[2].getCurve());
|
||||
}
|
||||
updateIfApproxEqual(attackTime, times[0]);
|
||||
updateIfApproxEqual(attackLevel, levels[1]);
|
||||
updateIfApproxEqual(attackShape, curves[0].getCurve());
|
||||
updateIfApproxEqual(decayTime, times[1]);
|
||||
updateIfApproxEqual(sustainLevel, levels[2]);
|
||||
updateIfApproxEqual(decayShape, curves[1].getCurve());
|
||||
updateIfApproxEqual(releaseTime, times[2]);
|
||||
updateIfApproxEqual(releaseShape, curves[2].getCurve());
|
||||
DBG("adsr changed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,20 +195,20 @@ public:
|
|||
std::atomic<bool> objectServerRendering = false;
|
||||
juce::ChangeBroadcaster fileChangeBroadcaster;
|
||||
|
||||
FloatParameter* attack = new FloatParameter("Attack", "attack", VERSION_HINT, 0.1, 0.0, 1.0);
|
||||
FloatParameter* attackTime = new FloatParameter("Attack Time", "attackTime", VERSION_HINT, 0.05, 0.0, 1.0);
|
||||
FloatParameter* attackLevel = new FloatParameter("Attack Level", "attackLevel", VERSION_HINT, 1.0, 0.0, 1.0);
|
||||
FloatParameter* decay = new FloatParameter("Decay", "decay", VERSION_HINT, 0.1, 0.0, 1.0);
|
||||
FloatParameter* sustain = new FloatParameter("Sustain", "sustain", VERSION_HINT, 0.1, 0.0, 1.0);
|
||||
FloatParameter* release = new FloatParameter("Release", "release", VERSION_HINT, 0.1, 0.0, 1.0);
|
||||
FloatParameter* attackShape = new FloatParameter("Attack Shape", "attackShape", VERSION_HINT, 0.0, 0.0, 1.0);
|
||||
FloatParameter* decayShape = new FloatParameter("Decay Shape", "decayShape", VERSION_HINT, 0.0, 0.0, 1.0);
|
||||
FloatParameter* releaseShape = new FloatParameter("Release Shape", "releaseShape", VERSION_HINT, 0.0, 0.0, 1.0);
|
||||
FloatParameter* decayTime = new FloatParameter("Decay Time", "decayTime", VERSION_HINT, 0.05, 0.0, 1.0);
|
||||
FloatParameter* sustainLevel = new FloatParameter("Sustain Level", "sustainLevel", VERSION_HINT, 0.8, 0.0, 1.0);
|
||||
FloatParameter* releaseTime = new FloatParameter("Release Time", "releaseTime", VERSION_HINT, 0.2, 0.0, 1.0);
|
||||
FloatParameter* attackShape = new FloatParameter("Attack Shape", "attackShape", VERSION_HINT, 5, -50, 50);
|
||||
FloatParameter* decayShape = new FloatParameter("Decay Shape", "decayShape", VERSION_HINT, -20, -50, 50);
|
||||
FloatParameter* releaseShape = new FloatParameter("Release Shape", "releaseShape", VERSION_HINT, 5,-50, 50);
|
||||
|
||||
Env adsrEnv = Env::adsr(
|
||||
attack->getValueUnnormalised(),
|
||||
decay->getValueUnnormalised(),
|
||||
sustain->getValueUnnormalised(),
|
||||
release->getValueUnnormalised(),
|
||||
attackTime->getValueUnnormalised(),
|
||||
decayTime->getValueUnnormalised(),
|
||||
sustainLevel->getValueUnnormalised(),
|
||||
releaseTime->getValueUnnormalised(),
|
||||
1.0,
|
||||
std::vector<EnvCurve>{ attackShape->getValueUnnormalised(), decayShape->getValueUnnormalised(), releaseShape->getValueUnnormalised() }
|
||||
);
|
||||
|
|
|
@ -470,7 +470,6 @@ void EnvelopeHandleComponent::setTimeAndValue(double timeToSet, double valueToSe
|
|||
dontUpdateTimeAndValue = oldDontUpdateTimeAndValue;
|
||||
|
||||
getParentComponent()->repaint();
|
||||
getParentComponent()->sendChangeMessage();
|
||||
}
|
||||
|
||||
void EnvelopeHandleComponent::offsetTimeAndValue(double offsetTime, double offsetValue, double quantise)
|
||||
|
@ -493,7 +492,7 @@ double EnvelopeHandleComponent::constrainDomain(double domainToConstrain) const
|
|||
if(previousHandle != 0) left += FINETUNE;
|
||||
if(nextHandle != 0) right -= FINETUNE;
|
||||
|
||||
return juce::jlimit(left, right, shouldLockTime ? time : domainToConstrain);
|
||||
return juce::jlimit(juce::jmin(left, right), juce::jmax(left, right), shouldLockTime ? time : domainToConstrain);
|
||||
}
|
||||
|
||||
double EnvelopeHandleComponent::constrainValue(double valueToConstrain) const
|
||||
|
@ -1274,8 +1273,9 @@ void EnvelopeComponent::setEnv(Env const& env)
|
|||
for (int i = 0; i < handles.size(); i++) {
|
||||
EnvelopeHandleComponent* handle = handles.getUnchecked(i);
|
||||
handle->setTimeAndValue(time, (double)levels[i], 0.0);
|
||||
handle->setCurve(curves[i]);
|
||||
quantiseHandle(handle);
|
||||
if (i > 0) {
|
||||
handle->curve = curves[i - 1];
|
||||
}
|
||||
if (i < times.size()) {
|
||||
time += times[i];
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue