Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
type.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/selection.h"
21#include "gui/menu_item/submenu.h"
22#include "gui/ui/sound_editor.h"
23#include "model/song/song.h"
24#include "processing/engines/audio_engine.h"
25#include "processing/sound/sound.h"
26#include "processing/source.h"
27#include "util/comparison.h"
28
30
31namespace deluge::gui::menu_item::osc {
32class Type final : public Selection, public FormattedTitle {
33public:
34 Type(l10n::String name, l10n::String title_format_str) : Selection(name), FormattedTitle(title_format_str) {};
35 void beginSession(MenuItem* navigatedBackwardFrom) override { Selection::beginSession(navigatedBackwardFrom); }
36
37 bool mayUseDx() { return !soundEditor.editingKit() && soundEditor.currentSourceIndex == 0; }
38
39 void readCurrentValue() override {
40 int32_t rawVal = (int32_t)soundEditor.currentSource->oscType;
41 if (!mayUseDx() && rawVal > (int32_t)OscType::DX7) {
42 rawVal -= 1;
43 }
44 this->setValue(rawVal);
45 }
46 void writeCurrentValue() override {
47
48 OscType oldValue = soundEditor.currentSource->oscType;
49 auto newValue = this->getValue<OscType>();
50 if (!mayUseDx() && (int32_t)newValue >= (int32_t)OscType::DX7) {
51 newValue = (OscType)((int32_t)newValue + 1);
52 }
53
54 auto needs_unassignment = {
55 OscType::INPUT_L,
56 OscType::INPUT_R,
57 OscType::INPUT_STEREO,
58 OscType::SAMPLE,
59 OscType::DX7,
60
61 // Haven't actually really determined if this needs to be here - maybe not?
62 OscType::WAVETABLE,
63 };
64
65 if (util::one_of(oldValue, needs_unassignment) || util::one_of(newValue, needs_unassignment)) {
66 soundEditor.currentSound->killAllVoices();
67 }
68
69 soundEditor.currentSource->setOscType(newValue);
70
71 if (oldValue == OscType::SQUARE || newValue == OscType::SQUARE) {
72 soundEditor.currentSound->setupPatchingForAllParamManagers(currentSong);
73 }
74 }
75
76 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
77
78 deluge::vector<std::string_view> getOptions(OptType optType) override {
79 (void)optType;
80 using enum l10n::String;
81 deluge::vector<std::string_view> options = {
82 l10n::getView(STRING_FOR_SINE), //<
83 l10n::getView(STRING_FOR_TRIANGLE), //<
84 l10n::getView(STRING_FOR_SQUARE), //<
85 l10n::getView(STRING_FOR_ANALOG_SQUARE), //<
86 l10n::getView(STRING_FOR_SAW), //<
87 l10n::getView(STRING_FOR_ANALOG_SAW), //<
88 l10n::getView(STRING_FOR_WAVETABLE), //<
89 };
90
91 if (soundEditor.currentSound->getSynthMode() == SynthMode::RINGMOD) {
92 return options;
93 }
94
95 options.emplace_back(l10n::getView(STRING_FOR_SAMPLE));
96
97 if (mayUseDx()) {
98 options.emplace_back(l10n::getView(STRING_FOR_DX7));
99 }
100
101 if (AudioEngine::micPluggedIn || AudioEngine::lineInPluggedIn) {
102 options.emplace_back(l10n::getView(STRING_FOR_INPUT_LEFT));
103 options.emplace_back(l10n::getView(STRING_FOR_INPUT_RIGHT));
104 options.emplace_back(l10n::getView(STRING_FOR_INPUT_STEREO));
105 }
106 else {
107 options.emplace_back(l10n::getView(STRING_FOR_INPUT));
108 }
109
110 return options;
111 }
112
113 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
114 Sound* sound = static_cast<Sound*>(modControllable);
115 return (sound->getSynthMode() != SynthMode::FM);
116 }
117
118 MenuItem* selectButtonPress() final {
119 if (soundEditor.currentSource->oscType != OscType::DX7) {
120 return nullptr;
121 }
122 return (MenuItem*)&dxMenu;
123 }
124};
125
126} // namespace deluge::gui::menu_item::osc
Definition mod_controllable_audio.h:47
Definition sound.h:71
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition enumeration.cpp:7
Definition selection.h:26
Definition submenu.h:29
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition type.h:35
MenuItem * selectButtonPress() final
Handle a select button press.
Definition type.h:118
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition type.h:39
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition type.h:113
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 type.h:76