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