Deluge Firmware
1.3.0
Build date: 2025.10.15
Loading...
Searching...
No Matches
value.h
1
/*
2
* Copyright © 2017-2023 Synthstrom Audible Limited
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
20
#include "gui/ui/ui.h"
21
#include "hid/display/display.h"
22
#include "menu_item.h"
23
#include "util/misc.h"
24
25
#include <hid/buttons.h>
26
27
namespace
deluge::gui::menu_item {
28
template
<
typename
T =
int
32_t>
29
class
Value
:
public
MenuItem {
30
public
:
31
using
MenuItem::MenuItem;
32
void
beginSession
(MenuItem* navigatedBackwardFrom)
override
;
33
void
selectEncoderAction
(int32_t offset)
override
;
34
void
readValueAgain
()
override
;
35
bool
selectEncoderActionEditsInstrument
() final {
return
true
; }
36
37
void
setValue(T value) {
38
D_PRINTLN(
"%d"
, value);
39
value_ = value;
40
}
41
42
template
<util::enumeration E>
43
void
setValue(E value) {
44
value_ = util::to_underlying(value);
45
}
46
47
T getValue() {
return
value_; }
48
49
template
<util::enumeration E>
50
E getValue() {
51
return
static_cast<
E
>
(value_);
52
}
53
54
protected
:
55
virtual
void
writeCurrentValue() {}
56
57
// 7SEG ONLY
58
virtual
void
drawValue() = 0;
59
60
private
:
61
T value_;
62
};
63
64
template
<
typename
T>
65
void
Value<T>::beginSession
(MenuItem* navigatedBackwardFrom) {
66
if
(display->haveOLED()) {
67
readCurrentValue
();
68
}
69
else
{
70
readValueAgain
();
71
}
72
}
73
74
template
<
typename
T>
75
void
Value<T>::selectEncoderAction
(int32_t offset) {
76
if
(Buttons::isButtonPressed(hid::button::SELECT_ENC)) {
77
Buttons::selectButtonPressUsedUp =
true
;
78
}
79
80
writeCurrentValue();
81
82
// For MenuItems referring to an AutoParam (so UnpatchedParam and PatchedParam), ideally we wouldn't want to render
83
// the display here, because that'll happen soon anyway due to a setting of TIMER_DISPLAY_AUTOMATION.
84
if
(display->haveOLED()) {
85
renderUIsForOled();
86
}
87
else
{
88
drawValue();
// Probably not necessary either...
89
}
90
}
91
92
template
<
typename
T>
93
void
Value<T>::readValueAgain
() {
94
readCurrentValue
();
95
if
(display->haveOLED()) {
96
renderUIsForOled();
97
}
98
else
{
99
drawValue();
100
}
101
}
102
103
}
// namespace deluge::gui::menu_item
MenuItem::readCurrentValue
virtual void readCurrentValue()
Like readValueAgain, but does not redraw.
Definition
menu_item.h:124
deluge::gui::menu_item::Value
Definition
value.h:29
deluge::gui::menu_item::Value::beginSession
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition
value.h:65
deluge::gui::menu_item::Value::selectEncoderAction
void selectEncoderAction(int32_t offset) override
Handle select encoder movement.
Definition
value.h:75
deluge::gui::menu_item::Value::readValueAgain
void readValueAgain() override
Re-read the value from the system and redraw the display to match.
Definition
value.h:93
deluge::gui::menu_item::Value::selectEncoderActionEditsInstrument
bool selectEncoderActionEditsInstrument() final
Used by the sound editor to mark the current instrument as edited when the select encoder is scrolled...
Definition
value.h:35