annotate framework/Align.h @ 671:b6cafe05017d tuning-difference

Make a completion figure available to alignment, + a couple of other fixes
author Chris Cannam
date Thu, 16 May 2019 15:55:46 +0100
parents 0960e27c3232
children 4d26b66931f8
rev   line source
Chris@420 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@420 2
Chris@420 3 /*
Chris@420 4 Sonic Visualiser
Chris@420 5 An audio file viewer and annotation editor.
Chris@420 6 Centre for Digital Music, Queen Mary, University of London.
Chris@420 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@420 8
Chris@420 9 This program is free software; you can redistribute it and/or
Chris@420 10 modify it under the terms of the GNU General Public License as
Chris@420 11 published by the Free Software Foundation; either version 2 of the
Chris@420 12 License, or (at your option) any later version. See the file
Chris@420 13 COPYING included with this distribution for more information.
Chris@420 14 */
Chris@420 15
Chris@420 16 #ifndef ALIGN_H
Chris@420 17 #define ALIGN_H
Chris@420 18
Chris@420 19 #include <QString>
Chris@423 20 #include <QObject>
Chris@423 21 #include <QProcess>
Chris@670 22 #include <QMutex>
Chris@423 23 #include <set>
Chris@420 24
Chris@420 25 class Model;
Chris@423 26 class AlignmentModel;
Chris@670 27 class SparseTimeValueModel;
Chris@670 28 class AggregateWaveModel;
Chris@664 29 class Document;
Chris@420 30
Chris@423 31 class Align : public QObject
Chris@420 32 {
Chris@423 33 Q_OBJECT
Chris@423 34
Chris@420 35 public:
Chris@670 36 Align() { }
Chris@420 37
Chris@423 38 /**
Chris@423 39 * Align the "other" model to the reference, attaching an
Chris@423 40 * AlignmentModel to it. Alignment is carried out by the method
Chris@423 41 * configured in the user preferences (either a plugin transform
Chris@423 42 * or an external process) and is done asynchronously.
Chris@423 43 *
Chris@670 44 * The return value indicates whether the alignment procedure
Chris@670 45 * started successfully. If it is true, then an AlignmentModel has
Chris@670 46 * been constructed and attached to the toAlign model, and you can
Chris@670 47 * query that model to discover the alignment progress, eventual
Chris@670 48 * outcome, and any error message generated during alignment. (The
Chris@670 49 * AlignmentModel is subsequently owned by the toAlign model.)
Chris@670 50 * Conversely if alignModel returns false, no AlignmentModel has
Chris@670 51 * been created, and the error return argument will contain an
Chris@670 52 * error report about whatever problem prevented this from
Chris@670 53 * happening.
Chris@670 54 *
Chris@423 55 * A single Align object may carry out many simultanous alignment
Chris@423 56 * calls -- you do not need to create a new Align object each
Chris@423 57 * time, nor to wait for an alignment to be complete before
Chris@423 58 * starting a new one.
Chris@423 59 *
Chris@423 60 * The Align object must survive after this call, for at least as
Chris@428 61 * long as the alignment takes. The usual expectation is that the
Chris@428 62 * Align object will simply share the process or document
Chris@428 63 * lifespan.
Chris@423 64 */
Chris@664 65 bool alignModel(Document *doc,
Chris@664 66 Model *reference,
Chris@670 67 Model *toAlign,
Chris@670 68 QString &error);
Chris@422 69
Chris@664 70 bool alignModelViaTransform(Document *doc,
Chris@664 71 Model *reference,
Chris@670 72 Model *toAlign,
Chris@670 73 QString &error);
Chris@664 74
Chris@664 75 bool alignModelViaProgram(Document *doc,
Chris@664 76 Model *reference,
Chris@670 77 Model *toAlign,
Chris@670 78 QString program,
Chris@670 79 QString &error);
Chris@420 80
Chris@428 81 /**
Chris@428 82 * Return true if the alignment facility is available (relevant
Chris@428 83 * plugin installed, etc).
Chris@428 84 */
Chris@428 85 static bool canAlign();
Chris@428 86
Chris@428 87 signals:
Chris@428 88 /**
Chris@428 89 * Emitted when an alignment is successfully completed. The
Chris@428 90 * reference and other models can be queried from the alignment
Chris@428 91 * model.
Chris@428 92 */
Chris@428 93 void alignmentComplete(AlignmentModel *alignment);
Chris@428 94
Chris@423 95 private slots:
Chris@428 96 void alignmentCompletionChanged();
Chris@670 97 void tuningDifferenceCompletionChanged();
Chris@423 98 void alignmentProgramFinished(int, QProcess::ExitStatus);
Chris@423 99
Chris@420 100 private:
Chris@428 101 static QString getAlignmentTransformName();
Chris@670 102 static QString getTuningDifferenceTransformName();
Chris@670 103
Chris@670 104 bool beginTransformDrivenAlignment(AggregateWaveModel *,
Chris@670 105 AlignmentModel *,
Chris@670 106 float tuningFrequency = 0.f);
Chris@670 107
Chris@670 108 QMutex m_mutex;
Chris@671 109
Chris@671 110 struct TuningDiffRec {
Chris@671 111 AggregateWaveModel *input;
Chris@671 112 AlignmentModel *alignment;
Chris@671 113 SparseTimeValueModel *preparatory;
Chris@671 114 };
Chris@671 115
Chris@671 116 // tuning-difference output model -> data needed for subsequent alignment
Chris@671 117 std::map<SparseTimeValueModel *, TuningDiffRec> m_pendingTuningDiffs;
Chris@671 118
Chris@671 119 // external alignment subprocess -> model into which to stuff the results
Chris@670 120 std::map<QProcess *, AlignmentModel *> m_pendingProcesses;
Chris@420 121 };
Chris@420 122
Chris@420 123 #endif
Chris@420 124