Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and modernize patcher #3366

Open
wants to merge 15 commits into
base: community
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/deluge/model/instrument/kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ void Kit::setupWithoutActiveClip(ModelStack* modelStack) {
FREEZE_WITH_ERROR("E174");
}

soundDrum->patcher.performInitialPatching(soundDrum, (ParamManagerForTimeline*)paramManager);
soundDrum->patcher.performInitialPatching(*soundDrum, *(ParamManagerForTimeline*)paramManager);
}
}

Expand Down Expand Up @@ -926,7 +926,7 @@ bool Kit::setActiveClip(ModelStackWithTimelineCounter* modelStack, PgmChangeSend

SoundDrum* soundDrum = (SoundDrum*)thisNoteRow->drum;

soundDrum->patcher.performInitialPatching(soundDrum, &thisNoteRow->paramManager);
soundDrum->patcher.performInitialPatching(*soundDrum, thisNoteRow->paramManager);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/model/note/note_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,7 @@ void NoteRow::setDrum(Drum* newDrum, Kit* kit, ModelStackWithNoteRow* modelStack
}

if (clip->isActiveOnOutput()) {
soundDrum->patcher.performInitialPatching(soundDrum, &paramManager);
soundDrum->patcher.performInitialPatching(*soundDrum, paramManager);
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/deluge/model/voice/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ PLACE_INTERNAL_FRUNK int32_t spareRenderingBuffer[4][SSI_TX_BUFFER_NUM_SAMPLES]

// Hopefully I could make this use the spareRenderingBuffer instead...

const PatchableInfo patchableInfoForVoice = {
.paramFinalValuesOffset = offsetof(Voice, paramFinalValues) - offsetof(Voice, patcher),
.sourceValuesOffset = offsetof(Voice, sourceValues) - offsetof(Voice, patcher),
const Patcher::Config kPatcherConfigForVoice = {
.firstParam = 0,
.firstNonVolumeParam = params::FIRST_LOCAL_NON_VOLUME,
.firstHybridParam = params::FIRST_LOCAL__HYBRID,
Expand All @@ -88,7 +86,7 @@ int32_t Voice::combineExpressionValues(const Sound& sound, int32_t expressionDim
return lshiftAndSaturate<1>(combinedValue);
}

Voice::Voice() : patcher(&patchableInfoForVoice) {
Voice::Voice() : patcher(kPatcherConfigForVoice, sourceValues, paramFinalValues) {
}

// Unusually, modelStack may be supplied as NULL, because when unassigning all voices e.g. on song swap, we won't have
Expand Down Expand Up @@ -204,7 +202,7 @@ bool Voice::noteOn(ModelStackWithVoice* modelStack, int32_t newNoteCodeBeforeArp
for (int32_t s = 0; s < util::to_underlying(kFirstLocalSource); s++) {
sourceValues[s] = sound.globalSourceValues[s];
}
patcher.performInitialPatching(&sound, paramManager);
patcher.performInitialPatching(sound, *paramManager);

// Setup and render envelopes - again. Because they're local params (since mid-late 2017), we really need to render
// them *after* initial patching is performed.
Expand Down Expand Up @@ -530,7 +528,8 @@ void Voice::calculatePhaseIncrements(ModelStackWithVoice* modelStack) {
if (sound.getSynthMode() == SynthMode::FM) {
for (int32_t m = 0; m < kNumModulators; m++) {

if (sound.getSmoothedPatchedParamValue(params::LOCAL_MODULATOR_0_VOLUME + m, paramManager) == -2147483648) {
if (sound.getSmoothedPatchedParamValue(params::LOCAL_MODULATOR_0_VOLUME + m, *paramManager)
== -2147483648) {
continue; // Only if modulator active
}

Expand Down Expand Up @@ -806,7 +805,7 @@ uint32_t Voice::getLocalLFOPhaseIncrement(LFO_ID lfoId, deluge::modulation::para
for (int32_t s = 0; s < util::to_underlying(kFirstLocalSource); s++) {
sourceValues[s] = sound.globalSourceValues[s];
}
patcher.performPatching(sourcesChanged, &sound, paramManager);
patcher.performPatching(sourcesChanged, sound, *paramManager);
}

// Sort out pitch
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/model/voice/voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class Voice final {
///
/// This is just for the *local* params, specific to this Voice only
///
int32_t paramFinalValues[deluge::modulation::params::LOCAL_LAST];
std::array<int32_t, deluge::modulation::params::LOCAL_LAST> paramFinalValues;

// At the start of this list are local copies of the "global" ones. It's cheaper to copy them here than to pick and
// choose where the Patcher looks for them
int32_t sourceValues[kNumPatchSources];
std::array<int32_t, kNumPatchSources> sourceValues;

std::bitset<kNumExpressionDimensions> expressionSourcesCurrentlySmoothing;
std::bitset<kNumExpressionDimensions> expressionSourcesFinalValueChanged;
Expand Down
1 change: 1 addition & 0 deletions src/deluge/modulation/patch/patch_cable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "modulation/patch/patch_cable.h"
#include "definitions_cxx.hpp"
#include "util/fixedpoint.h"

void PatchCable::setup(PatchSource newFrom, uint8_t newTo, int32_t newAmount) {
from = newFrom;
Expand Down
8 changes: 7 additions & 1 deletion src/deluge/modulation/patch/patch_cable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "modulation/automation/auto_param.h"
#include "modulation/params/param_descriptor.h"
#include "util/fixedpoint.h"
#include <cstdint>

class Sound;
Expand All @@ -33,8 +34,13 @@ class PatchCable {
void initAmount(int32_t value);
void makeUnusable();

[[gnu::always_inline]] [[nodiscard]] int32_t applyRangeAdjustment(int32_t value) const {
int32_t small = multiply_32x32_rshift32(value, *this->rangeAdjustmentPointer);
return signed_saturate<32 - 5>(small) << 3; // Not sure if these limits are as wide as they could be...
}

PatchSource from;
ParamDescriptor destinationParamDescriptor;
AutoParam param; // Amounts have to be within +1073741824 and -1073741824
int32_t const* rangeAdjustmentPointer;
int32_t const* rangeAdjustmentPointer = nullptr;
};
Loading
Loading