kwave  18.07.70
BandPassDialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  BandPassDialog.cpp - dialog for the "band_pass" plugin
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 #include "math.h"
20 
21 #include <QPainter>
22 #include <QPushButton>
23 #include <QRadioButton>
24 #include <QSlider>
25 #include <QSpinBox>
26 #include <QWidget>
27 
28 #include <KHelpClient>
29 #include <KLocalizedString>
30 
31 #include "libkwave/String.h"
32 #include "libkwave/Utils.h"
33 
35 #include "libgui/ScaleWidget.h"
36 
37 #include "BandPass.h"
38 #include "BandPassDialog.h"
39 
40 //***************************************************************************
41 Kwave::BandPassDialog::BandPassDialog(QWidget *parent, double sample_rate)
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 }
111 
112 //***************************************************************************
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 }
121 
122 //***************************************************************************
124 {
125  if (Kwave::toInt(m_frequency) != pos) {
126  m_frequency = pos;
127  updateDisplay();
128 
129  emit freqChanged(m_frequency);
130  }
131 }
132 //***************************************************************************
134 {
135  if (Kwave::toInt(m_bw) != pos) {
136  m_bw = pos;
137  updateDisplay();
138 
139  emit bwChanged(m_bw);
140  }
141 }
142 //***************************************************************************
144 {
145  QStringList list;
146  list << QString::number(m_frequency);
147  list << QString::number(m_bw);
148  return list;
149 }
150 
151 //***************************************************************************
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 }
172 
173 //***************************************************************************
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 }
184 
185 //***************************************************************************
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 }
201 
202 //***************************************************************************
204 {
205  if (btListen) btListen->setChecked(false);
206 }
207 
208 //***************************************************************************
210 {
211  KHelpClient::invokeHelp(_("plugin_sect_band_pass"));
212 }
213 
214 //***************************************************************************
215 //***************************************************************************
Definition: App.h:33
void freqValueChanged(int pos)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void freqChanged(double freq)
void setFrequency(const QVariant fc)
Definition: BandPass.cpp:141
int toInt(T x)
Definition: Utils.h:127
BandPassDialog(QWidget *parent, double sample_rate)
void setBandwidth(const QVariant bw)
Definition: BandPass.cpp:152
void bwChanged(double bw)
#define _(m)
Definition: memcpy.c:66
virtual QStringList params() Q_DECL_OVERRIDE
virtual void setParams(QStringList &params) Q_DECL_OVERRIDE
Kwave::BandPass * m_filter
void bwValueChanged(int pos)
void listenToggled(bool listen)
virtual ~BandPassDialog() Q_DECL_OVERRIDE