kwave  18.07.70
NewSignalPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  NewSignalPlugin.cpp - plugin for creating a new signal
3  -------------------
4  begin : Wed Jul 18 2001
5  copyright : (C) 2001 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 
21 #include <QStringList>
22 
23 #include <KLocalizedString>
24 
25 #include "libkwave/String.h"
26 #include "libkwave/Utils.h"
27 
28 #include "NewSignalDialog.h"
29 #include "NewSignalPlugin.h"
30 
31 KWAVE_PLUGIN(newsignal, NewSignalPlugin)
32 
33 //***************************************************************************
35  const QVariantList &args)
36  :Kwave::Plugin(parent, args), m_samples(2646000), m_rate(44100),
37  m_bits(16), m_tracks(2), m_bytime(true)
38 {
39 }
40 
41 //***************************************************************************
43 {
44 }
45 
46 //***************************************************************************
48 {
49  bool ok;
50  QString param;
51 
52  // evaluate the parameter list
53  if (params.count() != 5) return -EINVAL;
54 
55  param = params[0];
56  m_samples = param.toUInt(&ok);
57  Q_ASSERT(ok);
58  if (!ok) return -EINVAL;
59 
60  param = params[1];
61  m_rate = Kwave::toUint(param.toDouble(&ok));
62  Q_ASSERT(ok);
63  if (!ok) return -EINVAL;
64 
65  param = params[2];
66  m_bits = param.toUInt(&ok);
67  Q_ASSERT(ok);
68  if (!ok) return -EINVAL;
69 
70  param = params[3];
71  m_tracks = param.toUInt(&ok);
72  Q_ASSERT(ok);
73  if (!ok) return -EINVAL;
74 
75  param = params[4];
76  m_bytime = (param.toUInt(&ok) != 0);
77  Q_ASSERT(ok);
78  if (!ok) return -EINVAL;
79 
80  return 0;
81 }
82 
83 //***************************************************************************
84 QStringList *Kwave::NewSignalPlugin::setup(QStringList &previous_params)
85 {
86  // try to interprete the previous parameters
87  interpreteParameters(previous_params);
88 
89  // create the setup dialog
92  Q_ASSERT(dialog);
93  if (!dialog) return Q_NULLPTR;
94 
95  QStringList *list = new QStringList();
96  Q_ASSERT(list);
97  if (list && dialog->exec()) {
98  // user has pressed "OK"
99  *list << QString::number(dialog->samples());
100  *list << QString::number(dialog->rate());
101  *list << QString::number(dialog->bitsPerSample());
102  *list << QString::number(dialog->tracks());
103  *list << _(dialog->byTime() ? "1" : "0");
104 
105  emitCommand(_("newsignal(") +
106  QString::number(dialog->samples()) + _(",") +
107  QString::number(dialog->rate()) + _(",") +
108  QString::number(dialog->bitsPerSample()) + _(",") +
109  QString::number(dialog->tracks()) + _(")")
110  );
111  } else {
112  // user pressed "Cancel"
113  if (list) delete list;
114  list = Q_NULLPTR;
115  }
116 
117  if (dialog) delete dialog;
118  return list;
119 }
120 
121 //***************************************************************************
122 #include "NewSignalPlugin.moc"
123 //***************************************************************************
124 //***************************************************************************
unsigned int bitsPerSample()
void emitCommand(const QString &command)
Definition: Plugin.cpp:510
Definition: App.h:33
virtual QStringList * setup(QStringList &previous_params) Q_DECL_OVERRIDE
int interpreteParameters(QStringList &params)
QWidget * parentWidget() const
Definition: Plugin.cpp:450
virtual ~NewSignalPlugin() Q_DECL_OVERRIDE
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
#define _(m)
Definition: memcpy.c:66
unsigned int toUint(T x)
Definition: Utils.h:109
sample_index_t samples()