Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
iterance_preset.h
1/*
2 * Copyright (c) 2024 Sean Ditny / Raúl Muñoz
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
18#pragma once
19#include "definitions_cxx.hpp"
20#include "gui/menu_item/integer.h"
21#include "gui/menu_item/note/selected_note.h"
22#include "gui/menu_item/submenu.h"
23#include "gui/views/instrument_clip_view.h"
24#include "model/clip/instrument_clip.h"
25#include "model/note/note.h"
26#include "model/note/note_row.h"
27
28extern deluge::gui::menu_item::Submenu noteCustomIteranceRootMenu;
29
30namespace deluge::gui::menu_item::note {
31class IterancePreset final : public SelectedNote {
32public:
33 using SelectedNote::SelectedNote;
34
35 [[nodiscard]] int32_t getMaxValue() const override { return kNumIterancePresets + 1; }
36 [[nodiscard]] int32_t getMinValue() const override { return 0; }
37
41 void beginSession(MenuItem* navigatedBackwardFrom = nullptr) final override { readValueAgain(); }
42
43 void readCurrentValue() override {
44 Note* leftMostNote = instrumentClipView.getLeftMostNotePressed();
45
46 if (leftMostNote) {
47 // Convert value to preset to choose from, if preset not found, then maybe it is CUSTOM
48 int32_t preset = leftMostNote->getIterance().toPresetIndex();
49 this->setValue(preset);
50 }
51 }
52
53 void selectEncoderAction(int32_t offset) final override {
54 instrumentClipView.adjustNoteIteranceWithOffset(offset);
56 }
57
58 MenuItem* selectButtonPress() override {
59 int32_t iterancePreset = this->getValue();
60 if (iterancePreset == kCustomIterancePreset) {
61 // If the "CUSTOM" item is in focus, clicking the Select encoder will
62 // enter the editor for the custom iterance
63 return &noteCustomIteranceRootMenu;
64 }
65 return nullptr;
66 }
67
69 char buffer[20];
70
71 int32_t iterancePreset = this->getValue();
72
73 if (iterancePreset == kDefaultIterancePreset) {
74 strcpy(buffer, "OFF");
75 }
76 else if (iterancePreset == kCustomIterancePreset) {
77 strcpy(buffer, "CUSTOM");
78 }
79 else {
80 Iterance iterance = iterancePresets[iterancePreset - 1];
81 int32_t i = iterance.divisor;
82 for (; i >= 0; i--) {
83 // try to find which iteration step index is active
84 if (iterance.iteranceStep[i]) {
85 break;
86 }
87 }
88 sprintf(buffer, "%d of %d", i + 1, iterance.divisor);
89 }
90
91 deluge::hid::display::OLED::main.drawStringCentred(buffer, 18 + OLED_MAIN_TOPMOST_PIXEL, kTextHugeSpacingX,
92 kTextHugeSizeY);
93 }
94
95 void drawValue() final override {
96 char buffer[20];
97
98 int32_t iterancePreset = this->getValue();
99
100 if (iterancePreset == kDefaultIterancePreset) {
101 strcpy(buffer, "OFF");
102 }
103 else if (iterancePreset == kCustomIterancePreset) {
104 strcpy(buffer, "CUSTOM");
105 }
106 else {
107 Iterance iterance = iterancePresets[iterancePreset - 1];
108 int32_t i = iterance.divisor;
109 for (; i >= 0; i--) {
110 // try to find which iteration step index is active
111 if (iterance.iteranceStep[i]) {
112 break;
113 }
114 }
115 sprintf(buffer, "%dof%d", i + 1, iterance.divisor);
116 }
117
118 display->setText(buffer);
119 }
120
121 void writeCurrentValue() override { ; }
122};
123
124} // namespace deluge::gui::menu_item::note
Definition note.h:24
Definition submenu.h:29
void readValueAgain() override
Definition value.h:84
Definition iterance_preset.h:31
void selectEncoderAction(int32_t offset) final override
Handle select encoder movement.
Definition iterance_preset.h:53
void beginSession(MenuItem *navigatedBackwardFrom=nullptr) final override
Begin an editing session with this menu item.
Definition iterance_preset.h:41
MenuItem * selectButtonPress() override
Handle a select button press.
Definition iterance_preset.h:58
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition iterance_preset.h:43
void drawPixelsForOled()
Paints the pixels below the standard title block.
Definition iterance_preset.h:68
Definition selected_note.h:30
Definition iterance.h:23