kwave  18.07.70
PitchShiftPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  PitchShiftPlugin.cpp - plugin for modifying the "pitch_shift"
3  -------------------
4  begin : Sun Mar 23 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 <errno.h>
20 #include <math.h>
21 
22 #include <QStringList>
23 
24 #include <KLocalizedString>
25 
26 #include "PitchShiftDialog.h"
27 #include "PitchShiftFilter.h"
28 #include "PitchShiftPlugin.h"
30 
31 KWAVE_PLUGIN(pitch_shift, PitchShiftPlugin)
32 
33 //***************************************************************************
35  const QVariantList &args)
36  :Kwave::FilterPlugin(parent, args),
37  m_speed(1.0), m_frequency(5.0), m_percentage_mode(false),
38  m_last_speed(0), m_last_freq(0)
39 {
40 }
41 
42 //***************************************************************************
44 {
45 }
46 
47 //***************************************************************************
49 {
50  bool ok;
51  QString param;
52 
53  // evaluate the parameter list
54  if (params.count() != 3) return -EINVAL;
55 
56  param = params[0];
57  m_speed = param.toDouble(&ok);
58  Q_ASSERT(ok);
59  if (!ok) return -EINVAL;
60 
61  param = params[1];
62  m_frequency = param.toDouble(&ok);
63  Q_ASSERT(ok);
64  if (!ok) return -EINVAL;
65 
66  param = params[2];
67  m_percentage_mode = (param.toUInt(&ok));
68  Q_ASSERT(ok);
69  if (!ok) return -EINVAL;
70 
71  return 0;
72 }
73 
74 //***************************************************************************
76 {
78  Q_ASSERT(dialog);
79  if (!dialog) return Q_NULLPTR;
80 
81  // connect the signals for detecting value changes in pre-listen mode
82  connect(dialog, SIGNAL(changed(double,double)),
83  this, SLOT(setValues(double,double)));
84 
85  return dialog;
86 }
87 
88 //***************************************************************************
90 {
92 }
93 
94 //***************************************************************************
96 {
97  return (!qFuzzyCompare(m_speed, m_last_speed) ||
98  !qFuzzyCompare(m_frequency, m_last_freq));
99 }
100 
101 //***************************************************************************
103  bool force)
104 {
105  double sr = signalRate();
106 
107  if (!filter) return;
108 
109  if (!qFuzzyCompare(m_frequency, m_last_freq) || force)
110  filter->setAttribute(SLOT(setFrequency(QVariant)),
111  QVariant((m_frequency * 2.0 * M_PI) / sr));
112 
113  if (!qFuzzyCompare(m_speed, m_last_speed) || force)
114  filter->setAttribute(SLOT(setSpeed(QVariant)),
115  QVariant(m_speed));
116 
119 }
120 
121 //***************************************************************************
123 {
124  return i18n("Pitch Shift");
125 }
126 
127 //***************************************************************************
128 void Kwave::PitchShiftPlugin::setValues(double speed, double frequency)
129 {
130  m_frequency = frequency;
131  m_speed = speed;
132 }
133 
134 //***************************************************************************
135 #include "PitchShiftPlugin.moc"
136 //***************************************************************************
137 //***************************************************************************
virtual void updateFilter(Kwave::SampleSource *filter, bool force=false) Q_DECL_OVERRIDE
Definition: App.h:33
virtual ~PitchShiftPlugin() Q_DECL_OVERRIDE
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
virtual bool paramsChanged() Q_DECL_OVERRIDE
virtual Kwave::SampleSource * createFilter(unsigned int tracks) Q_DECL_OVERRIDE
virtual QString actionName() Q_DECL_OVERRIDE
virtual Kwave::PluginSetupDialog * createDialog(QWidget *parent) Q_DECL_OVERRIDE
virtual double signalRate()
Definition: Plugin.cpp:468
virtual int interpreteParameters(QStringList &params) Q_DECL_OVERRIDE
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
void setValues(double speed, double frequency)
void setAttribute(const char *attribute, const QVariant &value)