[3b672c]: plugins / goto / GotoPluginBase.cpp Maximize Restore History

Download this file

GotoPluginBase.cpp    141 lines (116 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
GotoPluginBase.cpp - base class for the goto plugin
-------------------
begin : Thu May 12 2011
copyright : (C) 2011 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include <errno.h>
#include <math.h>
#include <QDialog>
#include <QString>
#include <klocale.h>
#include "libkwave/Plugin.h"
#include "libkwave/PluginManager.h"
#include "libkwave/SignalManager.h"
#include "GotoPluginBase.h"
#include "GotoDialog.h"
//***************************************************************************
GotoPluginBase::GotoPluginBase(const PluginContext &c)
:Kwave::Plugin(c), m_mode(SelectTimeWidget::bySamples), m_position(0)
{
}
//***************************************************************************
GotoPluginBase::~GotoPluginBase()
{
}
//***************************************************************************
QStringList *GotoPluginBase::setup(QStringList &previous_params)
{
// try to interprete the previous parameters
interpreteParameters(previous_params);
// create the setup dialog
double rate = signalRate();
sample_index_t length = signalLength();
GotoDialog *dialog = new GotoDialog(parentWidget(),
m_mode, m_position, rate, length);
Q_ASSERT(dialog);
if (!dialog) return 0;
// set the title of the dialog, depending on the derived class
dialog->setWindowTitle(title());
QStringList *list = new QStringList();
Q_ASSERT(list);
if (list && dialog->exec()) {
// user has pressed "OK"
*list << QString::number(dialog->mode());
*list << QString::number(dialog->pos());
emitCommand("plugin:execute(" + command() + "," +
QString::number(dialog->mode()) + "," +
QString::number(dialog->pos()) +
")"
);
} else {
// user pressed "Cancel"
if (list) delete list;
list = 0;
}
if (dialog) delete dialog;
return list;
}
//***************************************************************************
int GotoPluginBase::start(QStringList &params)
{
// interprete the parameters
int result = interpreteParameters(params);
if (result) return result;
// get current offset of the signal
sample_index_t offset = SelectTimeWidget::timeToSamples(
m_mode, m_position, signalRate(), signalLength());
// change the selection through the signal manager
QString cmd = "nomacro:" + command() + "(%1)";
emitCommand(cmd.arg(offset));
return result;
}
//***************************************************************************
int GotoPluginBase::interpreteParameters(QStringList &params)
{
bool ok;
QString param;
int mode;
// evaluate the parameter list
if (params.count() != 2)
return -EINVAL;
// selection mode for start
param = params[0];
mode = param.toInt(&ok);
Q_ASSERT(ok);
if (!ok) return -EINVAL;
Q_ASSERT((mode == static_cast<int>(SelectTimeWidget::byTime)) ||
(mode == static_cast<int>(SelectTimeWidget::bySamples)) ||
(mode == static_cast<int>(SelectTimeWidget::byPercents)));
if ((mode != static_cast<int>(SelectTimeWidget::byTime)) &&
(mode != static_cast<int>(SelectTimeWidget::bySamples)) &&
(mode != static_cast<int>(SelectTimeWidget::byPercents)))
{
return -EINVAL;
}
m_mode = static_cast<SelectTimeWidget::Mode>(mode);
// position in ms, samples or percent
param = params[1];
m_position = param.toUInt(&ok);
if (!ok) return -EINVAL;
return 0;
}
//***************************************************************************
#include "GotoPluginBase.moc"
//***************************************************************************
//***************************************************************************