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/menu_item.h"
22#include "gui/menu_item/note_row/selected_note_row.h"
23#include "gui/menu_item/submenu.h"
24#include "gui/views/instrument_clip_view.h"
25#include "model/clip/instrument_clip.h"
26#include "model/instrument/kit.h"
27#include "model/model_stack.h"
28#include "model/note/note_row.h"
29#include "model/song/song.h"
30#include "util/lookuptables/lookuptables.h"
31
32extern deluge::gui::menu_item::Submenu noteRowCustomIteranceRootMenu;
33
34namespace deluge::gui::menu_item::note_row {
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
82 char buffer[20];
83
84 int32_t iterancePreset = this->getValue();
85
86 if (iterancePreset == kDefaultIterancePreset) {
87 strcpy(buffer, "OFF");
88 }
89 else if (iterancePreset == kCustomIterancePreset) {
90 strcpy(buffer, "CUSTOM");
91 }
92 else {
93 Iterance iterance = iterancePresets[iterancePreset - 1];
94 int32_t i = iterance.divisor;
95 for (; i >= 0; i--) {
96 // try to find which iteration step index is active
97 if (iterance.iteranceStep[i]) {
98 break;
99 }
100 }
101 sprintf(buffer, "%d of %d", i + 1, iterance.divisor);
102 }
103
104 deluge::hid::display::OLED::main.drawStringCentred(buffer, 18 + OLED_MAIN_TOPMOST_PIXEL, kTextHugeSpacingX,
105 kTextHugeSizeY);
106 }
107
108 void drawValue() final override {
109 char buffer[20];
110
111 int32_t iterancePreset = this->getValue();
112
113 if (iterancePreset == kDefaultIterancePreset) {
114 strcpy(buffer, "OFF");
115 }
116 else if (iterancePreset == kCustomIterancePreset) {
117 strcpy(buffer, "CUSTOM");
118 }
119 else {
120 Iterance iterance = iterancePresets[iterancePreset - 1];
121 int32_t i = iterance.divisor;
122 for (; i >= 0; i--) {
123 // try to find which iteration step index is active
124 if (iterance.iteranceStep[i]) {
125 break;
126 }
127 }
128 sprintf(buffer, "%dof%d", i + 1, iterance.divisor);
129 }
130
131 display->setText(buffer);
132 }
133
134 void writeCurrentValue() override { ; }
135};
136
137} // namespace deluge::gui::menu_item::note_row
Definition model_stack.h:189
Definition model_stack.h:129
Definition note_row.h:98
Definition submenu.h:29
void readValueAgain() override
Definition value.h:84
void drawPixelsForOled()
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 iterance.h:23