kwave  18.07.70
NotchFilterPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  NotchFilterPlugin.cpp - Plugin for simple notch filtering
3  -------------------
4  begin : Thu Jun 19 2003
5  copyright : (C) 2003 by Dave Flogeras
6  email : d.flogeras@unb.ca
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 <errno.h>
21 #include <math.h>
22 
23 #include <QStringList>
24 
25 #include <KLocalizedString>
26 
27 #include "NotchFilter.h"
28 #include "NotchFilterDialog.h"
29 #include "NotchFilterPlugin.h"
31 
32 KWAVE_PLUGIN(notch_filter, NotchFilterPlugin)
33 
34 //***************************************************************************
36  const QVariantList &args)
37  :Kwave::FilterPlugin(parent, args),
38  m_frequency(3500.0), m_last_freq(100), m_bw(100), m_last_bw(200)
39 {
40 }
41 
42 //***************************************************************************
44 {
45 }
46 
47 //***************************************************************************
49 {
50  bool ok;
51  QString param;
52 
53  // evaluate the parameter list
54  if (params.count() != 2) return -EINVAL;
55 
56  param = params[0];
57  m_frequency = param.toDouble(&ok);
58  Q_ASSERT(ok);
59  if (!ok) return -EINVAL;
60 
61  param = params[1];
62  m_bw = param.toDouble(&ok);
63  Q_ASSERT(ok);
64  if (!ok) return -EINVAL;
65 
66  return 0;
67 }
68 
69 //***************************************************************************
71 {
72  Kwave::NotchFilterDialog *dialog =
73  new Kwave::NotchFilterDialog(parent, signalRate());
74  Q_ASSERT(dialog);
75  if (!dialog) return Q_NULLPTR;
76 
77  // connect the signals for detecting value changes in pre-listen mode
78  connect(dialog, SIGNAL(freqChanged(double)),
79  this, SLOT(setFreqValue(double)));
80  connect(dialog, SIGNAL(bwChanged(double)),
81  this, SLOT(setBwValue(double)));
82  return dialog;
83 }
84 
85 //***************************************************************************
87 {
89 }
90 
91 //***************************************************************************
93 {
94  return (!qFuzzyCompare(m_frequency, m_last_freq) ||
95  !qFuzzyCompare(m_bw, m_last_bw));
96 }
97 
98 //***************************************************************************
100  bool force)
101 {
102  double sr = signalRate();
103 
104  if (!filter) return;
105 
106  if (!qFuzzyCompare(m_frequency, m_last_freq) || force)
107  filter->setAttribute(SLOT(setFrequency(QVariant)),
108  QVariant((m_frequency * 2.0 * M_PI) / sr));
109 
110  if (!qFuzzyCompare(m_bw, m_last_bw) || force)
111  filter->setAttribute(SLOT(setBandwidth(QVariant)),
112  QVariant((m_bw * 2.0 * M_PI) / sr));
113 
115  m_last_bw = m_bw;
116 }
117 
118 //***************************************************************************
120 {
121  return i18n("Notch Filter");
122 }
123 
124 //***************************************************************************
126 {
127  m_frequency = frequency;
128 }
129 
130 //***************************************************************************
132 {
133  m_bw = bw;
134 }
135 
136 //***************************************************************************
137 #include "NotchFilterPlugin.moc"
138 //***************************************************************************
139 //***************************************************************************
virtual QString actionName() Q_DECL_OVERRIDE
Definition: App.h:33
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
virtual Kwave::PluginSetupDialog * createDialog(QWidget *parent) Q_DECL_OVERRIDE
void setFreqValue(double frequency)
virtual bool paramsChanged() Q_DECL_OVERRIDE
virtual void updateFilter(Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
virtual int interpreteParameters(QStringList &params) Q_DECL_OVERRIDE
virtual Kwave::SampleSource * createFilter(unsigned int tracks) Q_DECL_OVERRIDE
virtual double signalRate()
Definition: Plugin.cpp:468
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
virtual ~NotchFilterPlugin() Q_DECL_OVERRIDE
void setAttribute(const char *attribute, const QVariant &value)