Deluge Firmware 1.3.0
Build date: 2025.09.14
Loading...
Searching...
No Matches
pulse_width.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 "definitions_cxx.hpp"
19#include "gui/menu_item/formatted_title.h"
20#include "gui/menu_item/source/patched_param.h"
21#include "modulation/params/param_set.h"
22#include "processing/sound/sound.h"
23
24namespace deluge::gui::menu_item::osc {
25class PulseWidth final : public source::PatchedParam, public FormattedTitle {
26public:
27 PulseWidth(l10n::String name, l10n::String title_format_str, int32_t newP, uint8_t source_id)
28 : PatchedParam(name, newP, source_id), FormattedTitle(title_format_str, source_id + 1) {}
29
30 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
31
32 int32_t getFinalValue() override { return computeFinalValueForHalfPrecisionMenuItem(this->getValue()); }
33
34 void readCurrentValue() override {
35 this->setValue(computeCurrentValueForHalfPrecisionMenuItem(
36 soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP())));
37 }
38
39 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
40 const auto sound = static_cast<Sound*>(modControllable);
41 if (sound->getSynthMode() == SynthMode::FM) {
42 return false;
43 }
44
45 const OscType oscType = sound->sources[source_id_].oscType;
46 if (oscType == OscType::WAVETABLE) {
47 auto& source = sound->sources[source_id_];
48 return source.hasAtLeastOneAudioFileLoaded();
49 }
50
51 return oscType != OscType::SAMPLE && oscType != OscType::INPUT_L && oscType != OscType::INPUT_R
52 && oscType != OscType::INPUT_STEREO;
53 }
54
55 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
56 oled_canvas::Canvas& image = OLED::main;
57
58 const float valueNormalized = getValue() / 50.0f;
59
60 constexpr int32_t xPadding = 4;
61 width -= xPadding * 2 + 1;
62
63 int32_t xStart = startX + xPadding;
64 int32_t xEnd = xStart + width;
65 int32_t yStart = startY + 3;
66 int32_t yEnd = startY + height - 5;
67
68 int32_t pwMinX = xStart + 2;
69 int32_t pwMaxX = xStart + width / 2;
70 int32_t pwWidth = pwMaxX - pwMinX;
71 int32_t pwX = pwMaxX - pwWidth * valueNormalized;
72
73 image.drawVerticalLine(xStart, yStart, yEnd);
74 image.drawHorizontalLine(yStart, xStart, pwX);
75 image.drawVerticalLine(pwX, yStart, yEnd);
76 image.drawHorizontalLine(yEnd, pwX, xEnd);
77 }
78};
79
80} // namespace deluge::gui::menu_item::osc
Definition mod_controllable_audio.h:47
Definition sound.h:71
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition pulse_width.h:34
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition pulse_width.h:39
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 pulse_width.h:30