Skip to content

Commit

Permalink
- added FilterType parameter to oversampling node
Browse files Browse the repository at this point in the history
- fixed crash when loading HardcodedFX modules
  • Loading branch information
christoph-hart committed Jan 27, 2025
1 parent c06f9f5 commit ea13649
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 18 deletions.
24 changes: 13 additions & 11 deletions hi_core/hi_modules/effects/fx/SlotFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,24 @@ class HardcodedMasterEditor : public ProcessorEditorBody
numObjectsFunction = [this](ExternalData::DataType dt){ return getEffect()->getNumDataObjects(dt); };
}

ExternalData::forEachType([&](ExternalData::DataType dt)
if(numObjectsFunction)
{
int numObjects = numObjectsFunction(dt);

for (int i = 0; i < numObjects; i++)
ExternalData::forEachType([&](ExternalData::DataType dt)
{
auto f = ExternalData::createEditor(getEffect()->getComplexBaseType(dt, i));

auto c = dynamic_cast<Component*>(f);
int numObjects = numObjectsFunction(dt);

currentEditors.add(f);
addAndMakeVisible(c);
}
});
for (int i = 0; i < numObjects; i++)
{
auto f = ExternalData::createEditor(getEffect()->getComplexBaseType(dt, i));

auto c = dynamic_cast<Component*>(f);

currentEditors.add(f);
addAndMakeVisible(c);
}
});
}

if (auto on = getEffect()->opaqueNode.get())
{
for(const auto& p: OpaqueNode::ParameterIterator(*on))
Expand Down
41 changes: 36 additions & 5 deletions hi_dsp_library/node_api/nodes/processors.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ struct oversample_base

using Oversampler = juce::dsp::Oversampling<float>;

using FilterType = Oversampler::FilterType;

oversample_base(int factor) :
oversamplingFactor(jmax(1, factor))
{};
Expand All @@ -699,7 +701,7 @@ struct oversample_base

ScopedPointer<Oversampler> newOverSampler;

newOverSampler = new Oversampler(numChannels, (int)std::log2(oversamplingFactor), Oversampler::FilterType::filterHalfBandPolyphaseIIR, false);
newOverSampler = new Oversampler(numChannels, (int)std::log2(oversamplingFactor), filterType, false);

if (originalBlockSize > 0)
newOverSampler->initProcessing(originalBlockSize);
Expand Down Expand Up @@ -747,6 +749,28 @@ struct oversample_base
if(originalSpecs)
prepare(originalSpecs);
}

FilterType getFilterType() const { return filterType; }

void setFilterType(int nt)
{
span<FilterType, 2> types = {
FilterType::filterHalfBandPolyphaseIIR,
FilterType::filterHalfBandFIREquiripple
};

auto newType = types[jlimit(0, 1, nt)];

if(newType != filterType)
{
SimpleReadWriteLock::ScopedWriteLock sl(this->lock);

filterType = newType;

if(originalSpecs)
prepare(originalSpecs);
}
}

protected:

Expand All @@ -757,7 +781,9 @@ struct oversample_base
int oversamplingFactor = 0;
int originalBlockSize = 0;
int numChannels = 0;


FilterType filterType = FilterType::filterHalfBandPolyphaseIIR;

void* pObj = nullptr;
prototypes::prepare prepareFunc;

Expand Down Expand Up @@ -940,10 +966,15 @@ template <int OversamplingFactor, class T, class InitFunctionClass=scriptnode_in

template <int P> void setParameter(double newValue)
{
static_assert(P == 0, "illegal parameter index");
static_assert(P == 0 || P == 1, "illegal parameter index");
static_assert(OversamplingFactor == 0 || P == 0, "wrong filter type index for static oversampling");

if constexpr(P == 0)
this->setOversamplingFactor((int)newValue);
if constexpr(P == 0 && OversamplingFactor == 0)
this->setOversamplingFactor((int)newValue);
else
this->setFilterType((int)newValue);


}
SN_FORWARD_PARAMETER_TO_MEMBER(oversample);

Expand Down
26 changes: 24 additions & 2 deletions hi_scripting/scripting/scriptnode/nodes/NodeContainerTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ template <int OversampleFactor> class OversampleNode : public SerialNode

enum Parameters
{
OversamplingFactor
OversamplingFactor,
FilterType
};

static String getOversampleName()
Expand All @@ -440,6 +441,7 @@ template <int OversampleFactor> class OversampleNode : public SerialNode
DEFINE_PARAMETERS
{
DEF_PARAMETER(OversamplingFactor, OversampleNode);
DEF_PARAMETER(FilterType, OversampleNode);
}

SN_PARAMETER_MEMBER_FUNCTION;
Expand All @@ -455,8 +457,16 @@ template <int OversampleFactor> class OversampleNode : public SerialNode
if(lastSpecs)
prepareNodes(lastSpecs);
}

void setFilterType(double filterType)
{
obj.setFilterType((int)filterType);

if(lastSpecs)
prepareNodes(lastSpecs);
}

bool hasFixedParameters() const final override { return OversampleFactor == -1; }
bool hasFixedParameters() const final override { return true; }

Component* createLeftTabComponent() const override
{
Expand All @@ -470,6 +480,7 @@ template <int OversampleFactor> class OversampleNode : public SerialNode
{
ParameterDataList data;

if(OversampleFactor == -1)
{
auto maxExponent = wrap::oversample_base::MaxOversamplingExponent;

Expand All @@ -494,6 +505,17 @@ template <int OversampleFactor> class OversampleNode : public SerialNode
data.add(std::move(p));
}

{
parameter::data p("FilterType");
p.info.index = data.size();
p.callback = parameter::inner<OversampleNode<OversampleFactor>, (int)Parameters::FilterType>(*this);

StringArray sa("Polyphase", "FIR");
p.setParameterValueNames(sa);

data.add(std::move(p));
}

return data;
}

Expand Down

0 comments on commit ea13649

Please sign in to comment.