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 @@
FREEZE_WITH_ERROR("E174");
}

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

Check failure on line 828 in src/deluge/model/instrument/kit.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-cstyle-cast,-warnings-as-errors]
}
}

Expand Down Expand Up @@ -926,7 +926,7 @@

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
18 changes: 6 additions & 12 deletions src/deluge/model/voice/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,12 @@
using namespace deluge;
namespace params = deluge::modulation::params;

#pragma GCC diagnostic push
// This is supported by GCC and other compilers should error (not warn), so turn off for this file
#pragma GCC diagnostic ignored "-Winvalid-offsetof"

PLACE_INTERNAL_FRUNK int32_t spareRenderingBuffer[4][SSI_TX_BUFFER_NUM_SAMPLES]
__attribute__((aligned(CACHE_LINE_SIZE)));

// 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 +82,7 @@
return lshiftAndSaturate<1>(combinedValue);
}

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

Check failure on line 85 in src/deluge/model/voice/voice.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

constructor does not initialize these fields: assignedToSound, paramFinalValues, sourceValues, localExpressionSourceValuesBeforeSmoothing, inputCharacteristics, noteCodeAfterArpeggiation, portaEnvelopePos, portaEnvelopeMaxAmplitude, lastSaturationTanHWorkingValue, overallOscAmplitudeLastTime, sourceAmplitudesLastTime, modulatorAmplitudeLastTime, sourceWaveIndexesLastTime, filterGainLastTime, doneFirstRender, previouslyIgnoredNoteOff, orderSounded, overrideAmplitudeEnvelopeReleaseRate, nextUnassigned [cppcoreguidelines-pro-type-member-init,-warnings-as-errors]
}

// 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 +198,7 @@
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 +524,8 @@
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)

Check notice on line 527 in src/deluge/model/voice/voice.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: note

+3, including nesting penalty of 2, nesting level increased to 3
== -2147483648) {

Check failure on line 528 in src/deluge/model/voice/voice.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

2147483648 is a magic number; consider replacing it with a named constant [readability-magic-numbers,-warnings-as-errors]
continue; // Only if modulator active
}

Expand Down Expand Up @@ -806,7 +801,7 @@
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 Expand Up @@ -2523,4 +2518,3 @@
// Bits 0-23 - time entered
+ ((uint32_t)(-envelopes[0].timeEnteredState) & (0xFFFFFFFF >> 8));
}
#pragma GCC diagnostic pop
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 @@
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...

Check failure on line 39 in src/deluge/modulation/patch/patch_cable.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

32 is a magic number; consider replacing it with a named constant [readability-magic-numbers,-warnings-as-errors]

Check failure on line 39 in src/deluge/modulation/patch/patch_cable.h

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

5 is a magic number; consider replacing it with a named constant [readability-magic-numbers,-warnings-as-errors]
}

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