Deluge Firmware 1.3.0
Build date: 2026.07.07
Loading...
Searching...
No Matches
transpose.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#include "gui/menu_item/formatted_title.h"
19#include "gui/menu_item/source/transpose.h"
20#include "gui/ui/sound_editor.h"
21#include "model/instrument/kit.h"
22#include "model/model_stack.h"
23#include "model/song/song.h"
24#include "processing/sound/sound.h"
25#include "processing/sound/sound_drum.h"
26#include "storage/multi_range/multisample_range.h"
27
28// NOTE: This is actually the Oscillator transpose!
29
30namespace deluge::gui::menu_item::sample {
31class Transpose final : public source::Transpose, public FormattedTitle {
32public:
33 Transpose(l10n::String name, l10n::String title_format_str, int32_t newP, uint8_t source_id)
34 : source::Transpose(name, newP, source_id), FormattedTitle(title_format_str, source_id + 1) {}
35
36 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
37
38 void readCurrentValue() override {
39 int32_t transpose = 0;
40 int32_t cents = 0;
41
42 Source& source = soundEditor.currentSound->sources[source_id_];
43
44 if (source.ranges.getNumElements() && soundEditor.currentSound->getSynthMode() != SynthMode::FM
45 && source.oscType == OscType::SAMPLE) {
46 const auto* multi_sample_range =
47 soundEditor.currentSourceIndex == source_id_ && soundEditor.currentMultiRange != nullptr
48 ? static_cast<MultisampleRange*>(soundEditor.currentMultiRange)
49 : static_cast<MultisampleRange*>(source.ranges.getElement(0));
50 transpose = multi_sample_range->sampleHolder.transpose;
51 cents = multi_sample_range->sampleHolder.cents;
52 }
53 else {
54 transpose = source.transpose;
55 cents = source.cents;
56 }
57 this->setValue(computeCurrentValueForTranspose(transpose, cents));
58 }
59
60 bool usesAffectEntire() override { return true; }
61
62 void writeCurrentValue() override {
63 int32_t transpose, cents;
64 computeFinalValuesForTranspose(this->getValue(), &transpose, &cents);
65
66 // If affect-entire button held, do whole kit
67 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKit()) {
68
69 Kit* kit = getCurrentKit();
70
71 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
72 if (thisDrum->type == DrumType::SOUND) {
73 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
74 Source& source = soundDrum->sources[source_id_];
75
76 if (source.ranges.getNumElements() && soundDrum->getSynthMode() != SynthMode::FM
77 && source.oscType == OscType::SAMPLE) {
78 auto* multi_sample_range = static_cast<MultisampleRange*>(source.ranges.getElement(0));
79 multi_sample_range->sampleHolder.transpose = transpose;
80 multi_sample_range->sampleHolder.setCents(cents);
81 }
82 else {
83 source.transpose = transpose;
84 source.setCents(cents);
85 }
86
87 char modelStackMemoryForSoundDrum[MODEL_STACK_MAX_SIZE];
88 ModelStackWithSoundFlags* modelStackForSoundDrum =
89 getModelStackFromSoundDrum(modelStackMemoryForSoundDrum, soundDrum)->addSoundFlags();
90
91 soundDrum->recalculateAllVoicePhaseIncrements(modelStackForSoundDrum);
92 }
93 }
94 }
95 // Or, the normal case of just one sound
96 else {
97 Source& source = soundEditor.currentSound->sources[source_id_];
98
99 if (source.ranges.getNumElements() && soundEditor.currentSound->getSynthMode() != SynthMode::FM
100 && source.oscType == OscType::SAMPLE) {
101 auto* multi_sample_range =
102 soundEditor.currentSourceIndex == source_id_ && soundEditor.currentMultiRange != nullptr
103 ? static_cast<MultisampleRange*>(soundEditor.currentMultiRange)
104 : static_cast<MultisampleRange*>(source.ranges.getElement(0));
105 multi_sample_range->sampleHolder.transpose = transpose;
106 multi_sample_range->sampleHolder.setCents(cents);
107 }
108 else {
109 source.transpose = transpose;
110 source.setCents(cents);
111 }
112
113 char modelStackMemory[MODEL_STACK_MAX_SIZE];
114 ModelStackWithSoundFlags* modelStack = soundEditor.getCurrentModelStack(modelStackMemory)->addSoundFlags();
115
116 soundEditor.currentSound->recalculateAllVoicePhaseIncrements(modelStack);
117 }
118 }
119
120 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t,
121 ::MultiRange** currentRange) override {
122 if (!isRelevant(modControllable, source_id_)) {
123 return MenuPermission::NO;
124 }
125
126 const auto sound = static_cast<Sound*>(modControllable);
127 const Source& source = sound->sources[source_id_];
128
129 if (sound->getSynthMode() == SynthMode::FM
130 || (source.oscType != OscType::SAMPLE && source.oscType != OscType::WAVETABLE)) {
131 return MenuPermission::YES;
132 }
133
134 return soundEditor.checkPermissionToBeginSessionForRangeSpecificParam(sound, source_id_, currentRange);
135 }
136
137 bool isRangeDependent() override { return true; }
138
139 bool isRelevant(ModControllableAudio* modControllable, int32_t) override {
140 const auto sound = static_cast<Sound*>(modControllable);
141 if (Source& source = sound->sources[source_id_];
142 source.oscType == OscType::SAMPLE || source.oscType == OscType::WAVETABLE) {
143 return source.hasAtLeastOneAudioFileLoaded();
144 }
145 return true;
146 }
147
148 void getNotificationValue(StringBuf& valueBuf) override {
150
151 Source& source = soundEditor.currentSound->sources[source_id_];
152 const int32_t rangeIndex = soundEditor.currentMultiRangeIndex;
153 const int32_t numRanges = source.ranges.getNumElements();
154
155 if (soundEditor.currentSourceIndex != source_id_ || soundEditor.currentMultiRange == nullptr || numRanges <= 1
156 || rangeIndex < 0 || rangeIndex >= numRanges || source.oscType != OscType::SAMPLE) {
157 return;
158 }
159
160 valueBuf.append(" (");
161
162 if (rangeIndex == 0) {
163 valueBuf.append(l10n::get(l10n::String::STRING_FOR_BOTTOM));
164 }
165 else {
166 char noteName[8];
167 noteCodeToString(source.ranges.getElement(rangeIndex - 1)->topNote + 1, noteName);
168 valueBuf.append(noteName);
169 }
170
171 valueBuf.append("-");
172
173 if (rangeIndex == numRanges - 1) {
174 valueBuf.append("top");
175 }
176 else {
177 char noteName[8];
178 noteCodeToString(source.ranges.getElement(rangeIndex)->topNote, noteName);
179 valueBuf.append(noteName);
180 }
181
182 valueBuf.append(")");
183 }
184};
185} // namespace deluge::gui::menu_item::sample
Definition drum.h:44
Definition kit.h:34
Definition mod_controllable_audio.h:47
Definition model_stack.h:287
Definition multisample_range.h:27
Definition sound_drum.h:28
Definition sound.h:71
Definition source.h:31
Definition d_stringbuf.h:16
void getNotificationValue(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition decimal.h:31
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition transpose.h:60
bool isRangeDependent() override
Returns true if this parameter is only relevant to some note ranges.
Definition transpose.h:137
bool isRelevant(ModControllableAudio *modControllable, int32_t) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition transpose.h:139
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition transpose.h:38
std::string_view getTitle() const override
Get the title to be used when rendering on OLED, both as a deluge::gui::menu_item::Submenu and when d...
Definition transpose.h:36
void getNotificationValue(StringBuf &valueBuf) override
Get the parameter value string to show in the popup.
Definition transpose.h:148