Deluge Firmware 1.3.0
Build date: 2025.07.12
Loading...
Searching...
No Matches
polyphony.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
19#include "definitions_cxx.hpp"
20#include "gui/menu_item/selection.h"
21#include "gui/ui/sound_editor.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
28#include <hid/display/oled.h>
29
30namespace deluge::gui::menu_item::voice {
31class VoiceCount : public IntegerWithOff {
32public:
33 using IntegerWithOff::IntegerWithOff;
34 void readCurrentValue() override {
35 uint8_t voiceCount = soundEditor.currentSound->maxVoiceCount;
36 if (voiceCount > getMaxValue()) {
37 voiceCount = 0;
38 }
39 this->setValue(voiceCount);
40 }
41 bool usesAffectEntire() override { return true; }
42 void writeCurrentValue() override {
43 int32_t current_value = this->getValue();
44 current_value = current_value == 0 ? 127 : current_value;
45
46 // If affect-entire button held, do whole kit
47 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
48
49 Kit* kit = getCurrentKit();
50
51 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
52 if (thisDrum->type == DrumType::SOUND) {
53 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
54 // Note: we need to apply the same filtering as stated in the isRelevant() function
55 if (soundDrum->polyphonic == PolyphonyMode::POLY) {
56 soundDrum->maxVoiceCount = current_value;
57 }
58 }
59 }
60 }
61 // Or, the normal case of just one sound
62 else {
63 soundEditor.currentSound->maxVoiceCount = current_value;
64 }
65 }
66 [[nodiscard]] int32_t getMinValue() const override { return 0; }
67 [[nodiscard]] int32_t getMaxValue() const override { return 16; }
68 [[nodiscard]] NumberStyle getNumberStyle() const override { return NUMBER; }
69
70 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
71 Sound* sound = static_cast<Sound*>(modControllable);
72 return (sound->polyphonic == PolyphonyMode::POLY);
73 }
74
75 void getColumnLabel(StringBuf& label) override {
76 label.append(deluge::l10n::get(l10n::String::STRING_FOR_MAX_VOICES_SHORT));
77 }
78
79 void getValueForPopup(StringBuf& valueBuf) override {
80 if (const auto value = getValue(); value == 0) {
81 valueBuf.append(l10n::get(l10n::String::STRING_FOR_OFF));
82 }
83 else {
84 valueBuf.appendInt(value);
85 }
86 }
87
88 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
89 if (getValue() == 0) {
90 const auto& icon = OLED::infinityIcon;
91 const int32_t y = startY + (height - 8) / 2;
92 const int32_t x = startX + (width - icon.size()) / 2;
93 return OLED::main.drawGraphicMultiLine(icon.data(), x, y, icon.size());
94 }
95 IntegerWithOff::renderInHorizontalMenu(startX, width, startY, height);
96 }
97};
98
99extern VoiceCount polyphonicVoiceCountMenu;
100
101class PolyphonyType final : public Selection {
102public:
103 using Selection::Selection;
104 void readCurrentValue() override { this->setValue(soundEditor.currentSound->polyphonic); }
105 bool usesAffectEntire() override { return true; }
106 void writeCurrentValue() override {
107 auto current_value = this->getValue<PolyphonyMode>();
108
109 // If affect-entire button held, do whole kit
110 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
111
112 Kit* kit = getCurrentKit();
113
114 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
115 if (thisDrum->type == DrumType::SOUND) {
116 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
117 soundDrum->polyphonic = current_value;
118 }
119 }
120 }
121 // Or, the normal case of just one sound
122 else {
123 soundEditor.currentSound->polyphonic = current_value;
124 }
125 }
126
127 deluge::vector<std::string_view> getOptions(OptType optType) override {
128 (void)optType;
129 deluge::vector<std::string_view> options = {
130 l10n::getView(l10n::String::STRING_FOR_AUTO),
131 l10n::getView(l10n::String::STRING_FOR_POLYPHONIC),
132 l10n::getView(l10n::String::STRING_FOR_MONOPHONIC),
133 l10n::getView(l10n::String::STRING_FOR_LEGATO),
134 };
135
136 if (soundEditor.editingKit()) {
137 options.push_back(l10n::getView(l10n::String::STRING_FOR_CHOKE));
138 }
139 return options;
140 }
141 MenuItem* selectButtonPress() override {
142 if (this->getValue<PolyphonyMode>() == PolyphonyMode::POLY) {
143 return &polyphonicVoiceCountMenu;
144 }
146 }
147
148 void getColumnLabel(StringBuf& label) override {
149 label.append(deluge::l10n::get(l10n::String::STRING_FOR_POLYPHONY_SHORT));
150 }
151};
152} // namespace deluge::gui::menu_item::voice
Definition drum.h:44
Definition kit.h:34
Definition mod_controllable_audio.h:47
Definition sound_drum.h:28
Definition sound.h:71
Definition d_stringbuf.h:16
Definition selection.h:26
MenuItem * selectButtonPress() override
Handle a select button press.
Definition selection.h:54
MenuItem * selectButtonPress() override
Handle a select button press.
Definition polyphony.h:141
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition polyphony.h:105
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:104
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition polyphony.h:41
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition polyphony.h:70
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:34
void getValueForPopup(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition polyphony.h:79