Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
segment.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 "deluge/modulation/params/param.h"
19#include "gui/menu_item/param.h"
20#include "gui/menu_item/source/patched_param.h"
21#include "gui/ui/sound_editor.h"
22#include "processing/sound/sound.h"
23#include "util/functions.h"
24#include <string>
25
26namespace deluge::gui::menu_item::envelope {
27
29inline modulation::EnvelopeMode currentEnvelopeMode(uint8_t envelopeIndex) {
30 if (soundEditor.currentSound == nullptr) {
31 return modulation::EnvelopeMode::ADSR;
32 }
33 return soundEditor.currentSound->envelopeConfig[envelopeIndex].mode;
34}
35
37class Segment : public source::PatchedParam {
38public:
39 Segment(l10n::String newName, l10n::String title, int32_t newP, uint8_t source_id)
40 : PatchedParam(newName, title, newP, source_id) {}
41
42 [[nodiscard]] std::string_view getName() const override { return l10n::getView(strings().name); }
43
44 [[nodiscard]] std::string_view getTitle() const override {
45 title_ = l10n::get(strings().title);
46 asterixToInt(title_.data(), source_id_ + 1);
47 return title_;
48 }
49
50 void getColumnLabel(StringBuf& label) override { label.append(deluge::l10n::get(strings().shortName)); }
51
52 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) const override {
53 using enum modulation::EnvelopeMode;
54 auto base = menu_item::PatchedParam::getP();
55 switch (currentEnvelopeMode(source_id_)) {
56 case AHD:
57 return base != modulation::params::LOCAL_ENV_0_SUSTAIN;
58 case AR:
59 case MPE:
60 return base != modulation::params::LOCAL_ENV_0_DECAY;
61 default:
62 return true;
63 }
64 }
65
66private:
67 struct Strings {
68 l10n::String name;
69 l10n::String shortName;
70 l10n::String title;
71 };
72
73 [[nodiscard]] Strings strings() const {
74 using namespace deluge::modulation;
75 using enum l10n::String;
76 EnvelopeMode mode = currentEnvelopeMode(source_id_);
77 switch (menu_item::PatchedParam::getP()) {
78 case params::LOCAL_ENV_0_ATTACK:
79 return {STRING_FOR_ATTACK, STRING_FOR_ATTACK_SHORT, STRING_FOR_ENV_ATTACK_MENU_TITLE};
80 case params::LOCAL_ENV_0_DECAY:
81 if (mode == EnvelopeMode::AHD) {
82 return {STRING_FOR_HOLD, STRING_FOR_HOLD_SHORT, STRING_FOR_ENV_HOLD_MENU_TITLE};
83 }
84 return {STRING_FOR_DECAY, STRING_FOR_DECAY_SHORT, STRING_FOR_ENV_DECAY_MENU_TITLE};
85 case params::LOCAL_ENV_0_SUSTAIN:
86 if (mode == EnvelopeMode::AR || mode == EnvelopeMode::MPE) {
87 return {STRING_FOR_ENV_LEVEL, STRING_FOR_ENV_LEVEL_SHORT, STRING_FOR_ENV_LEVEL_MENU_TITLE};
88 }
89 return {STRING_FOR_SUSTAIN, STRING_FOR_SUSTAIN_SHORT, STRING_FOR_ENV_SUSTAIN_MENU_TITLE};
90 case params::LOCAL_ENV_0_RELEASE:
91 if (mode == EnvelopeMode::AHD) {
92 // AHD decays at the release rate, so the release gold knob sets a drum's length
93 return {STRING_FOR_DECAY, STRING_FOR_DECAY_SHORT, STRING_FOR_ENV_DECAY_MENU_TITLE};
94 }
95 return {STRING_FOR_RELEASE, STRING_FOR_RELEASE_SHORT, STRING_FOR_ENV_RELEASE_MENU_TITLE};
96 }
97 return {STRING_FOR_NONE, STRING_FOR_NONE, STRING_FOR_NONE};
98 }
99
100 mutable std::string title_;
101};
102} // namespace deluge::gui::menu_item::envelope
deluge::l10n::String title
Can get overridden by getTitle(). Actual max num chars for OLED display is 14.
Definition menu_item.h:229
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 d_stringbuf.h:16
std::string_view getName() const override
Get the actual name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition segment.h:42
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 segment.h:52
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 segment.h:44