Deluge Firmware 1.3.0
Build date: 2025.04.16
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, bool newForModulator = false)
29 : Decimal(newName), FormattedTitle(title_format_str), forModulator(newForModulator) {}
30
31 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
32
33 [[nodiscard]] int32_t getMinValue() const override { return -soundEditor.numberEditSize; }
34 [[nodiscard]] int32_t getMaxValue() const override { return 360; }
35 [[nodiscard]] int32_t getNumDecimalPlaces() const override { return 0; }
36 [[nodiscard]] int32_t getDefaultEditPos() const override { return 1; }
37
38 void readCurrentValue() override {
39 uint32_t value = *getValueAddress();
40 if (value == 0xFFFFFFFF) {
41 this->setValue(-soundEditor.numberEditSize);
42 }
43 else {
44 this->setValue(value / 11930464);
45 }
46 }
47
48 void writeCurrentValue() override {
49 uint32_t value;
50 if (this->getValue() < 0) {
51 value = 0xFFFFFFFF;
52 }
53 else {
54 value = this->getValue() * 11930464;
55 }
56 *getValueAddress() = value;
57 }
58
59 void drawValue() override {
60 if (this->getValue() < 0) {
61 display->setText(l10n::get(l10n::String::STRING_FOR_DISABLED), false, 255, true);
62 }
63 else {
64 Decimal::drawValue();
65 }
66 }
67
68 void drawPixelsForOled() override {
69 deluge::hid::display::oled_canvas::Canvas& canvas = deluge::hid::display::OLED::main;
70 if (this->getValue() < 0) {
71 canvas.drawStringCentred(l10n::get(l10n::String::STRING_FOR_OFF), 20, kTextHugeSpacingX, kTextHugeSizeY);
72 }
73 else {
75 }
76 }
77
78 void horizontalEncoderAction(int32_t offset) override {
79 if (this->getValue() >= 0) {
81 }
82 }
83
84 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
85 Sound* sound = static_cast<Sound*>(modControllable);
86 Source* source = &sound->sources[whichThing];
87 if (forModulator && sound->getSynthMode() != SynthMode::FM) {
88 return false;
89 }
90 return (source->oscType != OscType::SAMPLE || sound->getSynthMode() == SynthMode::FM);
91 }
92
93private:
94 bool forModulator;
95 [[nodiscard]] uint32_t* getValueAddress() const {
96 if (forModulator) {
97 return &soundEditor.currentSound->modulatorRetriggerPhase[soundEditor.currentSourceIndex];
98 }
99 return &soundEditor.currentSound->oscRetriggerPhase[soundEditor.currentSourceIndex];
100 }
101};
102} // namespace deluge::gui::menu_item::osc
Definition mod_controllable_audio.h:47
Definition sound.h:71
Definition source.h:31
Definition decimal.h:24
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition decimal.cpp:133
void horizontalEncoderAction(int32_t offset) override
Handle horizontal encoder movement.
Definition decimal.cpp:82
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:31
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:84
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition retrigger_phase.h:68
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition retrigger_phase.h:38
void horizontalEncoderAction(int32_t offset) override
Handle horizontal encoder movement.
Definition retrigger_phase.h:78
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:189