Deluge Firmware 1.3.0
Build date: 2025.06.05
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.h"
24#include "processing/sound/sound_drum.h"
25
26namespace deluge::gui::menu_item::stutter {
27
28class StutterDirection final : public Selection {
29public:
30 using Selection::Selection;
31
32 enum Direction : uint8_t { USE_SONG_STUTTER = 0, FORWARD, REVERSED, FORWARD_PING_PONG, REVERSED_PING_PONG };
33
34 deluge::vector<std::string_view> getOptions(OptType optType = OptType::FULL) override {
35 using namespace deluge::l10n;
36
37 deluge::vector<std::string_view> result;
38
39 if (showUseSongOption()) {
40 result.push_back(l10n::getView(optType == OptType::SHORT ? String::STRING_FOR_USE_SONG_SHORT
41 : String::STRING_FOR_USE_SONG));
42 }
43 result.push_back(l10n::getView(String::STRING_FOR_FORWARD));
44 result.push_back(l10n::getView(String::STRING_FOR_REVERSED));
45 result.push_back(l10n::getView(String::STRING_FOR_FORWARD_PING_PONG));
46 result.push_back(l10n::getView(String::STRING_FOR_REVERSED_PING_PONG));
47
48 return result;
49 }
50
51 void readCurrentValue() override {
52 auto* stutter = &soundEditor.currentModControllable->stutterConfig;
53
54 if (showUseSongOption() && stutter->useSongStutter) {
55 setValue(USE_SONG_STUTTER);
56 }
57 else if (stutter->reversed && stutter->pingPong) {
58 setValue(REVERSED_PING_PONG);
59 }
60 else if (stutter->reversed) {
61 setValue(REVERSED);
62 }
63 else if (stutter->pingPong) {
64 setValue(FORWARD_PING_PONG);
65 }
66 else {
67 setValue(FORWARD);
68 }
69 }
70
71 bool usesAffectEntire() override { return true; }
72
73 void writeCurrentValue() override {
74 Direction value = getValue();
75
76 // If affect-entire button held, do whole kit
77 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
78 Kit* kit = getCurrentKit();
79 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
80 if (thisDrum->type == DrumType::SOUND) {
81 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
82 applyOptionToStutterConfig(value, soundDrum->stutterConfig);
83 }
84 }
85 }
86 // Or, the normal case of just one sound
87 else {
88 applyOptionToStutterConfig(value, soundEditor.currentModControllable->stutterConfig);
89 }
90 }
91
92 [[nodiscard]] int32_t getColumnSpan() const override { return 2; }
93
94private:
95 Direction getValue() {
96 const auto value = Selection::getValue();
97 const auto shift = showUseSongOption() ? 0 : 1;
98 return static_cast<Direction>(value + shift);
99 }
100
101 void setValue(Direction value) {
102 const auto shift = showUseSongOption() ? 0 : 1;
103 return Selection::setValue(value - shift);
104 }
105
106 bool showUseSongOption() { return !soundEditor.currentModControllable->isSong(); }
107
108 void applyOptionToStutterConfig(Direction value, StutterConfig& stutter) {
109 stutter.useSongStutter = value == USE_SONG_STUTTER;
110 stutter.reversed = value == REVERSED || value == REVERSED_PING_PONG;
111 stutter.pingPong = value == FORWARD_PING_PONG || value == REVERSED_PING_PONG;
112
113 if (stutter.useSongStutter) {
114 stutter.quantized = currentSong->globalEffectable.stutterConfig.quantized;
115 stutter.reversed = currentSong->globalEffectable.stutterConfig.reversed;
116 stutter.pingPong = currentSong->globalEffectable.stutterConfig.pingPong;
117 }
118 }
119};
120
121} // namespace deluge::gui::menu_item::stutter
Definition drum.h:44
Definition kit.h:34
Definition sound_drum.h:28
Definition selection.h:26
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition direction.h:51
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition direction.h:71
int32_t getColumnSpan() const override
Get the number of occupied virtual columns in the horizontal menu.
Definition direction.h:92
Definition stutterer.h:28