Deluge Firmware 1.3.0
Build date: 2025.07.11
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() override {
60 return (uint64_t)soundEditor.currentModControllable->compressor.getAttack();
61 }
62 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) override { compressor->setAttack(value); }
63 float getDisplayValue() override { return soundEditor.currentModControllable->compressor.getAttackMS(); }
64};
65class Release final : public CompressorValue {
66public:
67 using CompressorValue::CompressorValue;
68 uint64_t getCompressorValue() final {
69 return (uint64_t)soundEditor.currentModControllable->compressor.getRelease();
70 }
71 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) final { compressor->setRelease(value); }
72 float getDisplayValue() override { return soundEditor.currentModControllable->compressor.getReleaseMS(); }
73 [[nodiscard]] int32_t getNumDecimalPlaces() const { return 1; }
74};
75class Ratio final : public CompressorValue {
76public:
77 using CompressorValue::CompressorValue;
78 uint64_t getCompressorValue() override {
79 return (uint64_t)soundEditor.currentModControllable->compressor.getRatio();
80 }
81 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) override { compressor->setRatio(value); }
82 float getDisplayValue() override { return soundEditor.currentModControllable->compressor.getRatioForDisplay(); }
83 const char* getUnit() override { return " : 1"; }
84};
85class SideHPF final : public CompressorValue {
86public:
87 using CompressorValue::CompressorValue;
88 uint64_t getCompressorValue() override {
89 return (uint64_t)soundEditor.currentModControllable->compressor.getSidechain();
90 }
91 void setCompressorValue(q31_t value, RMSFeedbackCompressor* compressor) override {
92 compressor->setSidechain(value);
93 }
94 float getDisplayValue() override { return soundEditor.currentModControllable->compressor.getSidechainForDisplay(); }
95 const char* getUnit() override { return "HZ"; }
96};
97class Blend final : public CompressorValue {
98public:
99 using CompressorValue::CompressorValue;
100 uint64_t getCompressorValue() override {
101 return (uint64_t)soundEditor.currentModControllable->compressor.getBlend().raw();
102 }
103 void setCompressorValue(q31_t, RMSFeedbackCompressor* compressor) override {
104 auto value = this->getValue();
105
106 FixedPoint<31> knobPos = 1.f;
107 if (value < kMaxKnobPos) {
108 knobPos.raw() = lshiftAndSaturate<24>(value);
109 }
110 compressor->setBlend(knobPos);
111 }
112
113 float getDisplayValue() override { return soundEditor.currentModControllable->compressor.getBlendForDisplay(); }
114 const char* getUnit() override { return " %"; }
115 [[nodiscard]] int32_t getNumDecimalPlaces() const override { return 0; }
116 [[nodiscard]] int32_t getColumnSpan() const override { return 1; }
117};
118} // namespace deluge::gui::menu_item::audio_compressor
Definition drum.h:44
Fixed point number with a configurable number of fractional bits.
Definition fixedpoint.h:47
constexpr BaseType raw() const noexcept
Get the internal value.
Definition fixedpoint.h:232
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 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(FixedPoint< 31 > blend)
Definition rms_feedback.h:157
Definition sound_drum.h:28
Definition compressor_values.h:56
Definition compressor_values.h:97
int32_t getColumnSpan() const override
Get the number of occupied virtual columns in the horizontal menu.
Definition compressor_values.h:116
void readCurrentValue() final
Like readValueAgain, but does not redraw.
Definition compressor_values.h:20
Definition compressor_values.h:75
Definition compressor_values.h:65
Definition compressor_values.h:85