Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
settings.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#include "definitions_cxx.hpp"
19#include "gui/menu_item/formatted_title.h"
20#include "gui/menu_item/integer.h"
21#include "gui/menu_item/selection.h"
22#include "gui/ui/sound_editor.h"
23#include "hid/display/oled.h"
24#include "model/drum/drum.h"
25#include "model/instrument/kit.h"
26#include "model/song/song.h"
27#include "processing/sound/sound.h"
28#include "processing/sound/sound_drum.h"
29
30namespace deluge::gui::menu_item::envelope {
31
34template <typename Change>
35void changeEnvelopeConfig(uint8_t envelopeIndex, Change change) {
36 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
37 Kit* kit = getCurrentKit();
38 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
39 if (thisDrum->type == DrumType::SOUND) {
40 change(static_cast<SoundDrum*>(thisDrum)->envelopeConfig[envelopeIndex]);
41 }
42 }
43 }
44 else {
45 change(soundEditor.currentSound->envelopeConfig[envelopeIndex]);
46 }
47}
48
49class Mode final : public Selection, FormattedTitle {
50public:
51 Mode(l10n::String name, l10n::String title, uint8_t envelopeIndex)
52 : Selection(name, title), FormattedTitle(title, envelopeIndex + 1), envelopeIndex_(envelopeIndex) {}
53
54 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
55
56 deluge::vector<std::string_view> getOptions(OptType optType) override {
57 using enum l10n::String;
58 return {l10n::getView(STRING_FOR_ADSR), l10n::getView(STRING_FOR_AHD), l10n::getView(STRING_FOR_AR),
59 l10n::getView(STRING_FOR_MPE)};
60 }
61
62 void readCurrentValue() override { this->setValue(soundEditor.currentSound->envelopeConfig[envelopeIndex_].mode); }
63 bool usesAffectEntire() override { return true; }
64 void writeCurrentValue() override {
65 auto mode = this->getValue<modulation::EnvelopeMode>();
66 changeEnvelopeConfig(envelopeIndex_, [mode](modulation::EnvelopeConfig& config) { config.mode = mode; });
67 }
68
69private:
70 uint8_t envelopeIndex_;
71};
72
74class Follow final : public Selection, FormattedTitle {
75public:
76 Follow(l10n::String name, l10n::String title, uint8_t envelopeIndex)
77 : Selection(name, title), FormattedTitle(title, envelopeIndex + 1), envelopeIndex_(envelopeIndex) {}
78
79 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
80
81 deluge::vector<std::string_view> getOptions(OptType optType) override {
82 using enum l10n::String;
83 bool shortOpt = optType == OptType::SHORT;
84 return {l10n::getView(shortOpt ? STRING_FOR_ENV_FOLLOW_Z_SHORT : STRING_FOR_ENV_FOLLOW_Z),
85 l10n::getView(shortOpt ? STRING_FOR_ENV_FOLLOW_Y_SHORT : STRING_FOR_ENV_FOLLOW_Y)};
86 }
87
88 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) const override {
89 return soundEditor.currentSound != nullptr
90 && soundEditor.currentSound->envelopeConfig[envelopeIndex_].mode == modulation::EnvelopeMode::MPE;
91 }
92
93 void readCurrentValue() override {
94 this->setValue(soundEditor.currentSound->envelopeConfig[envelopeIndex_].follow);
95 }
96 bool usesAffectEntire() override { return true; }
97 void writeCurrentValue() override {
98 auto follow = this->getValue<modulation::EnvelopeFollow>();
99 changeEnvelopeConfig(envelopeIndex_, [follow](modulation::EnvelopeConfig& config) { config.follow = follow; });
100 }
101
102private:
103 uint8_t envelopeIndex_;
104};
105
107class Curve final : public Integer, FormattedTitle {
108public:
109 Curve(l10n::String name, l10n::String title, uint8_t envelopeIndex)
110 : Integer(name, title), FormattedTitle(title, envelopeIndex + 1), envelopeIndex_(envelopeIndex) {}
111
112 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
113
114 [[nodiscard]] int32_t getMinValue() const override { return modulation::EnvelopeShape::kMinCurve; }
115 [[nodiscard]] int32_t getMaxValue() const override { return modulation::EnvelopeShape::kMaxCurve; }
116 // Bipolar with a meaningful zero (linear) and default (32, classic), so show the number rather than a knob
117 [[nodiscard]] RenderingStyle getRenderingStyle() const override { return NUMBER; }
118
119 void readCurrentValue() override { this->setValue(soundEditor.currentSound->envelopeConfig[envelopeIndex_].curve); }
120 bool usesAffectEntire() override { return true; }
121 void writeCurrentValue() override {
122 int32_t curve = this->getValue();
123 changeEnvelopeConfig(envelopeIndex_, [curve](modulation::EnvelopeConfig& config) { config.setCurve(curve); });
124 }
125
126private:
127 uint8_t envelopeIndex_;
128};
129
130} // namespace deluge::gui::menu_item::envelope
const deluge::l10n::String name
Default name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:260
Definition mod_controllable_audio.h:47
Definition integer.h:24
Definition selection.h:26
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition settings.h:120
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition settings.h:119
std::string_view getTitle() const override
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition settings.h:112
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition settings.h:93
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition settings.h:96
std::string_view getTitle() const override
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition settings.h:79
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) const override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition settings.h:88
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition settings.h:63
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition settings.h:62
std::string_view getTitle() const override
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition settings.h:54
A sound's settings for one of its envelopes. Not a param: it doesn't vary per clip and can't be modul...
Definition envelope_curve.h:138
static constexpr int32_t kMinCurve
Definition envelope_curve.h:97