Skip to content

Commit

Permalink
fix!: increase num of split type
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Jul 31, 2024
1 parent 76dff66 commit 3db59ab
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions source/dsp/controller_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace zlDSP {

void ControllerAttach::parameterChanged(const juce::String &parameterID, float newValue) {
if (parameterID == splitType::ID) {
newValue = std::min(newValue, static_cast<float>(splitType::tsteady));
controllerRef.setType(static_cast<splitType::stype>(newValue));
triggerAsyncUpdate();
} else if (parameterID == mix::ID) {
Expand Down
2 changes: 1 addition & 1 deletion source/dsp/dsp_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace zlDSP {
auto static constexpr ID = "split_type";
auto static constexpr name = "Split Type";
inline auto static const choices = juce::StringArray{
"Left Right", "Mid Side", "Low High", "Transient Steady"
"Left Right", "Mid Side", "Low High", "Transient Steady", "", "", "", ""
};
int static constexpr defaultI = 0;

Expand Down
1 change: 1 addition & 0 deletions source/gui/combobox/combobox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
#include "compact_figure_combobox/compact_figure_combobox.hpp"
#include "left_right_combobox/left_right_combobox.hpp"
#include "click_combobox/click_combobox.hpp"
#include "combobox_sub_attachment.hpp"

#endif //ZLINTERFACE_COMBOBOX_H
75 changes: 75 additions & 0 deletions source/gui/combobox/combobox_sub_attachment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (C) 2024 - zsliu98
// This file is part of ZLSplitter
//
// ZLSplitter is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// ZLSplitter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with ZLSplitter. If not, see <https://www.gnu.org/licenses/>.

#ifndef COMBOBOX_SUB_ATTACHMENT_HPP
#define COMBOBOX_SUB_ATTACHMENT_HPP

#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_gui_basics/juce_gui_basics.h>

namespace zlInterface {
class ComboBoxSubAttachment final : private juce::ComboBox::Listener {
public:
ComboBoxSubAttachment(const juce::AudioProcessorValueTreeState &stateToUse,
const juce::String &parameterID,
juce::ComboBox &combo,
const int numItem)
: comboBox(combo),
storedParameter(*(stateToUse.getParameter(parameterID))),
numItems(numItem),
attachment(*(stateToUse.getParameter(parameterID)),
[this](const float f) { setValue(f); },
stateToUse.undoManager) {
sendInitialUpdate();
comboBox.addListener(this);
}

~ComboBoxSubAttachment() override {
comboBox.removeListener(this);
}

/** Call this after setting up your combo box in the case where you need to do
extra setup after constructing this attachment.
*/
void sendInitialUpdate() {
attachment.sendInitialUpdate();
}

private:
void setValue(const float newValue) {
const auto normValue = storedParameter.convertTo0to1(newValue);
const auto index = std::min(juce::roundToInt(normValue * static_cast<float>(numItems - 1)),
comboBox.getNumItems() - 1);

if (index == comboBox.getSelectedItemIndex()) return;

const juce::ScopedValueSetter<bool> svs(ignoreCallbacks, true);
comboBox.setSelectedItemIndex(index, juce::sendNotificationSync);
}

void comboBoxChanged(juce::ComboBox *) override {
if (ignoreCallbacks)
return;

const auto selected = static_cast<float>(comboBox.getSelectedItemIndex());
const auto newValue = numItems > 1
? selected / static_cast<float>(numItems - 1)
: 0.0f;
attachment.setValueAsCompleteGesture(storedParameter.convertFrom0to1(newValue));
}

juce::ComboBox &comboBox;
juce::RangedAudioParameter &storedParameter;
int numItems;
juce::ParameterAttachment attachment;
bool ignoreCallbacks = false;
};
}

#endif //COMBOBOX_SUB_ATTACHMENT_HPP
5 changes: 2 additions & 3 deletions source/panel/top_panel/top_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ namespace zlPanel {
tsIcon(juce::Drawable::createFromImageData(BinaryData::transientsteady_svg,
BinaryData::transientsteady_svgSize)),
swapButton("", base),
splitBox({lrIcon.get(), msIcon.get(), lhIcon.get(), tsIcon.get()}, base) {
splitBox({lrIcon.get(), msIcon.get(), lhIcon.get(), tsIcon.get()}, base),
boxAttachment(processor.parameters, zlDSP::splitType::ID, splitBox.getBox(), zlDSP::splitType::choices.size()) {
attach({&swapButton.getButton()}, {zlDSP::swap::ID}, processor.parameters, buttonAttachments);
attach({&splitBox.getBox()}, {zlDSP::splitType::ID}, processor.parameters, boxAttachments);

addAndMakeVisible(logoPanel);

swapButton.getLAF().enableShadow(false);
Expand Down
2 changes: 1 addition & 1 deletion source/panel/top_panel/top_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace zlPanel {
zlInterface::CompactFigureCombobox splitBox;

juce::OwnedArray<juce::AudioProcessorValueTreeState::ButtonAttachment> buttonAttachments;
juce::OwnedArray<juce::AudioProcessorValueTreeState::ComboBoxAttachment> boxAttachments;
zlInterface::ComboBoxSubAttachment boxAttachment;
};
} // zlPanel

Expand Down

0 comments on commit 3db59ab

Please sign in to comment.