Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
specific_output_source_selector.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/context_menu/audio_input_selector.h"
19#include "gui/menu_item/menu_item.h"
20#include "hid/display/display.h"
21#include "hid/display/oled.h"
22#include "model/song/song.h"
23#include "processing/audio_output.h"
24
25namespace deluge::gui::menu_item::audio_clip {
26class SpecificSourceOutputSelector final : public MenuItem {
27public:
28 using MenuItem::MenuItem;
29
30 void beginSession(MenuItem* navigatedBackwardFrom) override {
31 audioOutputBeingEdited = (AudioOutput*)getCurrentOutput();
32 if (audioOutputBeingEdited->getOutputRecordingFrom()) {
33 outputIndex = currentSong->getOutputIndex(audioOutputBeingEdited->getOutputRecordingFrom());
34 }
35 else {
36 outputIndex = 0;
37 }
38 numOutputs = currentSong->getNumOutputs();
39 if (display->haveOLED()) {
40 renderUIsForOled();
41 }
42 else {
43 drawFor7seg(); // Probably not necessary either...
44 }
45 }
46
47 void selectEncoderAction(int32_t offset) override {
48 outputIndex += offset;
49 outputIndex = std::clamp<int32_t>(outputIndex, 0, numOutputs - 1);
50 auto newRecordingFrom = currentSong->getOutputFromIndex(outputIndex);
51 audioOutputBeingEdited->setOutputRecordingFrom(newRecordingFrom);
52 if (display->haveOLED()) {
53 renderUIsForOled();
54 }
55 else {
56 drawFor7seg(); // Probably not necessary either...
57 }
58 }
59 void drawPixelsForOled() override {
60 deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main;
61
62 // track
63 Output* output = currentSong->getOutputFromIndex(outputIndex);
64
65 // track type
66 OutputType outputType = output->type;
67
68 // for midi instruments, get the channel
69 int32_t channel;
70 if (outputType == OutputType::MIDI_OUT) {
71 Instrument* instrument = (Instrument*)output;
72 channel = ((NonAudioInstrument*)instrument)->getChannel();
73 }
74
75 char const* outputTypeText = getOutputTypeName(outputType, channel);
76
77 // draw the track type
78 canvas.drawStringCentred(outputTypeText, OLED_MAIN_TOPMOST_PIXEL + 14, kTextSpacingX, kTextSpacingY);
79
80 int32_t yPos = OLED_MAIN_TOPMOST_PIXEL + 28;
81
82 // draw the track name
83 char const* name = audioOutputBeingEdited->getOutputRecordingFrom()->name.get();
84
85 int32_t stringLengthPixels = canvas.getStringWidthInPixels(name, kTextTitleSizeY);
86
87 if (stringLengthPixels <= OLED_MAIN_WIDTH_PIXELS) {
88 canvas.drawStringCentred(name, yPos, kTextTitleSpacingX, kTextTitleSizeY);
89 }
90 else {
91 canvas.drawString(name, 0, yPos, kTextTitleSpacingX, kTextTitleSizeY);
92 deluge::hid::display::OLED::setupSideScroller(0, name, 0, OLED_MAIN_WIDTH_PIXELS, yPos,
93 yPos + kTextTitleSizeY, kTextTitleSpacingX, kTextTitleSizeY,
94 false);
95 }
96 }
97
98 void drawFor7seg() {
99 char const* text = audioOutputBeingEdited->getOutputRecordingFrom()->name.get();
100 display->setScrollingText(text, 0);
101 }
102
103 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
104 audioOutputBeingEdited = (AudioOutput*)getCurrentOutput();
105 return audioOutputBeingEdited->inputChannel == AudioInputChannel::SPECIFIC_OUTPUT;
106 }
107
108 bool shouldEnterSubmenu() override { return true; }
109
110 AudioOutput* audioOutputBeingEdited{nullptr};
111 // this is the index that the output is recording from
112 int32_t outputIndex{0};
113 int32_t numOutputs{0};
114};
115} // namespace deluge::gui::menu_item::audio_clip
Definition audio_output.h:37
Definition instrument.h:45
const deluge::l10n::String name
Default name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:239
Definition mod_controllable_audio.h:47
Definition non_audio_instrument.h:27
Definition output.h:81
Definition specific_output_source_selector.h:26
bool shouldEnterSubmenu() override
Check if selecting this menu item (with select encoder) should enter a submenu.
Definition specific_output_source_selector.h:108
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition specific_output_source_selector.h:30
void selectEncoderAction(int32_t offset) override
Handle select encoder movement.
Definition specific_output_source_selector.h:47
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition specific_output_source_selector.h:59
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition specific_output_source_selector.h:103
void drawString(std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t scrollPos=0, int32_t endX=OLED_MAIN_WIDTH_PIXELS, bool useTextWidth=false)
Definition canvas.cpp:123
int32_t getStringWidthInPixels(char const *string, int32_t textHeight)
Definition canvas.cpp:387
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