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