kwave  18.07.70
LowPassDialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  LowPassDialog.cpp - dialog for the "lowpass" plugin
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 #include <math.h>
20 
21 #include <QObject>
22 #include <QPainter>
23 #include <QPushButton>
24 #include <QRadioButton>
25 #include <QSlider>
26 #include <QSpinBox>
27 #include <QWidget>
28 
29 #include <KHelpClient>
30 #include <KLocalizedString>
31 
32 #include "libkwave/String.h"
33 #include "libkwave/Utils.h"
34 
36 #include "libgui/ScaleWidget.h"
37 
38 #include "LowPassDialog.h"
39 #include "LowPassFilter.h"
40 
41 //***************************************************************************
42 Kwave::LowPassDialog::LowPassDialog(QWidget *parent, double sample_rate)
43  :QDialog(parent), Ui::LowPassDlg(), Kwave::PluginSetupDialog(),
44  m_frequency(3500),
45  m_sample_rate(sample_rate), m_filter(Q_NULLPTR)
46 {
47  setupUi(this);
48  setModal(true);
49 
50  // set maximum frequency to sample rate / 2
51  double f_max = sample_rate / 2.0;
52 
53  slider->setMaximum(Kwave::toInt(f_max));
54  spinbox->setMaximum(Kwave::toInt(f_max));
55 
56  // initialize the frequency scale widget
57  scale_freq->setMinMax(0, Kwave::toInt(f_max));
58  scale_freq->setLogMode(false);
59  scale_freq->setUnit(i18n("Hz"));
60 
61  // initialize the attenuation scale widget
62  scale_db->setMinMax(-24, +6);
63  scale_db->setLogMode(false);
64  scale_db->setUnit(i18n("dB"));
65 
66  // initialize the frequency response widget
67  freq_response->init(f_max, -24, +6);
68 
69  // set up the low pass filter dunction
71  freq_response->setFilter(m_filter);
72 
73  // initialize the controls and the curve display
74  slider->setValue(Kwave::toInt(m_frequency));
75  spinbox->setValue(Kwave::toInt(m_frequency));
76  updateDisplay();
77 
78  // changes in the slider or spinbox
79  connect(spinbox, SIGNAL(valueChanged(int)),
80  this, SLOT(valueChanged(int)));
81  // click to the "Listen" button
82  connect(btListen, SIGNAL(toggled(bool)),
83  this, SLOT(listenToggled(bool)));
84 
85  // expand the "Listen" button to it's maximum width
86  listenToggled(true);
87  if (btListen->width() > btListen->minimumWidth())
88  btListen->setMinimumWidth(btListen->width());
89  listenToggled(false);
90  if (btListen->width() > btListen->minimumWidth())
91  btListen->setMinimumWidth(btListen->width());
92 
93  // set the initial size of the dialog
94  int h = (width() * 3) / 5;
95  if (height() < h) resize(width(), h);
96  int w = (height() * 5) / 3;
97  if (width() < w) resize(w, height());
98 
99  connect(buttonBox_Help->button(QDialogButtonBox::Help), SIGNAL(clicked()),
100  this, SLOT(invokeHelp()));
101 
102  // set the focus onto the "OK" button
103  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
104 }
105 
106 //***************************************************************************
108 {
109  // better stop pre-listen now
110  listenToggled(false);
111 
112  if (freq_response) freq_response->setFilter(Q_NULLPTR);
113  if (m_filter) delete m_filter;
114 }
115 
116 //***************************************************************************
118 {
119  if (Kwave::toInt(m_frequency) != pos) {
120  m_frequency = pos;
121  updateDisplay();
122 
123  emit changed(m_frequency);
124  }
125 }
126 
127 //***************************************************************************
129 {
130  QStringList list;
131  list << QString::number(m_frequency);
132  return list;
133 }
134 
135 //***************************************************************************
137 {
138  // evaluate the parameter list
139  bool ok;
140  double frequency = params[0].toDouble(&ok);
141  Q_ASSERT(ok);
142  if (ok) m_frequency = frequency;
143 
144  slider->setValue(Kwave::toInt(m_frequency));
145  spinbox->setValue(Kwave::toInt(m_frequency));
146 
147  updateDisplay();
148 }
149 
150 //***************************************************************************
152 {
153  double fs = m_sample_rate;
154  if (m_filter && (fs > 0.0))
155  {
156  m_filter->setFrequency(QVariant(2.0 * M_PI * m_frequency / fs));
157  if (freq_response) freq_response->repaint();
158  }
159 }
160 
161 //***************************************************************************
163 {
164  Q_ASSERT(btListen);
165  if (!btListen) return;
166 
167  if (listen) {
168  // start pre-listen mode
169  emit startPreListen();
170  btListen->setText(i18n("&Stop"));
171  } else {
172  // stop pre-listen mode
173  emit stopPreListen();
174  btListen->setText(i18n("&Listen"));
175  }
176 }
177 
178 //***************************************************************************
180 {
181  if (!btListen) btListen->setChecked(false);
182 }
183 
184 //***************************************************************************
186 {
187  KHelpClient::invokeHelp(_("plugin_sect_lowpass"));
188 }
189 
190 //***************************************************************************
191 //***************************************************************************
virtual ~LowPassDialog() Q_DECL_OVERRIDE
Definition: App.h:33
void changed(double freq)
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
virtual void setParams(QStringList &params) Q_DECL_OVERRIDE
LowPassDialog(QWidget *parent, double sample_rate)
void valueChanged(int pos)
virtual QStringList params() Q_DECL_OVERRIDE
void setFrequency(const QVariant fc)
#define _(m)
Definition: memcpy.c:66
void listenToggled(bool listen)
Kwave::LowPassFilter * m_filter