Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
audio_recorder.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/l10n/l10n.h"
19#include "gui/menu_item/formatted_title.h"
20#include "gui/menu_item/horizontal_menu.h"
21#include "gui/menu_item/menu_item.h"
22#include "gui/ui/audio_recorder.h"
23#include "gui/ui/sound_editor.h"
24#include "gui/ui_timer_manager.h"
25#include "processing/sound/sound.h"
26#include "storage/flash_storage.h"
27
28namespace deluge::gui::menu_item::osc {
29class AudioRecorder final : public MenuItem, FormattedTitle {
30public:
31 AudioRecorder(l10n::String newName, uint8_t sourceId)
32 : MenuItem(newName), FormattedTitle(newName, sourceId + 1), source_id_{sourceId} {}
33
34 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
35 [[nodiscard]] std::string_view getName() const override { return FormattedTitle::title(); }
36
37 void beginSession(MenuItem* navigatedBackwardFrom) override {
38 soundEditor.shouldGoUpOneLevelOnBegin = true;
39 soundEditor.setCurrentSource(source_id_);
40
41 // These can be left over from a session that never began, so only go there if it'll render horizontally
42 if (parentMenuHeadingTo != nullptr && menuItemHeadingTo != nullptr
43 && parentMenuHeadingTo->renderingStyle() == Submenu::HORIZONTAL) {
44 parentMenuHeadingTo->focusChild(menuItemHeadingTo);
45 soundEditor.navigationDepth = 0;
46 soundEditor.menuItemNavigationRecord[soundEditor.navigationDepth] = parentMenuHeadingTo;
47 soundEditor.shouldGoUpOneLevelOnBegin = false;
48 }
49 parentMenuHeadingTo = nullptr;
50 menuItemHeadingTo = nullptr;
51
52 if (bool success = openUI(&audioRecorder); !success) {
53 if (getCurrentUI() == &soundEditor) {
54 soundEditor.goUpOneLevel();
55 }
56 return uiTimerManager.unsetTimer(TimerName::SHORTCUT_BLINK);
57 }
58
59 audioRecorder.process();
60 }
61
62 bool isRelevant(ModControllableAudio* modControllable, int32_t) const override {
63 const auto sound = static_cast<Sound*>(modControllable);
64 return sound->getSynthMode() == SynthMode::SUBTRACTIVE;
65 }
66
67 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t,
68 ::MultiRange** currentRange) override {
69 if (!isRelevant(modControllable, source_id_)) {
70 display->displayPopup(l10n::get(l10n::String::STRING_FOR_CANT_RECORD_AUDIO_FM_MODE));
71 return MenuPermission::NO;
72 }
73
74 Sound* sound = static_cast<Sound*>(modControllable);
75 return soundEditor.checkPermissionToBeginSessionForRangeSpecificParam(sound, source_id_, currentRange);
76 }
77
78 [[nodiscard]] bool allowToBeginSessionFromHorizontalMenu() override { return true; }
79 [[nodiscard]] int32_t getOccupiedSlots() const override { return 2; }
80 [[nodiscard]] bool showColumnLabel() const override { return false; }
81 [[nodiscard]] bool showNotification() const override { return false; }
82
83 void renderInHorizontalMenu(const SlotPosition& slot) override {
84 using namespace hid::display;
85 oled_canvas::Canvas& image = OLED::main;
86
87 // Draw "rec" part
88 const uint8_t start_x = slot.start_x + 8;
89 const uint8_t start_y = slot.start_y + kHorizontalMenuSlotYOffset + 6;
90 constexpr uint8_t circle_radius = 3;
91 image.drawCircle(start_x + circle_radius + 1, start_y + circle_radius + 1, circle_radius, true);
92 image.drawString("rec", start_x + circle_radius * 2 + 5, start_y, kTextSpacingX, kTextSpacingY);
93
94 // Draw the source number
95 DEF_STACK_STRING_BUF(buf, kShortStringBufferSize);
96 buf.appendInt(source_id_ + 1);
97 uint8_t source_x = slot.start_x + slot.width - kTextBigSpacingX - 7;
98 uint8_t source_y = slot.start_y + kHorizontalMenuSlotYOffset + 4;
99
100 const bool full_inversion = FlashStorage::accessibilityMenuHighlighting == MenuHighlighting::FULL_INVERSION;
101 if (full_inversion || parent->getCurrentItem() == this) {
102 image.drawString(buf.data(), source_x, source_y, kTextBigSpacingX, kTextBigSizeY);
103 }
104 else {
105 image.drawString(buf.data(), source_x - 1, source_y + 2, kTextSpacingX, kTextSpacingY);
106 }
107
108 // Draw separator in the middle
109 if (!full_inversion && source_id_ == 0) {
110 const uint8_t y0 = slot.start_y + kHorizontalMenuSlotYOffset + 1;
111 const uint8_t y1 = y0 + 18;
112 for (uint8_t y = y0; y <= y1; y += 2) {
113 image.drawPixel(slot.start_x + slot.width - 1, y);
114 }
115 }
116 }
117
118 HorizontalMenu* parentMenuHeadingTo{nullptr};
119 MenuItem* menuItemHeadingTo{nullptr};
120
121private:
122 uint8_t source_id_;
123};
124} // namespace deluge::gui::menu_item::osc
Definition mod_controllable_audio.h:47
Definition sound.h:78
Definition multi_range.h:24
int32_t getOccupiedSlots() const override
Get the number of occupied slots in Horizontal menu.
Definition audio_recorder.h:79
bool allowToBeginSessionFromHorizontalMenu() override
Allow entering menu session by selecting the menu item twice in Horizontal menu.
Definition audio_recorder.h:78
bool isRelevant(ModControllableAudio *modControllable, int32_t) const override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition audio_recorder.h:62
bool showColumnLabel() const override
Show a label for the parameter in Horizontal menu.
Definition audio_recorder.h:80
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition audio_recorder.h:37
bool showNotification() const override
Show a popup with the full name and value of the editing parameter at the top of Horizontal menu.
Definition audio_recorder.h:81
std::string_view getName() const override
Get the actual name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition audio_recorder.h:35
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 audio_recorder.h:34
Definition menu_item.h:35