Deluge Firmware 1.3.0
Build date: 2025.06.24
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 [[nodiscard]] NumberStyle getNumberStyle() const override { return NUMBER; }
67
68 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
69 Sound* sound = static_cast<Sound*>(modControllable);
70 return (sound->polyphonic == PolyphonyMode::POLY);
71 }
72
73 void getColumnLabel(StringBuf& label) override {
74 label.append(deluge::l10n::get(l10n::String::STRING_FOR_MAX_VOICES_SHORT));
75 }
76};
77
78extern VoiceCount polyphonicVoiceCountMenu;
79
80class PolyphonyType final : public Selection {
81public:
82 using Selection::Selection;
83 void readCurrentValue() override { this->setValue(soundEditor.currentSound->polyphonic); }
84 bool usesAffectEntire() override { return true; }
85 void writeCurrentValue() override {
86 auto current_value = this->getValue<PolyphonyMode>();
87
88 // If affect-entire button held, do whole kit
89 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
90
91 Kit* kit = getCurrentKit();
92
93 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
94 if (thisDrum->type == DrumType::SOUND) {
95 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
96 soundDrum->polyphonic = current_value;
97 }
98 }
99 }
100 // Or, the normal case of just one sound
101 else {
102 soundEditor.currentSound->polyphonic = current_value;
103 }
104 }
105
106 deluge::vector<std::string_view> getOptions(OptType optType) override {
107 (void)optType;
108 deluge::vector<std::string_view> options = {
109 l10n::getView(l10n::String::STRING_FOR_AUTO),
110 l10n::getView(l10n::String::STRING_FOR_POLYPHONIC),
111 l10n::getView(l10n::String::STRING_FOR_MONOPHONIC),
112 l10n::getView(l10n::String::STRING_FOR_LEGATO),
113 };
114
115 if (soundEditor.editingKit()) {
116 options.push_back(l10n::getView(l10n::String::STRING_FOR_CHOKE));
117 }
118 return options;
119 }
120 MenuItem* selectButtonPress() override {
121 if (this->getValue<PolyphonyMode>() == PolyphonyMode::POLY) {
122 return &polyphonicVoiceCountMenu;
123 }
125 }
126
127 void getColumnLabel(StringBuf& label) override {
128 label.append(deluge::l10n::get(l10n::String::STRING_FOR_POLYPHONY_SHORT));
129 }
130};
131} // 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:120
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition polyphony.h:84
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:83
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:68
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition polyphony.h:32