Deluge Firmware 1.3.0
Build date: 2025.04.16
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/clip/instrument_clip.h"
22#include "model/instrument/kit.h"
23#include "model/model_stack.h"
24#include "model/song/song.h"
25#include "processing/sound/sound.h"
26#include "processing/sound/sound_drum.h"
27#include "storage/multi_range/multisample_range.h"
28
29// NOTE: This is actually the Oscillator transpose!
30
31namespace deluge::gui::menu_item::sample {
32class Transpose final : public source::Transpose, public FormattedTitle {
33public:
34 Transpose(l10n::String name, l10n::String title_format_str, int32_t newP)
35 : source::Transpose(name, newP), FormattedTitle(title_format_str) {}
36
37 [[nodiscard]] std::string_view getTitle() const override { return FormattedTitle::title(); }
38
39 void readCurrentValue() override {
40 int32_t transpose = 0;
41 int32_t cents = 0;
42 if ((soundEditor.currentMultiRange != nullptr) && soundEditor.currentSound->getSynthMode() != SynthMode::FM
43 && soundEditor.currentSource->oscType == OscType::SAMPLE) {
44 transpose = (static_cast<MultisampleRange*>(soundEditor.currentMultiRange))->sampleHolder.transpose;
45 cents = (static_cast<MultisampleRange*>(soundEditor.currentMultiRange))->sampleHolder.cents;
46 }
47 else {
48 transpose = soundEditor.currentSource->transpose;
49 cents = soundEditor.currentSource->cents;
50 }
51 this->setValue(computeCurrentValueForTranspose(transpose, cents));
52 }
53 bool usesAffectEntire() override { return true; }
54 void writeCurrentValue() override {
55 int32_t transpose, cents;
56 computeFinalValuesForTranspose(this->getValue(), &transpose, &cents);
57
58 // If affect-entire button held, do whole kit
59 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKit()) {
60
61 Kit* kit = getCurrentKit();
62
63 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
64 if (thisDrum->type == DrumType::SOUND) {
65 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
66
67 if (soundDrum->sources[soundEditor.currentSourceIndex].ranges.getNumElements()
68 && soundDrum->getSynthMode() != SynthMode::FM
69 && soundDrum->sources[soundEditor.currentSourceIndex].oscType == OscType::SAMPLE) {
70 MultisampleRange* multisampleRange = static_cast<MultisampleRange*>(
71 soundDrum->sources[soundEditor.currentSourceIndex].ranges.getElement(0));
72 multisampleRange->sampleHolder.transpose = transpose;
73 multisampleRange->sampleHolder.setCents(cents);
74 }
75 else {
76 soundDrum->sources[soundEditor.currentSourceIndex].transpose = transpose;
77 soundDrum->sources[soundEditor.currentSourceIndex].setCents(cents);
78 }
79
80 char modelStackMemoryForSoundDrum[MODEL_STACK_MAX_SIZE];
81 ModelStackWithSoundFlags* modelStackForSoundDrum =
82 getModelStackFromSoundDrum(modelStackMemoryForSoundDrum, soundDrum)->addSoundFlags();
83
84 soundDrum->recalculateAllVoicePhaseIncrements(modelStackForSoundDrum);
85 }
86 }
87 }
88 // Or, the normal case of just one sound
89 else {
90 if ((soundEditor.currentMultiRange != nullptr) && soundEditor.currentSound->getSynthMode() != SynthMode::FM
91 && soundEditor.currentSource->oscType == OscType::SAMPLE) {
92 (static_cast<MultisampleRange*>(soundEditor.currentMultiRange))->sampleHolder.transpose = transpose;
93 (static_cast<MultisampleRange*>(soundEditor.currentMultiRange))->sampleHolder.setCents(cents);
94 }
95 else {
96 soundEditor.currentSource->transpose = transpose;
97 soundEditor.currentSource->setCents(cents);
98 }
99
100 char modelStackMemory[MODEL_STACK_MAX_SIZE];
101 ModelStackWithSoundFlags* modelStack = soundEditor.getCurrentModelStack(modelStackMemory)->addSoundFlags();
102
103 soundEditor.currentSound->recalculateAllVoicePhaseIncrements(modelStack);
104 }
105 }
106
107 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t whichThing,
108 ::MultiRange** currentRange) override {
109
110 if (!isRelevant(modControllable, whichThing)) {
111 return MenuPermission::NO;
112 }
113
114 Sound* sound = static_cast<Sound*>(modControllable);
115 Source* source = &sound->sources[whichThing];
116
117 if (sound->getSynthMode() == SynthMode::FM
118 || (source->oscType != OscType::SAMPLE && source->oscType != OscType::WAVETABLE)) {
119 return MenuPermission::YES;
120 }
121
122 return soundEditor.checkPermissionToBeginSessionForRangeSpecificParam(sound, whichThing, currentRange);
123 }
124
125 bool isRangeDependent() override { return true; }
126};
127} // namespace deluge::gui::menu_item::sample
Definition drum.h:44
Definition kit.h:34
virtual bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing)
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition menu_item.h:254
Definition model_stack.h:287
Definition multisample_range.h:27
Definition sound_drum.h:28
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition transpose.h:53
bool isRangeDependent() override
Returns true if this parameter is only relevant to some note ranges.
Definition transpose.h:125
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition transpose.h:39
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:37