Chris@420: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@420: Chris@420: /* Chris@420: Sonic Visualiser Chris@420: An audio file viewer and annotation editor. Chris@420: Centre for Digital Music, Queen Mary, University of London. Chris@420: This file copyright 2006 Chris Cannam and QMUL. Chris@420: Chris@420: This program is free software; you can redistribute it and/or Chris@420: modify it under the terms of the GNU General Public License as Chris@420: published by the Free Software Foundation; either version 2 of the Chris@420: License, or (at your option) any later version. See the file Chris@420: COPYING included with this distribution for more information. Chris@420: */ Chris@420: Chris@420: #ifndef ALIGN_H Chris@420: #define ALIGN_H Chris@420: Chris@420: #include Chris@423: #include Chris@423: #include Chris@670: #include Chris@423: #include Chris@420: Chris@420: class Model; Chris@423: class AlignmentModel; Chris@670: class SparseTimeValueModel; Chris@670: class AggregateWaveModel; Chris@664: class Document; Chris@420: Chris@423: class Align : public QObject Chris@420: { Chris@423: Q_OBJECT Chris@423: Chris@420: public: Chris@670: Align() { } Chris@420: Chris@423: /** Chris@423: * Align the "other" model to the reference, attaching an Chris@423: * AlignmentModel to it. Alignment is carried out by the method Chris@423: * configured in the user preferences (either a plugin transform Chris@423: * or an external process) and is done asynchronously. Chris@423: * Chris@670: * The return value indicates whether the alignment procedure Chris@670: * started successfully. If it is true, then an AlignmentModel has Chris@670: * been constructed and attached to the toAlign model, and you can Chris@670: * query that model to discover the alignment progress, eventual Chris@670: * outcome, and any error message generated during alignment. (The Chris@670: * AlignmentModel is subsequently owned by the toAlign model.) Chris@670: * Conversely if alignModel returns false, no AlignmentModel has Chris@670: * been created, and the error return argument will contain an Chris@670: * error report about whatever problem prevented this from Chris@670: * happening. Chris@670: * Chris@423: * A single Align object may carry out many simultanous alignment Chris@423: * calls -- you do not need to create a new Align object each Chris@423: * time, nor to wait for an alignment to be complete before Chris@423: * starting a new one. Chris@423: * Chris@423: * The Align object must survive after this call, for at least as Chris@428: * long as the alignment takes. The usual expectation is that the Chris@428: * Align object will simply share the process or document Chris@428: * lifespan. Chris@423: */ Chris@664: bool alignModel(Document *doc, Chris@664: Model *reference, Chris@670: Model *toAlign, Chris@670: QString &error); Chris@422: Chris@664: bool alignModelViaTransform(Document *doc, Chris@664: Model *reference, Chris@670: Model *toAlign, Chris@670: QString &error); Chris@664: Chris@664: bool alignModelViaProgram(Document *doc, Chris@664: Model *reference, Chris@670: Model *toAlign, Chris@670: QString program, Chris@670: QString &error); Chris@420: Chris@428: /** Chris@428: * Return true if the alignment facility is available (relevant Chris@428: * plugin installed, etc). Chris@428: */ Chris@428: static bool canAlign(); Chris@428: Chris@428: signals: Chris@428: /** Chris@428: * Emitted when an alignment is successfully completed. The Chris@428: * reference and other models can be queried from the alignment Chris@428: * model. Chris@428: */ Chris@428: void alignmentComplete(AlignmentModel *alignment); Chris@428: Chris@423: private slots: Chris@428: void alignmentCompletionChanged(); Chris@670: void tuningDifferenceCompletionChanged(); Chris@423: void alignmentProgramFinished(int, QProcess::ExitStatus); Chris@423: Chris@420: private: Chris@428: static QString getAlignmentTransformName(); Chris@670: static QString getTuningDifferenceTransformName(); Chris@670: Chris@670: bool beginTransformDrivenAlignment(AggregateWaveModel *, Chris@670: AlignmentModel *, Chris@670: float tuningFrequency = 0.f); Chris@670: Chris@670: QMutex m_mutex; Chris@671: Chris@671: struct TuningDiffRec { Chris@671: AggregateWaveModel *input; Chris@671: AlignmentModel *alignment; Chris@671: SparseTimeValueModel *preparatory; Chris@671: }; Chris@671: Chris@671: // tuning-difference output model -> data needed for subsequent alignment Chris@671: std::map m_pendingTuningDiffs; Chris@671: Chris@671: // external alignment subprocess -> model into which to stuff the results Chris@670: std::map m_pendingProcesses; Chris@420: }; Chris@420: Chris@420: #endif Chris@420: