kwave  18.07.70
Kwave::NoiseDialog Class Reference

#include <NoiseDialog.h>

Inheritance diagram for Kwave::NoiseDialog:
Inheritance graph
Collaboration diagram for Kwave::NoiseDialog:
Collaboration graph

Signals

void levelChanged (double level)
 
void startPreListen ()
 
void stopPreListen ()
 

Public Member Functions

 NoiseDialog (QWidget *parent, Kwave::OverViewCache *overview_cache)
 
virtual ~NoiseDialog () 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 Types

enum  Mode { MODE_PERCENT = 0, MODE_DECIBEL = 1 }
 

Protected Slots

void modeChanged (bool)
 
void sliderChanged (int pos)
 
void spinboxChanged (int pos)
 
void listenToggled (bool listen)
 
void listenStopped ()
 

Protected Member Functions

void setMode (Mode mode)
 
void updateDisplay (double value)
 

Private Slots

void invokeHelp ()
 

Private Attributes

double m_noise
 
Mode m_mode
 
bool m_enable_updates
 
Kwave::OverViewCachem_overview_cache
 

Detailed Description

Definition at line 37 of file NoiseDialog.h.

Member Enumeration Documentation

◆ Mode

enum Kwave::NoiseDialog::Mode
protected

Mode for amplification selection by percentage or by decibel

Enumerator
MODE_PERCENT 
MODE_DECIBEL 

Definition at line 106 of file NoiseDialog.h.

Constructor & Destructor Documentation

◆ NoiseDialog()

Kwave::NoiseDialog::NoiseDialog ( QWidget *  parent,
Kwave::OverViewCache overview_cache 
)

Constructor

Definition at line 44 of file NoiseDialog.cpp.

References Kwave::connect(), invokeHelp(), listenToggled(), m_mode, modeChanged(), setMode(), sliderChanged(), spinboxChanged(), and updateDisplay().

46  :QDialog(parent), Kwave::PluginSetupDialog(), Ui::NoiseDlg(),
48  m_enable_updates(true), m_overview_cache(overview_cache)
49 {
50  setupUi(this);
51  setModal(true);
52 
53  // process changed in mode selection
54  connect(rbPercentage, SIGNAL(toggled(bool)),
55  this, SLOT(modeChanged(bool)));
56  connect(rbLogarithmic, SIGNAL(toggled(bool)),
57  this, SLOT(modeChanged(bool)));
58 
59  // changes in the slider or spinbox
60  connect(slider, SIGNAL(valueChanged(int)),
61  this, SLOT(sliderChanged(int)));
62  connect(spinbox, SIGNAL(valueChanged(int)),
63  this, SLOT(spinboxChanged(int)));
64  // click to the "Listen" button
65  connect(btListen, SIGNAL(toggled(bool)),
66  this, SLOT(listenToggled(bool)));
67 
68  // force activation of the layout
69  layout()->activate();
70 
71  // give the preview image a odd height, for better symmetry
72  int h = preview->height();
73  if (~h & 1) h++;
74  preview->setFixedHeight(h);
75 
76  // expand the "Listen" button to it's maximum width
77  listenToggled(true);
78  if (btListen->width() > btListen->minimumWidth())
79  btListen->setMinimumWidth(btListen->width());
80  listenToggled(false);
81  if (btListen->width() > btListen->minimumWidth())
82  btListen->setMinimumWidth(btListen->width());
83 
84  // set the initial size of the dialog
85  h = (sizeHint().height() * 12) / 10;
86  int w = (3 * h) / 4;
87  if (sizeHint().width() > w) w = sizeHint().width();
88  setFixedSize(w, h);
89 
90  // set default: 10%
91  setMode(m_mode);
92  updateDisplay(+0.1);
93 
94  connect(buttonBox_Help->button(QDialogButtonBox::Help), SIGNAL(clicked()),
95  this, SLOT(invokeHelp()));
96 
97  // set the focus onto the "OK" button
98  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
99 }
void updateDisplay(double value)
void modeChanged(bool)
void setMode(Mode mode)
void listenToggled(bool listen)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
Kwave::OverViewCache * m_overview_cache
Definition: NoiseDialog.h:131
void spinboxChanged(int pos)
void sliderChanged(int pos)
Here is the call graph for this function:

◆ ~NoiseDialog()

Kwave::NoiseDialog::~NoiseDialog ( )
virtual

Destructor

Definition at line 102 of file NoiseDialog.cpp.

References listenToggled(), and m_overview_cache.

103 {
104  // better stop pre-listen now
105  listenToggled(false);
106 
107  delete m_overview_cache;
108  m_overview_cache = Q_NULLPTR;
109 }
void listenToggled(bool listen)
Kwave::OverViewCache * m_overview_cache
Definition: NoiseDialog.h:131
Here is the call graph for this function:

Member Function Documentation

◆ dialog()

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

retruns a pointer to this as a QDialog

Implements Kwave::PluginSetupDialog.

Definition at line 57 of file NoiseDialog.h.

References invokeHelp(), levelChanged(), listenStopped(), listenToggled(), modeChanged(), sliderChanged(), spinboxChanged(), startPreListen(), and stopPreListen().

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

◆ invokeHelp

void Kwave::NoiseDialog::invokeHelp ( )
privateslot

invoke the online help

Definition at line 376 of file NoiseDialog.cpp.

References _.

Referenced by dialog(), and NoiseDialog().

377 {
378  KHelpClient::invokeHelp(_("plugin_sect_noise"));
379 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ levelChanged

void Kwave::NoiseDialog::levelChanged ( double  level)
signal

Emitted whenever the noise level changes

Parameters
levelthe noise level [0 .. 1.0]

Referenced by dialog(), and updateDisplay().

Here is the caller graph for this function:

◆ listenStopped

void Kwave::NoiseDialog::listenStopped ( )
protectedslot

called when the pre-listen mode stopped/aborted

Definition at line 370 of file NoiseDialog.cpp.

Referenced by dialog().

371 {
372  if (btListen) btListen->setChecked(false);
373 }
Here is the caller graph for this function:

◆ listenToggled

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

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

Definition at line 353 of file NoiseDialog.cpp.

References startPreListen(), and stopPreListen().

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

354 {
355  Q_ASSERT(btListen);
356  if (!btListen) return;
357 
358  if (listen) {
359  // start pre-listen mode
360  emit startPreListen();
361  btListen->setText(i18n("&Stop"));
362  } else {
363  // stop pre-listen mode
364  emit stopPreListen();
365  btListen->setText(i18n("&Listen"));
366  }
367 }
Here is the caller graph for this function:

◆ modeChanged

void Kwave::NoiseDialog::modeChanged ( bool  )
protectedslot

called when the mode radio buttons changed

Definition at line 150 of file NoiseDialog.cpp.

References m_enable_updates, MODE_DECIBEL, MODE_PERCENT, and setMode().

Referenced by dialog(), and NoiseDialog().

151 {
152  bool old_enable_updates = m_enable_updates;
153  m_enable_updates = false;
154 
155  if (rbPercentage->isChecked()) setMode(MODE_PERCENT);
156  if (rbLogarithmic->isChecked()) setMode(MODE_DECIBEL);
157 
158  m_enable_updates = old_enable_updates;
159 }
void setMode(Mode mode)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ params()

QStringList Kwave::NoiseDialog::params ( )
virtual

Returns the parameters as string list

Implements Kwave::PluginSetupDialog.

Definition at line 323 of file NoiseDialog.cpp.

References m_mode, and m_noise.

324 {
325  QStringList list;
326  list << QString::number(m_noise);
327  list << QString::number(static_cast<int>(m_mode));
328  return list;
329 }

◆ setMode()

void Kwave::NoiseDialog::setMode ( Mode  mode)
protected

Sets a new volume selection mode

Definition at line 112 of file NoiseDialog.cpp.

References m_enable_updates, m_mode, m_noise, MODE_DECIBEL, MODE_PERCENT, and updateDisplay().

Referenced by modeChanged(), NoiseDialog(), and setParams().

113 {
114  double value = m_noise;
115  m_mode = mode;
116  bool old_enable_updates = m_enable_updates;
117  m_enable_updates = false;
118 
119  switch (m_mode) {
120  case MODE_PERCENT: {
121  rbPercentage->setChecked(true);
122 
123  slider->setMinimum(1);
124  slider->setMaximum(100);
125  slider->setPageStep(100);
126  slider->setTickInterval(10);
127  spinbox->setMinimum(1);
128  spinbox->setMaximum(100);
129  break;
130  }
131  case MODE_DECIBEL: {
132  rbLogarithmic->setChecked(true);
133 
134  slider->setMinimum(-21);
135  slider->setMaximum(0);
136  slider->setPageStep(6);
137  slider->setTickInterval(3);
138  spinbox->setMinimum(-21);
139  spinbox->setMaximum(0);
140  break;
141  }
142  }
143 
144  // update the value in the display
145  updateDisplay(value);
146  m_enable_updates = old_enable_updates;
147 }
void updateDisplay(double value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setParams()

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

Sets the from a list of parameters

Implements Kwave::PluginSetupDialog.

Definition at line 332 of file NoiseDialog.cpp.

References m_mode, m_noise, MODE_DECIBEL, MODE_PERCENT, setMode(), and updateDisplay().

333 {
334  // evaluate the parameter list
335  double factor = params[0].toDouble();
336  factor = qBound<double>(0.0, factor, 1.0);
337 
338  switch (params[1].toUInt()) {
339  case 0: m_mode = MODE_PERCENT; break;
340  case 1: m_mode = MODE_DECIBEL; break;
341  default: m_mode = MODE_DECIBEL;
342  }
343 
344  // update mode, using default factor 1.0
345  m_noise = 1.0; // works with every mode
346  setMode(m_mode);
347 
348  // update factor
349  updateDisplay(factor);
350 }
void updateDisplay(double value)
void setMode(Mode mode)
virtual QStringList params() Q_DECL_OVERRIDE
Here is the call graph for this function:

◆ sliderChanged

void Kwave::NoiseDialog::sliderChanged ( int  pos)
protectedslot

called when the slider's position has changed

Definition at line 293 of file NoiseDialog.cpp.

References m_enable_updates, and spinboxChanged().

Referenced by dialog(), and NoiseDialog().

294 {
295  if (!m_enable_updates) return;
296 
297  int sv = slider->maximum() + slider->minimum() - pos;
298  spinboxChanged(sv);
299 }
void spinboxChanged(int pos)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinboxChanged

void Kwave::NoiseDialog::spinboxChanged ( int  pos)
protectedslot

called when the spinbox value has changed

Definition at line 302 of file NoiseDialog.cpp.

References m_enable_updates, m_mode, m_noise, MODE_DECIBEL, MODE_PERCENT, and updateDisplay().

Referenced by dialog(), NoiseDialog(), and sliderChanged().

303 {
304  if (!m_enable_updates) return;
305 
306  double factor = m_noise;
307 
308  switch (m_mode) {
309  case MODE_PERCENT:
310  // percentage
311  factor = static_cast<double>(pos) / 100.0;
312  break;
313  case MODE_DECIBEL:
314  // decibel
315  factor = pow(10.0, pos / 20.0);
316  break;
317  }
318 
319  updateDisplay(factor);
320 }
void updateDisplay(double value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startPreListen

void Kwave::NoiseDialog::startPreListen ( )
signal

Pre-listen mode has been started

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ stopPreListen

void Kwave::NoiseDialog::stopPreListen ( )
signal

Pre-listen mode has been stopped

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ updateDisplay()

void Kwave::NoiseDialog::updateDisplay ( double  value)
protected

Update the slider position and the spinbox value

Definition at line 162 of file NoiseDialog.cpp.

References _, Kwave::Colors::ColorSet::background, Kwave::OverViewCache::getMinMax(), Kwave::Colors::ColorSet::interpolated, levelChanged(), m_enable_updates, m_mode, m_noise, m_overview_cache, MODE_DECIBEL, MODE_PERCENT, Kwave::Colors::Normal, Kwave::Colors::ColorSet::sample, sample2double(), Kwave::toInt(), and zero().

Referenced by NoiseDialog(), setMode(), setParams(), and spinboxChanged().

163 {
164  int new_spinbox_value = 0;
165  int new_slider_value = 0;
166  bool old_enable_updates = m_enable_updates;
167  m_enable_updates = false;
168 
170 
171  if (!qFuzzyCompare(m_noise, value)) {
172 
173  // take over the new factor
174  m_noise = value;
175 
176  // update the preview widget
177  if (m_overview_cache && preview) {
178  int width = preview->width();
179  int height = preview->height();
180  QColor color_bg = Kwave::Colors::Normal.background;
181  QColor color_sig = Kwave::Colors::Normal.interpolated;
182  QColor color_noise = Kwave::Colors::Normal.sample;
183 
184  // get the min/max information
185  int count = m_overview_cache->getMinMax(width, m_minmax);
186 
187  QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
188  QPainter p;
189  p.begin(&image);
190  p.fillRect(image.rect(), color_bg);
191 
192  // calculate scaling factor and (noise level / 2) in pixel
193  const int middle = height >> 1;
194  const int noise_2 = Kwave::toInt(middle * m_noise);
195 
196  /*
197  * mixing of noise goes like this:
198  *
199  * y[t] = x[t] * (1 - n) + noise(t) * n;
200  *
201  * and has this effect on min/max:
202  *
203  * [---noise---] [---noise---]
204  * [min -------------------max]
205  * ^ ^ ^ ^ ^ ^
206  * | | | | | |
207  * y1 y2 y3 y4 y5 y6
208  */
209 
210  for (int x = 0; x < count; ++x) {
211  int y2 = Kwave::toInt((sample2double(m_minmax[x].min) *
212  (1.0 - m_noise)) * middle);
213  int y5 = Kwave::toInt((sample2double(m_minmax[x].max) *
214  (1.0 - m_noise)) * middle);
215  int y1 = y2 - noise_2;
216  int y3 = y2 + noise_2;
217  int y4 = y5 - noise_2;
218  int y6 = y5 + noise_2;
219 
220  if (y4 > y3) {
221  // noise around "min" [y1 ... y3]
222  p.setPen(color_noise);
223  p.drawLine(x, middle - y3, x, middle - y1);
224 
225  // noise around "max" [y4 ... y6]
226  p.drawLine(x, middle - y6, x, middle - y4);
227 
228  // original signal [y3 ... y4 ]
229  p.setPen(color_sig);
230  p.drawLine(x, middle - y4, x, middle - y3);
231  } else {
232  // only noise [y1 ... y6]
233  p.setPen(color_noise);
234  p.drawLine(x, middle - y6, x, middle - y1);
235  }
236  }
237 
238  // zero line
239  p.setCompositionMode(QPainter::CompositionMode_SourceOver);
240  p.setPen(Kwave::Colors::Normal.zero);
241  p.drawLine(0, middle, width - 1, middle);
242 
243  p.end();
244 
245  // update the image view
246  preview->setImage(image);
247  }
248 
249  // emit the noise level change to the plugin
250  emit levelChanged(m_noise);
251  }
252 
253  switch (m_mode) {
254  case MODE_PERCENT: {
255  // factor 1.0 means 100%
256  new_spinbox_value = Kwave::toInt(rint(value * 100.0));
257  new_slider_value = new_spinbox_value;
258  spinbox->setPrefix(_(""));
259  spinbox->setSuffix(_("%"));
260  spinbox->setInverse(false);
261  break;
262  }
263  case MODE_DECIBEL: {
264  // factor 1.0 means 0dB
265  if (!qFuzzyIsNull(value))
266  new_slider_value = Kwave::toInt(rint(20.0 * log10(value)));
267  else
268  new_slider_value = 0;
269  new_spinbox_value = new_slider_value;
270  if (new_spinbox_value >= 0) {
271  spinbox->setPrefix(new_spinbox_value ? _("+") : _("+/- "));
272  } else {
273  // negative value
274  spinbox->setPrefix(_(""));
275  }
276  spinbox->setSuffix(_(" ") + i18n("dB"));
277  spinbox->setInverse(false);
278  break;
279  }
280  }
281 
282  // update the spinbox
283  if (spinbox->value() != new_spinbox_value) spinbox->setValue(new_spinbox_value);
284 
285  // update the slider, it's inverse => top=maximum, bottom=minimum !
286  int sv = slider->maximum() + slider->minimum() - new_slider_value;
287  if (slider->value() != sv) slider->setValue(sv);
288 
289  m_enable_updates = old_enable_updates;
290 }
int getMinMax(int width, MinMaxArray &minmax)
Kwave::OverViewCache * m_overview_cache
Definition: NoiseDialog.h:131
QVector< MinMax > MinMaxArray
Definition: OverViewCache.h:60
int toInt(T x)
Definition: Utils.h:127
static double sample2double(const sample_t s)
Definition: Sample.h:73
#define _(m)
Definition: memcpy.c:66
static double zero(double)
Definition: Functions.cpp:83
static Q_DECL_EXPORT ColorSet Normal
Definition: Colors.h:49
void levelChanged(double level)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_enable_updates

bool Kwave::NoiseDialog::m_enable_updates
private

if false, ignore the signals of slider and spinbox

Definition at line 128 of file NoiseDialog.h.

Referenced by modeChanged(), setMode(), sliderChanged(), spinboxChanged(), and updateDisplay().

◆ m_mode

Mode Kwave::NoiseDialog::m_mode
private

current mode for noise level selection

Definition at line 125 of file NoiseDialog.h.

Referenced by NoiseDialog(), params(), setMode(), setParams(), spinboxChanged(), and updateDisplay().

◆ m_noise

double Kwave::NoiseDialog::m_noise
private

noise level, as a linear factor [0...1]

Definition at line 120 of file NoiseDialog.h.

Referenced by params(), setMode(), setParams(), spinboxChanged(), and updateDisplay().

◆ m_overview_cache

Kwave::OverViewCache* Kwave::NoiseDialog::m_overview_cache
private

overview cache for calculating the preview image

Definition at line 131 of file NoiseDialog.h.

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


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