Deluge Firmware 1.3.0
Build date: 2025.06.24
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
25class Sound;
27class InstrumentClip;
28
29enum class Polarity : uint8_t {
30 UNIPOLAR = 0,
31 BIPOLAR = 1,
32};
33Polarity stringToPolarity(std::string_view string);
34std::string_view polarityToString(Polarity polarity);
35
36class PatchCable {
37public:
38 PatchCable() = default;
39 void setup(PatchSource newFrom, uint8_t newTo, int32_t newAmount);
40 bool isActive();
41 void initAmount(int32_t value);
42 void makeUnusable();
45 int32_t toPolarity(int32_t value) {
46 // aftertouch is stored unipolar, all others are stored bipolar
47 if (from == PatchSource::AFTERTOUCH) {
48 if (polarity == Polarity::UNIPOLAR) {
49 return value;
50 }
51 return (value - (std::numeric_limits<int32_t>::max() / 2)) * 2; // Convert from unipolar to bipolar
52 }
53 // Because unipolar mod wheel and bipolar MPE y share the same mod source we can't convert :(
54 if (from == PatchSource::Y || polarity == Polarity::BIPOLAR) {
55 return value;
56 }
57 return (value / 2) + (std::numeric_limits<int32_t>::max() / 2); // Convert from bipolar to unipolar
58 }
59 [[gnu::always_inline]] [[nodiscard]] int32_t applyRangeAdjustment(int32_t value) const {
60 int32_t small = multiply_32x32_rshift32(value, *this->rangeAdjustmentPointer);
61 return signed_saturate<32 - 5>(small) << 3; // Not sure if these limits are as wide as they could be...
62 }
63
64 PatchSource from{PatchSource::NONE};
65 Polarity polarity{Polarity::BIPOLAR};
66 ParamDescriptor destinationParamDescriptor;
67 AutoParam param; // Amounts have to be within +1073741824 and -1073741824
68 int32_t const* rangeAdjustmentPointer = nullptr;
69};
Definition instrument_clip.h:48
Definition param_manager.h:174
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:45
Definition sound.h:71