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