kwave  18.07.70
NoisePlugin.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  NoisePlugin.cpp - overwrites the selected range of samples with noise
3  -------------------
4  begin : Wed Dec 12 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <new>
21 
22 #include <errno.h>
23 
24 #include <KLocalizedString> // for the i18n macro
25 
26 #include "libkwave/Connect.h"
29 #include "libkwave/PluginManager.h"
30 #include "libkwave/SampleSink.h"
31 #include "libkwave/SampleSource.h"
33 
34 #include "libgui/OverViewCache.h"
35 
36 #include "NoiseDialog.h"
37 #include "NoiseGenerator.h"
38 #include "NoisePlugin.h"
39 
40 KWAVE_PLUGIN(noise, NoisePlugin)
41 
42 //***************************************************************************
43 Kwave::NoisePlugin::NoisePlugin(QObject *parent, const QVariantList &args)
44  :Kwave::FilterPlugin(parent, args), m_level(1.0), m_last_level(0.0)
45 {
46 }
47 
48 //***************************************************************************
50 {
51 }
52 
53 //***************************************************************************
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 }
75 
76 //***************************************************************************
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 }
105 
106 //***************************************************************************
108 {
110 }
111 
112 //***************************************************************************
114 {
115  return (!qFuzzyCompare(m_level, m_last_level));
116 }
117 
118 //***************************************************************************
120  bool force)
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 }
130 
131 //***************************************************************************
133 {
134  return i18n("Add Noise");
135 }
136 
137 //***************************************************************************
139 {
140  m_level = level;
141 }
142 
143 //***************************************************************************
144 #include "NoisePlugin.moc"
145 //***************************************************************************
146 //***************************************************************************
void setNoiseLevel(double level)
Definition: App.h:33
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 bool paramsChanged() Q_DECL_OVERRIDE
virtual Kwave::SampleSource * createFilter(unsigned int tracks) Q_DECL_OVERRIDE
virtual void updateFilter(Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
virtual Kwave::PluginSetupDialog * createDialog(QWidget *parent) Q_DECL_OVERRIDE
Definition: NoisePlugin.cpp:77
virtual QString actionName() Q_DECL_OVERRIDE
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
virtual ~NoisePlugin() Q_DECL_OVERRIDE
Definition: NoisePlugin.cpp:49
virtual int interpreteParameters(QStringList &params) Q_DECL_OVERRIDE
Definition: NoisePlugin.cpp:54
void setAttribute(const char *attribute, const QVariant &value)
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