kwave  18.07.70
LowPassPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  LowPassPlugin.cpp - Plugin for simple lowpass filtering
3  -------------------
4  begin : Fri Mar 07 2003
5  copyright : (C) 2003 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 <errno.h>
21 #include <math.h>
22 
23 #include <QStringList>
24 
25 #include <KLocalizedString>
26 
27 #include "LowPassDialog.h"
28 #include "LowPassFilter.h"
29 #include "LowPassPlugin.h"
31 
32 KWAVE_PLUGIN(lowpass, LowPassPlugin)
33 
34 //***************************************************************************
35 Kwave::LowPassPlugin::LowPassPlugin(QObject *parent,
36  const QVariantList &args)
37  :Kwave::FilterPlugin(parent, args),
38  m_frequency(3500.0), m_last_freq(100)
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() != 1) return -EINVAL;
55 
56  param = params[0];
57  m_frequency = param.toDouble(&ok);
58  Q_ASSERT(ok);
59  if (!ok) return -EINVAL;
60 
61  return 0;
62 }
63 
64 //***************************************************************************
66 {
67  Kwave::LowPassDialog *dialog =
68  new Kwave::LowPassDialog(parent, signalRate());
69  Q_ASSERT(dialog);
70  if (!dialog) return Q_NULLPTR;
71 
72  // connect the signals for detecting value changes in pre-listen mode
73  connect(dialog, SIGNAL(changed(double)),
74  this, SLOT(setValue(double)));
75 
76  return dialog;
77 }
78 
79 //***************************************************************************
81 {
83 }
84 
85 //***************************************************************************
87 {
88  return (!qFuzzyCompare(m_frequency, m_last_freq));
89 }
90 
91 //***************************************************************************
93  bool force)
94 {
95  double sr = signalRate();
96 
97  if (!filter) return;
98 
99  if (!qFuzzyCompare(m_frequency, m_last_freq) || force)
100  filter->setAttribute(SLOT(setFrequency(QVariant)),
101  QVariant((m_frequency * 2.0 * M_PI) / sr));
102 
104 }
105 
106 //***************************************************************************
108 {
109  return i18n("Low Pass");
110 }
111 
112 //***************************************************************************
113 void Kwave::LowPassPlugin::setValue(double frequency)
114 {
115  m_frequency = frequency;
116 }
117 
118 //***************************************************************************
119 #include "LowPassPlugin.moc"
120 //***************************************************************************
121 //***************************************************************************
Definition: App.h:33
virtual Kwave::SampleSource * createFilter(unsigned int tracks) Q_DECL_OVERRIDE
virtual QString actionName() Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void setValue(double frequency)
virtual double signalRate()
Definition: Plugin.cpp:468
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
virtual int interpreteParameters(QStringList &params) Q_DECL_OVERRIDE
virtual ~LowPassPlugin() Q_DECL_OVERRIDE
virtual Kwave::PluginSetupDialog * createDialog(QWidget *parent) Q_DECL_OVERRIDE
virtual void updateFilter(Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
void setAttribute(const char *attribute, const QVariant &value)
virtual bool paramsChanged() Q_DECL_OVERRIDE