kwave  18.07.70
Kwave::Plugin Class Reference

#include <Plugin.h>

Inheritance diagram for Kwave::Plugin:
Inheritance graph
Collaboration diagram for Kwave::Plugin:
Collaboration graph

Public Slots

virtual void setProgressDialogEnabled (bool enable)
 
virtual void updateProgress (qreal progress)
 
virtual void cancel ()
 
virtual void close ()
 
void release ()
 

Signals

void sigRunning (Kwave::Plugin *plugin)
 
void sigDone (Kwave::Plugin *plugin)
 
void sigClosed (Kwave::Plugin *p)
 
void sigCommand (const QString &command)
 
void setProgressText (const QString &text)
 

Public Member Functions

 Plugin (QObject *parent, const QVariantList &args)
 
virtual ~Plugin () Q_DECL_OVERRIDE
 
virtual QString name () const
 
virtual QString description () const
 
virtual QString progressText ()
 
virtual bool canClose () const
 
bool isRunning () const
 
bool shouldStop () const
 
virtual void load (QStringList &params)
 
virtual void unload ()
 
virtual QStringList * setup (QStringList &previous_params)
 
virtual int start (QStringList &params)
 
virtual int stop ()
 
virtual void run (QStringList params)
 
Kwave::PluginManagermanager () const
 
Kwave::SignalManagersignalManager ()
 
QWidget * parentWidget () const
 
QString signalName ()
 
virtual sample_index_t signalLength ()
 
virtual double signalRate ()
 
virtual const QList< unsigned int > selectedTracks ()
 
virtual sample_index_t selection (QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
 
virtual void selectRange (sample_index_t offset, sample_index_t length)
 
virtual void migrateToActiveContext ()
 
- Public Member Functions inherited from Kwave::Runnable
virtual ~Runnable ()
 

Protected Member Functions

int execute (QStringList &params)
 
void emitCommand (const QString &command)
 
void use ()
 
void setPluginManager (Kwave::PluginManager *new_plugin_manager)
 
virtual void run_wrapper (const QVariant &params) Q_DECL_OVERRIDE
 

Private Slots

void closeProgressDialog (Kwave::Plugin *)
 
void updateProgressTick ()
 

Private Attributes

Kwave::PluginManagerm_plugin_manager
 
QString m_name
 
QString m_description
 
Kwave::WorkerThreadm_thread
 
QMutex m_thread_lock
 
bool m_progress_enabled
 
QAtomicInt m_stop
 
QProgressDialog * m_progress
 
Kwave::ConfirmCancelProxym_confirm_cancel
 
unsigned int m_usage_count
 
QMutex m_usage_lock
 
QTimer m_progress_timer
 
qreal m_current_progress
 
QMutex m_progress_lock
 

Friends

class Kwave::PluginManager
 
class Kwave::WorkerThread
 

Detailed Description

Generic class that should be used for all types of Kwave plugins. This interface is the only one that should be used, it provides all necessary functions to access the functionality of the main Kwave program.

Definition at line 75 of file Plugin.h.

Constructor & Destructor Documentation

◆ Plugin()

Kwave::Plugin::Plugin ( QObject *  parent,
const QVariantList &  args 
)

Constructor

Parameters
parentpointer to our plugin manager
argsargument list for initializing the plugin

Definition at line 71 of file Plugin.cpp.

References Kwave::connect(), m_plugin_manager, m_progress_timer, and updateProgressTick().

72  :QObject(Q_NULLPTR),
74  m_plugin_manager(qobject_cast<Kwave::PluginManager *>(parent)),
75  m_name(args[0].toString()),
76  m_description(args[1].toString()),
77  m_thread(Q_NULLPTR),
78  m_thread_lock(),
79  m_progress_enabled(true),
80  m_stop(0),
81  m_progress(Q_NULLPTR),
82  m_confirm_cancel(Q_NULLPTR),
83  m_usage_count(1),
84  m_usage_lock(),
87  m_progress_lock(QMutex::Recursive)
88 {
89  Q_ASSERT(m_plugin_manager);
90  connect(&m_progress_timer, SIGNAL(timeout()),
91  this, SLOT(updateProgressTick()),
92  Qt::DirectConnection);
93 }
QAtomicInt m_stop
Definition: Plugin.h:367
unsigned int m_usage_count
Definition: Plugin.h:379
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
QProgressDialog * m_progress
Definition: Plugin.h:370
QTimer m_progress_timer
Definition: Plugin.h:385
QString m_name
Definition: Plugin.h:350
QMutex m_usage_lock
Definition: Plugin.h:382
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
QMutex m_thread_lock
Definition: Plugin.h:361
QString m_description
Definition: Plugin.h:353
bool m_progress_enabled
Definition: Plugin.h:364
void updateProgressTick()
Definition: Plugin.cpp:281
Kwave::PluginManager * m_plugin_manager
Definition: Plugin.h:347
QMutex m_progress_lock
Definition: Plugin.h:391
Kwave::ConfirmCancelProxy * m_confirm_cancel
Definition: Plugin.h:376
qreal m_current_progress
Definition: Plugin.h:388
Here is the call graph for this function:

◆ ~Plugin()

Kwave::Plugin::~Plugin ( )
virtual

Destructor.

Definition at line 96 of file Plugin.cpp.

References close(), closeProgressDialog(), m_thread, m_thread_lock, m_usage_lock, and Kwave::WorkerThread::stop().

97 {
98  // inform our owner that we close. This allows the plugin to
99  // delete itself
100  close();
101 
102  // lock usage
103  QMutexLocker lock_usage(&m_usage_lock);
104  {
105  QMutexLocker lock_thread(&m_thread_lock);
106  if (m_thread) {
107  if (m_thread->isRunning()) m_thread->wait(5000);
108  if (m_thread->isRunning()) m_thread->stop();
109  if (m_thread->isRunning()) m_thread->wait(1000);
110  if (m_thread->isRunning()) {
111  // unable to stop the thread
112  qWarning("Kwave::Plugin::stop(): stale thread !");
113  }
114  delete m_thread;
115  m_thread = Q_NULLPTR;
116  }
117  }
118 
119  // finally get rid of the confirm/cancel proxy and the progress dialog
120  closeProgressDialog(this);
121 }
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
virtual void close()
Definition: Plugin.cpp:394
QMutex m_usage_lock
Definition: Plugin.h:382
QMutex m_thread_lock
Definition: Plugin.h:361
void closeProgressDialog(Kwave::Plugin *)
Definition: Plugin.cpp:293
virtual int stop(unsigned int timeout=10000)
Here is the call graph for this function:

Member Function Documentation

◆ cancel

void Kwave::Plugin::cancel ( )
virtualslot

called when the user has pressed "Cancel" in the progress dialog and also has confirmed the cancel confirmation message box.

Definition at line 325 of file Plugin.cpp.

References m_stop.

Referenced by start(), stop(), Kwave::PlayBackPlugin::testPlayBack(), and Kwave::SonagramPlugin::windowDestroyed().

326 {
327  m_stop = true;
328 }
QAtomicInt m_stop
Definition: Plugin.h:367
Here is the caller graph for this function:

◆ canClose()

bool Kwave::Plugin::canClose ( ) const
virtual

Returns true if the plugin can be closed. The default implementation returns "!isRunning()"

Definition at line 351 of file Plugin.cpp.

References isRunning().

352 {
353  return !isRunning();
354 }
bool isRunning() const
Definition: Plugin.cpp:357
Here is the call graph for this function:

◆ close

void Kwave::Plugin::close ( )
virtualslot

Called to close the plugin. This will be called from the plugin manager and can as well be used from inside the plugin if it wishes to close itself.

Definition at line 394 of file Plugin.cpp.

References closeProgressDialog(), m_thread, and stop().

Referenced by Kwave::SonagramPlugin::start(), Kwave::PlayBackPlugin::testPlayBack(), and ~Plugin().

395 {
396  // only call stop() if we are NOT in the worker thread / run function !
397  if (m_thread && m_thread->isRunning() &&
398  (QThread::currentThread() != m_thread) )
399  {
400  // check: this must be called from the GUI thread only!
401  Q_ASSERT(this->thread() == QThread::currentThread());
402  Q_ASSERT(this->thread() == qApp->thread());
403 
404  closeProgressDialog(this);
405  stop();
406  } else if ((QThread::currentThread() == m_thread)) {
407  qWarning("Kwave::Plugin::close -> called from worker thread?");
408  }
409 }
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
virtual int stop()
Definition: Plugin.cpp:214
void closeProgressDialog(Kwave::Plugin *)
Definition: Plugin.cpp:293
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeProgressDialog

void Kwave::Plugin::closeProgressDialog ( Kwave::Plugin )
privateslot

closes the progress dialog and the confirm/cancel proxy

Definition at line 293 of file Plugin.cpp.

References m_confirm_cancel, m_progress, m_progress_lock, and m_progress_timer.

Referenced by close(), start(), and ~Plugin().

294 {
295  // check: this must be called from the GUI thread only!
296  Q_ASSERT(this->thread() == QThread::currentThread());
297  Q_ASSERT(this->thread() == qApp->thread());
298 
299  QMutexLocker lock(&m_progress_lock);
300 
301  // stop the progress timer
302  m_progress_timer.stop();
303  m_progress_timer.disconnect();
304 
305  if (m_confirm_cancel) m_confirm_cancel->disconnect();
306  if (m_progress) m_progress->disconnect();
307 
308  // NOTE: as the progress dialog is *modal*, it is higly probable
309  // that this function is called from the context of the event
310  // loop that is provided by the progress dialog
311  // => deleting this object should be done somewhere later...
312  if (m_confirm_cancel) {
313  m_confirm_cancel->deleteLater();
314  m_confirm_cancel = Q_NULLPTR;
315  }
316 
317  if (m_progress) {
318  m_progress->done(0);
319  m_progress->deleteLater();
320  m_progress = Q_NULLPTR;
321  }
322 }
QProgressDialog * m_progress
Definition: Plugin.h:370
QTimer m_progress_timer
Definition: Plugin.h:385
QMutex m_progress_lock
Definition: Plugin.h:391
Kwave::ConfirmCancelProxy * m_confirm_cancel
Definition: Plugin.h:376
Here is the caller graph for this function:

◆ description()

QString Kwave::Plugin::description ( ) const
virtual

Returns the description of the plugin (already translated).

Definition at line 202 of file Plugin.cpp.

References m_description.

Referenced by Kwave::SaveBlocksPlugin::setup(), and Kwave::K3BExportPlugin::setup().

203 {
204  return m_description;
205 }
QString m_description
Definition: Plugin.h:353
Here is the caller graph for this function:

◆ emitCommand()

◆ execute()

int Kwave::Plugin::execute ( QStringList &  params)
protected

Gets called to execute the plugin's run function in a separate thread.

Parameters
paramslist of strings with parameters
Bug:
the return value is never evaluated

Definition at line 331 of file Plugin.cpp.

References m_stop, m_thread, m_thread_lock, Kwave::WorkerThread::start(), and use().

Referenced by Kwave::FilterPlugin::startPreListen(), and Kwave::PlayBackPlugin::testPlayBack().

332 {
333  QMutexLocker lock(&m_thread_lock);
334  m_stop = false;
335 
336  m_thread = new(std::nothrow) Kwave::WorkerThread(this, QVariant(params));
337  Q_ASSERT(m_thread);
338  if (!m_thread) return -ENOMEM;
339 
340  // increment the use count, it is decremented at the end of
341  // the run_wrapper when the thread is finished
342  use();
343 
344  // start the thread, this executes run()
345  m_thread->start();
346 
347  return 0;
348 }
QAtomicInt m_stop
Definition: Plugin.h:367
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
QMutex m_thread_lock
Definition: Plugin.h:361
virtual void start()
void use()
Definition: Plugin.cpp:412
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRunning()

bool Kwave::Plugin::isRunning ( ) const

Returns true if the plugin has a running thread.

Definition at line 357 of file Plugin.cpp.

References m_thread.

Referenced by canClose(), and Kwave::PlayBackPlugin::testPlayBack().

358 {
359  return (m_thread) && m_thread->isRunning();
360 }
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
Here is the caller graph for this function:

◆ load()

void Kwave::Plugin::load ( QStringList &  params)
virtual

Called after the plugin has been loaded into memory. This is useful for plugins that don't use start() and execute(), maybe for some persistent plugins like playback and record. The default implementation does nothing.

Reimplemented in Kwave::K3BExportPlugin, Kwave::PlayBackPlugin, Kwave::CodecPlugin, Kwave::MemoryPlugin, Kwave::DebugPlugin, Kwave::StringEnterPlugin, and Kwave::MP3CodecPlugin.

Definition at line 124 of file Plugin.cpp.

125 {
126 }

◆ manager()

◆ migrateToActiveContext()

void Kwave::Plugin::migrateToActiveContext ( )
virtual

Migrates this plugin instance to the currently active file context. This might be necessary for plugins that create a new file context and then expect that all operations are executed in the context of that new file context. Example: the record plugin creates a new context and does recording into that new created file context.

Definition at line 516 of file Plugin.cpp.

References manager(), and Kwave::PluginManager::migratePluginToActiveContext().

Referenced by Kwave::RecordPlugin::resetRecording(), and Kwave::RecordPlugin::startRecording().

517 {
519 }
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
void migratePluginToActiveContext(Kwave::Plugin *plugin)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

◆ parentWidget()

◆ progressText()

QString Kwave::Plugin::progressText ( )
virtual

Returns a text for the progress dialog if enabled. (already be localized)

Reimplemented in Kwave::FilterPlugin, and Kwave::AmplifyFreePlugin.

Definition at line 208 of file Plugin.cpp.

References name().

Referenced by start().

209 {
210  return i18n("Running plugin '%1'...", name());
211 }
virtual QString name() const
Definition: Plugin.cpp:196
Here is the call graph for this function:
Here is the caller graph for this function:

◆ release

void Kwave::Plugin::release ( )
slot

decrements the usage counter

Definition at line 420 of file Plugin.cpp.

References m_usage_count, m_usage_lock, and sigClosed().

Referenced by Kwave::PluginManager::pluginDone(), run_wrapper(), Kwave::PluginManager::setupPlugin(), Kwave::PlayBackPlugin::unload(), Kwave::CodecPlugin::unload(), and Kwave::SonagramPlugin::windowDestroyed().

421 {
422  bool finished = false;
423 
424  {
425  QMutexLocker lock(&m_usage_lock);
426  Q_ASSERT(m_usage_count);
427  if (m_usage_count) {
428  m_usage_count--;
429  if (!m_usage_count) finished = true;
430  }
431  }
432 
433  if (finished) emit sigClosed(this);
434 }
unsigned int m_usage_count
Definition: Plugin.h:379
QMutex m_usage_lock
Definition: Plugin.h:382
void sigClosed(Kwave::Plugin *p)
Here is the caller graph for this function:

◆ run()

void Kwave::Plugin::run ( QStringList  params)
virtual

Gets called from the plugin's execute function and should be overwritten to perform some action. This function runs in a separate thread!

Parameters
paramslist of strings with parameters
See also
sigDone

Reimplemented in Kwave::SonagramPlugin, Kwave::FilterPlugin, Kwave::PlayBackPlugin, Kwave::DebugPlugin, Kwave::NormalizePlugin, Kwave::AmplifyFreePlugin, Kwave::VolumePlugin, Kwave::ReversePlugin, Kwave::ZeroPlugin, and Kwave::SampleRatePlugin.

Definition at line 363 of file Plugin.cpp.

Referenced by run_wrapper().

364 {
365  Q_UNUSED(params);
366 }
Here is the caller graph for this function:

◆ run_wrapper()

void Kwave::Plugin::run_wrapper ( const QVariant &  params)
protectedvirtual

Wrapper for run() that contains a call to release()

Implements Kwave::Runnable.

Definition at line 369 of file Plugin.cpp.

References DBG, m_stop, name(), release(), run(), sigDone(), and sigRunning().

370 {
371  // signal that we are running
372  emit sigRunning(this);
373 
374  // start time measurement
375  QTime t;
376  t.start();
377 
378  // call the plugin's run function in this worker thread context
379  run(params.toStringList());
380 
381  // evaluate the elapsed time
382  double seconds = static_cast<double>(t.elapsed()) * 1E-3;
383  qDebug("plugin %s done, running for %0.03g seconds",
384  DBG(name()), seconds);
385 
386  // emit the "done" signal
387  emit sigDone(this);
388 
389  m_stop = false;
390  release();
391 }
QAtomicInt m_stop
Definition: Plugin.h:367
virtual QString name() const
Definition: Plugin.cpp:196
void release()
Definition: Plugin.cpp:420
void sigRunning(Kwave::Plugin *plugin)
void sigDone(Kwave::Plugin *plugin)
#define DBG(qs)
Definition: String.h:55
virtual void run(QStringList params)
Definition: Plugin.cpp:363
Here is the call graph for this function:

◆ selectedTracks()

const QList< unsigned int > Kwave::Plugin::selectedTracks ( )
virtual

Returns an array of indices of currently selected channels.

Definition at line 474 of file Plugin.cpp.

References Kwave::SignalManager::selectedTracks(), and signalManager().

Referenced by Kwave::VolumePlugin::run(), Kwave::AmplifyFreePlugin::run(), and Kwave::FilterPlugin::startPreListen().

475 {
476  return signalManager().selectedTracks();
477 }
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
const QList< unsigned int > selectedTracks()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ selection()

sample_index_t Kwave::Plugin::selection ( QList< unsigned int > *  tracks = Q_NULLPTR,
sample_index_t left = Q_NULLPTR,
sample_index_t right = Q_NULLPTR,
bool  expand_if_empty = false 
)
virtual

Returns the left and right sample index of the current selection in samples from 1 to (size-1). The left and right samples are included in the selection and might be equal. The left is always less or equal than the right. Note that there is always at least one sample selected!

Parameters
tracksreceived a list of selected tracks (optional or null-pointer)
leftreceives the first selected sample (optional or null-pointer)
rightreceives the last selected sample (optional or null-pointer)
expand_if_emptyif set to true, the selection will be made equal to the whole signal if left==right
Returns
the number of selected samples (right-left+1) [1..length]

Definition at line 480 of file Plugin.cpp.

References manager(), Kwave::SignalManager::selectedTracks(), Kwave::PluginManager::selectionEnd(), Kwave::PluginManager::selectionStart(), Kwave::PluginManager::signalLength(), and signalManager().

Referenced by Kwave::NoisePlugin::createDialog(), Kwave::SampleRatePlugin::run(), Kwave::ReversePlugin::run(), Kwave::ZeroPlugin::run(), Kwave::VolumePlugin::run(), Kwave::AmplifyFreePlugin::run(), Kwave::NormalizePlugin::run(), Kwave::FilterPlugin::run(), Kwave::SaveBlocksPlugin::scanBlocksToSave(), Kwave::VolumePlugin::setup(), Kwave::SaveBlocksPlugin::setup(), Kwave::K3BExportPlugin::setup(), Kwave::SaveBlocksPlugin::start(), Kwave::K3BExportPlugin::start(), Kwave::SonagramPlugin::start(), and start().

484 {
487 
488  // expand to the whole signal if left==right and expand_if_empty is set
489  if ((l == r) && (expand_if_empty)) {
490  l = 0;
491  r = manager().signalLength();
492  if (r) r--;
493  }
494 
495  // get the list of selected tracks
496  if (tracks) *tracks = signalManager().selectedTracks();
497 
498  if (left) *left = l;
499  if (right) *right = r;
500  return (r != l) ? (r - l + 1) : 0;
501 }
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
quint64 sample_index_t
Definition: Sample.h:28
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
sample_index_t signalLength()
sample_index_t selectionStart()
const QList< unsigned int > selectedTracks()
sample_index_t selectionEnd()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectRange()

void Kwave::Plugin::selectRange ( sample_index_t  offset,
sample_index_t  length 
)
virtual

Sets the current start and length of the selection to new values.

Parameters
offsetindex of the first sample
lengthnumber of samples

Definition at line 504 of file Plugin.cpp.

References manager(), and Kwave::PluginManager::selectRange().

Referenced by Kwave::SaveBlocksPlugin::start(), and Kwave::SelectRangePlugin::start().

505 {
506  manager().selectRange(offset, length);
507 }
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
void selectRange(sample_index_t offset, sample_index_t length)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPluginManager()

void Kwave::Plugin::setPluginManager ( Kwave::PluginManager new_plugin_manager)
protected

assign this plugin to a new plugin manager (when migrating)

Definition at line 522 of file Plugin.cpp.

References m_confirm_cancel, m_plugin_manager, m_progress, and Kwave::PluginManager::parentWidget().

Referenced by Kwave::PluginManager::migratePluginToActiveContext().

523 {
524  Q_ASSERT(new_plugin_manager);
525  if (!new_plugin_manager) return;
526  m_plugin_manager = new_plugin_manager;
527 
528  if (m_progress)
530  if (m_confirm_cancel)
532 }
QPointer< QWidget > parentWidget()
QProgressDialog * m_progress
Definition: Plugin.h:370
Kwave::PluginManager * m_plugin_manager
Definition: Plugin.h:347
Kwave::ConfirmCancelProxy * m_confirm_cancel
Definition: Plugin.h:376
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setProgressDialogEnabled

void Kwave::Plugin::setProgressDialogEnabled ( bool  enable)
virtualslot

Switches the support for a progress dialog on [default] or off

Definition at line 254 of file Plugin.cpp.

References m_progress_enabled.

Referenced by Kwave::FilterPlugin::startPreListen(), and Kwave::FilterPlugin::stopPreListen().

255 {
256  m_progress_enabled = enable;
257 }
bool m_progress_enabled
Definition: Plugin.h:364
Here is the caller graph for this function:

◆ setProgressText

void Kwave::Plugin::setProgressText ( const QString &  text)
signal

Sets the text of the progress dialog

Parameters
textnew progress bar text, already be localized

Referenced by Kwave::SampleRatePlugin::run(), Kwave::NormalizePlugin::run(), and start().

Here is the caller graph for this function:

◆ setup()

QStringList * Kwave::Plugin::setup ( QStringList &  previous_params)
virtual

Sets up all necessary parameters for executing the plugin. Could be overwritten and show a dialog box. This only will be called if currently no parameters are given from the function that loads the plugin (the normal case) but not in the context of replaying a previously recorded macro.

Parameters
previous_paramsthe parameters of a previous call, could be used to initialize the controls of a setup dialog
Returns
a string list with all parameters, an empty list (if nothing has to be set up) or null if the setup (dialog) has been aborted and the plugin should not get executed

Reimplemented in Kwave::SonagramPlugin, Kwave::FilterPlugin, Kwave::K3BExportPlugin, Kwave::PlayBackPlugin, Kwave::RecordPlugin, Kwave::DebugPlugin, Kwave::MemoryPlugin, Kwave::StringEnterPlugin, Kwave::AmplifyFreePlugin, Kwave::GotoPluginBase, Kwave::SelectRangePlugin, Kwave::MP3CodecPlugin, Kwave::SaveBlocksPlugin, Kwave::VolumePlugin, Kwave::NewSignalPlugin, and Kwave::FileInfoPlugin.

Definition at line 134 of file Plugin.cpp.

Referenced by Kwave::PluginManager::setupPlugin().

135 {
136  QStringList *result = new QStringList();
137  Q_ASSERT(result);
138  return result;
139 }
Here is the caller graph for this function:

◆ shouldStop()

bool Kwave::Plugin::shouldStop ( ) const
inline

◆ sigClosed

void Kwave::Plugin::sigClosed ( Kwave::Plugin p)
signal

will be emitted in the plugin's destructor

Referenced by release(), and Kwave::SonagramPlugin::start().

Here is the caller graph for this function:

◆ sigCommand

void Kwave::Plugin::sigCommand ( const QString &  command)
signal

can be used by plugins to execute toplevel commands

◆ sigDone

void Kwave::Plugin::sigDone ( Kwave::Plugin plugin)
signal

will be emitted when the "run" function has finished

See also
run

Referenced by run_wrapper(), Kwave::FilterPlugin::setup(), start(), and Kwave::PlayBackPlugin::testPlayBack().

Here is the caller graph for this function:

◆ signalLength()

sample_index_t Kwave::Plugin::signalLength ( )
virtual

Returns the length of the current signal in samples. If no signal is present the return value will be zero.

Definition at line 462 of file Plugin.cpp.

References manager(), and Kwave::PluginManager::signalLength().

Referenced by Kwave::RecordPlugin::recordStopped(), Kwave::SampleRatePlugin::run(), Kwave::ZeroPlugin::run(), Kwave::DebugPlugin::run(), Kwave::SaveBlocksPlugin::scanBlocksToSave(), Kwave::K3BExportPlugin::scanBlocksToSave(), Kwave::SaveBlocksPlugin::setup(), Kwave::GotoPluginBase::setup(), Kwave::SelectRangePlugin::setup(), Kwave::K3BExportPlugin::setup(), Kwave::SaveBlocksPlugin::start(), Kwave::GotoPluginBase::start(), Kwave::SelectRangePlugin::start(), and Kwave::K3BExportPlugin::start().

463 {
464  return manager().signalLength();
465 }
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
sample_index_t signalLength()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signalManager()

◆ signalName()

QString Kwave::Plugin::signalName ( )

Returns the name of the current signal. This can be used to set the caption of a plugin's main window. If no signal is currently loaded the returned string is empty.

Definition at line 456 of file Plugin.cpp.

References signalManager(), and Kwave::SignalManager::signalName().

Referenced by Kwave::SaveBlocksPlugin::setup(), Kwave::K3BExportPlugin::setup(), and Kwave::SonagramPlugin::start().

457 {
458  return signalManager().signalName();
459 }
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signalRate()

double Kwave::Plugin::signalRate ( )
virtual

◆ sigRunning

void Kwave::Plugin::sigRunning ( Kwave::Plugin plugin)
signal

will be emitted when the "run" function starts

See also
run

Referenced by run_wrapper().

Here is the caller graph for this function:

◆ start()

int Kwave::Plugin::start ( QStringList &  params)
virtual

Is called from the main program before the run() function and can be overwritten to show a window or initialize some things before the run() function gets called.

Parameters
paramslist of strings with parameters
Returns
an error code if the execution failed or zero if everything was ok.

Reimplemented in Kwave::SonagramPlugin, Kwave::K3BExportPlugin, Kwave::AmplifyFreePlugin, Kwave::SelectRangePlugin, Kwave::GotoPluginBase, Kwave::SaveBlocksPlugin, and Kwave::AboutPlugin.

Definition at line 142 of file Plugin.cpp.

References cancel(), closeProgressDialog(), Kwave::connect(), m_confirm_cancel, m_progress, m_progress_enabled, m_stop, m_thread_lock, parentWidget(), PROGRESS_MAXIMUM, progressText(), selection(), setProgressText(), and sigDone().

Referenced by Kwave::AmplifyFreePlugin::start().

143 {
144  QMutexLocker lock(&m_thread_lock);
145  m_stop = false;
146 
147  // check: start() must be called from the GUI thread only!
148  Q_ASSERT(this->thread() == QThread::currentThread());
149  Q_ASSERT(this->thread() == qApp->thread());
150 
151  // create a progress dialog for processing mode (not used for pre-listen)
152  if (m_progress_enabled && !m_progress) {
153  m_progress = new QProgressDialog(parentWidget());
154  Q_ASSERT(m_progress);
155  }
156 
157  // set up the progress dialog when in processing (not pre-listen) mode
159  sample_index_t first, last;
160  QList<unsigned int> tracks;
161 
162  selection(&tracks, &first, &last, true);
163  m_progress->setModal(true);
164  m_progress->setVisible(false);
165  m_progress->setMinimumDuration(2000);
166  m_progress->setAutoClose(false);
167  m_progress->setMaximum(PROGRESS_MAXIMUM);
168  m_progress->setValue(0);
169  m_progress->setLabelText(progressText());
170  int h = m_progress->sizeHint().height();
171  int w = m_progress->sizeHint().height();
172  if (w < 4 * h) w = 4 * h;
173  m_progress->setFixedSize(w, h);
174 
175  // use a "proxy" that asks for confirmation of cancel
176  if (!m_confirm_cancel) {
178  Q_NULLPTR, Q_NULLPTR, this, SLOT(cancel()));
179  Q_ASSERT(m_confirm_cancel);
180  }
181  connect(m_progress, SIGNAL(canceled()),
182  m_confirm_cancel, SLOT(cancel()));
183  connect(this, SIGNAL(setProgressText(QString)),
184  m_progress, SLOT(setLabelText(QString)),
185  Qt::QueuedConnection);
186  connect(this, SIGNAL(sigDone(Kwave::Plugin*)),
187  this, SLOT(closeProgressDialog(Kwave::Plugin*)),
188  Qt::QueuedConnection);
189  m_progress->setVisible(true);
190  }
191 
192  return 0;
193 }
QAtomicInt m_stop
Definition: Plugin.h:367
QWidget * parentWidget() const
Definition: Plugin.cpp:450
QProgressDialog * m_progress
Definition: Plugin.h:370
#define PROGRESS_MAXIMUM
Definition: Plugin.cpp:52
quint64 sample_index_t
Definition: Sample.h:28
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void sigDone(Kwave::Plugin *plugin)
QMutex m_thread_lock
Definition: Plugin.h:361
void closeProgressDialog(Kwave::Plugin *)
Definition: Plugin.cpp:293
virtual QString progressText()
Definition: Plugin.cpp:208
virtual void cancel()
Definition: Plugin.cpp:325
bool m_progress_enabled
Definition: Plugin.h:364
void setProgressText(const QString &text)
Kwave::ConfirmCancelProxy * m_confirm_cancel
Definition: Plugin.h:376
virtual sample_index_t selection(QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
Definition: Plugin.cpp:480
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

int Kwave::Plugin::stop ( )
virtual

Stops any threads and is called from the close() function and the plugin's destructor.

Definition at line 214 of file Plugin.cpp.

References cancel(), DBG, m_thread, m_thread_lock, name(), and Kwave::WorkerThread::stop().

Referenced by close(), Kwave::FilterPlugin::stopPreListen(), and Kwave::PlayBackPlugin::testPlayBack().

215 {
216  cancel();
217 
218  if (m_thread && m_thread->isRunning() &&
219  (QThread::currentThread() == m_thread)) {
220  qWarning("Kwave::Plugin::stop(): plugin '%s' called stop() from "
221  "within it's own worker thread (from run() ?). "
222  "This would produce a deadlock, PLEASE FIX THIS !",
223  DBG(name()));
224 
225 #ifdef DEBUG
226  qDebug("pthread_self()=%p, tid=%p",
227  reinterpret_cast<void *>(QThread::currentThread()),
228  reinterpret_cast<void *>(m_thread));
229  void *buf[256];
230  int n = backtrace(buf, 256);
231  backtrace_symbols_fd(buf, n, 2);
232 #endif
233  return -EBUSY;
234  }
235 
236  {
237  QMutexLocker lock(&m_thread_lock);
238  if (m_thread) {
239  if (m_thread->isRunning()) m_thread->wait(5000);
240  if (m_thread->isRunning()) m_thread->stop();
241  if (m_thread->isRunning()) m_thread->wait(1000);
242  if (m_thread->isRunning()) {
243  // unable to stop the thread
244  qWarning("Kwave::Plugin::stop(): stale thread !");
245  }
246  delete m_thread;
247  m_thread = Q_NULLPTR;
248  }
249  }
250  return 0;
251 }
Kwave::WorkerThread * m_thread
Definition: Plugin.h:358
virtual QString name() const
Definition: Plugin.cpp:196
QMutex m_thread_lock
Definition: Plugin.h:361
virtual void cancel()
Definition: Plugin.cpp:325
#define DBG(qs)
Definition: String.h:55
virtual int stop(unsigned int timeout=10000)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unload()

void Kwave::Plugin::unload ( )
virtual

Called before the plugin gets unloaded. Can be used by a plugin to do some cleanup tasks before it gets unloaded from memory.

Reimplemented in Kwave::CodecPlugin, and Kwave::PlayBackPlugin.

Definition at line 129 of file Plugin.cpp.

130 {
131 }

◆ updateProgress

void Kwave::Plugin::updateProgress ( qreal  progress)
virtualslot

update the progress dialog

Parameters
progressthe current progress in percent [0...100]

Definition at line 260 of file Plugin.cpp.

References m_current_progress, m_progress, m_progress_lock, m_progress_timer, PROGRESS_MAXIMUM, and PROGRESS_UPDATES_PER_SECOND.

Referenced by Kwave::SampleRatePlugin::run(), Kwave::ZeroPlugin::run(), Kwave::VolumePlugin::run(), Kwave::AmplifyFreePlugin::run(), Kwave::NormalizePlugin::run(), Kwave::DebugPlugin::run(), Kwave::FilterPlugin::run(), and Kwave::ReversePlugin::updateProgress().

261 {
262  // check: this must be called from the GUI thread only!
263  Q_ASSERT(this->thread() == QThread::currentThread());
264  Q_ASSERT(this->thread() == qApp->thread());
265 
266 // qDebug("Kwave::Plugin::updateProgress(%0.1f)", progress);
267  QMutexLocker lock(&m_progress_lock);
268 
269  // take over the current progress
270  // note: no lock needed, this is called in the GUI thread context!
271  m_current_progress = qreal(PROGRESS_MAXIMUM / 100.0) * progress;
272 
273  // start the timer for updating the progress bar if it is not active
274  if (!m_progress_timer.isActive() && m_progress) {
275  m_progress_timer.setSingleShot(true);
277  }
278 }
QProgressDialog * m_progress
Definition: Plugin.h:370
#define PROGRESS_MAXIMUM
Definition: Plugin.cpp:52
QTimer m_progress_timer
Definition: Plugin.h:385
QMutex m_progress_lock
Definition: Plugin.h:391
#define PROGRESS_UPDATES_PER_SECOND
Definition: Plugin.cpp:49
qreal m_current_progress
Definition: Plugin.h:388
Here is the caller graph for this function:

◆ updateProgressTick

void Kwave::Plugin::updateProgressTick ( )
privateslot

updates the progress bar, triggered by timer

Definition at line 281 of file Plugin.cpp.

References m_current_progress, m_progress, m_progress_lock, PROGRESS_MAXIMUM, and Kwave::toInt().

Referenced by Plugin().

282 {
283  // check: this must be called from the GUI thread only!
284  Q_ASSERT(this->thread() == QThread::currentThread());
285  Q_ASSERT(this->thread() == qApp->thread());
286 
287  QMutexLocker lock(&m_progress_lock);
288  if (m_progress) m_progress->setValue(
289  Kwave::toInt(qBound<double>(0.0, m_current_progress, PROGRESS_MAXIMUM)));
290 }
QProgressDialog * m_progress
Definition: Plugin.h:370
#define PROGRESS_MAXIMUM
Definition: Plugin.cpp:52
int toInt(T x)
Definition: Utils.h:127
QMutex m_progress_lock
Definition: Plugin.h:391
qreal m_current_progress
Definition: Plugin.h:388
Here is the call graph for this function:
Here is the caller graph for this function:

◆ use()

void Kwave::Plugin::use ( )
protected

increments the usage counter

Definition at line 412 of file Plugin.cpp.

References m_usage_count, and m_usage_lock.

Referenced by execute(), Kwave::CodecPlugin::load(), Kwave::PlayBackPlugin::load(), Kwave::PluginManager::pluginStarted(), and Kwave::SonagramPlugin::start().

413 {
414  QMutexLocker lock(&m_usage_lock);
415  Q_ASSERT(m_usage_count); // should be at least 1 (from constructor)
416  m_usage_count++;
417 }
unsigned int m_usage_count
Definition: Plugin.h:379
QMutex m_usage_lock
Definition: Plugin.h:382
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Kwave::PluginManager

friend class Kwave::PluginManager
friend

Definition at line 254 of file Plugin.h.

◆ Kwave::WorkerThread

friend class Kwave::WorkerThread
friend

Definition at line 339 of file Plugin.h.

Member Data Documentation

◆ m_confirm_cancel

Kwave::ConfirmCancelProxy* Kwave::Plugin::m_confirm_cancel
private

proxy dialog that asks for confirmation if the user pressed cancel in the progress dialog

Definition at line 376 of file Plugin.h.

Referenced by closeProgressDialog(), setPluginManager(), and start().

◆ m_current_progress

qreal Kwave::Plugin::m_current_progress
private

latest progress value [percent]

Definition at line 388 of file Plugin.h.

Referenced by updateProgress(), and updateProgressTick().

◆ m_description

QString Kwave::Plugin::m_description
private

description of the plugin, for GUI purposes, captions etc

Definition at line 353 of file Plugin.h.

Referenced by description().

◆ m_name

QString Kwave::Plugin::m_name
private

name of the plugin, for undo/redo

Definition at line 350 of file Plugin.h.

Referenced by name().

◆ m_plugin_manager

Kwave::PluginManager* Kwave::Plugin::m_plugin_manager
private

reference to the plugin manager

Definition at line 347 of file Plugin.h.

Referenced by manager(), Plugin(), and setPluginManager().

◆ m_progress

QProgressDialog* Kwave::Plugin::m_progress
private

a progress dialog, if the audio processing takes longer...

Definition at line 370 of file Plugin.h.

Referenced by closeProgressDialog(), setPluginManager(), start(), updateProgress(), and updateProgressTick().

◆ m_progress_enabled

bool Kwave::Plugin::m_progress_enabled
private

determines whether a progress dialog should be used in run()

Definition at line 364 of file Plugin.h.

Referenced by setProgressDialogEnabled(), and start().

◆ m_progress_lock

QMutex Kwave::Plugin::m_progress_lock
private

Mutex for locking the progress bar

Definition at line 391 of file Plugin.h.

Referenced by closeProgressDialog(), updateProgress(), and updateProgressTick().

◆ m_progress_timer

QTimer Kwave::Plugin::m_progress_timer
private

timer for updating the progress dialog

Definition at line 385 of file Plugin.h.

Referenced by closeProgressDialog(), Plugin(), and updateProgress().

◆ m_stop

QAtomicInt Kwave::Plugin::m_stop
private

flag for stopping the process (stop if set to non-zero)

Definition at line 367 of file Plugin.h.

Referenced by cancel(), execute(), run_wrapper(), and start().

◆ m_thread

Kwave::WorkerThread* Kwave::Plugin::m_thread
private

Thread that executes the run() member function.

Definition at line 358 of file Plugin.h.

Referenced by close(), execute(), isRunning(), stop(), and ~Plugin().

◆ m_thread_lock

QMutex Kwave::Plugin::m_thread_lock
private

Mutex for control over the thread

Definition at line 361 of file Plugin.h.

Referenced by execute(), start(), stop(), and ~Plugin().

◆ m_usage_count

unsigned int Kwave::Plugin::m_usage_count
private

Usage counter

Definition at line 379 of file Plugin.h.

Referenced by release(), and use().

◆ m_usage_lock

QMutex Kwave::Plugin::m_usage_lock
private

Mutex for locking the usage counter

Definition at line 382 of file Plugin.h.

Referenced by release(), use(), and ~Plugin().


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