Deluge Firmware 1.3.0
Build date: 2025.11.26
Loading...
Searching...
No Matches
info.h
1/*
2 * Copyright (c) 2014-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "gui/menu_item/number.h"
20#include "gui/ui/sound_editor.h"
21#include "model/mod_controllable/filters/filter_config.h"
22#include "model/mod_controllable/mod_controllable_audio.h"
23#include "modulation/patch/patch_cable_set.h"
24
25namespace deluge::gui::menu_item::filter {
26
27enum class FilterSlot : uint8_t {
28 LPF,
29 HPF,
30};
31
32enum class FilterParamType : uint8_t {
33 FREQUENCY,
34 RESONANCE,
35 MORPH,
36 MODE,
37};
38
39class FilterInfo {
40public:
41 FilterInfo(FilterSlot slot_, FilterParamType type_) : slot{slot_}, type{type_} {}
42 ::FilterMode getMode() const {
43 if (slot == FilterSlot::LPF) {
44 return soundEditor.currentModControllable->lpfMode;
45 }
46 else {
47 return soundEditor.currentModControllable->hpfMode;
48 }
49 }
50 int32_t getModeValue() const {
51 if (slot == FilterSlot::HPF) {
52 return util::to_underlying(soundEditor.currentModControllable->hpfMode) - kFirstHPFMode;
53 }
54 else {
55 // Off is located past the HPFLadder, which isn't an option for the low pass filter (should it be?)
56 int32_t selection = util::to_underlying(soundEditor.currentModControllable->lpfMode);
57 return std::min(selection, kNumLPFModes);
58 }
59 }
60 void setMode(int32_t value) const { setModeForModControllable(value, soundEditor.currentModControllable); }
61 void setModeForModControllable(int32_t value, ModControllableAudio* modControllable) const {
62 if (slot == FilterSlot::HPF) {
63 modControllable->hpfMode = static_cast<FilterMode>(value + kFirstHPFMode);
64 }
65 else {
66 // num lpf modes counts off but there's HPF modes in the middle
67 if (value >= kNumLPFModes) {
68 modControllable->lpfMode = FilterMode::OFF;
69 }
70 else {
71 modControllable->lpfMode = static_cast<FilterMode>(value);
72 }
73 }
74 }
75 FilterParamType getFilterParamType() const { return type; }
76 FilterSlot getSlot() const { return slot; }
78 [[nodiscard]] std::string_view getMorphNameOr(std::string_view alt, bool shortName = false) const {
79 if (type == FilterParamType::MORPH) {
80 using enum l10n::String;
81 auto filt = dsp::filter::SpecificFilter(getMode());
82 return l10n::getView(filt.getMorphName(shortName));
83 }
84 return alt;
85 }
86 [[nodiscard]] bool isMorphable() const {
87 auto filter = dsp::filter::SpecificFilter(getMode());
88 return filter.getFamily() == dsp::filter::FilterFamily::SVF;
89 }
90
91 bool isOn() const { return getMode() != ::FilterMode::OFF; }
92
93private:
94 FilterSlot slot;
95 FilterParamType type;
96};
97
98static_assert(sizeof(FilterInfo) <= 4);
99
100} // namespace deluge::gui::menu_item::filter
Definition mod_controllable_audio.h:47
A filters family (types which can all share an implementation for toggling) and specific type within ...
Definition filter_config.h:72
std::string_view getMorphNameOr(std::string_view alt, bool shortName=false) const
Returns morphname for morph parameters, and the alt argument for others.
Definition info.h:78