kwave  18.07.70
BandPassPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  BandPassPlugin.cpp - Plugin for band pass filtering
3  -------------------
4  begin : Tue Jun 24 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 <KLocalizedString>
24 #include <QStringList>
25 
26 #include "libkwave/PluginManager.h"
27 
28 #include "BandPass.h"
29 #include "BandPassDialog.h"
30 #include "BandPassPlugin.h"
32 
33 KWAVE_PLUGIN(band_pass, BandPassPlugin)
34 
35 //***************************************************************************
37  const QVariantList &args)
38  :Kwave::FilterPlugin(parent, args),
39  m_frequency(3500.0), m_last_freq(100),m_bw(100),m_last_bw(200)
40 {
41 }
42 
43 //***************************************************************************
45 {
46 }
47 
48 //***************************************************************************
50 {
51  bool ok;
52  QString param;
53 
54  if (params.isEmpty()) return -EINVAL;
55 
56  // evaluate the parameter list
57  Q_ASSERT(params.count() == 2);
58  if (params.count() != 2) return -EINVAL;
59 
60  param = params[0];
61  m_frequency = param.toDouble(&ok);
62  Q_ASSERT(ok);
63  if (!ok) return -EINVAL;
64 
65  param = params[1];
66  m_bw = param.toDouble(&ok);
67  Q_ASSERT(ok);
68  if (!ok) return -EINVAL;
69 
70  return 0;
71 }
72 
73 //***************************************************************************
75 {
76  Kwave::BandPassDialog *dialog =
77  new Kwave::BandPassDialog(parent, signalRate());
78  Q_ASSERT(dialog);
79  if (!dialog) return Q_NULLPTR;
80 
81  // connect the signals for detecting value changes in pre-listen mode
82  connect(dialog, SIGNAL(freqChanged(double)),
83  this, SLOT(setFreqValue(double)));
84  connect(dialog, SIGNAL(bwChanged(double)),
85  this, SLOT(setBwValue(double)));
86  return dialog;
87 }
88 
89 //***************************************************************************
91 {
93 }
94 
95 //***************************************************************************
97 {
98  return (!qFuzzyCompare(m_frequency, m_last_freq) ||
99  !qFuzzyCompare(m_bw, m_last_bw));
100 }
101 
102 //***************************************************************************
104  bool force)
105 {
106  double sr = signalRate();
107 
108  if (!filter) return;
109 
110  if (!qFuzzyCompare(m_frequency, m_last_freq) || force)
111  filter->setAttribute(SLOT(setFrequency(QVariant)),
112  QVariant((m_frequency * 2.0 * M_PI) / sr));
113 
114  if (!qFuzzyCompare(m_bw, m_last_bw) || force)
115  filter->setAttribute(SLOT(setBandwidth(QVariant)),
116  QVariant((m_bw * 2.0 * M_PI) / sr));
117 
119  m_last_bw = m_bw;
120 }
121 
122 //***************************************************************************
124 {
125  return i18n("Band Pass");
126 }
127 
128 //***************************************************************************
130 {
131  m_frequency = frequency;
132 }
133 
134 //***************************************************************************
136 {
137  m_bw = bw;
138 }
139 
140 //***************************************************************************
141 #include "BandPassPlugin.moc"
142 //***************************************************************************
143 //***************************************************************************
void setFreqValue(double frequency)
Definition: App.h:33
virtual void updateFilter(Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
virtual int interpreteParameters(QStringList &params) Q_DECL_OVERRIDE
virtual Kwave::PluginSetupDialog * createDialog(QWidget *parent) Q_DECL_OVERRIDE
virtual Kwave::SampleSource * createFilter(unsigned int tracks) Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
virtual ~BandPassPlugin() Q_DECL_OVERRIDE
virtual bool paramsChanged() Q_DECL_OVERRIDE
void setBwValue(double bw)
virtual double signalRate()
Definition: Plugin.cpp:468
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
void setAttribute(const char *attribute, const QVariant &value)
virtual QString actionName() Q_DECL_OVERRIDE