Deluge Firmware 1.3.0
Build date: 2026.10.08
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/menu_item.h"
21#include "gui/menu_item/note_row/selected_note_row.h"
22#include "gui/menu_item/submenu.h"
23#include "gui/views/instrument_clip_view.h"
24#include "hid/display/oled.h"
25#include "model/model_stack.h"
26#include "model/note/note_row.h"
27#include "model/song/song.h"
28
29extern gui::menu_item::Submenu noteRowCustomIteranceRootMenu;
30
31namespace deluge::gui::menu_item::note_row {
32
33using namespace deluge::hid::display;
34
35class IterancePreset final : public SelectedNoteRow {
36public:
37 using SelectedNoteRow::SelectedNoteRow;
38
39 [[nodiscard]] int32_t getMaxValue() const override { return kNumIterancePresets + 1; }
40 [[nodiscard]] int32_t getMinValue() const override { return 0; }
41
45 void beginSession(MenuItem* navigatedBackwardFrom = nullptr) final override { readValueAgain(); }
46
47 void readCurrentValue() override {
48 char modelStackMemory[MODEL_STACK_MAX_SIZE];
49 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
50 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
51
52 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
53 NoteRow* noteRow = modelStackWithNoteRow->getNoteRowAllowNull();
54 // Convert value to preset to choose from, if preset not found, then maybe it is CUSTOM
55 int32_t preset = noteRow->iteranceValue.toPresetIndex();
56 this->setValue(preset);
57 updateDisplay();
58 }
59 }
60
61 void selectEncoderAction(int32_t offset) final override {
62 int32_t newValue = instrumentClipView.setNoteRowIteranceWithOffset(offset);
63 if (newValue != -1) {
64 // Convert value to preset to choose from, if preset not found, then maybe it is CUSTOM
65 int32_t preset = Iterance::fromInt(newValue).toPresetIndex();
66 this->setValue(preset);
67 updateDisplay();
68 }
69 }
70
71 MenuItem* selectButtonPress() override {
72 int32_t iterancePreset = this->getValue();
73 if (iterancePreset == kCustomIterancePreset) {
74 // If the "CUSTOM" item is in focus, clicking the Select encoder will
75 // enter the editor for the custom iterance
76 return &noteRowCustomIteranceRootMenu;
77 }
78 return nullptr;
79 }
80
81 void drawPixelsForOled() override {
82 const std::string value = get_iterance_display_value("%d of %d", Iterance::DisplayLabelType::LONG);
83 OLED::main.drawStringCentred(value.data(), 18 + OLED_MAIN_TOPMOST_PIXEL, kTextHugeSpacingX, kTextHugeSizeY);
84 }
85
86 void renderInHorizontalMenu(const SlotPosition& slot) override {
87 const std::string value = get_iterance_display_value("%d:%d", Iterance::DisplayLabelType::SHORT);
88 OLED::main.drawStringCentered(value.data(), slot.start_x, slot.start_y + kHorizontalMenuSlotYOffset,
89 kTextSpacingX, kTextSpacingY, slot.width);
90 }
91
92 void drawValue() override {
93 const std::string value = get_iterance_display_value("%dof%d", Iterance::DisplayLabelType::SHORT);
94 display->setText(value);
95 }
96
97 void getNotificationValue(StringBuf& valueBuf) override {
98 valueBuf.append(get_iterance_display_value("%d of %d", Iterance::DisplayLabelType::LONG));
99 }
100
101 void writeCurrentValue() override { ; }
102
103private:
104 std::string get_iterance_display_value(const std::string& format, Iterance::DisplayLabelType label_type) {
105 char buffer[20];
106 Iterance::format_preset_display_value(this->getValue(), buffer, sizeof(buffer),
107 {.step_format = format.c_str(), .label_type = label_type});
108
109 return std::string(buffer);
110 }
111};
112
113} // namespace deluge::gui::menu_item::note_row
Definition model_stack.h:189
Definition model_stack.h:129
Definition note_row.h:99
Definition d_stringbuf.h:16
Definition submenu.h:28
void readValueAgain() override
Definition value.h:90
void getNotificationValue(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition iterance_preset.h:97
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition iterance_preset.h:81
void selectEncoderAction(int32_t offset) final override
Handle select encoder movement.
Definition iterance_preset.h:61
void beginSession(MenuItem *navigatedBackwardFrom=nullptr) final override
Begin an editing session with this menu item.
Definition iterance_preset.h:45
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition iterance_preset.h:47
MenuItem * selectButtonPress() override
Handle a select button press.
Definition iterance_preset.h:71
Definition selected_note_row.h:30
Definition menu_item.h:33