Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
patcher.h
1/*
2 * Copyright © 2014-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 "model/note/note_locks.h"
22#include <cstdint>
23#include <span>
24
25struct CableGroup;
26
27class Sound;
29class PatchCableSet;
30struct Destination;
31class ParamManager;
32class PatchCable;
33
34enum Globality {
35 GLOBALITY_LOCAL = 0,
36 GLOBALITY_GLOBAL = 1,
37};
38
39class Patcher {
40public:
41 struct Config {
42 uint8_t firstParam;
43 uint8_t firstNonVolumeParam;
44 uint8_t firstHybridParam;
45 uint8_t firstExpParam;
46 uint8_t endParams;
47 uint8_t globality;
48 };
49
52 Patcher(const Config& config, std::span<int32_t> source_values, std::span<int32_t> param_final_values,
53 const deluge::note_locks::LockSet* locks = nullptr)
54 : config(config), source_values_(source_values), param_final_values_(param_final_values), locks_(locks) {};
55 // Each entry point checks for locks inline, so a voice without them goes straight to the <false> instantiation
56 // (the code as it was before locks): these run per voice per render.
57 void performInitialPatching(Sound& sound, ParamManager& param_manager) {
58 hasLocks() ? performInitialPatchingImpl<true>(sound, param_manager)
59 : performInitialPatchingImpl<false>(sound, param_manager);
60 }
61 void performPatching(uint32_t sources_changed, Sound& sound, ParamManagerForTimeline& param_manager) {
62 hasLocks() ? performPatchingImpl<true>(sources_changed, sound, param_manager)
63 : performPatchingImpl<false>(sources_changed, sound, param_manager);
64 }
65 void recalculateFinalValueForParamWithNoCables(int32_t param, Sound& sound,
66 ParamManagerForTimeline& param_manager) {
67 hasLocks() ? recalculateFinalValueForParamWithNoCablesImpl<true>(param, sound, param_manager)
68 : recalculateFinalValueForParamWithNoCablesImpl<false>(param, sound, param_manager);
69 }
70
71private:
72 [[nodiscard]] bool hasLocks() const { return locks_ != nullptr && !locks_->empty(); }
73 template <bool kLocks>
74 void performInitialPatchingImpl(Sound& sound, ParamManager& param_manager);
75 template <bool kLocks>
76 void performPatchingImpl(uint32_t sources_changed, Sound& sound, ParamManagerForTimeline& param_manager);
77 template <bool kLocks>
78 void recalculateFinalValueForParamWithNoCablesImpl(int32_t param, Sound& sound,
79 ParamManagerForTimeline& param_manager);
80 template <bool kLocks>
81 int32_t presetValue(uint32_t param, Sound& sound, ParamManager& param_manager) const;
82
83 int32_t combineCablesLinearForRangeParam(Destination const* destination, ParamManager& param_manager);
84 template <bool kLocks>
85 int32_t combineCablesLinear(Destination const* destination, uint32_t param, Sound& sound,
86 ParamManager& param_manager);
87 template <bool kLocks>
88 int32_t combineCablesExp(Destination const* destination, uint32_t param, Sound& sound, ParamManager& param_manager);
89 static int32_t cableToLinearParamWithoutRangeAdjustment(int32_t running_total, int32_t source_value,
90 int32_t cable_strength);
91 static int32_t cableToLinearParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
92 int32_t cable_strength);
93 static int32_t cableToExpParamWithoutRangeAdjustment(int32_t running_total, int32_t source_value,
94 int32_t cable_strength);
95 static int32_t cableToExpParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
96 int32_t cable_strength);
97
98 const Config& config;
99 std::span<int32_t> source_values_;
100 std::span<int32_t> param_final_values_;
101 const deluge::note_locks::LockSet* locks_;
102};
Definition param_manager.h:156
Definition param_manager.h:45
Definition patch_cable_set.h:41
Definition patch_cable.h:38
Patcher(const Config &config, std::span< int32_t > source_values, std::span< int32_t > param_final_values, const deluge::note_locks::LockSet *locks=nullptr)
Definition patcher.h:52
Definition sound.h:78
Definition note_locks.h:63
Definition patch_cable_set.h:29
Definition patch_cable_set.h:34
Definition patcher.h:41