Deluge Firmware 1.3.0
Build date: 2025.07.07
Loading...
Searching...
No Matches
detune.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/integer.h"
19#include "gui/ui/sound_editor.h"
20#include "model/instrument/kit.h"
21#include "model/model_stack.h"
22#include "model/song/song.h"
23#include "processing/sound/sound.h"
24#include "processing/sound/sound_drum.h"
25
26namespace deluge::gui::menu_item::unison {
27class Detune final : public Integer {
28public:
29 using Integer::Integer;
30
31 void readCurrentValue() override { this->setValue(soundEditor.currentSound->unisonDetune); }
32 bool usesAffectEntire() override { return true; }
33 void writeCurrentValue() override {
34 int32_t current_value = this->getValue();
35
36 // If affect-entire button held, do whole kit
37 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
38
39 Kit* kit = getCurrentKit();
40
41 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
42 if (thisDrum->type == DrumType::SOUND) {
43 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
44
45 char modelStackMemoryForSoundDrum[MODEL_STACK_MAX_SIZE];
46 ModelStackWithSoundFlags* modelStackForSoundDrum =
47 getModelStackFromSoundDrum(modelStackMemoryForSoundDrum, soundDrum)->addSoundFlags();
48
49 soundDrum->setUnisonDetune(current_value, modelStackForSoundDrum);
50 }
51 }
52 }
53 // Or, the normal case of just one sound
54 else {
55 char modelStackMemory[MODEL_STACK_MAX_SIZE];
56 ModelStackWithSoundFlags* modelStack = soundEditor.getCurrentModelStack(modelStackMemory)->addSoundFlags();
57
58 soundEditor.currentSound->setUnisonDetune(current_value, modelStack);
59 }
60 }
61 [[nodiscard]] int32_t getMaxValue() const override { return kMaxUnisonDetune; }
62
63 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
64 oled_canvas::Canvas& image = OLED::main;
65
66 const float t = getValue() / 50.0f;
67
68 for (int i = 0; i < 3; ++i) {
69 constexpr int32_t lineSpacing = 5;
70 constexpr int32_t maxYOffset = 4;
71
72 const int32_t y = startY + 3 + i * lineSpacing;
73 const int32_t x0 = startX + 7;
74 const int32_t x1 = startX + width - 7;
75
76 if (i == 0) {
77 // Top line
78 const int32_t offset = static_cast<int32_t>(maxYOffset * t * 0.30f);
79 image.drawLine(x0, y, x1, y + offset);
80 }
81 else if (i == 1) {
82 // Middle line
83 const int32_t offset = static_cast<int32_t>(maxYOffset * t * 0.5f);
84 image.drawLine(x0, y - offset, x1, y + offset);
85
86 if (t > 0.7 && t < 1) {
87 image.clearPixel(x0, y - offset);
88 image.clearPixel(x1, y + offset);
89 image.drawPixel(x0, y - offset - 1);
90 image.drawPixel(x1, y + offset + 1);
91 }
92 }
93 else if (i == 2) {
94 // Bottom line
95 int32_t offset = y - static_cast<int32_t>(maxYOffset * t * 0.8f);
96 if (t > 0 && offset == y) {
97 offset -= 1;
98 }
99
100 image.drawLine(x0, offset, x1 - 8, y);
101 image.drawHorizontalLine(y, x1 - 8, x1);
102 }
103 }
104 }
105};
106} // namespace deluge::gui::menu_item::unison
Definition drum.h:44
Definition kit.h:34
Definition model_stack.h:287
Definition sound_drum.h:28
Definition integer.h:24
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition detune.h:31
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition detune.h:32