Deluge Firmware 1.3.0
Build date: 2025.06.05
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
28namespace deluge::gui::menu_item::voice {
29class VoiceCount : public IntegerWithOff {
30public:
31 using IntegerWithOff::IntegerWithOff;
32 void readCurrentValue() override {
33 uint8_t voiceCount = soundEditor.currentSound->maxVoiceCount;
34 if (voiceCount > getMaxValue()) {
35 voiceCount = 0;
36 }
37 this->setValue(voiceCount);
38 }
39 bool usesAffectEntire() override { return true; }
40 void writeCurrentValue() override {
41 int32_t current_value = this->getValue();
42 current_value = current_value == 0 ? 127 : current_value;
43
44 // If affect-entire button held, do whole kit
45 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
46
47 Kit* kit = getCurrentKit();
48
49 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
50 if (thisDrum->type == DrumType::SOUND) {
51 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
52 // Note: we need to apply the same filtering as stated in the isRelevant() function
53 if (soundDrum->polyphonic == PolyphonyMode::POLY) {
54 soundDrum->maxVoiceCount = current_value;
55 }
56 }
57 }
58 }
59 // Or, the normal case of just one sound
60 else {
61 soundEditor.currentSound->maxVoiceCount = current_value;
62 }
63 }
64 [[nodiscard]] int32_t getMinValue() const override { return 0; }
65 [[nodiscard]] int32_t getMaxValue() const override { return 16; }
66
67 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
68 Sound* sound = static_cast<Sound*>(modControllable);
69 return (sound->polyphonic == PolyphonyMode::POLY);
70 }
71
72 void getColumnLabel(StringBuf& label) override {
73 label.append(deluge::l10n::get(deluge::l10n::String::STRING_FOR_MAX_VOICES_SHORT));
74 }
75};
76
77extern VoiceCount polyphonicVoiceCountMenu;
78
79class PolyphonyType final : public Selection {
80public:
81 using Selection::Selection;
82 void readCurrentValue() override { this->setValue(soundEditor.currentSound->polyphonic); }
83 bool usesAffectEntire() override { return true; }
84 void writeCurrentValue() override {
85 auto current_value = this->getValue<PolyphonyMode>();
86
87 // If affect-entire button held, do whole kit
88 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
89
90 Kit* kit = getCurrentKit();
91
92 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
93 if (thisDrum->type == DrumType::SOUND) {
94 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
95 soundDrum->polyphonic = current_value;
96 }
97 }
98 }
99 // Or, the normal case of just one sound
100 else {
101 soundEditor.currentSound->polyphonic = current_value;
102 }
103 }
104
105 deluge::vector<std::string_view> getOptions(OptType optType) override {
106 (void)optType;
107 deluge::vector<std::string_view> options = {
108 l10n::getView(l10n::String::STRING_FOR_AUTO),
109 l10n::getView(l10n::String::STRING_FOR_POLYPHONIC),
110 l10n::getView(l10n::String::STRING_FOR_MONOPHONIC),
111 l10n::getView(l10n::String::STRING_FOR_LEGATO),
112 };
113
114 if (soundEditor.editingKit()) {
115 options.push_back(l10n::getView(l10n::String::STRING_FOR_CHOKE));
116 }
117 return options;
118 }
119 MenuItem* selectButtonPress() override {
120 if (this->getValue<PolyphonyMode>() == PolyphonyMode::POLY) {
121 return &polyphonicVoiceCountMenu;
122 }
124 }
125
126 void getColumnLabel(StringBuf& label) override {
127 label.append(deluge::l10n::get(l10n::String::STRING_FOR_POLYPHONY_SHORT));
128 }
129};
130} // 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:119
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition polyphony.h:83
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:82
void getColumnLabel(StringBuf &label) override
Get the name for use on horizontal menus.
Definition polyphony.h:126
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition polyphony.h:39
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:67
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:32
void getColumnLabel(StringBuf &label) override
Get the name for use on horizontal menus.
Definition polyphony.h:72