Deluge Firmware
1.3.0
Build date: 2026.08.29
Toggle main menu visibility
Loading...
Searching...
No Matches
patch_cable.h
1
/*
2
* Copyright © 2016-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
18
#pragma once
19
20
#include "modulation/automation/auto_param.h"
21
#include "modulation/params/param_descriptor.h"
22
#include "util/fixedpoint.h"
23
#include <cstdint>
24
25
class
Sound
;
26
class
ParamManagerForTimeline
;
27
class
InstrumentClip
;
28
29
enum class
Polarity : uint8_t {
30
UNIPOLAR = 0,
31
BIPOLAR = 1,
32
};
33
34
Polarity stringToPolarity(std::string_view
string
);
35
std::string_view polarityToString(Polarity polarity);
36
std::string_view polarityToStringShort(
const
Polarity polarity);
37
38
class
PatchCable {
39
public
:
40
PatchCable() =
default
;
41
void
setDefaultPolarity();
42
static
bool
hasPolarity(PatchSource source);
43
static
Polarity getDefaultPolarity(PatchSource source);
44
void
setup(PatchSource newFrom, uint8_t newTo, int32_t newAmount);
45
bool
isActive();
46
void
initAmount(int32_t value);
47
void
makeUnusable();
50
int32_t
toPolarity
(int32_t value) {
51
// aftertouch is stored unipolar, all others are stored bipolar
52
if
(from == PatchSource::AFTERTOUCH) {
53
if
(polarity == Polarity::UNIPOLAR) {
54
return
value;
55
}
56
return
(value - (std::numeric_limits<int32_t>::max() / 2)) * 2;
// Convert from unipolar to bipolar
57
}
58
// Because unipolar mod wheel and bipolar MPE y share the same mod source we can't convert :(
59
if
(from == PatchSource::Y || polarity == Polarity::BIPOLAR) {
60
return
value;
61
}
62
return
(value / 2) + (std::numeric_limits<int32_t>::max() / 2);
// Convert from bipolar to unipolar
63
}
64
[[gnu::always_inline]] [[nodiscard]] int32_t applyRangeAdjustment(int32_t value)
const
{
65
int32_t small = multiply_32x32_rshift32(value, *this->rangeAdjustmentPointer);
66
return
signed_saturate<32 - 5>(small) << 3;
// Not sure if these limits are as wide as they could be...
67
}
68
69
PatchSource from{PatchSource::NONE};
70
Polarity polarity{Polarity::BIPOLAR};
71
ParamDescriptor destinationParamDescriptor;
72
AutoParam param;
// Amounts have to be within +1073741824 and -1073741824
73
int32_t
const
* rangeAdjustmentPointer =
nullptr
;
74
};
InstrumentClip
Definition
instrument_clip.h:48
ParamManagerForTimeline
Definition
param_manager.h:174
PatchCable::toPolarity
int32_t toPolarity(int32_t value)
Converts a patch cable source to the correct polarity. The source is required because some sources ar...
Definition
patch_cable.h:50
Sound
Definition
sound.h:71