kwave  18.07.70
Kwave::NotchFilterDialog Class Reference

#include <NotchFilterDialog.h>

Inheritance diagram for Kwave::NotchFilterDialog:
Inheritance graph
Collaboration diagram for Kwave::NotchFilterDialog:
Collaboration graph

Signals

void freqChanged (double freq)
 
void bwChanged (double bw)
 
void startPreListen ()
 
void stopPreListen ()
 

Public Member Functions

 NotchFilterDialog (QWidget *parent, double sample_rate)
 
virtual ~NotchFilterDialog () Q_DECL_OVERRIDE
 
virtual QStringList params () Q_DECL_OVERRIDE
 
virtual void setParams (QStringList &params) Q_DECL_OVERRIDE
 
virtual QDialog * dialog () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::PluginSetupDialog
virtual ~PluginSetupDialog ()
 

Protected Slots

void freqValueChanged (int pos)
 
void bwValueChanged (int pos)
 
void listenToggled (bool listen)
 
void listenStopped ()
 

Protected Member Functions

void updateDisplay ()
 

Private Slots

void invokeHelp ()
 

Private Attributes

double m_frequency
 
double m_bw
 
double m_sample_rate
 
Kwave::NotchFilterm_filter
 

Detailed Description

Definition at line 36 of file NotchFilterDialog.h.

Constructor & Destructor Documentation

◆ NotchFilterDialog()

Kwave::NotchFilterDialog::NotchFilterDialog ( QWidget *  parent,
double  sample_rate 
)

Constructor.

Parameters
parentparent widget
sample_ratesample rate of the audio data to be processed, needed for determining the allowed range of the cutoff frequency

Definition at line 42 of file NotchFilterDialog.cpp.

References bwValueChanged(), Kwave::connect(), freqValueChanged(), invokeHelp(), listenToggled(), m_bw, m_filter, m_frequency, Kwave::toInt(), and updateDisplay().

43  :QDialog(parent), Kwave::PluginSetupDialog(),
44  Ui::NotchFilterDlg(),
45  m_frequency(3500),m_bw(100),
46  m_sample_rate(sample_rate), m_filter(Q_NULLPTR)
47 {
48  setupUi(this);
49  setModal(true);
50 
51  // set maximum frequency to sample rate / 2
52  double f_max = sample_rate / 2.0;
53 
54  slider->setMaximum(Kwave::toInt(f_max));
55  spinbox->setMaximum(Kwave::toInt(f_max));
56 
57  slider_2->setMaximum(Kwave::toInt(f_max));
58  spinbox_2->setMaximum(Kwave::toInt(f_max));
59 
60  // initialize the frequency scale widget
61  scale_freq->setMinMax(0, Kwave::toInt(f_max));
62  scale_freq->setLogMode(false);
63  scale_freq->setUnit(i18n("Hz"));
64 
65  // initialize the attenuation scale widget
66  scale_db->setMinMax(-24, +6);
67  scale_db->setLogMode(false);
68  scale_db->setUnit(i18n("dB"));
69 
70  // initialize the frequency response widget
71  freq_response->init(f_max, -24, +6);
72 
73  // set up the low pass filter dunction
74  m_filter = new NotchFilter();
75  freq_response->setFilter(m_filter);
76 
77  // initialize the controls and the curve display
78  slider->setValue(Kwave::toInt(m_frequency));
79  spinbox->setValue(Kwave::toInt(m_frequency));
80  slider_2->setValue(Kwave::toInt(m_bw));
81  spinbox_2->setValue(Kwave::toInt(m_bw));
82  updateDisplay();
83 
84  // changes in the slider or spinbox
85  connect(spinbox, SIGNAL(valueChanged(int)),
86  this, SLOT(freqValueChanged(int)));
87  connect(spinbox_2, SIGNAL(valueChanged(int)),
88  this, SLOT(bwValueChanged(int)));
89  // click to the "Listen" button
90  connect(btListen, SIGNAL(toggled(bool)),
91  this, SLOT(listenToggled(bool)));
92 
93  // expand the "Listen" button to it's maximum width
94  listenToggled(true);
95  if (btListen->width() > btListen->minimumWidth())
96  btListen->setMinimumWidth(btListen->width());
97  listenToggled(false);
98  if (btListen->width() > btListen->minimumWidth())
99  btListen->setMinimumWidth(btListen->width());
100 
101  // set the initial size of the dialog
102  int h = (width() * 3) / 5;
103  if (height() < h) resize(width(), h);
104  int w = (height() * 5) / 3;
105  if (width() < w) resize(w, height());
106 
107  connect(buttonHelp->button(QDialogButtonBox::Help), SIGNAL(clicked()),
108  this, SLOT(invokeHelp()));
109 
110  // set the focus onto the "OK" button
111  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
112 }
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
Kwave::NotchFilter * m_filter
int toInt(T x)
Definition: Utils.h:127
void listenToggled(bool listen)
Here is the call graph for this function:

◆ ~NotchFilterDialog()

Kwave::NotchFilterDialog::~NotchFilterDialog ( )
virtual

Destructor

Definition at line 115 of file NotchFilterDialog.cpp.

References listenToggled(), and m_filter.

116 {
117  // better stop pre-listen now
118  listenToggled(false);
119 
120  if (freq_response) freq_response->setFilter(Q_NULLPTR);
121  if (m_filter) delete m_filter;
122 }
Kwave::NotchFilter * m_filter
void listenToggled(bool listen)
Here is the call graph for this function:

Member Function Documentation

◆ bwChanged

void Kwave::NotchFilterDialog::bwChanged ( double  bw)
signal

Emitted when the bandwidth selectio has changed

Parameters
bwthe bandwidth parameter in Hz

Referenced by bwValueChanged(), and dialog().

Here is the caller graph for this function:

◆ bwValueChanged

void Kwave::NotchFilterDialog::bwValueChanged ( int  pos)
protectedslot

called when the bw spinbox or slider value has changed

Definition at line 136 of file NotchFilterDialog.cpp.

References bwChanged(), m_bw, Kwave::toInt(), and updateDisplay().

Referenced by dialog(), and NotchFilterDialog().

137 {
138  if (Kwave::toInt(m_bw) != pos) {
139  m_bw = pos;
140  updateDisplay();
141 
142  emit bwChanged(m_bw);
143  }
144 }
void bwChanged(double bw)
int toInt(T x)
Definition: Utils.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dialog()

virtual QDialog* Kwave::NotchFilterDialog::dialog ( )
inlinevirtual

retruns a pointer to this as a QDialog

Implements Kwave::PluginSetupDialog.

Definition at line 62 of file NotchFilterDialog.h.

References bwChanged(), bwValueChanged(), freqChanged(), freqValueChanged(), invokeHelp(), listenStopped(), listenToggled(), startPreListen(), stopPreListen(), and updateDisplay().

62 { return this; }
Here is the call graph for this function:

◆ freqChanged

void Kwave::NotchFilterDialog::freqChanged ( double  freq)
signal

Emitted whenever the frequency changes

Parameters
freqthe frequency parameter in Hz

Referenced by dialog(), and freqValueChanged().

Here is the caller graph for this function:

◆ freqValueChanged

void Kwave::NotchFilterDialog::freqValueChanged ( int  pos)
protectedslot

called when the freq spinbox or slider value has changed

Definition at line 125 of file NotchFilterDialog.cpp.

References freqChanged(), m_frequency, Kwave::toInt(), and updateDisplay().

Referenced by dialog(), and NotchFilterDialog().

126 {
127  if (Kwave::toInt(m_frequency) != pos) {
128  m_frequency = pos;
129  updateDisplay();
130 
131  emit freqChanged(m_frequency);
132  }
133 }
void freqChanged(double freq)
int toInt(T x)
Definition: Utils.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeHelp

void Kwave::NotchFilterDialog::invokeHelp ( )
privateslot

invoke the online help

Definition at line 214 of file NotchFilterDialog.cpp.

References _.

Referenced by dialog(), and NotchFilterDialog().

215 {
216  KHelpClient::invokeHelp(_("plugin_sect_notch_filter"));
217 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ listenStopped

void Kwave::NotchFilterDialog::listenStopped ( )
protectedslot

called when the pre-listen mode stopped/aborted

Definition at line 207 of file NotchFilterDialog.cpp.

Referenced by dialog().

208 {
209  if (btListen) btListen->setChecked(false);
210 }
Here is the caller graph for this function:

◆ listenToggled

void Kwave::NotchFilterDialog::listenToggled ( bool  listen)
protectedslot

called when the "Listen" button has been toggled, to start or stop the pre-listen mode

Definition at line 190 of file NotchFilterDialog.cpp.

References startPreListen(), and stopPreListen().

Referenced by dialog(), NotchFilterDialog(), and ~NotchFilterDialog().

191 {
192  Q_ASSERT(btListen);
193  if (!btListen) return;
194 
195  if (listen) {
196  // start pre-listen mode
197  emit startPreListen();
198  btListen->setText(i18n("&Stop"));
199  } else {
200  // stop pre-listen mode
201  emit stopPreListen();
202  btListen->setText(i18n("&Listen"));
203  }
204 }
Here is the caller graph for this function:

◆ params()

QStringList Kwave::NotchFilterDialog::params ( )
virtual

Returns the parameters as string list

Implements Kwave::PluginSetupDialog.

Definition at line 147 of file NotchFilterDialog.cpp.

References m_bw, and m_frequency.

148 {
149  QStringList list;
150  list << QString::number(m_frequency);
151  list << QString::number(m_bw);
152  return list;
153 }

◆ setParams()

void Kwave::NotchFilterDialog::setParams ( QStringList &  params)
virtual

Sets the from a list of parameters

Implements Kwave::PluginSetupDialog.

Definition at line 156 of file NotchFilterDialog.cpp.

References m_bw, m_frequency, Kwave::toInt(), and updateDisplay().

157 {
158  // evaluate the parameter list
159  bool ok;
160  double frequency = params[0].toDouble(&ok);
161  Q_ASSERT(ok);
162  if (ok) m_frequency = frequency;
163 
164  double bw = params[1].toDouble(&ok);
165  Q_ASSERT(ok);
166  if (ok) m_bw = bw;
167 
168  slider->setValue(Kwave::toInt(m_frequency));
169  spinbox->setValue(Kwave::toInt(m_frequency));
170 
171  slider_2->setValue(Kwave::toInt(m_bw));
172  spinbox_2->setValue(Kwave::toInt(m_bw));
173 
174  updateDisplay();
175 }
int toInt(T x)
Definition: Utils.h:127
virtual QStringList params() Q_DECL_OVERRIDE
Here is the call graph for this function:

◆ startPreListen

void Kwave::NotchFilterDialog::startPreListen ( )
signal

Pre-listen mode has been started

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ stopPreListen

void Kwave::NotchFilterDialog::stopPreListen ( )
signal

Pre-listen mode has been stopped

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ updateDisplay()

void Kwave::NotchFilterDialog::updateDisplay ( )
protected

Update the graphic display

Definition at line 178 of file NotchFilterDialog.cpp.

References m_bw, m_filter, m_frequency, m_sample_rate, Kwave::NotchFilter::setBandwidth(), and Kwave::NotchFilter::setFrequency().

Referenced by bwValueChanged(), dialog(), freqValueChanged(), NotchFilterDialog(), and setParams().

179 {
180  double fs = m_sample_rate;
181  if (m_filter && (fs > 0.0))
182  {
183  m_filter->setFrequency(QVariant(2.0 * M_PI * m_frequency / fs));
184  m_filter->setBandwidth(QVariant(2.0 * M_PI * m_bw / fs));
185  if (freq_response) freq_response->repaint();
186  }
187 }
void setBandwidth(const QVariant bw)
Kwave::NotchFilter * m_filter
void setFrequency(const QVariant fc)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bw

double Kwave::NotchFilterDialog::m_bw
private

the bw in Hz

Definition at line 119 of file NotchFilterDialog.h.

Referenced by bwValueChanged(), NotchFilterDialog(), params(), setParams(), and updateDisplay().

◆ m_filter

Kwave::NotchFilter* Kwave::NotchFilterDialog::m_filter
private

filter function for calculating the frequency response

Definition at line 125 of file NotchFilterDialog.h.

Referenced by NotchFilterDialog(), updateDisplay(), and ~NotchFilterDialog().

◆ m_frequency

double Kwave::NotchFilterDialog::m_frequency
private

the cutoff frequency in Hz

Definition at line 116 of file NotchFilterDialog.h.

Referenced by freqValueChanged(), NotchFilterDialog(), params(), setParams(), and updateDisplay().

◆ m_sample_rate

double Kwave::NotchFilterDialog::m_sample_rate
private

sample rate of the signal in samples/sec

Definition at line 122 of file NotchFilterDialog.h.

Referenced by updateDisplay().


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