Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
loop_crossfade.h
1/*
2 * Copyright © 2026 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/formatted_title.h"
19#include "gui/menu_item/integer.h"
20#include "gui/menu_item/sample/utils.h"
21#include "gui/ui/sound_editor.h"
22#include "model/drum/drum.h"
23#include "model/instrument/kit.h"
24#include "model/song/song.h"
25#include "processing/sound/sound_drum.h"
26
27namespace deluge::gui::menu_item::sample {
28class LoopCrossfade final : public IntegerWithOff, public FormattedTitle {
29public:
30 LoopCrossfade(l10n::String name, l10n::String title_format_str, uint8_t source_id)
31 : IntegerWithOff(name), FormattedTitle(title_format_str, source_id + 1), source_id_{source_id} {}
32
33 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
34
35 bool usesAffectEntire() override { return true; }
36
37 bool isRelevant(ModControllableAudio* modControllable, int32_t) const override {
38 return isSampleModeSample(modControllable, source_id_);
39 }
40
41 // The menu works in 10 ms steps, but the Source keeps milliseconds
42 static constexpr int32_t kMsPerStep = 10;
43
44 void readCurrentValue() override {
45 setValue(soundEditor.currentSound->sources[source_id_].loopCrossfadeMs / kMsPerStep);
46 }
47
48 void writeCurrentValue() override {
49 uint16_t ms = getValue() * kMsPerStep;
50
51 // If affect-entire button held, do whole kit
52 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
53 const Kit* kit = getCurrentKit();
54 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
55 if (thisDrum->type == DrumType::SOUND) {
56 static_cast<SoundDrum*>(thisDrum)->sources[source_id_].loopCrossfadeMs = ms;
57 }
58 }
59 }
60 // Or, the normal case of just one sound
61 else {
62 soundEditor.currentSound->sources[source_id_].loopCrossfadeMs = ms;
63 }
64 }
65
66 [[nodiscard]] int32_t getMinValue() const override { return 0; }
67 [[nodiscard]] int32_t getMaxValue() const override { return kMaxLoopCrossfadeMs / kMsPerStep; }
68 int32_t getDisplayValue() override { return getValue() * kMsPerStep; }
69 const char* getUnit() override { return "MS"; }
70 void getNotificationValue(StringBuf& value) override {
71 if (getValue() == 0) {
72 value.append(l10n::get(l10n::String::STRING_FOR_OFF));
73 }
74 else {
75 value.appendInt(getDisplayValue());
76 value.append(getUnit());
77 }
78 }
79
80 // A time in ms, drawn as a ramp like the compressor and sidechain attack times
81 [[nodiscard]] RenderingStyle getRenderingStyle() const override { return ATTACK; }
82 void getColumnLabel(StringBuf& label) override {
83 label.append(l10n::get(l10n::String::STRING_FOR_LOOP_CROSSFADE_SHORT));
84 }
85
86private:
87 uint8_t source_id_;
88};
89} // namespace deluge::gui::menu_item::sample
Definition drum.h:44
Definition kit.h:34
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 sound_drum.h:28
Definition d_stringbuf.h:16
bool isRelevant(ModControllableAudio *modControllable, int32_t) const override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition loop_crossfade.h:37
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition loop_crossfade.h:44
void getNotificationValue(StringBuf &value) override
Get the parameter value string to show in the popup.
Definition loop_crossfade.h:70
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 loop_crossfade.h:33
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition loop_crossfade.h:35