Deluge Firmware 1.3.0
Build date: 2025.08.12
Loading...
Searching...
No Matches
direction.h
1/*
2 * Copyright (c) 2014-2025 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 "gui/menu_item/selection.h"
19#include "gui/ui/sound_editor.h"
20#include "model/drum/drum.h"
21#include "model/instrument/kit.h"
22#include "model/mod_controllable/mod_controllable_audio.h"
23#include "processing/sound/sound_drum.h"
24
25#include <hid/display/oled.h>
26
27namespace deluge::gui::menu_item::stutter {
28
29class StutterDirection final : public Selection {
30public:
31 using Selection::Selection;
32
33 enum Direction : uint8_t { USE_SONG_STUTTER = 0, FORWARD, REVERSED, FORWARD_PING_PONG, REVERSED_PING_PONG };
34
35 deluge::vector<std::string_view> getOptions(OptType optType = OptType::FULL) override {
36 using namespace deluge::l10n;
37
38 deluge::vector<std::string_view> result;
39
40 if (showUseSongOption()) {
41 result.push_back(l10n::getView(optType == OptType::SHORT ? String::STRING_FOR_USE_SONG_SHORT
42 : String::STRING_FOR_USE_SONG));
43 }
44 result.push_back(l10n::getView(String::STRING_FOR_FORWARD));
45 result.push_back(l10n::getView(String::STRING_FOR_REVERSED));
46 result.push_back(l10n::getView(String::STRING_FOR_FORWARD_PING_PONG));
47 result.push_back(l10n::getView(String::STRING_FOR_REVERSED_PING_PONG));
48
49 return result;
50 }
51
52 void readCurrentValue() override {
53 const auto* stutter = &soundEditor.currentModControllable->stutterConfig;
54
55 if (showUseSongOption() && stutter->useSongStutter) {
56 setValue(USE_SONG_STUTTER);
57 }
58 else if (stutter->reversed && stutter->pingPong) {
59 setValue(REVERSED_PING_PONG);
60 }
61 else if (stutter->reversed) {
62 setValue(REVERSED);
63 }
64 else if (stutter->pingPong) {
65 setValue(FORWARD_PING_PONG);
66 }
67 else {
68 setValue(FORWARD);
69 }
70 }
71
72 bool usesAffectEntire() override { return true; }
73
74 void writeCurrentValue() override {
75 Direction value = getValue();
76
77 // If affect-entire button held, do whole kit
78 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
79 Kit* kit = getCurrentKit();
80 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
81 if (thisDrum->type == DrumType::SOUND) {
82 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
83 applyOptionToStutterConfig(value, soundDrum->stutterConfig);
84 }
85 }
86 }
87 // Or, the normal case of just one sound
88 else {
89 applyOptionToStutterConfig(value, soundEditor.currentModControllable->stutterConfig);
90 }
91 }
92
93private:
94 Direction getValue() {
95 const auto value = Selection::getValue();
96 const auto shift = showUseSongOption() ? 0 : 1;
97 return static_cast<Direction>(value + shift);
98 }
99
100 void setValue(Direction value) {
101 const auto shift = showUseSongOption() ? 0 : 1;
102 return Selection::setValue(value - shift);
103 }
104
105 static bool showUseSongOption() { return !soundEditor.currentModControllable->isSong(); }
106
107 static void applyOptionToStutterConfig(const Direction value, StutterConfig& stutter) {
108 stutter.useSongStutter = value == USE_SONG_STUTTER;
109 stutter.reversed = value == REVERSED || value == REVERSED_PING_PONG;
110 stutter.pingPong = value == FORWARD_PING_PONG || value == REVERSED_PING_PONG;
111
112 if (stutter.useSongStutter) {
113 stutter.quantized = currentSong->globalEffectable.stutterConfig.quantized;
114 stutter.reversed = currentSong->globalEffectable.stutterConfig.reversed;
115 stutter.pingPong = currentSong->globalEffectable.stutterConfig.pingPong;
116 }
117 }
118
119 void getNotificationValue(StringBuf& valueBuf) override {
120 const auto value = Selection::getValue();
121 valueBuf.append(getOptions(OptType::SHORT)[value]);
122 }
123
124 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
125 using namespace deluge::hid::display;
126 oled_canvas::Canvas& image = OLED::main;
127
128 const auto value = getValue();
129
130 if (value == USE_SONG_STUTTER) {
131 // Draw a song icon centered
132 const uint8_t* icon = OLED::songIcon;
133 constexpr int32_t songIconWidth = 9;
134 const int32_t x = startX + (width - songIconWidth) / 2;
135 return image.drawGraphicMultiLine(icon, x, startY + 3, songIconWidth);
136 }
137
138 // Draw the direction icon centered
139 const bool reversed = value == REVERSED || value == REVERSED_PING_PONG;
140 image.drawIconCentered(OLED::directionIcon, startX, width, startY + 3, reversed);
141
142 if (value == FORWARD_PING_PONG || value == REVERSED_PING_PONG) {
143 // Draw ping-pong dots
144 const int32_t centerX = startX + width / 2;
145 image.drawPixel(centerX, startY + 3);
146 image.drawPixel(centerX, startY + 10);
147 }
148 }
149};
150
151} // namespace deluge::gui::menu_item::stutter
Definition drum.h:44
Definition kit.h:34
Definition sound_drum.h:28
Definition d_stringbuf.h:16
Definition selection.h:26
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition direction.h:52
void getNotificationValue(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition direction.h:119
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition direction.h:72