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