Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
direction.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/selection.h"
20#include "gui/ui/sound_editor.h"
21#include "gui/views/instrument_clip_view.h"
22#include "model/clip/instrument_clip.h"
23#include "model/instrument/kit.h"
24#include "model/model_stack.h"
25#include "model/note/note_row.h"
26#include "model/song/song.h"
27
28namespace deluge::gui::menu_item::sequence {
29class Direction final : public Selection {
30public:
31 using Selection::Selection;
32
34 if (getCurrentUI() == &soundEditor && soundEditor.inNoteRowEditor() && !isUIModeActive(UI_MODE_AUDITIONING)) {
35 display->displayPopup("Select Row");
36 return false;
37 }
38 return true;
39 }
40
41 ModelStackWithNoteRow* getIndividualNoteRow(ModelStackWithTimelineCounter* modelStack) {
42 auto* clip = static_cast<InstrumentClip*>(modelStack->getTimelineCounter());
43 if (!clip->affectEntire && clip->output->type == OutputType::KIT) {
44 Kit* kit = getCurrentKit();
45 if (kit->selectedDrum != nullptr) {
46 return clip->getNoteRowForDrum(modelStack, kit->selectedDrum); // Still might be NULL;
47 }
48 }
49 else if (clip->output->type != OutputType::KIT) {
50 if (soundEditor.selectedNoteRow) {
51 // get model stack with note row but don't create note row if it doesn't exist
52 ModelStackWithNoteRow* modelStackWithNoteRow =
53 clip->getNoteRowOnScreen(instrumentClipView.lastAuditionedYDisplay, modelStack);
54 if (!modelStackWithNoteRow->getNoteRowAllowNull()) { // if note row doesn't exist yet, create it
55 modelStackWithNoteRow = instrumentClipView.createNoteRowForYDisplay(
56 modelStack, instrumentClipView.lastAuditionedYDisplay);
57 }
58 return modelStackWithNoteRow;
59 }
60 }
61 return modelStack->addNoteRow(0, nullptr);
62 }
63
64 void readCurrentValue() override {
65 char modelStackMemory[MODEL_STACK_MAX_SIZE];
66 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
67 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
68
69 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
70 this->setValue(modelStackWithNoteRow->getNoteRow()->sequenceDirectionMode);
71 }
72 else {
73 this->setValue(getCurrentInstrumentClip()->sequenceDirectionMode);
74 }
75 }
76
77 void writeCurrentValue() override {
78 auto current_value = this->getValue<SequenceDirection>();
79 char modelStackMemory[MODEL_STACK_MAX_SIZE];
80 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
81 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
82 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
83 modelStackWithNoteRow->getNoteRow()->setSequenceDirectionMode(modelStackWithNoteRow, current_value);
84 }
85 else {
86 getCurrentInstrumentClip()->setSequenceDirectionMode(modelStackWithNoteRow->toWithTimelineCounter(),
87 current_value);
88 }
89 }
90
91 deluge::vector<std::string_view> getOptions(OptType optType) override {
92 (void)optType;
93 deluge::vector<std::string_view> sequenceDirectionOptions = {
94 l10n::getView(l10n::String::STRING_FOR_FORWARD),
95 l10n::getView(l10n::String::STRING_FOR_REVERSED),
96 l10n::getView(l10n::String::STRING_FOR_PING_PONG),
97 };
98
99 char modelStackMemory[MODEL_STACK_MAX_SIZE];
100 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
101 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
102 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
103 sequenceDirectionOptions.push_back(l10n::getView(l10n::String::STRING_FOR_NONE));
104 }
105
106 return sequenceDirectionOptions;
107 }
108
109 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t whichThing,
110 ::MultiRange** currentRange) override {
111 OutputType outputType = getCurrentOutputType();
112 if (!getCurrentInstrumentClip()->affectEntire && outputType == OutputType::KIT
113 && (getCurrentKit()->selectedDrum == nullptr)) {
114 return MenuPermission::NO;
115 }
116 else if (outputType != OutputType::KIT) {
117 soundEditor.selectedNoteRow = isUIModeActive(UI_MODE_AUDITIONING);
118 }
119 return MenuPermission::YES;
120 }
121};
122} // namespace deluge::gui::menu_item::sequence
Definition instrument_clip.h:48
Definition kit.h:34
Definition model_stack.h:189
Definition model_stack.h:129
Definition selection.h:26
bool shouldEnterSubmenu()
Check if selecting this menu item (with select encoder) should enter a submenu.
Definition direction.h:33
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition direction.h:64