Deluge Firmware 1.3.0
Build date: 2025.09.27
Loading...
Searching...
No Matches
retrigger_phase.h
1/*
2 * Copyright (c) 2014-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#pragma once
18#include "gui/menu_item/decimal.h"
19#include "gui/menu_item/formatted_title.h"
20#include "gui/ui/sound_editor.h"
21#include "hid/display/display.h"
22#include "hid/display/oled.h"
23#include "processing/sound/sound.h"
24
25namespace deluge::gui::menu_item::osc {
26class RetriggerPhase final : public Decimal, public FormattedTitle {
27public:
28 RetriggerPhase(l10n::String newName, l10n::String title_format_str, uint8_t source_id, bool newForModulator = false)
29 : Decimal(newName), FormattedTitle(title_format_str, source_id + 1), for_modulator_(newForModulator),
30 source_id_(source_id) {}
31
32 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
33
34 [[nodiscard]] int32_t getMinValue() const override { return -1; }
35 [[nodiscard]] int32_t getMaxValue() const override { return 360; }
36 [[nodiscard]] int32_t getNumDecimalPlaces() const override { return 0; }
37 [[nodiscard]] int32_t getDefaultEditPos() const override { return 1; }
38
39 void readCurrentValue() override {
40 uint32_t value = *getValueAddress();
41 if (value == 0xFFFFFFFF) {
42 this->setValue(-1);
43 }
44 else {
45 this->setValue(value / 11930464);
46 }
47 }
48
49 void writeCurrentValue() override {
50 uint32_t value;
51 if (this->getValue() < 0) {
52 value = 0xFFFFFFFF;
53 }
54 else {
55 value = this->getValue() * 11930464;
56 }
57 *getValueAddress() = value;
58 }
59
60 void drawValue() override {
61 if (this->getValue() < 0) {
62 display->setText(l10n::get(l10n::String::STRING_FOR_DISABLED), false, 255, true);
63 }
64 else {
65 Decimal::drawValue();
66 }
67 }
68
69 void drawPixelsForOled() override {
70 oled_canvas::Canvas& canvas = OLED::main;
71 if (this->getValue() < 0) {
72 canvas.drawStringCentred(l10n::get(l10n::String::STRING_FOR_OFF), 20, kTextHugeSpacingX, kTextHugeSizeY);
73 }
74 else {
76 }
77 }
78
79 void horizontalEncoderAction(int32_t offset) override {
80 if (this->getValue() >= 0) {
82 }
83 }
84
85 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
86 const auto sound = static_cast<Sound*>(modControllable);
87 Source& source = sound->sources[source_id_];
88
89 if (for_modulator_ && sound->getSynthMode() != SynthMode::FM) {
90 return false;
91 }
92 if (source.oscType == OscType::WAVETABLE) {
93 return source.hasAtLeastOneAudioFileLoaded();
94 }
95
96 return source.oscType != OscType::SAMPLE || sound->getSynthMode() == SynthMode::FM;
97 }
98
99 int32_t getNumberEditSize() override {
100 if (parent != nullptr && parent->renderingStyle() == Submenu::RenderingStyle::HORIZONTAL) {
101 // In Horizontal menus we edit with 0.10 step by default, and with 0.01 step if the shift is pressed
102 return Buttons::isButtonPressed(hid::button::SHIFT) ? 1 : 10;
103 }
104 return Decimal::getNumberEditSize();
105 }
106
107 void selectEncoderAction(int32_t offset) override {
108 if (offset > 0 && getValue() < 0) {
109 setValue(-getNumberEditSize());
110 }
112 }
113
114 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
115 oled_canvas::Canvas& canvas = OLED::main;
116 if (this->getValue() < 0) {
117 const char* off = l10n::get(l10n::String::STRING_FOR_OFF);
118 return canvas.drawStringCentered(off, startX, startY + 3, kTextSpacingX, kTextSpacingY, width);
119 }
120
121 return Decimal::renderInHorizontalMenu(startX, width, startY, height);
122 }
123
124 void getNotificationValue(StringBuf& valueBuf) override {
125 if (this->getValue() < 0) {
126 return valueBuf.append(l10n::get(l10n::String::STRING_FOR_OFF));
127 }
128 valueBuf.appendInt(getValue());
129 }
130
131 void getColumnLabel(StringBuf& label) override {
132 label.append(l10n::get(l10n::String::STRING_FOR_RETRIGGER_PHASE_SHORT));
133 }
134
135 [[nodiscard]] NumberStyle getNumberStyle() const override { return SLIDER; }
136
137private:
138 bool for_modulator_;
139 uint8_t source_id_;
140
141 [[nodiscard]] uint32_t* getValueAddress() const {
142 if (for_modulator_) {
143 return &soundEditor.currentSound->modulatorRetriggerPhase[source_id_];
144 }
145 return &soundEditor.currentSound->oscRetriggerPhase[source_id_];
146 }
147};
148} // namespace deluge::gui::menu_item::osc
Definition mod_controllable_audio.h:47
Definition sound.h:71
Definition source.h:31
Definition d_stringbuf.h:16
Definition decimal.h:24
void selectEncoderAction(int32_t offset) override
Handle select encoder movement.
Definition decimal.cpp:65
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition decimal.cpp:142
void horizontalEncoderAction(int32_t offset) override
Handle horizontal encoder movement.
Definition decimal.cpp:91
std::string_view getTitle() const override
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition retrigger_phase.h:32
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition retrigger_phase.h:85
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition retrigger_phase.h:69
void selectEncoderAction(int32_t offset) override
Handle select encoder movement.
Definition retrigger_phase.h:107
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition retrigger_phase.h:39
void horizontalEncoderAction(int32_t offset) override
Handle horizontal encoder movement.
Definition retrigger_phase.h:79
void getNotificationValue(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition retrigger_phase.h:124
void drawStringCentered(char const *string, int32_t startX, int32_t startY, int32_t textSpacingX, int32_t textSpacingY, int32_t totalWidth)
Definition canvas.cpp:274
void drawStringCentred(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos=OLED_MAIN_WIDTH_PIXELS/2)
Definition canvas.cpp:266