Deluge Firmware 1.3.0
Build date: 2026.03.02
Loading...
Searching...
No Matches
preset_mode.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/arpeggiator/octave_mode.h"
20#include "gui/menu_item/selection.h"
21#include "gui/ui/sound_editor.h"
22#include "model/clip/clip.h"
23#include "model/clip/instrument_clip.h"
24#include "model/drum/drum.h"
25#include "model/instrument/kit.h"
26#include "model/model_stack.h"
27#include "model/song/song.h"
28#include "processing/sound/sound.h"
29
30#include <hid/display/oled.h>
31#include <numeric>
32
33namespace deluge::gui::menu_item::arpeggiator {
34class PresetMode final : public Selection {
35public:
36 using Selection::Selection;
37 void readCurrentValue() override { this->setValue(soundEditor.currentArpSettings->preset); }
38
39 bool usesAffectEntire() override { return true; }
40 void writeCurrentValue() override {
41 auto current_value = this->getValue<ArpPreset>();
42
43 // If affect-entire button held, do the whole kit
44 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
45
46 Kit* kit = getCurrentKit();
47
48 // If was off, or is now becoming off...
49 if (soundEditor.currentArpSettings->mode == ArpMode::OFF || current_value == ArpPreset::OFF) {
50 if (getCurrentClip()->isActiveOnOutput() && !soundEditor.editingKitAffectEntire()) {
51 kit->cutAllSound();
52 }
53 }
54
55 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
56 thisDrum->arpSettings.preset = current_value;
57 thisDrum->arpSettings.updateSettingsFromCurrentPreset();
58 thisDrum->arpSettings.flagForceArpRestart = true;
59 }
60 }
61 // Or, the normal case of just one sound
62 else {
63 // If was off, or is now becoming off...
64 if (soundEditor.currentArpSettings->mode == ArpMode::OFF || current_value == ArpPreset::OFF) {
65 if (getCurrentClip()->isActiveOnOutput() && !soundEditor.editingKitAffectEntire()) {
66 char modelStackMemory[MODEL_STACK_MAX_SIZE];
67 ModelStackWithThreeMainThings* modelStack = soundEditor.getCurrentModelStack(modelStackMemory);
68
69 if (soundEditor.editingKit()) {
70 // Drum
71 Drum* currentDrum = ((Kit*)getCurrentClip()->output)->selectedDrum;
72 if (currentDrum != nullptr) {
73 currentDrum->killAllVoices();
74 }
75 }
76 else if (soundEditor.editingCVOrMIDIClip()) {
77 getCurrentInstrumentClip()->stopAllNotesForMIDIOrCV(modelStack->toWithTimelineCounter());
78 }
79 else {
80 ModelStackWithSoundFlags* modelStackWithSoundFlags = modelStack->addSoundFlags();
81 soundEditor.currentSound->allNotesOff(
82 modelStackWithSoundFlags,
83 soundEditor.currentSound
84 ->getArp()); // Must switch off all notes when switching arp on / off
85 soundEditor.currentSound->reassessRenderSkippingStatus(modelStackWithSoundFlags);
86 }
87 }
88 }
89
90 soundEditor.currentArpSettings->preset = current_value;
91 soundEditor.currentArpSettings->updateSettingsFromCurrentPreset();
92 soundEditor.currentArpSettings->flagForceArpRestart = true;
93 }
94 }
95
96 deluge::vector<std::string_view> getOptions(OptType optType) override {
97 (void)optType;
98 using enum l10n::String;
99 return {
100 l10n::getView(STRING_FOR_OFF), //<
101 l10n::getView(STRING_FOR_UP), //<
102 l10n::getView(STRING_FOR_DOWN), //<
103 l10n::getView(STRING_FOR_BOTH), //<
104 l10n::getView(STRING_FOR_RANDOM), //<
105 l10n::getView(STRING_FOR_WALK), //<
106 l10n::getView(STRING_FOR_CUSTOM), //<
107 };
108 }
109
110 MenuItem* selectButtonPress() override {
111 auto current_value = this->getValue<ArpPreset>();
112 if (current_value == ArpPreset::CUSTOM) {
113 if (soundEditor.editingKitRow()) {
114 return &arpOctaveModeToNoteModeMenuForDrums;
115 }
116 return &arpOctaveModeToNoteModeMenu;
117 }
118 return nullptr;
119 }
120
121 [[nodiscard]] bool showColumnLabel() const override { return false; }
122
123 void getColumnLabel(StringBuf& label) override { label.append(l10n::get(l10n::String::STRING_FOR_MODE)); }
124
125 void renderInHorizontalMenu(const SlotPosition& slot) override {
126 using namespace deluge::hid::display;
127 oled_canvas::Canvas& image = OLED::main;
128
129 if (this->getValue<ArpPreset>() == ArpPreset::OFF) {
130 const auto off = l10n::get(l10n::String::STRING_FOR_OFF);
131 return image.drawStringCentered(off, slot.start_x, slot.start_y + kHorizontalMenuSlotYOffset + 5,
132 kTextTitleSpacingX, kTextTitleSizeY, slot.width);
133 }
134
135 const auto arpPreset = getValue<ArpPreset>();
136 const Icon& icon = [&] {
137 switch (arpPreset) {
138 case ArpPreset::UP:
139 case ArpPreset::DOWN:
140 return OLED::arpModeIconUp;
141 case ArpPreset::BOTH:
142 return OLED::arpModeIconUpDown;
143 case ArpPreset::RANDOM:
144 return OLED::diceIcon;
145 case ArpPreset::WALK:
146 return OLED::arpModeIconWalk;
147 case ArpPreset::CUSTOM:
148 return OLED::arpModeIconCustom;
149 default:
150 return OLED::arpModeIconUp;
151 }
152 }();
153
154 const bool reversed = arpPreset == ArpPreset::DOWN;
155 image.drawIconCentered(icon, slot.start_x, slot.width, slot.start_y + kHorizontalMenuSlotYOffset + 1, reversed);
156 }
157};
158} // namespace deluge::gui::menu_item::arpeggiator
Definition drum.h:44
Definition kit.h:34
Definition model_stack.h:231
Definition d_stringbuf.h:16
Definition selection.h:26
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition preset_mode.h:37
MenuItem * selectButtonPress() override
Handle a select button press.
Definition preset_mode.h:110
bool showColumnLabel() const override
Show a label for the parameter in Horizontal menu.
Definition preset_mode.h:121
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition preset_mode.h:39
Definition menu_item.h:33