Skip to content

Commit

Permalink
Use etl::vector and sort for patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
stellar-aria committed Feb 11, 2025
1 parent 00e86e9 commit e4ce3c8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
61 changes: 33 additions & 28 deletions src/deluge/modulation/patch/patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "modulation/patch/patch_cable.h"
#include "modulation/patch/patch_cable_set.h"
#include "processing/sound/sound.h"
#include <etl/map.h>
#include <etl/vector.h>
#include <utility>

namespace params = deluge::modulation::params;
Expand Down Expand Up @@ -85,7 +85,7 @@ void Patcher::performPatching(uint32_t sourcesChanged, Sound& sound, ParamManage
}

// param_id, cable_combo
etl::map<int32_t, int32_t, params::kNumParams> cable_combos;
etl::vector<std::pair<int32_t, int32_t>, params::kNumParams> cable_combos;

// Now normal, actual params/destinations
for (; destination->destinationParamDescriptor.data < (config.firstHybridParam | 0xFFFFFF00); destination++) {

Check failure on line 91 in src/deluge/modulation/patch/patcher.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

0xFFFFFF00 is a magic number; consider replacing it with a named constant [readability-magic-numbers,-warnings-as-errors]
Expand All @@ -94,44 +94,49 @@ void Patcher::performPatching(uint32_t sourcesChanged, Sound& sound, ParamManage
}

int32_t param = destination->destinationParamDescriptor.getJustTheParam();
cable_combos[param] = combineCablesLinear(destination, param, sound, param_manager);
cable_combos.push_back({param, combineCablesLinear(destination, param, sound, param_manager)});
}

for (; destination->sources != 0u; destination++) {
if ((destination->sources & sourcesChanged) == 0u) {
continue;
}

int32_t p = destination->destinationParamDescriptor.getJustTheParam();
cable_combos[p] = combineCablesExp(destination, p, sound, param_manager);
int32_t param = destination->destinationParamDescriptor.getJustTheParam();
cable_combos.push_back({param, combineCablesExp(destination, param, sound, param_manager)});
}

// Now, turn those cableCombinations into paramFinalValues. Splitting these up like this caused a massive speed-up
// on all presets tested, somewhat surprisingly!
for (auto& [param, cable_combo] : cable_combos) {
// Volume params
if (param < config.firstNonVolumeParam) {
param_final_values_[param - config.firstParam] =
getFinalParameterValueVolume(paramNeutralValues[param], cable_combo);
}
// sort by param_id
std::ranges::sort(cable_combos, std::less(), &std::pair<int32_t, int32_t>::first);

// Linear params
else if (param < config.firstHybridParam) {
param_final_values_[param - config.firstParam] =
getFinalParameterValueLinear(paramNeutralValues[param], cable_combo);
}
auto* iterator = cable_combos.begin();

// Hybrid params
else if (param < config.firstExpParam) {
param_final_values_[param - config.firstParam] =
getFinalParameterValueHybrid(paramNeutralValues[param], cable_combo);
}
// Now, turn those cableCombinations into paramFinalValues.
// Volume params
for (; iterator->first < config.firstNonVolumeParam; iterator++) {
auto [param, combo] = *iterator;
param_final_values_[param - config.firstParam] = getFinalParameterValueVolume(paramNeutralValues[param], combo);
}

// Exp params
else {
param_final_values_[param - config.firstParam] =
getFinalParameterValueExpWithDumbEnvelopeHack(paramNeutralValues[param], cable_combo, param);
}
// Linear params
for (; iterator->first < config.firstHybridParam; iterator++) {
auto [param, cable_combo] = *iterator;
param_final_values_[param - config.firstParam] =
getFinalParameterValueLinear(paramNeutralValues[param], cable_combo);
}

// Hybrid params
for (; iterator->first < config.firstExpParam; iterator++) {
auto [param, cable_combo] = *iterator;
param_final_values_[param - config.firstParam] =
getFinalParameterValueHybrid(paramNeutralValues[param], cable_combo);
}

// Exp params
for (; iterator < cable_combos.end(); iterator++) {
auto [param, cable_combo] = *iterator;
param_final_values_[param - config.firstParam] =
getFinalParameterValueExpWithDumbEnvelopeHack(paramNeutralValues[param], cable_combo, param);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/deluge/modulation/patch/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class Patcher {
int32_t combineCablesExp(Destination const* destination, uint32_t param, Sound& sound, ParamManager& param_manager);
static int32_t cableToLinearParamWithoutRangeAdjustment(int32_t running_total, int32_t source_value,
int32_t cable_strength);
int32_t cableToLinearParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
int32_t cable_strength);
static int32_t cableToLinearParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
int32_t cable_strength);
static int32_t cableToExpParamWithoutRangeAdjustment(int32_t running_total, int32_t source_value,
int32_t cable_strength);
int32_t cableToExpParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
int32_t cable_strength);
static int32_t cableToExpParam(int32_t running_total, const PatchCable& cable, int32_t source_value,
int32_t cable_strength);

const Config& config;
std::span<int32_t> source_values_;
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/util/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ int32_t getFinalParameterValueVolume(int32_t paramNeutralValue, int32_t patchedV

int32_t getFinalParameterValueLinear(int32_t paramNeutralValue, int32_t patchedValue) {

// patchedValue's range is ideally +- 536870912, but may get up to 1610612736 due to multiple patch cables having
// been multiplied
// patchedValue's range is ideally +- 536870912 ('1'), but may get up to 1610612736 ('3') due to multiple patch
// cables having been multiplied

// No need for max/min here - it's already been taken care of in patchAllCablesToParameter(),
// ... or if we got here from patchSourceToAllExclusiveCables(), there's no way it could have been too big
Expand Down

0 comments on commit e4ce3c8

Please sign in to comment.