kwave  18.07.70
Kwave::PitchShiftDialog Class Reference

#include <PitchShiftDialog.h>

Inheritance diagram for Kwave::PitchShiftDialog:
Inheritance graph
Collaboration diagram for Kwave::PitchShiftDialog:
Collaboration graph

Signals

void changed (double speed, double freq)
 
void startPreListen ()
 
void stopPreListen ()
 

Public Member Functions

 PitchShiftDialog (QWidget *parent)
 
virtual ~PitchShiftDialog () 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_FACTOR = 0, MODE_PERCENT = 1 }
 

Protected Slots

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

Protected Member Functions

void setMode (Mode mode)
 
void updateSpeed (double speed)
 

Private Slots

void invokeHelp ()
 

Private Attributes

double m_speed
 
double m_frequency
 
Mode m_mode
 
bool m_enable_updates
 

Detailed Description

Definition at line 35 of file PitchShiftDialog.h.

Member Enumeration Documentation

◆ Mode

Mode for amplification selection by factor (x1, x2, x5,...) or by percentage

Enumerator
MODE_FACTOR 
MODE_PERCENT 

Definition at line 108 of file PitchShiftDialog.h.

Constructor & Destructor Documentation

◆ PitchShiftDialog()

Kwave::PitchShiftDialog::PitchShiftDialog ( QWidget *  parent)
explicit

Constructor

Definition at line 37 of file PitchShiftDialog.cpp.

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

38  :QDialog(parent), Ui::PitchShiftDlg(), Kwave::PluginSetupDialog(),
40  m_enable_updates(true)
41 {
42  setupUi(this);
43  setModal(true);
44 
45  setMode(m_mode);
46 
47  // process changed in mode selection
48  connect(rbFactor, SIGNAL(toggled(bool)),
49  this, SLOT(modeChanged(bool)));
50  connect(rbPercentage, SIGNAL(toggled(bool)),
51  this, SLOT(modeChanged(bool)));
52 
53  // changes in the speed slider or spinbox
54  connect(slSpeed, SIGNAL(valueChanged(int)),
55  this, SLOT(sliderChanged(int)));
56  connect(sbSpeed, SIGNAL(valueChanged(int)),
57  this, SLOT(spinboxChanged(int)));
58 
59  // changes in the frequency spinbox
60  connect(sbFrequency, SIGNAL(valueChanged(int)),
61  this, SLOT(frequencyChanged(int)));
62 
63  // click to the "Listen" button
64  connect(btListen, SIGNAL(toggled(bool)),
65  this, SLOT(listenToggled(bool)));
66 
67  // expand the "Listen" button to it's maximum width
68  listenToggled(true);
69  if (btListen->width() > btListen->minimumWidth())
70  btListen->setMinimumWidth(btListen->width());
71  listenToggled(false);
72  if (btListen->width() > btListen->minimumWidth())
73  btListen->setMinimumWidth(btListen->width());
74 
75  // set the initial size of the dialog
76  setFixedHeight(sizeHint().height());
77  int w = (height() * 3) / 5;
78  if (width() < w) resize(w, height());
79 
80  connect(btHelp->button(QDialogButtonBox::Help), SIGNAL(clicked()),
81  this, SLOT(invokeHelp()));
82 
83  // set the focus onto the "OK" button
84  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
85 }
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void listenToggled(bool listen)
Here is the call graph for this function:

◆ ~PitchShiftDialog()

Kwave::PitchShiftDialog::~PitchShiftDialog ( )
virtual

Destructor

Definition at line 88 of file PitchShiftDialog.cpp.

References listenToggled().

89 {
90  // better stop pre-listen now
91  listenToggled(false);
92 }
void listenToggled(bool listen)
Here is the call graph for this function:

Member Function Documentation

◆ changed

void Kwave::PitchShiftDialog::changed ( double  speed,
double  freq 
)
signal

Emitted whenever the speed or the frequency changes

Parameters
speedthe speed factor, floating point
freqthe frequency parameter in Hz

Referenced by dialog(), frequencyChanged(), sliderChanged(), and spinboxChanged().

Here is the caller graph for this function:

◆ dialog()

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

retruns a pointer to this as a QDialog

Implements Kwave::PluginSetupDialog.

Definition at line 55 of file PitchShiftDialog.h.

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

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

◆ frequencyChanged

void Kwave::PitchShiftDialog::frequencyChanged ( int  pos)
protectedslot

called if the frequency sbinbox value has changed

Definition at line 276 of file PitchShiftDialog.cpp.

References changed(), m_frequency, and m_speed.

Referenced by dialog(), and PitchShiftDialog().

277 {
278  // emit changes
279  if (!qFuzzyCompare(m_frequency, pos)) {
280  m_frequency = pos;
281  emit changed(m_speed, m_frequency);
282  }
283 }
void changed(double speed, double freq)
Here is the caller graph for this function:

◆ invokeHelp

void Kwave::PitchShiftDialog::invokeHelp ( )
privateslot

invoke the online help

Definition at line 344 of file PitchShiftDialog.cpp.

References _.

Referenced by dialog(), and PitchShiftDialog().

345 {
346  KHelpClient::invokeHelp(_("plugin_sect_pitch_shift"));
347 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ listenStopped

void Kwave::PitchShiftDialog::listenStopped ( )
protectedslot

called when the pre-listen mode stopped/aborted

Definition at line 334 of file PitchShiftDialog.cpp.

Referenced by dialog().

335 {
336  Q_ASSERT(btListen);
337  if (!btListen) return;
338 
339  btListen->setChecked(false);
340 }
Here is the caller graph for this function:

◆ listenToggled

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

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

Definition at line 317 of file PitchShiftDialog.cpp.

References startPreListen(), and stopPreListen().

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

318 {
319  Q_ASSERT(btListen);
320  if (!btListen) return;
321 
322  if (listen) {
323  // start pre-listen mode
324  emit startPreListen();
325  btListen->setText(i18n("&Stop"));
326  } else {
327  // stop pre-listen mode
328  emit stopPreListen();
329  btListen->setText(i18n("&Listen"));
330  }
331 }
Here is the caller graph for this function:

◆ modeChanged

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

called when the mode radio buttons changed

Definition at line 138 of file PitchShiftDialog.cpp.

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

Referenced by dialog(), and PitchShiftDialog().

139 {
140  bool old_enable_updates = m_enable_updates;
141  m_enable_updates = false;
142 
143  if (rbFactor->isChecked()) setMode(MODE_FACTOR);
144  if (rbPercentage->isChecked()) setMode(MODE_PERCENT);
145 
146  m_enable_updates = old_enable_updates;
147 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ params()

QStringList Kwave::PitchShiftDialog::params ( )
virtual

Returns the parameters as string list

Implements Kwave::PluginSetupDialog.

Definition at line 286 of file PitchShiftDialog.cpp.

References m_frequency, m_mode, and m_speed.

287 {
288  QStringList list;
289  list << QString::number(m_speed);
290  list << QString::number(m_frequency);
291  list << QString::number(static_cast<int>(m_mode));
292  return list;
293 }

◆ setMode()

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

Sets a new volume selection mode

Definition at line 95 of file PitchShiftDialog.cpp.

References m_enable_updates, m_mode, m_speed, MODE_FACTOR, MODE_PERCENT, and updateSpeed().

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

96 {
97  double speed = m_speed;
98  m_mode = mode;
99  bool old_enable_updates = m_enable_updates;
100  m_enable_updates = false;
101 
102  switch (m_mode) {
103  case MODE_FACTOR: {
104  rbFactor->setChecked(true);
105 
106  slSpeed->setMinimum(-9);
107  slSpeed->setMaximum(+4);
108  slSpeed->setPageStep(1);
109  slSpeed->setTickInterval(1);
110 
111  sbSpeed->setMinimum(-10);
112  sbSpeed->setMaximum(+10);
113  sbSpeed->setSingleStep(1);
114  break;
115  }
116  case MODE_PERCENT: {
117  rbPercentage->setChecked(true);
118 
119  slSpeed->setMinimum(1);
120  slSpeed->setMaximum(400);
121  slSpeed->setPageStep(10);
122  slSpeed->setTickInterval(50);
123 
124  sbSpeed->setMinimum(1);
125  sbSpeed->setMaximum(400);
126  sbSpeed->setSingleStep(1);
127  break;
128  }
129  }
130 
131  // update the spped value in the display
132  m_speed = speed;
134  m_enable_updates = old_enable_updates;
135 }
void updateSpeed(double speed)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setParams()

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

Sets the from a list of parameters

Implements Kwave::PluginSetupDialog.

Definition at line 296 of file PitchShiftDialog.cpp.

References m_frequency, m_mode, m_speed, MODE_FACTOR, MODE_PERCENT, setMode(), and updateSpeed().

297 {
298  // evaluate the parameter list
299  double speed = params[0].toDouble();
300  m_frequency = params[1].toDouble();
301  switch (params[2].toUInt()) {
302  case 0: m_mode = MODE_FACTOR; break;
303  case 1: m_mode = MODE_PERCENT; break;
304  default: m_mode = MODE_PERCENT;
305  }
306 
307  // update mode, using default factor 1.0
308  m_speed = 1.0; // works with every mode
309  setMode(m_mode);
310 
311  // update speed factor
312  m_speed = speed;
313  updateSpeed(speed);
314 }
virtual QStringList params() Q_DECL_OVERRIDE
void updateSpeed(double speed)
Here is the call graph for this function:

◆ sliderChanged

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

called when the speed slider's position has changed

Definition at line 209 of file PitchShiftDialog.cpp.

References changed(), m_enable_updates, m_frequency, m_mode, m_speed, MODE_FACTOR, MODE_PERCENT, spinboxChanged(), and updateSpeed().

Referenced by dialog(), and PitchShiftDialog().

210 {
211  if (!m_enable_updates) return;
212 
213  double last_speed = m_speed;
214 
215  switch (m_mode) {
216  case MODE_FACTOR: {
217  // -1 <=> /2
218  // 0 <=> x1
219  // +1 <=> x2
220  if (pos >= 0) {
221  m_speed = (pos + 1);
222  } else {
223  m_speed = -1.0 / static_cast<double>(pos - 1);
224  }
226  break;
227  }
228  case MODE_PERCENT:
229  spinboxChanged(pos);
230  break;
231  }
232 
233  // emit changes
234  if (!qFuzzyCompare(m_speed, last_speed)) {
235  emit changed(m_speed, m_frequency);
236  }
237 }
void changed(double speed, double freq)
void updateSpeed(double speed)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinboxChanged

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

called when the spped spinbox value has changed

Definition at line 240 of file PitchShiftDialog.cpp.

References changed(), m_enable_updates, m_frequency, m_mode, m_speed, MODE_FACTOR, MODE_PERCENT, and updateSpeed().

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

241 {
242  if (!m_enable_updates) return;
243 
244  double last_speed = m_speed;
245  int sv = sbSpeed->value();
246  switch (m_mode) {
247  case MODE_FACTOR: {
248  // multiply or divide by factor
249  // -1 <=> /2
250  // 0 <=> x1
251  // +1 <=> x2
252  if (m_speed >= 1) {
253  m_speed = sv ? sv : 0.5;
254  } else {
255  if (!sv) sv = 1;
256  m_speed = 1.0 / static_cast<double>(sv);
257  }
258  break;
259  }
260  case MODE_PERCENT: {
261  // percentage
262  m_speed = static_cast<double>(pos) / 100.0;
263  break;
264  }
265  }
266 
267  // emit changes
268  if (!qFuzzyCompare(m_speed, last_speed)) {
269  emit changed(m_speed, m_frequency);
270  }
271 
273 }
void changed(double speed, double freq)
void updateSpeed(double speed)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startPreListen

void Kwave::PitchShiftDialog::startPreListen ( )
signal

Pre-listen mode has been started

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ stopPreListen

void Kwave::PitchShiftDialog::stopPreListen ( )
signal

Pre-listen mode has been stopped

Referenced by dialog(), and listenToggled().

Here is the caller graph for this function:

◆ updateSpeed()

void Kwave::PitchShiftDialog::updateSpeed ( double  speed)
protected

Update the speed slider position and the speed spinbox value

Definition at line 150 of file PitchShiftDialog.cpp.

References _, m_enable_updates, m_mode, m_speed, MODE_FACTOR, MODE_PERCENT, and Kwave::toInt().

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

151 {
152  int new_spinbox_value = 0;
153  int new_slider_value = 0;
154  bool old_enable_updates = m_enable_updates;
155  m_enable_updates = false;
156 
157  switch (m_mode) {
158  case MODE_FACTOR: {
159  // -1 => /2
160  // 0 => x1
161  // +1 => x2
162  if (Kwave::toInt(m_speed) >= 1) {
163  // greater or equal to one -> multiply
164  int new_value = Kwave::toInt(speed);
165  sbSpeed->setPrefix(_("x "));
166  sbSpeed->setSuffix(_(""));
167  sbSpeed->setInverse(false);
168 
169  new_spinbox_value = new_value;
170  new_slider_value = new_value-1;
171  } else {
172  // less than one -> divide
173  int new_value = Kwave::toInt(-1.0 / speed);
174 
175  sbSpeed->setPrefix(_("1/"));
176  sbSpeed->setSuffix(_(""));
177  sbSpeed->setInverse(true);
178 
179  new_spinbox_value = -1*new_value;
180  new_slider_value = (new_value+1);
181  }
182 
183  m_enable_updates = old_enable_updates;
184  break;
185  }
186  case MODE_PERCENT: {
187  // factor 1.0 means 100%
188  new_spinbox_value = Kwave::toInt(rint(speed * 100.0));
189  new_slider_value = new_spinbox_value;
190  sbSpeed->setPrefix(_(""));
191  sbSpeed->setSuffix(_("%"));
192  sbSpeed->setInverse(false);
193  break;
194  }
195  }
196 
197  // update the spinbox
198  if (sbSpeed->value() != new_spinbox_value)
199  sbSpeed->setValue(new_spinbox_value);
200 
201  // update the slider
202  if (slSpeed->value() != new_slider_value)
203  slSpeed->setValue(new_slider_value);
204 
205  m_enable_updates = old_enable_updates;
206 }
int toInt(T x)
Definition: Utils.h:127
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_enable_updates

bool Kwave::PitchShiftDialog::m_enable_updates
private

if false, ignore the signals of slider and spinbox

Definition at line 131 of file PitchShiftDialog.h.

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

◆ m_frequency

double Kwave::PitchShiftDialog::m_frequency
private

base frequency,

See also
aRts documentation

Definition at line 125 of file PitchShiftDialog.h.

Referenced by frequencyChanged(), params(), setParams(), sliderChanged(), and spinboxChanged().

◆ m_mode

Mode Kwave::PitchShiftDialog::m_mode
private

mode for selecting speed (factor or percentage)

Definition at line 128 of file PitchShiftDialog.h.

Referenced by params(), PitchShiftDialog(), setMode(), setParams(), sliderChanged(), spinboxChanged(), and updateSpeed().

◆ m_speed

double Kwave::PitchShiftDialog::m_speed
private

speed factor

Definition at line 122 of file PitchShiftDialog.h.

Referenced by frequencyChanged(), params(), setMode(), setParams(), sliderChanged(), spinboxChanged(), and updateSpeed().


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