Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Sep 6, 2023
1 parent 3ed3c1e commit 024334e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
38 changes: 21 additions & 17 deletions include/private/plugins/noise_generator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2022 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2022 Stefano Tronci <[email protected]>
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Stefano Tronci <[email protected]>
*
* This file is part of lsp-plugins
* Created on: 27 Feb 2022
Expand Down Expand Up @@ -153,19 +153,8 @@ namespace lsp
plug::IPort *pReactivity; // FFT reactivity
plug::IPort *pShiftGain; // FFT gain shift

public:
explicit noise_generator(const meta::plugin_t *meta);
virtual ~noise_generator();

virtual void init(plug::IWrapper *wrapper, plug::IPort **ports);
void destroy();

public:
virtual void update_sample_rate(long sr);
virtual void update_settings();
virtual void process(size_t samples);
virtual bool inline_display(plug::ICanvas *cv, size_t width, size_t height);
virtual void dump(dspu::IStateDumper *v) const;
protected:
void do_destroy();

protected:
inline ssize_t make_seed() const;
Expand All @@ -174,9 +163,24 @@ namespace lsp
static dspu::ng_color_t get_color(size_t value);
static dspu::stlt_slope_unit_t get_color_slope_unit(size_t value);
static ch_mode_t get_channel_mode(size_t value);

public:
explicit noise_generator(const meta::plugin_t *meta);
virtual ~noise_generator() override;

virtual void init(plug::IWrapper *wrapper, plug::IPort **ports) override;
void destroy() override;

public:
virtual void update_sample_rate(long sr) override;
virtual void update_settings() override;
virtual void process(size_t samples) override;
virtual bool inline_display(plug::ICanvas *cv, size_t width, size_t height) override;
virtual void dump(dspu::IStateDumper *v) const override;
};
}
}

} /* namespace plugins */
} /* namespace lsp */


#endif /* PRIVATE_PLUGINS_NOISE_GENERATOR_H_ */
49 changes: 43 additions & 6 deletions src/main/plug/noise_generator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2022 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2022 Stefano Tronci <[email protected]>
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Stefano Tronci <[email protected]>
*
* This file is part of lsp-plugins
* Created on: 27 Feb 2022
Expand Down Expand Up @@ -75,6 +75,40 @@ namespace lsp
if (meta::is_audio_in_port(p))
++nChannels;

for (size_t i=0; i<meta::noise_generator::NUM_GENERATORS; ++i)
{
generator_t *g = &vGenerators[i];

g->fGain = 0.0f;
g->bActive = false;
g->bInaudible = false;
g->bUpdPlots = true;

g->vBuffer = NULL;
g->vFreqChart = NULL;

g->pNoiseType = NULL;
g->pAmplitude = NULL;
g->pOffset = NULL;
g->pSlSw = NULL;
g->pMtSw = NULL;
g->pInaSw = NULL;
g->pLCGdist = NULL;
g->pVelvetType = NULL;
g->pVelvetWin = NULL;
g->pVelvetARNd = NULL;
g->pVelvetCSW = NULL;
g->pVelvetCpr = NULL;
g->pColorSel = NULL;
g->pCslopeNPN = NULL;
g->pCslopeDBO = NULL;
g->pCslopeDBD = NULL;
g->pFft = NULL;
g->pMeterOut = NULL;
g->pMsh = NULL;
g->pSpectrum = NULL;
}

// Initialize other parameters
vChannels = NULL;
vFreqs = NULL;
Expand All @@ -97,7 +131,7 @@ namespace lsp

noise_generator::~noise_generator()
{
destroy();
do_destroy();
}

ssize_t noise_generator::make_seed() const
Expand Down Expand Up @@ -422,6 +456,12 @@ namespace lsp
}

void noise_generator::destroy()
{
Module::destroy();
do_destroy();
}

void noise_generator::do_destroy()
{
// Drop inline display data structures
if (pIDisplay != NULL)
Expand Down Expand Up @@ -464,9 +504,6 @@ namespace lsp

// Destroy analyzer
sAnalyzer.destroy();

// Destroy parent module
Module::destroy();
}

void noise_generator::update_sample_rate(long sr)
Expand Down

0 comments on commit 024334e

Please sign in to comment.