Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
param_descriptor.h
1/*
2 * Copyright © 2021-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 "definitions_cxx.hpp"
21#include "util/misc.h"
22#include <cstdint>
23
27class ParamDescriptor {
28public:
29 ParamDescriptor() = default;
30 ParamDescriptor(const ParamDescriptor&) = default;
31 ParamDescriptor(ParamDescriptor&&) = default;
32 ParamDescriptor& operator=(const ParamDescriptor&) = default;
33 ParamDescriptor& operator=(ParamDescriptor&&) = default;
34
36 explicit ParamDescriptor(int32_t data_) : data(data_) {}
37
38 constexpr void setToHaveParamOnly(int32_t p) { data = p | 0xFFFFFF00; }
39
40 constexpr void setToHaveParamAndSource(int32_t p, PatchSource s) {
41 data = p | (util::to_underlying(s) << 8) | 0xFFFF0000;
42 }
43
44 constexpr void setToHaveParamAndTwoSources(int32_t p, PatchSource s, PatchSource sLowestLevel) {
45 data = p | (util::to_underlying(s) << 8) | (util::to_underlying(sLowestLevel) << 16) | 0xFF000000;
46 }
47
48 [[nodiscard]] constexpr bool isSetToParamWithNoSource(int32_t p) const { return (data == (p | 0xFFFFFF00)); }
49
50 [[nodiscard]] constexpr inline bool isSetToParamAndSource(int32_t p, PatchSource s) const {
51 return (data == (p | (util::to_underlying(s) << 8) | 0xFFFF0000));
52 }
53
54 [[nodiscard]] constexpr bool isJustAParam() const { return (data & 0x0000FF00) == 0x0000FF00; }
55
56 [[nodiscard]] constexpr int32_t getJustTheParam() const { return data & 0xFF; }
57
58 constexpr void changeParam(int32_t newParam) { data = (data & 0xFFFFFF00) | newParam; }
59
60 [[nodiscard]] constexpr PatchSource getBottomLevelSource() const { // As in, the one furthest away from the param.
61 if ((data & 0x00FF0000) == 0x00FF0000) {
62 return static_cast<PatchSource>((data >> 8) & 0xFF);
63 }
64
65 return static_cast<PatchSource>((data >> 16) & 0xFF);
66 }
67
68 constexpr void addSource(PatchSource newSource) {
69 uint8_t newSourceUnderlying = util::to_underlying(newSource);
70 if ((data & 0x0000FF00) == 0x0000FF00) {
71 data = (data & 0xFFFF00FF) | (newSourceUnderlying << 8);
72 }
73 else if ((data & 0x00FF0000) == 0x00FF0000) {
74 data = (data & 0xFF00FFFF) | (newSourceUnderlying << 16);
75 }
76 else {
77 data = (data & 0x00FFFFFF) | (newSourceUnderlying << 24);
78 }
79 }
80
81 [[nodiscard]] constexpr ParamDescriptor getDestination() const {
82 ParamDescriptor newParamDescriptor{};
83 if ((data & 0x00FF0000) == 0x00FF0000) {
84 newParamDescriptor.data = data | 0x0000FF00;
85 }
86 else {
87 newParamDescriptor.data = data | 0x00FF0000;
88 }
89 return newParamDescriptor;
90 }
91
92 [[nodiscard]] constexpr bool hasJustOneSource() const {
93 return ((data & 0xFFFF0000) == 0xFFFF0000) && ((data & 0x0000FF00) != 0x0000FF00);
94 }
95
96 [[nodiscard]] constexpr PatchSource getTopLevelSource() const { // As in, the one, nearest the param.
97 return static_cast<PatchSource>((data & 0x0000FF00) >> 8);
98 }
99
100 [[nodiscard]] constexpr PatchSource getSecondSourceFromTop() const {
101 return static_cast<PatchSource>((data & 0x00FF0000) >> 16);
102 }
103
104 [[nodiscard]] constexpr bool hasSecondSource() const { return ((data & 0x00FF0000) != 0x00FF0000); }
105
106 constexpr void setToNull() { data = 0xFFFFFFFF; }
107
108 [[nodiscard]] constexpr bool isNull() const { return (data == 0xFFFFFFFF); }
109
110 uint32_t data{0};
111};
112
113constexpr bool operator==(const ParamDescriptor& lhs, const ParamDescriptor& rhs) {
114 return (lhs.data == rhs.data);
115}
116constexpr bool operator!=(const ParamDescriptor& lhs, const ParamDescriptor& rhs) {
117 return !(lhs == rhs);
118}
Definition param_descriptor.h:27
ParamDescriptor(int32_t data_)
Construct a ParamDescriptor directly from its value.
Definition param_descriptor.h:36