Deluge Firmware 1.3.0
Build date: 2025.04.16
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
30namespace deluge::gui::menu_item::arpeggiator {
31class PresetMode final : public Selection {
32public:
33 using Selection::Selection;
34 void readCurrentValue() override { this->setValue(soundEditor.currentArpSettings->preset); }
35
36 bool usesAffectEntire() override { return true; }
37 void writeCurrentValue() override {
38 auto current_value = this->getValue<ArpPreset>();
39
40 // If affect-entire button held, do whole kit
41 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
42
43 Kit* kit = getCurrentKit();
44
45 // If was off, or is now becoming off...
46 if (soundEditor.currentArpSettings->mode == ArpMode::OFF || current_value == ArpPreset::OFF) {
47 if (getCurrentClip()->isActiveOnOutput() && !soundEditor.editingKitAffectEntire()) {
48 kit->cutAllSound();
49 }
50 }
51
52 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
53 thisDrum->arpSettings.preset = current_value;
54 thisDrum->arpSettings.updateSettingsFromCurrentPreset();
55 thisDrum->arpSettings.flagForceArpRestart = true;
56 }
57 }
58 // Or, the normal case of just one sound
59 else {
60 // If was off, or is now becoming off...
61 if (soundEditor.currentArpSettings->mode == ArpMode::OFF || current_value == ArpPreset::OFF) {
62 if (getCurrentClip()->isActiveOnOutput() && !soundEditor.editingKitAffectEntire()) {
63 char modelStackMemory[MODEL_STACK_MAX_SIZE];
64 ModelStackWithThreeMainThings* modelStack = soundEditor.getCurrentModelStack(modelStackMemory);
65
66 if (soundEditor.editingKit()) {
67 // Drum
68 Drum* currentDrum = ((Kit*)getCurrentClip()->output)->selectedDrum;
69 if (currentDrum != nullptr) {
70 currentDrum->killAllVoices();
71 }
72 }
73 else if (soundEditor.editingCVOrMIDIClip()) {
74 getCurrentInstrumentClip()->stopAllNotesForMIDIOrCV(modelStack->toWithTimelineCounter());
75 }
76 else {
77 ModelStackWithSoundFlags* modelStackWithSoundFlags = modelStack->addSoundFlags();
78 soundEditor.currentSound->allNotesOff(
79 modelStackWithSoundFlags,
80 soundEditor.currentSound
81 ->getArp()); // Must switch off all notes when switching arp on / off
82 soundEditor.currentSound->reassessRenderSkippingStatus(modelStackWithSoundFlags);
83 }
84 }
85 }
86
87 soundEditor.currentArpSettings->preset = current_value;
88 soundEditor.currentArpSettings->updateSettingsFromCurrentPreset();
89 soundEditor.currentArpSettings->flagForceArpRestart = true;
90 }
91 }
92
93 deluge::vector<std::string_view> getOptions(OptType optType) override {
94 (void)optType;
95 using enum l10n::String;
96 return {
97 l10n::getView(STRING_FOR_OFF), //<
98 l10n::getView(STRING_FOR_UP), //<
99 l10n::getView(STRING_FOR_DOWN), //<
100 l10n::getView(STRING_FOR_BOTH), //<
101 l10n::getView(STRING_FOR_RANDOM), //<
102 l10n::getView(STRING_FOR_WALK), //<
103 l10n::getView(STRING_FOR_CUSTOM), //<
104 };
105 }
106
107 MenuItem* selectButtonPress() override {
108 auto current_value = this->getValue<ArpPreset>();
109 if (current_value == ArpPreset::CUSTOM) {
110 if (soundEditor.editingKitRow()) {
111 return &arpeggiator::arpOctaveModeToNoteModeMenuForDrums;
112 }
113 return &arpeggiator::arpOctaveModeToNoteModeMenu;
114 }
115 return nullptr;
116 }
117};
118} // namespace deluge::gui::menu_item::arpeggiator
Definition drum.h:44
Definition kit.h:34
Definition model_stack.h:231
Definition selection.h:26
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition preset_mode.h:34
MenuItem * selectButtonPress() override
Handle a select button press.
Definition preset_mode.h:107
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition preset_mode.h:36