Skip to content

Commit

Permalink
move ref tone to adjust and amp env with others, make param class lis…
Browse files Browse the repository at this point in the history
…teners
  • Loading branch information
bboettcher3 committed Jan 16, 2024
1 parent abea894 commit 046b11e
Show file tree
Hide file tree
Showing 20 changed files with 354 additions and 312 deletions.
72 changes: 46 additions & 26 deletions Source/Components/AdjustPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
#include "Utils/Colour.h"

AdjustPanel::AdjustPanel(Parameters& parameters)
: mParameters(parameters),
mCurSelectedParams(parameters.selectedParams),
mParamColour(Utils::GLOBAL_COLOUR),
mSliderPitchAdjust(parameters, ParamCommon::Type::PITCH_ADJUST),
mSliderPitchSpray(parameters, ParamCommon::Type::PITCH_SPRAY),
mSliderPosAdjust(parameters, ParamCommon::Type::POS_ADJUST),
mSliderPosSpray(parameters, ParamCommon::Type::POS_SPRAY),
mSliderPanAdjust(parameters, ParamCommon::Type::PAN_ADJUST),
mSliderPanSpray(parameters, ParamCommon::Type::PAN_SPRAY) {

mCurSelectedParams->addListener(this);
updateSelectedParams();

: mParameters(parameters),
mCurSelectedParams(parameters.getSelectedParams()),
mParamColour(Utils::GLOBAL_COLOUR),
mSliderPitchAdjust(parameters, ParamCommon::Type::PITCH_ADJUST),
mSliderPitchSpray(parameters, ParamCommon::Type::PITCH_SPRAY),
mSliderPosAdjust(parameters, ParamCommon::Type::POS_ADJUST),
mSliderPosSpray(parameters, ParamCommon::Type::POS_SPRAY),
mSliderPanAdjust(parameters, ParamCommon::Type::PAN_ADJUST),
mSliderPanSpray(parameters, ParamCommon::Type::PAN_SPRAY) {
// Default slider settings
std::vector<std::reference_wrapper<CommonSlider>> sliders = { mSliderPanSpray, mSliderPanAdjust, mSliderPosSpray, mSliderPosAdjust, mSliderPitchSpray, mSliderPitchAdjust };
for (auto& slider : sliders) {
Expand All @@ -35,20 +31,29 @@ AdjustPanel::AdjustPanel(Parameters& parameters)
}

// Default button settings
std::vector<std::reference_wrapper<juce::ToggleButton>> buttons = { mBtnReverse };
std::vector<std::reference_wrapper<juce::ToggleButton>> buttons = { mBtnReverse, mBtnRefTone };
for (auto& btn : buttons) {
btn.get().setColour(juce::ToggleButton::ColourIds::tickColourId, Utils::GLOBAL_COLOUR);
addAndMakeVisible(btn.get());
}

// Default label settings
std::vector<std::reference_wrapper<juce::Label>> labels = { mLabelReverse, mLabelPanSpray, mLabelPanAdjust, mLabelPosSpray, mLabelPosAdjust, mLabelPitchSpray, mLabelPitchAdjust };
std::vector<std::reference_wrapper<juce::Label>> labels = { mLabelReverse, mLabelRefTone, mLabelPanSpray, mLabelPanAdjust, mLabelPosSpray, mLabelPosAdjust, mLabelPitchSpray, mLabelPitchAdjust };
for (auto& label : labels) {
label.get().setColour(juce::Label::ColourIds::textColourId, Utils::GLOBAL_COLOUR);
label.get().setJustificationType(juce::Justification::centredTop);
label.get().setFont(juce::Font(14));
addAndMakeVisible(label.get());
}

// Reference tone
mBtnRefTone.onClick = [this]() {
if (mBtnRefTone.getToggleState() && onRefToneOn != nullptr) {
onRefToneOn();
}
else if (!mBtnRefTone.getToggleState() && onRefToneOff != nullptr) onRefToneOff();
};
mLabelRefTone.setText("ref tone", juce::dontSendNotification);

// Adjust pitch
mSliderPitchAdjust.setRange(ParamRanges::PITCH_ADJUST.start, ParamRanges::PITCH_ADJUST.end, 0.01);
Expand All @@ -65,7 +70,7 @@ AdjustPanel::AdjustPanel(Parameters& parameters)
mLabelPosAdjust.setText("pos adjust", juce::dontSendNotification);

// Position spray
mSliderPosSpray.setTextValueSuffix("s");
mSliderPosSpray.setTextValueSuffix(" s");
mSliderPosSpray.setNumDecimalPlacesToDisplay(3);
mSliderPosSpray.setRange(ParamRanges::POSITION_SPRAY.start, ParamRanges::POSITION_SPRAY.end, 0.005);
mLabelPosSpray.setText("pos spray", juce::dontSendNotification);
Expand All @@ -75,7 +80,7 @@ AdjustPanel::AdjustPanel(Parameters& parameters)
mLabelPanAdjust.setText("pan adjust", juce::dontSendNotification);

// Pan spray
mSliderPanSpray.setTextValueSuffix("s");
mSliderPanSpray.setTextValueSuffix(" s");
mSliderPanSpray.setNumDecimalPlacesToDisplay(3);
mSliderPanSpray.setRange(ParamRanges::PAN_SPRAY.start, ParamRanges::PAN_SPRAY.end, 0.005);
mLabelPanSpray.setText("pan spray", juce::dontSendNotification);
Expand All @@ -86,10 +91,15 @@ AdjustPanel::AdjustPanel(Parameters& parameters)
};
mLabelReverse.setText("reverse", juce::dontSendNotification);

mParameters.addListener(this);
mCurSelectedParams->addListener(this);
selectedCommonParamsChanged(mCurSelectedParams);

startTimer(100);
}

AdjustPanel::~AdjustPanel() {
mParameters.removeListener(this);
mCurSelectedParams->removeListener(this);
stopTimer();
}
Expand All @@ -115,20 +125,26 @@ void AdjustPanel::timerCallback() {
}
}

void AdjustPanel::updateSelectedParams() {
void AdjustPanel::selectedCommonParamsChanged(ParamCommon* newParams) {
if (mCurSelectedParams != nullptr) mCurSelectedParams->removeListener(this);
mCurSelectedParams = mParameters.selectedParams;
mCurSelectedParams = newParams;
mCurSelectedParams->addListener(this);

mParamColour = mParameters.getSelectedParamColour();
mSliderPitchAdjust.updateSelectedParams();
mSliderPitchSpray.updateSelectedParams();
mSliderPosAdjust.updateSelectedParams();
mSliderPosSpray.updateSelectedParams();
mSliderPanAdjust.updateSelectedParams();
mSliderPanSpray.updateSelectedParams();
mBtnReverse.setColour(juce::ToggleButton::ColourIds::tickColourId, mParamColour);


Utils::PitchClass selectedPitch = mParameters.getSelectedPitchClass();
// Turn ref tone off if global parameters
if (selectedPitch == Utils::PitchClass::NONE && mBtnRefTone.getToggleState() && onRefToneOff != nullptr) {
mBtnRefTone.setToggleState(false, juce::dontSendNotification);
onRefToneOff();
}
// Change ref tone frequency if already active
if (mBtnRefTone.getToggleState() && onRefToneOn != nullptr) onRefToneOn();
// Disable ref tone button if global parameters
mBtnRefTone.setEnabled(selectedPitch != Utils::PitchClass::NONE);
mBtnRefTone.setColour(juce::ToggleButton::ColourIds::tickColourId, mParamColour);

mParamHasChanged.store(true);
repaint();
}
Expand Down Expand Up @@ -162,6 +178,10 @@ void AdjustPanel::resized() {
mLabelPosAdjust.setBounds(knobPanel.removeFromBottom(Utils::LABEL_HEIGHT));
mSliderPosAdjust.setBounds(
knobPanel.removeFromBottom(Utils::KNOB_HEIGHT).withSizeKeepingCentre(Utils::KNOB_HEIGHT * 2, Utils::KNOB_HEIGHT));
// Reference tone button
knobPanel.removeFromBottom(Utils::PADDING);
mLabelRefTone.setBounds(knobPanel.removeFromBottom(Utils::LABEL_HEIGHT));
mBtnRefTone.setBounds(knobPanel.withSizeKeepingCentre(Utils::BUTTON_WIDTH, Utils::LABEL_HEIGHT));

// Middle: Pan spray/adjust and reverse
knobPanel = r;
Expand Down
14 changes: 11 additions & 3 deletions Source/Components/AdjustPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//==============================================================================
/*
*/
class AdjustPanel : public juce::Component, juce::AudioProcessorParameter::Listener, juce::Timer {
class AdjustPanel : public juce::Component,
public Parameters::Listener,
public juce::AudioProcessorParameter::Listener,
public juce::Timer {
public:
AdjustPanel(Parameters& parameters);
~AdjustPanel();
Expand All @@ -28,9 +31,12 @@ class AdjustPanel : public juce::Component, juce::AudioProcessorParameter::Liste
void parameterValueChanged(int idx, float value) override;
void parameterGestureChanged(int, bool) override {}

void timerCallback() override;
void selectedCommonParamsChanged(ParamCommon* newParams) override;

void updateSelectedParams();
void timerCallback() override;

std::function<void(void)> onRefToneOn = nullptr;
std::function<void(void)> onRefToneOff = nullptr;

private:
// Bookkeeping
Expand All @@ -54,6 +60,8 @@ class AdjustPanel : public juce::Component, juce::AudioProcessorParameter::Liste
juce::Label mLabelPanSpray;
juce::ToggleButton mBtnReverse;
juce::Label mLabelReverse;
juce::ToggleButton mBtnRefTone;
juce::Label mLabelRefTone;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AdjustPanel)
};
6 changes: 3 additions & 3 deletions Source/Components/ArcSpectrogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void ArcSpectrogram::paint(juce::Graphics& g) {
// Draw position lines from active note
ParamNote* note = nullptr;
int genIdx = -1; // Currently selected generator. If >= 0, darken generator's line
switch (mParameters.selectedParams->type) {
case ParamType::NOTE: note = dynamic_cast<ParamNote*>(mParameters.selectedParams); break;
switch (mParameters.getSelectedParams()->type) {
case ParamType::NOTE: note = dynamic_cast<ParamNote*>(mParameters.getSelectedParams()); break;
case ParamType::GENERATOR: {
auto gen = dynamic_cast<ParamGenerator*>(mParameters.selectedParams);
auto gen = dynamic_cast<ParamGenerator*>(mParameters.getSelectedParams());
note = mParameters.note.notes[gen->noteIdx].get();
genIdx = gen->genIdx;
}
Expand Down
21 changes: 8 additions & 13 deletions Source/Components/EnvelopeADSR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//==============================================================================
EnvelopeADSR::EnvelopeADSR(Parameters& parameters)
: mParameters(parameters),
mCurSelectedParams(parameters.selectedParams),
mCurSelectedParams(parameters.getSelectedParams()),
mSliderAttack(parameters, ParamCommon::Type::ATTACK),
mSliderDecay(parameters, ParamCommon::Type::DECAY),
mSliderSustain(parameters, ParamCommon::Type::SUSTAIN),
Expand All @@ -36,7 +36,7 @@ EnvelopeADSR::EnvelopeADSR(Parameters& parameters)
// Decay
mSliderDecay.setNumDecimalPlacesToDisplay(2);
mSliderDecay.setRange(ParamRanges::DECAY.start, ParamRanges::DECAY.end, 0.01);
mSliderDecay.setTextValueSuffix("s");
mSliderDecay.setTextValueSuffix(" s");
mSliderDecay.setPopupDisplayEnabled(true, true, this);
addAndMakeVisible(mSliderDecay);

Expand All @@ -59,7 +59,7 @@ EnvelopeADSR::EnvelopeADSR(Parameters& parameters)
// Release
mSliderRelease.setNumDecimalPlacesToDisplay(2);
mSliderRelease.setRange(ParamRanges::RELEASE.start, ParamRanges::RELEASE.end, 0.01);
mSliderRelease.setTextValueSuffix("s");
mSliderRelease.setTextValueSuffix(" s");
mSliderRelease.setPopupDisplayEnabled(true, true, this);
addAndMakeVisible(mSliderRelease);

Expand All @@ -68,13 +68,15 @@ EnvelopeADSR::EnvelopeADSR(Parameters& parameters)
mLabelRelease.setJustificationType(juce::Justification::centredTop);
addAndMakeVisible(mLabelRelease);

mParameters.addListener(this);
mCurSelectedParams->addListener(this);
updateSelectedParams();
selectedCommonParamsChanged(mCurSelectedParams);

startTimer(Utils::UI_REFRESH_INTERVAL);
}

EnvelopeADSR::~EnvelopeADSR() {
mParameters.removeListener(this);
mCurSelectedParams->removeListener(this);
stopTimer();
}
Expand All @@ -91,15 +93,11 @@ void EnvelopeADSR::timerCallback() {
}
}

void EnvelopeADSR::updateSelectedParams() {
void EnvelopeADSR::selectedCommonParamsChanged(ParamCommon* newParams) {
if (mCurSelectedParams != nullptr) mCurSelectedParams->removeListener(this);
mCurSelectedParams = mParameters.selectedParams;
mCurSelectedParams = newParams;
mCurSelectedParams->addListener(this);
mParamColour = mParameters.getSelectedParamColour();
mSliderAttack.updateSelectedParams();
mSliderDecay.updateSelectedParams();
mSliderSustain.updateSelectedParams();
mSliderRelease.updateSelectedParams();
mParamHasChanged.store(true);
repaint();
}
Expand All @@ -121,8 +119,6 @@ void EnvelopeADSR::paint(juce::Graphics& g) {
const float release = ParamRanges::RELEASE.convertTo0to1(mSliderRelease.getValue());

// Draw ADSR path
g.setFillType(juce::ColourGradient(colour.withAlpha(0.35f), mVizRect.getTopLeft(), colour.withAlpha(0.05f), mVizRect.getBottomLeft(), false));

auto adsrRect = mVizRect.reduced(Utils::PADDING * 2, Utils::PADDING * 2);

juce::Path adsrPath;
Expand All @@ -138,7 +134,6 @@ void EnvelopeADSR::paint(juce::Graphics& g) {
adsrPath.lineTo(sustainPt);
adsrPath.lineTo(endPt);
adsrPath.closeSubPath();
g.fillPath(adsrPath.createPathWithRoundedCorners(5));
g.setColour(colour);
g.strokePath(adsrPath.createPathWithRoundedCorners(5), juce::PathStrokeType(3));
}
Expand Down
9 changes: 6 additions & 3 deletions Source/Components/EnvelopeADSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
//==============================================================================
/*
*/
class EnvelopeADSR : public juce::Component, juce::AudioProcessorParameter::Listener, juce::Timer {
class EnvelopeADSR : public juce::Component,
public Parameters::Listener,
public juce::AudioProcessorParameter::Listener,
public juce::Timer {
public:
EnvelopeADSR(Parameters& parameters);
~EnvelopeADSR();
Expand All @@ -28,11 +31,11 @@ class EnvelopeADSR : public juce::Component, juce::AudioProcessorParameter::List

void parameterValueChanged(int idx, float value) override;
void parameterGestureChanged(int, bool) override {}

void selectedCommonParamsChanged(ParamCommon* newParams) override;

void timerCallback() override;

void updateSelectedParams();

private:
// Bookkeeping
Parameters& mParameters;
Expand Down
16 changes: 7 additions & 9 deletions Source/Components/EnvelopeGrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

EnvelopeGrain::EnvelopeGrain(Parameters& parameters)
: mParameters(parameters),
mCurSelectedParams(parameters.selectedParams),
mCurSelectedParams(parameters.getSelectedParams()),
mParamColour(Utils::GLOBAL_COLOUR),
mSliderShape(parameters, ParamCommon::Type::GRAIN_SHAPE),
mSliderTilt(parameters, ParamCommon::Type::GRAIN_TILT),
Expand Down Expand Up @@ -73,17 +73,19 @@ EnvelopeGrain::EnvelopeGrain(Parameters& parameters)
mBtnSync.setColour(juce::TextButton::textColourOffId, juce::Colours::white);
mBtnSync.setColour(juce::TextButton::textColourOnId, juce::Colours::black);
mBtnSync.onClick = [this]() {
ParamHelper::setCommonParam(mParameters.selectedParams, ParamCommon::Type::GRAIN_SYNC, !mBtnSync.getToggleState());
ParamHelper::setCommonParam(mParameters.getSelectedParams(), ParamCommon::Type::GRAIN_SYNC, !mBtnSync.getToggleState());
};
addAndMakeVisible(mBtnSync);

mParameters.addListener(this);
mCurSelectedParams->addListener(this);
updateSelectedParams();
selectedCommonParamsChanged(mCurSelectedParams);

startTimer(Utils::UI_REFRESH_INTERVAL);
}

EnvelopeGrain::~EnvelopeGrain() {
mParameters.removeListener(this);
mCurSelectedParams->removeListener(this);
stopTimer();
}
Expand All @@ -109,15 +111,11 @@ void EnvelopeGrain::timerCallback() {
}
}

void EnvelopeGrain::updateSelectedParams() {
void EnvelopeGrain::selectedCommonParamsChanged(ParamCommon* newParams) {
if (mCurSelectedParams != nullptr) mCurSelectedParams->removeListener(this);
mCurSelectedParams = mParameters.selectedParams;
mCurSelectedParams = newParams;
mCurSelectedParams->addListener(this);
mParamColour = mParameters.getSelectedParamColour();
mSliderShape.updateSelectedParams();
mSliderTilt.updateSelectedParams();
mSliderRate.updateSelectedParams();
mSliderDuration.updateSelectedParams();
mBtnSync.setColour(juce::TextButton::buttonColourId, mParamColour);
mBtnSync.setColour(juce::TextButton::buttonOnColourId, mParamColour.interpolatedWith(juce::Colours::white, 0.6f));
mParamHasChanged.store(true);
Expand Down
9 changes: 6 additions & 3 deletions Source/Components/EnvelopeGrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//==============================================================================
/*
*/
class EnvelopeGrain : public juce::Component, juce::AudioProcessorParameter::Listener, juce::Timer {
class EnvelopeGrain : public juce::Component,
public Parameters::Listener,
public juce::AudioProcessorParameter::Listener,
public juce::Timer {
public:
EnvelopeGrain(Parameters& parameters);
~EnvelopeGrain();
Expand All @@ -27,11 +30,11 @@ class EnvelopeGrain : public juce::Component, juce::AudioProcessorParameter::Lis

void parameterValueChanged(int idx, float value) override;
void parameterGestureChanged(int, bool) override {}

void selectedCommonParamsChanged(ParamCommon* newParams) override;

void timerCallback() override;

void updateSelectedParams();

private:
static constexpr double WINDOW_SECONDS = 0.4; // Width in seconds of the display window

Expand Down
Loading

0 comments on commit 046b11e

Please sign in to comment.