Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
audio.h
1/*
2 * Copyright © 2026 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 "drivers/usb/usb_audio.h"
19#include "gui/menu_item/selection.h"
20#include "gui/menu_item/toggle.h"
21#include "gui/ui/sound_editor.h"
22#include "hid/display/display.h"
23#include "model/output.h"
24#include "model/song/song.h"
25#include "storage/flash_storage.h"
26#include <algorithm>
27#include <array>
28
29namespace deluge::gui::menu_item::usb {
30
33class Audio final : public Selection {
34public:
35 using Selection::Selection;
36 // Shown in this order, which isn't how they're stored
37 static constexpr std::array<usb_audio::Mode, usb_audio::kNumModes> kModes = {
38 usb_audio::Mode::OFF, usb_audio::Mode::STEREO, usb_audio::Mode::MULTITRACK};
39
40 void readCurrentValue() override {
41 this->setValue(std::find(kModes.begin(), kModes.end(), FlashStorage::usbAudioMode) - kModes.begin());
42 }
43 void writeCurrentValue() override {
44 FlashStorage::usbAudioMode = kModes[this->getValue()];
45 if (FlashStorage::usbAudioMode != activeMode()) {
46 display->displayPopup(l10n::get(l10n::String::STRING_FOR_RESTART_TO_APPLY));
47 }
48 }
49 deluge::vector<std::string_view> getOptions(OptType optType) override {
50 (void)optType;
51 using enum l10n::String;
52 return {l10n::getView(STRING_FOR_OFF), l10n::getView(STRING_FOR_STEREO), l10n::getView(STRING_FOR_MULTITRACK)};
53 }
54
55private:
56 static usb_audio::Mode activeMode() {
57 return usb_audio::multitrackActive() ? usb_audio::Mode::MULTITRACK
58 : usbAudioActive() ? usb_audio::Mode::STEREO
59 : usb_audio::Mode::OFF;
60 }
61};
62
64class DirectMonitoring final : public Toggle {
65public:
66 using Toggle::Toggle;
67 void readCurrentValue() override { this->setValue(usb_audio::directMonitoring); }
68 void writeCurrentValue() override { usb_audio::directMonitoring = this->getValue(); }
69};
70
72class OutputSource final : public Selection {
73public:
74 using Selection::Selection;
75 void readCurrentValue() override { this->setValue(usb_audio::outputSource); }
76 void writeCurrentValue() override { usb_audio::outputSource = this->getValue<usb_audio::OutputSource>(); }
77 deluge::vector<std::string_view> getOptions(OptType optType) override {
78 (void)optType;
79 using enum l10n::String;
80 return {l10n::getView(STRING_FOR_MAIN_MIX), l10n::getView(STRING_FOR_LINE_IN)};
81 }
82};
83
87class TrackBus final : public Selection {
88public:
89 using Selection::Selection;
90 void readCurrentValue() override { this->setValue(getCurrentOutput()->getUSBBus()); }
91 void writeCurrentValue() override { getCurrentOutput()->setUSBBus(this->getValue()); }
92 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) const override {
93 return usb_audio::multitrackActive() && !soundEditor.editingKitRow();
94 }
95 deluge::vector<std::string_view> getOptions(OptType optType) override {
96 (void)optType;
97 using enum l10n::String;
98 static_assert(usb_audio::kNumTrackBuses == 3);
99 return {l10n::getView(STRING_FOR_MAIN_MIX), l10n::getView(STRING_FOR_USB_BUS_1),
100 l10n::getView(STRING_FOR_USB_BUS_2), l10n::getView(STRING_FOR_USB_BUS_3)};
101 }
102};
103
104} // namespace deluge::gui::menu_item::usb
Definition mod_controllable_audio.h:47
Definition selection.h:26
Definition toggle.h:8
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition audio.h:40
Whether audio from the host is mixed straight into the Deluge's outputs.
Definition audio.h:64
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition audio.h:67
What the host receives from the Deluge: its main mix, or its line input.
Definition audio.h:72
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition audio.h:75
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) const override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition audio.h:92
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition audio.h:90