Skip to content

Commit

Permalink
implementing the gate preset class
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Jan 23, 2025
1 parent 0ca06a8 commit 93e77a0
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 123 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_sources(easyeffects PRIVATE
fir_filter_highpass.cpp
fir_filter_lowpass.cpp
gate.cpp
gate_preset.cpp
kconfig_base_ee.cpp
limiter.cpp
limiter_preset.cpp
Expand Down
137 changes: 27 additions & 110 deletions src/contents/kcfg/easyeffects_db_gate.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,11 @@
<max>20</max>
<default>0</default>
</entry>
<entry name="mode" type="Enum">
<entry name="modeLabels" type="StringList">
<default>Downward,Upward,Boosting</default>
</entry>
<entry name="mode" type="Int">
<label>Mode</label>
<choices>
<choice name="downward">
<label>Downward</label>
</choice>
<choice name="upward">
<label>Upward</label>
</choice>
<choice name="boosting">
<label>Boosting</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="attack" type="Double">
Expand Down Expand Up @@ -106,89 +98,36 @@
<label></label>
<default>false</default>
</entry>
<entry name="sidechainType" type="Enum">
<entry name="sidechainTypeLabels" type="StringList">
<default>Internal,External,Link</default>
</entry>
<entry name="sidechainType" type="Int">
<label>Sidechain Type</label>
<choices>
<choice name="internal">
<label>Internal</label>
</choice>
<choice name="external">
<label>External</label>
</choice>
<choice name="link">
<label>Link</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="sidechainMode" type="Enum">
<entry name="sidechainModeLabels" type="StringList">
<default>Peak,RMS,Low-Pass,SMA</default>
</entry>
<entry name="sidechainMode" type="Int">
<label>Sidechain Mode</label>
<choices>
<choice name="peak">
<label>Peak</label>
</choice>
<choice name="rms">
<label>RMS</label>
</choice>
<choice name="lowPass">
<label>Low-Pass</label>
</choice>
<choice name="sma">
<label>SMA</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="stereoSplit" type="Bool">
<label></label>
<default>false</default>
</entry>
<entry name="sidechainSource" type="Enum">
<entry name="sidechainSourceLabels" type="StringList">
<default>Middle,Side,Left,Right,Min,Max</default>
</entry>
<entry name="sidechainSource" type="Int">
<label>Sidechain Source</label>
<choices>
<choice name="middle">
<label>Middle</label>
</choice>
<choice name="side">
<label>Side</label>
</choice>
<choice name="left">
<label>Left</label>
</choice>
<choice name="right">
<label>Right</label>
</choice>
<choice name="min">
<label>Min</label>
</choice>
<choice name="max">
<label>Max</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="stereoSplitSource" type="Enum">
<entry name="stereoSplitSourceLabels" type="StringList">
<default>Left/Right,Right/Left,Mid/Side,Side/Mid,Min,Max</default>
</entry>
<entry name="stereoSplitSource" type="Int">
<label>Stereo Split Mode</label>
<choices>
<choice name="leftRight">
<label>Left/Right</label>
</choice>
<choice name="rightLeft">
<label>Right/Left</label>
</choice>
<choice name="midSide">
<label>Mid/Side</label>
</choice>
<choice name="sideMid">
<label>Side/Mid</label>
</choice>
<choice name="min">
<label>Min</label>
</choice>
<choice name="max">
<label>Max</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="sidechainPreamp" type="Double">
Expand All @@ -209,22 +148,11 @@
<max>20</max>
<default>0</default>
</entry>
<entry name="hpfMode" type="Enum">
<entry name="hpfModeLabels" type="StringList">
<default>Off,12 dB/oct,24 dB/oct,36 dB/oct</default>
</entry>
<entry name="hpfMode" type="Int">
<label>High-pass Filter Mode</label>
<choices>
<choice name="off">
<label>Off</label>
</choice>
<choice name="v12dBoct">
<label>12 dB/oct</label>
</choice>
<choice name="v24dBoct">
<label>24 dB/oct</label>
</choice>
<choice name="v36dBoct">
<label>36 dB/oct</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="hpfFrequency" type="Double">
Expand All @@ -233,22 +161,11 @@
<max>20000</max>
<default>10</default>
</entry>
<entry name="lpfModeLabels" type="StringList">
<default>Off,12 dB/oct,24 dB/oct,36 dB/oct</default>
</entry>
<entry name="lpfMode" type="Enum">
<label>Low-pass Filter Mode</label>
<choices>
<choice name="off">
<label>Off</label>
</choice>
<choice name="v12dBoct">
<label>12 dB/oct</label>
</choice>
<choice name="v24dBoct">
<label>24 dB/oct</label>
</choice>
<choice name="v36dBoct">
<label>36 dB/oct</label>
</choice>
</choices>
<default>0</default>
</entry>
<entry name="lpfFrequency" type="Double">
Expand Down
2 changes: 1 addition & 1 deletion src/gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void Gate::process(std::span<float>& left_in,
}

void Gate::update_sidechain_links() {
if (settings->sidechainType() != db::Gate::EnumSidechainType::type::external) {
if (settings->defaultSidechainTypeLabelsValue()[settings->sidechainType()] != "External") {
pm->destroy_links(list_proxies);

list_proxies.clear();
Expand Down
123 changes: 123 additions & 0 deletions src/gate_preset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright © 2017-2024 Wellington Wallace
*
* This file is part of Easy Effects.
*
* Easy Effects 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.
*
* Easy Effects 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 Easy Effects. If not, see <https://www.gnu.org/licenses/>.
*/

#include "gate_preset.hpp"
#include <qstringview.h>
#include <nlohmann/json_fwd.hpp>
#include <string>
#include "easyeffects_db_gate.h"
#include "pipeline_type.hpp"
#include "plugin_preset_base.hpp"
#include "presets_macros.hpp"

GatePreset::GatePreset(PipelineType pipeline_type, const std::string& instance_name)
: PluginPresetBase(pipeline_type, instance_name) {
settings = get_db_instance<db::Gate>(pipeline_type);
}

void GatePreset::save(nlohmann::json& json) {
json[section][instance_name]["bypass"] = settings->bypass();

json[section][instance_name]["input-gain"] = settings->inputGain();

json[section][instance_name]["output-gain"] = settings->outputGain();

json[section][instance_name]["dry"] = settings->dry();

json[section][instance_name]["wet"] = settings->wet();

json[section][instance_name]["attack"] = settings->attack();

json[section][instance_name]["release"] = settings->release();

json[section][instance_name]["curve-threshold"] = settings->curveThreshold();

json[section][instance_name]["curve-zone"] = settings->curveZone();

json[section][instance_name]["hysteresis"] = settings->hysteresis();

json[section][instance_name]["hysteresis-threshold"] = settings->hysteresisThreshold();

json[section][instance_name]["hysteresis-zone"] = settings->hysteresisZone();

json[section][instance_name]["reduction"] = settings->reduction();

json[section][instance_name]["makeup"] = settings->makeup();

json[section][instance_name]["stereo-split"] = settings->stereoSplit();

json[section][instance_name]["sidechain"]["type"] =
settings->defaultSidechainTypeLabelsValue()[settings->sidechainType()].toStdString();

json[section][instance_name]["sidechain"]["mode"] =
settings->defaultSidechainModeLabelsValue()[settings->sidechainMode()].toStdString();

json[section][instance_name]["sidechain"]["source"] =
settings->defaultSidechainSourceLabelsValue()[settings->sidechainSource()].toStdString();

json[section][instance_name]["sidechain"]["stereo-split-source"] =
settings->defaultStereoSplitSourceLabelsValue()[settings->stereoSplitSource()].toStdString();

json[section][instance_name]["sidechain"]["preamp"] = settings->sidechainPreamp();

json[section][instance_name]["sidechain"]["reactivity"] = settings->sidechainReactivity();

json[section][instance_name]["sidechain"]["lookahead"] = settings->sidechainLookahead();

json[section][instance_name]["hpf-mode"] = settings->defaultHpfModeLabelsValue()[settings->hpfMode()].toStdString();

json[section][instance_name]["hpf-frequency"] = settings->hpfFrequency();

json[section][instance_name]["lpf-mode"] = settings->defaultLpfModeLabelsValue()[settings->lpfMode()].toStdString();

json[section][instance_name]["lpf-frequency"] = settings->lpfFrequency();
}

void GatePreset::load(const nlohmann::json& json) {
UPDATE_PROPERTY("bypass", Bypass);
UPDATE_PROPERTY("input-gain", InputGain);
UPDATE_PROPERTY("output-gain", OutputGain);
UPDATE_PROPERTY("dry", Dry);
UPDATE_PROPERTY("wet", Wet);
UPDATE_PROPERTY("attack", Attack);
UPDATE_PROPERTY("release", Release);
UPDATE_PROPERTY("curve-threshold", CurveThreshold);
UPDATE_PROPERTY("curve-zone", CurveZone);
UPDATE_PROPERTY("hysteresis", Hysteresis);
UPDATE_PROPERTY("hysteresis-threshold", HysteresisThreshold);
UPDATE_PROPERTY("hysteresis-zone", HysteresisZone);
UPDATE_PROPERTY("reduction", Reduction);
UPDATE_PROPERTY("makeup", Makeup);
UPDATE_PROPERTY("reduction", Reduction);
UPDATE_PROPERTY("stereo-split", StereoSplit);
UPDATE_PROPERTY("hpf-frequency", HpfFrequency);
UPDATE_PROPERTY("lpf-frequency", LpfFrequency);

UPDATE_ENUM_LIKE_PROPERTY("hpf-mode", HpfMode);
UPDATE_ENUM_LIKE_PROPERTY("lpf-mode", LpfMode);

UPDATE_PROPERTY_INSIDE_SUBSECTION("sidechain", "preamp", SidechainPreamp);
UPDATE_PROPERTY_INSIDE_SUBSECTION("sidechain", "reactivity", SidechainReactivity);
UPDATE_PROPERTY_INSIDE_SUBSECTION("sidechain", "lookahead", SidechainLookahead);

UPDATE_ENUM_LIKE_PROPERTY_INSIDE_SUBSECTION("sidechain", "type", SidechainType);
UPDATE_ENUM_LIKE_PROPERTY_INSIDE_SUBSECTION("sidechain", "mode", SidechainMode);
UPDATE_ENUM_LIKE_PROPERTY_INSIDE_SUBSECTION("sidechain", "source", SidechainSource);
UPDATE_ENUM_LIKE_PROPERTY_INSIDE_SUBSECTION("sidechain", "stereo-split-source", StereoSplitSource);
}
38 changes: 38 additions & 0 deletions src/gate_preset.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright © 2017-2024 Wellington Wallace
*
* This file is part of Easy Effects.
*
* Easy Effects 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.
*
* Easy Effects 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 Easy Effects. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <nlohmann/json_fwd.hpp>
#include <string>
#include "easyeffects_db_gate.h"
#include "pipeline_type.hpp"
#include "plugin_preset_base.hpp"

class GatePreset : public PluginPresetBase {
public:
explicit GatePreset(PipelineType pipeline_type, const std::string& instance_name);

private:
db::Gate* settings = nullptr;

void save(nlohmann::json& json) override;

void load(const nlohmann::json& json) override;
};
3 changes: 2 additions & 1 deletion src/presets_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "easyeffects_db_streamoutputs.h"
#include "exciter_preset.hpp"
#include "filter_preset.hpp"
#include "gate_preset.hpp"
#include "limiter_preset.hpp"
#include "maximizer_preset.hpp"
#include "pipeline_type.hpp"
Expand Down Expand Up @@ -1311,7 +1312,7 @@ auto Manager::create_wrapper(const PipelineType& pipeline_type, const QString& f
}

if (filter_name.startsWith(tags::plugin_name::BaseName::gate)) {
// return std::make_unique<GatePreset>(pipeline_type, filter_name.toStdString());
return std::make_unique<GatePreset>(pipeline_type, filter_name.toStdString());
}

if (filter_name.startsWith(tags::plugin_name::BaseName::levelMeter)) {
Expand Down
Loading

0 comments on commit 93e77a0

Please sign in to comment.