Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
channel.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/integer.h"
20#include "gui/ui/sound_editor.h"
21#include "hid/display/oled.h"
22#include "model/drum/drum.h"
23#include "model/instrument/kit.h"
24#include "model/song/song.h"
25#include "processing/sound/sound.h"
26#include "processing/sound/sound_drum.h"
27
28namespace deluge::gui::menu_item::midi::sound {
29
30class OutputMidiChannel final : public Integer {
31public:
32 using Integer::Integer;
33 [[nodiscard]] int32_t getMinValue() const override { return 0; }
34 [[nodiscard]] int32_t getMaxValue() const override { return 16; }
35 void readCurrentValue() override {
36 int32_t value = soundEditor.currentSound->outputMidiChannel;
37 if (value == MIDI_CHANNEL_NONE) {
38 value = 0;
39 }
40 else {
41 value = value + 1;
42 }
43 this->setValue(value);
44 }
45 bool usesAffectEntire() override { return true; }
46 void writeCurrentValue() override {
47 int32_t value = this->getValue();
48 if (value == 0) {
49 value = MIDI_CHANNEL_NONE;
50 }
51 else {
52 value = value - 1;
53 }
54 // If affect-entire button held, do whole kit
55 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
56
57 Kit* kit = getCurrentKit();
58
59 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
60 if (thisDrum->type == DrumType::SOUND) {
61 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
62 soundDrum->outputMidiChannel = value;
63 }
64 }
65 }
66 // Or, the normal case of just one sound
67 else {
68 soundEditor.currentSound->outputMidiChannel = value;
69 }
70 }
71
72 void drawValue() override {
73 int32_t value = this->getValue();
74 if (value == 0) {
75 display->setScrollingText(l10n::get(l10n::String::STRING_FOR_OFF));
76 }
77 else {
78 char name[12];
79 snprintf(name, sizeof(name), "%d", value);
80 display->setScrollingText(name);
81 }
82 }
83
84 void drawInteger(int32_t textWidth, int32_t textHeight, int32_t yPixel) override {
85 deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main;
86 int32_t value = this->getValue();
87 if (value == 0) {
88 canvas.drawStringCentred(l10n::get(l10n::String::STRING_FOR_OFF), yPixel + OLED_MAIN_TOPMOST_PIXEL,
89 textWidth, textHeight);
90 }
91 else {
92 char name[12];
93 snprintf(name, sizeof(name), "%d", value);
94 canvas.drawStringCentred(name, yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth, textHeight);
95 }
96 }
97};
98} // namespace deluge::gui::menu_item::midi::sound
Definition drum.h:44
Definition kit.h:34
const deluge::l10n::String name
Default name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:239
Definition sound_drum.h:28
Definition integer.h:24
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition channel.h:35
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition channel.h:45
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