kwave  18.07.70
Kwave::NoisePlugin Class Reference

#include <NoisePlugin.h>

Inheritance diagram for Kwave::NoisePlugin:
Inheritance graph
Collaboration diagram for Kwave::NoisePlugin:
Collaboration graph

Public Member Functions

 NoisePlugin (QObject *parent, const QVariantList &args)
 
virtual ~NoisePlugin () Q_DECL_OVERRIDE
 
virtual Kwave::PluginSetupDialogcreateDialog (QWidget *parent) Q_DECL_OVERRIDE
 
virtual Kwave::SampleSourcecreateFilter (unsigned int tracks) Q_DECL_OVERRIDE
 
virtual bool paramsChanged () Q_DECL_OVERRIDE
 
virtual void updateFilter (Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
 
virtual QString actionName () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::FilterPlugin
 FilterPlugin (QObject *parent, const QVariantList &args)
 
virtual ~FilterPlugin () Q_DECL_OVERRIDE
 
virtual QStringList * setup (QStringList &previous_params) Q_DECL_OVERRIDE
 
virtual void run (QStringList params) Q_DECL_OVERRIDE
 
virtual QString progressText () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::Plugin
 Plugin (QObject *parent, const QVariantList &args)
 
virtual ~Plugin () Q_DECL_OVERRIDE
 
virtual QString name () const
 
virtual QString description () const
 
virtual bool canClose () const
 
bool isRunning () const
 
bool shouldStop () const
 
virtual void load (QStringList &params)
 
virtual void unload ()
 
virtual int start (QStringList &params)
 
virtual int stop ()
 
Kwave::PluginManagermanager () const
 
Kwave::SignalManagersignalManager ()
 
QWidget * parentWidget () const
 
QString signalName ()
 
virtual sample_index_t signalLength ()
 
virtual double signalRate ()
 
virtual const QList< unsigned int > selectedTracks ()
 
virtual sample_index_t selection (QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
 
virtual void selectRange (sample_index_t offset, sample_index_t length)
 
virtual void migrateToActiveContext ()
 
- Public Member Functions inherited from Kwave::Runnable
virtual ~Runnable ()
 

Protected Slots

void setNoiseLevel (double level)
 
- Protected Slots inherited from Kwave::FilterPlugin
void startPreListen ()
 
void stopPreListen ()
 

Protected Member Functions

virtual int interpreteParameters (QStringList &params) Q_DECL_OVERRIDE
 
- Protected Member Functions inherited from Kwave::Plugin
int execute (QStringList &params)
 
void emitCommand (const QString &command)
 
void use ()
 
void setPluginManager (Kwave::PluginManager *new_plugin_manager)
 
virtual void run_wrapper (const QVariant &params) Q_DECL_OVERRIDE
 

Private Attributes

double m_level
 
double m_last_level
 

Additional Inherited Members

- Public Slots inherited from Kwave::Plugin
virtual void setProgressDialogEnabled (bool enable)
 
virtual void updateProgress (qreal progress)
 
virtual void cancel ()
 
virtual void close ()
 
void release ()
 
- Signals inherited from Kwave::FilterPlugin
void sigCancelPressed ()
 
- Signals inherited from Kwave::Plugin
void sigRunning (Kwave::Plugin *plugin)
 
void sigDone (Kwave::Plugin *plugin)
 
void sigClosed (Kwave::Plugin *p)
 
void sigCommand (const QString &command)
 
void setProgressText (const QString &text)
 

Detailed Description

Definition at line 30 of file NoisePlugin.h.

Constructor & Destructor Documentation

◆ NoisePlugin()

Kwave::NoisePlugin::NoisePlugin ( QObject *  parent,
const QVariantList &  args 
)

Constructor

Parameters
parentreference to our plugin manager
argsargument list [unused]

Definition at line 43 of file NoisePlugin.cpp.

44  :Kwave::FilterPlugin(parent, args), m_level(1.0), m_last_level(0.0)
45 {
46 }

◆ ~NoisePlugin()

Kwave::NoisePlugin::~NoisePlugin ( )
virtual

Destructor

Definition at line 49 of file NoisePlugin.cpp.

50 {
51 }

Member Function Documentation

◆ actionName()

QString Kwave::NoisePlugin::actionName ( )
virtual

Returns a verbose name of the performed action. Used for giving the undo action a readable name.

Implements Kwave::FilterPlugin.

Definition at line 132 of file NoisePlugin.cpp.

133 {
134  return i18n("Add Noise");
135 }

◆ createDialog()

Kwave::PluginSetupDialog * Kwave::NoisePlugin::createDialog ( QWidget *  parent)
virtual

Creates the setup dialog and connects it's signals

Implements Kwave::FilterPlugin.

Definition at line 77 of file NoisePlugin.cpp.

References Kwave::connect(), Kwave::SignalManager::isEmpty(), Kwave::Plugin::manager(), Kwave::Plugin::parentWidget(), Kwave::Plugin::selection(), setNoiseLevel(), and Kwave::PluginManager::signalManager().

78 {
79  Q_UNUSED(parent);
80 
81  // initialize the overview cache
83  QList<unsigned int> tracks;
84  sample_index_t first, last;
85  sample_index_t length = selection(&tracks, &first, &last, true);
86  Kwave::OverViewCache *overview_cache =
87  new(std::nothrow) Kwave::OverViewCache(mgr, first, length,
88  tracks.isEmpty() ? Q_NULLPTR : &tracks);
89  Q_ASSERT(overview_cache);
90 
91  // create the setup dialog
92  Kwave::NoiseDialog *dialog =
93  new Kwave::NoiseDialog(parentWidget(), overview_cache);
94  if (!dialog) {
95  if (overview_cache) delete overview_cache;
96  return Q_NULLPTR;
97  }
98 
99  // connect the signals for detecting value changes in pre-listen mode
100  connect(dialog, SIGNAL(levelChanged(double)),
101  this, SLOT(setNoiseLevel(double)));
102 
103  return dialog;
104 }
void setNoiseLevel(double level)
QWidget * parentWidget() const
Definition: Plugin.cpp:450
quint64 sample_index_t
Definition: Sample.h:28
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
Kwave::SignalManager & signalManager()
virtual sample_index_t selection(QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
Definition: Plugin.cpp:480
Here is the call graph for this function:

◆ createFilter()

Kwave::SampleSource * Kwave::NoisePlugin::createFilter ( unsigned int  tracks)
virtual

Creates a multi-track filter with the given number of tracks

Parameters
tracksnumber of tracks that the filter should have
Returns
pointer to the filter or null if failed

Implements Kwave::FilterPlugin.

Definition at line 107 of file NoisePlugin.cpp.

◆ interpreteParameters()

int Kwave::NoisePlugin::interpreteParameters ( QStringList &  params)
protectedvirtual

Reads values from the parameter list

Implements Kwave::FilterPlugin.

Definition at line 54 of file NoisePlugin.cpp.

References m_level.

55 {
56  bool ok;
57  QString param;
58 
59  // evaluate the parameter list
60  if (params.count() != 2) return -EINVAL;
61 
62  param = params[0];
63  m_level = param.toDouble(&ok);
64  Q_ASSERT(ok);
65  if (!ok) return -EINVAL;
66 
67  param = params[1];
68  unsigned int mode = param.toUInt(&ok);
69  Q_ASSERT(ok);
70  if (!ok || (mode > 2)) return -EINVAL;
71 
72  // all parameters accepted
73  return 0;
74 }

◆ paramsChanged()

bool Kwave::NoisePlugin::paramsChanged ( )
virtual

Returns true if the parameters have changed during pre-listen.

Reimplemented from Kwave::FilterPlugin.

Definition at line 113 of file NoisePlugin.cpp.

References m_last_level, and m_level.

114 {
115  return (!qFuzzyCompare(m_level, m_last_level));
116 }

◆ setNoiseLevel

void Kwave::NoisePlugin::setNoiseLevel ( double  level)
protectedslot

called when the noise level setting changed during pre-listen

Parameters
levelnoise level, as a factor between 0 and 1

Definition at line 138 of file NoisePlugin.cpp.

References m_level.

Referenced by createDialog(), and updateFilter().

139 {
140  m_level = level;
141 }
Here is the caller graph for this function:

◆ updateFilter()

void Kwave::NoisePlugin::updateFilter ( Kwave::SampleSource filter,
bool  force = false 
)
virtual

Update the filter with new parameters if it has changed changed during the pre-listen.

Parameters
filterthe Kwave::SampleSource to be updated, should be the same one as created with createFilter()
forceif true, even update if no settings have changed

Reimplemented from Kwave::FilterPlugin.

Definition at line 119 of file NoisePlugin.cpp.

References m_last_level, m_level, Kwave::StreamObject::setAttribute(), and setNoiseLevel().

121 {
122  if (!filter) return;
123 
124  if (!qFuzzyCompare(m_level, m_last_level) || force)
125  filter->setAttribute(SLOT(setNoiseLevel(QVariant)),
126  QVariant(m_level));
127 
129 }
void setNoiseLevel(double level)
void setAttribute(const char *attribute, const QVariant &value)
Here is the call graph for this function:

Member Data Documentation

◆ m_last_level

double Kwave::NoisePlugin::m_last_level
private

last value of m_level

Definition at line 97 of file NoisePlugin.h.

Referenced by paramsChanged(), and updateFilter().

◆ m_level

double Kwave::NoisePlugin::m_level
private

noise level, as linear factor ]0 ... 1.0]

Definition at line 94 of file NoisePlugin.h.

Referenced by interpreteParameters(), paramsChanged(), setNoiseLevel(), and updateFilter().


The documentation for this class was generated from the following files: