Deluge Firmware 1.3.0
Build date: 2025.04.16
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/ui/sound_editor.h"
20#include "model/mod_controllable/filters/filter_config.h"
21#include "model/mod_controllable/mod_controllable_audio.h"
22#include "modulation/patch/patch_cable_set.h"
23
24namespace deluge::gui::menu_item::filter {
25
26enum class FilterSlot : uint8_t {
27 LPF,
28 HPF,
29};
30
31enum class FilterParamType : uint8_t {
32 FREQUENCY,
33 RESONANCE,
34 MORPH,
35 MODE,
36};
37
38class FilterInfo {
39public:
40 FilterInfo(FilterSlot slot_, FilterParamType type_) : slot{slot_}, type{type_} {}
41 ::FilterMode getMode() const {
42 if (slot == FilterSlot::LPF) {
43 return soundEditor.currentModControllable->lpfMode;
44 }
45 else {
46 return soundEditor.currentModControllable->hpfMode;
47 }
48 }
49 int32_t getModeValue() const {
50 if (slot == FilterSlot::HPF) {
51 return util::to_underlying(soundEditor.currentModControllable->hpfMode) - kFirstHPFMode;
52 }
53 else {
54 // Off is located past the HPFLadder, which isn't an option for the low pass filter (should it be?)
55 int32_t selection = util::to_underlying(soundEditor.currentModControllable->lpfMode);
56 return std::min(selection, kNumLPFModes);
57 }
58 }
59 void setMode(int32_t value) const { setModeForModControllable(value, soundEditor.currentModControllable); }
60 void setModeForModControllable(int32_t value, ModControllableAudio* modControllable) const {
61 if (slot == FilterSlot::HPF) {
62 modControllable->hpfMode = static_cast<FilterMode>(value + kFirstHPFMode);
63 }
64 else {
65 // num lpf modes counts off but there's HPF modes in the middle
66 if (value >= kNumLPFModes) {
67 modControllable->lpfMode = FilterMode::OFF;
68 }
69 else {
70 modControllable->lpfMode = static_cast<FilterMode>(value);
71 }
72 }
73 }
74 FilterParamType getFilterParamType() const { return type; }
75 FilterSlot getSlot() const { return slot; }
77 [[nodiscard]] std::string_view getMorphNameOr(std::string_view alt) const {
78 if (type == FilterParamType::MORPH) {
79 using enum l10n::String;
80 auto filt = deluge::dsp::filter::SpecificFilter(getMode());
81 return l10n::getView(filt.getMorphName());
82 }
83 else {
84 return alt;
85 }
86 }
87 bool isOn() const { return getMode() != ::FilterMode::OFF; }
88
89private:
90 FilterSlot slot;
91 FilterParamType type;
92};
93
94static_assert(sizeof(FilterInfo) <= 4);
95
96} // 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) const
Returns morphname for morph parameters, and the alt argument for others.
Definition info.h:77