Deluge Firmware 1.3.0
Build date: 2025.09.14
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* multiRange = static_cast<MultisampleRange*>(source.ranges.getElement(0));
47 transpose = multiRange->sampleHolder.transpose;
48 cents = multiRange->sampleHolder.cents;
49 }
50 else {
51 transpose = source.transpose;
52 cents = source.cents;
53 }
54 this->setValue(computeCurrentValueForTranspose(transpose, cents));
55 }
56
57 bool usesAffectEntire() override { return true; }
58
59 void writeCurrentValue() override {
60 int32_t transpose, cents;
61 computeFinalValuesForTranspose(this->getValue(), &transpose, &cents);
62
63 // If affect-entire button held, do whole kit
64 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKit()) {
65
66 Kit* kit = getCurrentKit();
67
68 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
69 if (thisDrum->type == DrumType::SOUND) {
70 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
71 Source& source = soundDrum->sources[source_id_];
72
73 if (source.ranges.getNumElements() && soundDrum->getSynthMode() != SynthMode::FM
74 && source.oscType == OscType::SAMPLE) {
75 auto* multisampleRange = static_cast<MultisampleRange*>(source.ranges.getElement(0));
76 multisampleRange->sampleHolder.transpose = transpose;
77 multisampleRange->sampleHolder.setCents(cents);
78 }
79 else {
80 source.transpose = transpose;
81 source.setCents(cents);
82 }
83
84 char modelStackMemoryForSoundDrum[MODEL_STACK_MAX_SIZE];
85 ModelStackWithSoundFlags* modelStackForSoundDrum =
86 getModelStackFromSoundDrum(modelStackMemoryForSoundDrum, soundDrum)->addSoundFlags();
87
88 soundDrum->recalculateAllVoicePhaseIncrements(modelStackForSoundDrum);
89 }
90 }
91 }
92 // Or, the normal case of just one sound
93 else {
94 Source& source = soundEditor.currentSound->sources[source_id_];
95
96 if (source.ranges.getNumElements() && soundEditor.currentSound->getSynthMode() != SynthMode::FM
97 && source.oscType == OscType::SAMPLE) {
98 auto* multisampleRange = static_cast<MultisampleRange*>(source.ranges.getElement(0));
99 multisampleRange->sampleHolder.transpose = transpose;
100 multisampleRange->sampleHolder.setCents(cents);
101 }
102 else {
103 source.transpose = transpose;
104 source.setCents(cents);
105 }
106
107 char modelStackMemory[MODEL_STACK_MAX_SIZE];
108 ModelStackWithSoundFlags* modelStack = soundEditor.getCurrentModelStack(modelStackMemory)->addSoundFlags();
109
110 soundEditor.currentSound->recalculateAllVoicePhaseIncrements(modelStack);
111 }
112 }
113
114 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t,
115 ::MultiRange** currentRange) override {
116 if (!isRelevant(modControllable, source_id_)) {
117 return MenuPermission::NO;
118 }
119
120 const auto sound = static_cast<Sound*>(modControllable);
121 const Source& source = sound->sources[source_id_];
122
123 if (sound->getSynthMode() == SynthMode::FM
124 || (source.oscType != OscType::SAMPLE && source.oscType != OscType::WAVETABLE)) {
125 return MenuPermission::YES;
126 }
127
128 return soundEditor.checkPermissionToBeginSessionForRangeSpecificParam(sound, source_id_, currentRange);
129 }
130
131 bool isRangeDependent() override { return true; }
132
133 bool isRelevant(ModControllableAudio* modControllable, int32_t) override {
134 const auto sound = static_cast<Sound*>(modControllable);
135 if (Source& source = sound->sources[source_id_];
136 source.oscType == OscType::SAMPLE || source.oscType == OscType::WAVETABLE) {
137 return source.hasAtLeastOneAudioFileLoaded();
138 }
139 return true;
140 }
141};
142} // 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
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition transpose.h:57
bool isRangeDependent() override
Returns true if this parameter is only relevant to some note ranges.
Definition transpose.h:131
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:133
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