Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
compressor_values.h
1#pragma once
2#include "definitions_cxx.hpp"
3#include "dsp/compressor/rms_feedback.h"
4#include "gui/menu_item/decimal.h"
5#include "gui/menu_item/integer.h"
6#include "gui/ui/sound_editor.h"
7#include "model/drum/drum.h"
8#include "model/instrument/kit.h"
9#include "model/mod_controllable/mod_controllable_audio.h"
10#include "model/song/song.h"
11#include "modulation/params/param_set.h"
12#include "processing/sound/sound.h"
13#include "processing/sound/sound_drum.h"
14#include "util/fixedpoint.h"
15
16namespace deluge::gui::menu_item::audio_compressor {
17
19 using DecimalWithoutScrolling::DecimalWithoutScrolling;
20 void readCurrentValue() final {
21 uint64_t value = getCompressorValue();
22 this->setValue(value >> 24);
23 }
24 void writeCurrentValue() final {
25 auto value = this->getValue();
26 if (value >= kMaxKnobPos) {
27 value = kMaxKnobPos - 1;
28 }
29 q31_t knobPos = lshiftAndSaturate<24>(value);
30
31 // If affect-entire button held, do whole kit
32 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
33
34 Kit* kit = getCurrentKit();
35
36 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
37 if (thisDrum->type == DrumType::SOUND) {
38 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
39
40 setCompressorValue(knobPos, &soundDrum->compressor);
41 }
42 }
43 }
44 // Or, the normal case of just one sound
45 else {
46 setCompressorValue(knobPos, &soundEditor.currentModControllable->compressor);
47 }
48 }
49 virtual uint64_t getCompressorValue() = 0;
50 virtual void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) = 0;
51 [[nodiscard]] int32_t getMaxValue() const final { return kMaxKnobPos; }
52 [[nodiscard]] int32_t getNumDecimalPlaces() const override { return 2; }
53 const char* getUnit() override { return "MS"; }
54};
55
56class Attack final : public CompressorValue {
57public:
58 using CompressorValue::CompressorValue;
59 uint64_t getCompressorValue() final { return (uint64_t)soundEditor.currentModControllable->compressor.getAttack(); }
60 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) final { compressor->setAttack(value); }
61 float getDisplayValue() final { return soundEditor.currentModControllable->compressor.getAttackMS(); }
62};
63class Release final : public CompressorValue {
64public:
65 using CompressorValue::CompressorValue;
66 uint64_t getCompressorValue() final {
67 return (uint64_t)soundEditor.currentModControllable->compressor.getRelease();
68 }
69 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) final { compressor->setRelease(value); }
70 float getDisplayValue() final { return soundEditor.currentModControllable->compressor.getReleaseMS(); }
71 [[nodiscard]] int32_t getNumDecimalPlaces() const final { return 1; }
72};
73class Ratio final : public CompressorValue {
74public:
75 using CompressorValue::CompressorValue;
76 uint64_t getCompressorValue() final { return (uint64_t)soundEditor.currentModControllable->compressor.getRatio(); }
77 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) final { compressor->setRatio(value); }
78 float getDisplayValue() final { return soundEditor.currentModControllable->compressor.getRatioForDisplay(); }
79 const char* getUnit() final { return " : 1"; }
80};
81class SideHPF final : public CompressorValue {
82public:
83 using CompressorValue::CompressorValue;
84 uint64_t getCompressorValue() final {
85 return (uint64_t)soundEditor.currentModControllable->compressor.getSidechain();
86 }
87 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) final { compressor->setSidechain(value); }
88 float getDisplayValue() final { return soundEditor.currentModControllable->compressor.getSidechainForDisplay(); }
89 const char* getUnit() final { return "HZ"; }
90};
91class Blend final : public Integer {
92public:
93 using Integer::Integer;
94 void readCurrentValue() override {
95 auto value = (uint64_t)soundEditor.currentModControllable->compressor.getBlend();
96 this->setValue(value >> 24);
97 }
98 bool usesAffectEntire() override { return true; }
99 void writeCurrentValue() override {
100 auto value = this->getValue();
101
102 q31_t knobPos;
103 if (value < kMaxKnobPos) {
104 knobPos = lshiftAndSaturate<24>(value);
105 }
106 else {
107 knobPos = ONE_Q31;
108 }
109
110 // If affect-entire button held, do whole kit
111 if (currentUIMode == UI_MODE_HOLDING_AFFECT_ENTIRE_IN_SOUND_EDITOR && soundEditor.editingKitRow()) {
112
113 Kit* kit = getCurrentKit();
114
115 for (Drum* thisDrum = kit->firstDrum; thisDrum != nullptr; thisDrum = thisDrum->next) {
116 if (thisDrum->type == DrumType::SOUND) {
117 auto* soundDrum = static_cast<SoundDrum*>(thisDrum);
118
119 soundDrum->compressor.setBlend(knobPos);
120 }
121 }
122 }
123 // Or, the normal case of just one sound
124 else {
125 soundEditor.currentModControllable->compressor.setBlend(knobPos);
126 }
127 }
128 int32_t getDisplayValue() override { return soundEditor.currentModControllable->compressor.getBlendForDisplay(); }
129 const char* getUnit() override { return "%"; }
130 [[nodiscard]] int32_t getMaxValue() const override { return kMaxKnobPos; }
131};
132} // namespace deluge::gui::menu_item::audio_compressor
Definition drum.h:44
Definition kit.h:34
Definition rms_feedback.h:26
constexpr int32_t setAttack(q31_t attack)
Definition rms_feedback.h:78
constexpr int32_t setSidechain(q31_t f)
Definition rms_feedback.h:138
constexpr int32_t getBlendForDisplay()
returns blend as an integer percentage
Definition rms_feedback.h:152
constexpr int32_t setRatio(q31_t rat)
Definition rms_feedback.h:122
constexpr int32_t setRelease(q31_t release)
Definition rms_feedback.h:95
constexpr int32_t setBlend(q31_t blend)
Definition rms_feedback.h:156
Definition sound_drum.h:28
Definition integer.h:24
Definition compressor_values.h:56
Definition compressor_values.h:91
bool usesAffectEntire() override
Claim support for Kit AFFECT_ENTIRE editing.
Definition compressor_values.h:98
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition compressor_values.h:94
void readCurrentValue() final
Like readValueAgain, but does not redraw.
Definition compressor_values.h:20
Definition compressor_values.h:73
Definition compressor_values.h:63
Definition compressor_values.h:81