kwave  18.07.70
Kwave::BandPassDialog Class Reference

#include <BandPassDialog.h>

Inheritance diagram for Kwave::BandPassDialog:
Inheritance graph
Collaboration diagram for Kwave::BandPassDialog:
Collaboration graph

Signals

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

Public Member Functions

 BandPassDialog (QWidget *parent, double sample_rate)
 
virtual ~BandPassDialog () 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::BandPassm_filter
 

Detailed Description

Definition at line 39 of file BandPassDialog.h.

Constructor & Destructor Documentation

◆ BandPassDialog()

Kwave::BandPassDialog::BandPassDialog ( 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 41 of file BandPassDialog.cpp.

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

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

◆ ~BandPassDialog()

Kwave::BandPassDialog::~BandPassDialog ( )
virtual

Destructor

Definition at line 113 of file BandPassDialog.cpp.

References listenToggled(), and m_filter.

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

Member Function Documentation

◆ bwChanged

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

emitted whenever the bandwidth setting has changed

Parameters
bwbandwith parameter [0 .. 1.0]

Referenced by bwValueChanged(), and dialog().

Here is the caller graph for this function:

◆ bwValueChanged

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

called when the bw spinbox or slider value has changed

Definition at line 133 of file BandPassDialog.cpp.

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

Referenced by BandPassDialog(), and dialog().

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

◆ dialog()

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

retruns a pointer to this as a QDialog

Implements Kwave::PluginSetupDialog.

Definition at line 65 of file BandPassDialog.h.

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

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

◆ freqChanged

void Kwave::BandPassDialog::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::BandPassDialog::freqValueChanged ( int  pos)
protectedslot

called when the freq spinbox or slider value has changed

Definition at line 123 of file BandPassDialog.cpp.

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

Referenced by BandPassDialog(), and dialog().

124 {
125  if (Kwave::toInt(m_frequency) != pos) {
126  m_frequency = pos;
127  updateDisplay();
128 
129  emit freqChanged(m_frequency);
130  }
131 }
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::BandPassDialog::invokeHelp ( )
privateslot

invoke the online help

Definition at line 209 of file BandPassDialog.cpp.

References _.

Referenced by BandPassDialog(), and dialog().

210 {
211  KHelpClient::invokeHelp(_("plugin_sect_band_pass"));
212 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ listenStopped

void Kwave::BandPassDialog::listenStopped ( )
protectedslot

called when the pre-listen mode stopped/aborted

Definition at line 203 of file BandPassDialog.cpp.

Referenced by dialog().

204 {
205  if (btListen) btListen->setChecked(false);
206 }
Here is the caller graph for this function:

◆ listenToggled

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

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

Definition at line 186 of file BandPassDialog.cpp.

References startPreListen(), and stopPreListen().

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

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

◆ params()

QStringList Kwave::BandPassDialog::params ( )
virtual

Returns the parameters as string list

Implements Kwave::PluginSetupDialog.

Definition at line 143 of file BandPassDialog.cpp.

References m_bw, and m_frequency.

144 {
145  QStringList list;
146  list << QString::number(m_frequency);
147  list << QString::number(m_bw);
148  return list;
149 }

◆ setParams()

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

Sets the from a list of parameters

Implements Kwave::PluginSetupDialog.

Definition at line 152 of file BandPassDialog.cpp.

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

153 {
154  // evaluate the parameter list
155  bool ok;
156  double frequency = params[0].toDouble(&ok);
157  Q_ASSERT(ok);
158  if (ok) m_frequency = frequency;
159 
160  double bw = params[1].toDouble(&ok);
161  Q_ASSERT(ok);
162  if (ok) m_bw = bw;
163 
164  slider->setValue(Kwave::toInt(m_frequency));
165  spinbox->setValue(Kwave::toInt(m_frequency));
166 
167  slider_2->setValue(Kwave::toInt(m_bw));
168  spinbox_2->setValue(Kwave::toInt(m_bw));
169 
170  updateDisplay();
171 }
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::BandPassDialog::startPreListen ( )
signal

Pre-listen mode has been started

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ stopPreListen

void Kwave::BandPassDialog::stopPreListen ( )
signal

Pre-listen mode has been stopped

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ updateDisplay()

void Kwave::BandPassDialog::updateDisplay ( )
protected

Update the graphic display

Definition at line 174 of file BandPassDialog.cpp.

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

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

175 {
176  double fs = m_sample_rate;
177  if (m_filter && (fs > 0.0))
178  {
179  m_filter->setFrequency(QVariant(2.0 * M_PI * m_frequency / fs));
180  m_filter->setBandwidth(QVariant(2.0 * M_PI * m_bw / fs));
181  if (freq_response) freq_response->repaint();
182  }
183 }
void setFrequency(const QVariant fc)
Definition: BandPass.cpp:141
void setBandwidth(const QVariant bw)
Definition: BandPass.cpp:152
Kwave::BandPass * m_filter
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bw

double Kwave::BandPassDialog::m_bw
private

the bw in Hz

Definition at line 122 of file BandPassDialog.h.

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

◆ m_filter

Kwave::BandPass* Kwave::BandPassDialog::m_filter
private

filter function for calculating the frequency response

Definition at line 128 of file BandPassDialog.h.

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

◆ m_frequency

double Kwave::BandPassDialog::m_frequency
private

the cutoff frequency in Hz

Definition at line 119 of file BandPassDialog.h.

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

◆ m_sample_rate

double Kwave::BandPassDialog::m_sample_rate
private

sample rate of the signal in samples/sec

Definition at line 125 of file BandPassDialog.h.

Referenced by updateDisplay().


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