Deluge Firmware
1.4.0
Build date: 2026.11.30
Toggle main menu visibility
Loading...
Searching...
No Matches
sound_template.h
1
/*
2
* Copyright © 2026 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 "gui/l10n/l10n.h"
19
#include "gui/menu_item/file_selector.h"
20
#include "gui/menu_item/horizontal_menu.h"
21
#include "gui/menu_item/selection.h"
22
#include "gui/menu_item/submenu.h"
23
#include "gui/ui/sound_editor.h"
24
#include "gui/views/view.h"
25
#include "model/drum/drum.h"
26
#include "model/instrument/kit.h"
27
#include "model/model_stack.h"
28
#include "model/song/song.h"
29
#include "processing/sound/sound.h"
30
#include "processing/sound/sound_drum.h"
31
#include "processing/sound/sound_template.h"
32
33
namespace
deluge::gui
{
34
35
extern
gui::menu_item::Submenu dxMenu;
36
37
}
// namespace deluge::gui
38
39
using
deluge::gui::dxMenu;
40
41
namespace
deluge::gui::menu_item {
42
46
class
SoundTemplateSelection
final :
public
Selection
{
47
public
:
48
using
Selection::Selection;
49
50
deluge::vector<std::string_view> getOptions(OptType optType)
override
{
51
(void)optType;
52
using
enum l10n::String;
53
return
{l10n::getView(STRING_FOR_ADSR), l10n::getView(STRING_FOR_TEMPLATE_DRUM), l10n::getView(STRING_FOR_MPE),
54
l10n::getView(STRING_FOR_SAMPLE), l10n::getView(STRING_FOR_DX7)};
55
}
56
57
void
getColumnLabel(
StringBuf
& label)
override
{
58
label.append(l10n::get(l10n::String::STRING_FOR_SOUND_TEMPLATE_SHORT));
59
}
60
61
// The horizontal menu re-reads every item each time it renders, so keep the template chosen until another item gets
62
// the focus or the menu closes
63
void
readCurrentValue
()
override
{
64
if
(!isFocused()) {
65
setValue(SoundTemplate::ADSR);
66
}
67
}
68
70
void
writeCurrentValue
()
override
{}
71
72
bool
usesAffectEntire
()
override
{
return
true
; }
73
// Applying a template overwrites a lot, so only the SELECT button does it
74
bool
columnButtonActsAsSelect
()
override
{
return
false
; }
75
76
MenuItem*
selectButtonPress
()
override
{
77
auto
chosen = getValue<SoundTemplate>();
78
apply(chosen);
79
80
if
(chosen == SoundTemplate::SAMPLE) {
81
return
&file0SelectorMenu;
// pick the sample, as a new kit row does
82
}
83
if
(chosen == SoundTemplate::DX7) {
84
return
&dxMenu;
// pick a patch, as SELECT on a DX7 oscillator does
85
}
86
if
(soundEditor.getCurrentMenuItem() ==
this
) {
87
return
nullptr
;
// back up a level, like other selections
88
}
89
readValueAgain
();
90
return
NO_NAVIGATION;
91
}
92
93
void
beginSession
(MenuItem* navigatedBackwardFrom)
override
{
94
setValue(SoundTemplate::ADSR);
95
Selection::beginSession
(navigatedBackwardFrom);
96
}
97
void
parentMenuClosed
()
override
{ setValue(SoundTemplate::ADSR); }
98
99
private
:
100
[[nodiscard]]
bool
isFocused()
const
{
101
return
parent !=
nullptr
? parent->getCurrentItem() == this : soundEditor.getCurrentMenuItem() ==
this
;
102
}
103
104
static
void
apply(SoundTemplate chosen) {
105
if
(currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
106
Kit
* kit = getCurrentKit();
107
for
(
Drum
* thisDrum = kit->firstDrum; thisDrum !=
nullptr
; thisDrum = thisDrum->next) {
108
if
(thisDrum->type == DrumType::SOUND) {
109
auto
* soundDrum =
static_cast<
SoundDrum
*
>
(thisDrum);
110
char
modelStackMemory[MODEL_STACK_MAX_SIZE];
111
soundDrum->
applyTemplate
(chosen, getModelStackFromSoundDrum(modelStackMemory, soundDrum));
112
}
113
}
114
}
115
else
{
116
char
modelStackMemory[MODEL_STACK_MAX_SIZE];
117
soundEditor.currentSound->
applyTemplate
(chosen, soundEditor.getCurrentModelStack(modelStackMemory));
118
}
119
120
if
(chosen == SoundTemplate::SAMPLE) {
121
// Changing oscillator types can leave the editor on another oscillator's (or kit row's) range, so point it
122
// at the one the browser will fill
123
soundEditor.currentMultiRangeIndex = 0;
124
soundEditor.currentMultiRange = soundEditor.currentSound->sources[0].ranges.getElement(0);
125
}
126
view.setKnobIndicatorLevels();
127
}
128
};
129
130
}
// namespace deluge::gui::menu_item
Drum
Definition
drum.h:44
Kit
Definition
kit.h:34
SoundDrum
Definition
sound_drum.h:28
Sound::applyTemplate
void applyTemplate(deluge::SoundTemplate soundTemplate, ModelStackWithThreeMainThings *modelStack)
Definition
sound.cpp:3158
StringBuf
Definition
d_stringbuf.h:16
deluge::gui::menu_item::Enumeration::beginSession
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition
enumeration.cpp:7
deluge::gui::menu_item::Selection
Definition
selection.h:26
deluge::gui::menu_item::SoundTemplateSelection
Definition
sound_template.h:46
deluge::gui::menu_item::SoundTemplateSelection::selectButtonPress
MenuItem * selectButtonPress() override
Handle a select button press.
Definition
sound_template.h:76
deluge::gui::menu_item::SoundTemplateSelection::columnButtonActsAsSelect
bool columnButtonActsAsSelect() override
Definition
sound_template.h:74
deluge::gui::menu_item::SoundTemplateSelection::parentMenuClosed
void parentMenuClosed() override
Definition
sound_template.h:97
deluge::gui::menu_item::SoundTemplateSelection::usesAffectEntire
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition
sound_template.h:72
deluge::gui::menu_item::SoundTemplateSelection::beginSession
void beginSession(MenuItem *navigatedBackwardFrom) override
Begin an editing session with this menu item.
Definition
sound_template.h:93
deluge::gui::menu_item::SoundTemplateSelection::readCurrentValue
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition
sound_template.h:63
deluge::gui::menu_item::SoundTemplateSelection::writeCurrentValue
void writeCurrentValue() override
Turning the encoder only picks a template; SELECT applies it.
Definition
sound_template.h:70
deluge::gui::menu_item::Value< int32_t >::readValueAgain
void readValueAgain() override
Definition
value.h:90
deluge::gui
Definition
palette.h:4