Deluge Firmware 1.3.0
Build date: 2026.02.12
Loading...
Searching...
No Matches
iterance_step_toggle.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/toggle.h"
20#include "gui/views/instrument_clip_view.h"
21#include "model/clip/instrument_clip.h"
22#include "model/note/note.h"
23
24namespace deluge::gui::menu_item::note {
25class IteranceStepToggle : public Toggle {
26public:
27 using Toggle::Toggle;
28
29 IteranceStepToggle(l10n::String newName, l10n::String title, uint8_t newIndex) : Toggle(newName, title) {
30 this->index = newIndex;
31 }
32
33 void readCurrentValue() override {
34 Note* leftMostNote = instrumentClipView.getLeftMostNotePressed();
35
36 if (leftMostNote) {
37 Iterance iterance = leftMostNote->getIterance();
38 if (iterance == kDefaultIteranceValue) {
39 // if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
40 // so we can make edits from here
41 iterance = kCustomIteranceValue;
42 }
43 this->setValue(iterance.iteranceStep[index]);
44 }
45 }
46 void writeCurrentValue() override {
47 bool value = this->getValue();
48 Note* leftMostNote = instrumentClipView.getLeftMostNotePressed();
49
50 if (leftMostNote) {
51 Iterance iterance = leftMostNote->getIterance();
52 if (iterance == kDefaultIteranceValue) {
53 // if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
54 // so we can make edits from here
55 iterance = kCustomIteranceValue;
56 }
57 int32_t newIteranceSteps = iterance.toInt() & 0xFF;
58 if (value) {
59 newIteranceSteps |= (1 << index);
60 }
61 else {
62 newIteranceSteps &= ~(1 << index);
63 }
64 instrumentClipView.adjustNoteIteranceWithFinalValue(Iterance{iterance.divisor, newIteranceSteps});
65 }
66 }
67
68 uint8_t index;
69
70 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
71 Note* leftMostNote = instrumentClipView.getLeftMostNotePressed();
72
73 if (leftMostNote) {
74 Iterance iterance = leftMostNote->getIterance();
75 // Only show this iteration step if its index is smaller than current divisor value
76 return (iterance == kDefaultIteranceValue && index == 0) || iterance.divisor > index;
77 }
78 return false;
79 }
80};
81} // namespace deluge::gui::menu_item::note
deluge::l10n::String title
Can get overridden by getTitle(). Actual max num chars for OLED display is 14.
Definition menu_item.h:222
Definition mod_controllable_audio.h:47
Definition note.h:24
Definition toggle.h:8
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition iterance_step_toggle.h:33
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition iterance_step_toggle.h:70
Definition iterance.h:23