annotate framework/Align.h @ 731:16932dfaf64e

Default to CSV now
author Chris Cannam
date Wed, 15 Jan 2020 14:00:18 +0000
parents e4d92aaa689c
children
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
Chris@420 8 This program is free software; you can redistribute it and/or
Chris@420 9 modify it under the terms of the GNU General Public License as
Chris@420 10 published by the Free Software Foundation; either version 2 of the
Chris@420 11 License, or (at your option) any later version. See the file
Chris@420 12 COPYING included with this distribution for more information.
Chris@420 13 */
Chris@420 14
Chris@420 15 #ifndef ALIGN_H
Chris@420 16 #define ALIGN_H
Chris@420 17
Chris@420 18 #include <QString>
Chris@423 19 #include <QObject>
Chris@423 20 #include <QProcess>
Chris@670 21 #include <QMutex>
Chris@423 22 #include <set>
Chris@420 23
Chris@683 24 #include "data/model/Model.h"
Chris@683 25
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@683 66 ModelId reference,
Chris@683 67 ModelId toAlign,
Chris@670 68 QString &error);
Chris@422 69
Chris@664 70 bool alignModelViaTransform(Document *doc,
Chris@683 71 ModelId reference,
Chris@683 72 ModelId toAlign,
Chris@670 73 QString &error);
Chris@664 74
Chris@664 75 bool alignModelViaProgram(Document *doc,
Chris@683 76 ModelId reference,
Chris@683 77 ModelId 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@683 93 void alignmentComplete(ModelId alignmentModel); // an AlignmentModel
Chris@428 94
Chris@423 95 private slots:
Chris@687 96 void alignmentCompletionChanged(ModelId);
Chris@687 97 void tuningDifferenceCompletionChanged(ModelId);
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@683 104 bool beginTransformDrivenAlignment(ModelId, // an AggregateWaveModel
Chris@683 105 ModelId, // an AlignmentModel
Chris@670 106 float tuningFrequency = 0.f);
Chris@670 107
Chris@702 108 void abandonOngoingAlignment(ModelId otherId);
Chris@702 109
Chris@670 110 QMutex m_mutex;
Chris@671 111
Chris@671 112 struct TuningDiffRec {
Chris@683 113 ModelId input; // an AggregateWaveModel
Chris@683 114 ModelId alignment; // an AlignmentModel
Chris@683 115 ModelId preparatory; // a SparseTimeValueModel
Chris@671 116 };
Chris@702 117
Chris@683 118 // tuning-difference output model (a SparseTimeValueModel) -> data
Chris@683 119 // needed for subsequent alignment
Chris@683 120 std::map<ModelId, TuningDiffRec> m_pendingTuningDiffs;
Chris@671 121
Chris@691 122 // alignment model id -> path output model id
Chris@691 123 std::map<ModelId, ModelId> m_pendingAlignments;
Chris@691 124
Chris@683 125 // external alignment subprocess -> model into which to stuff the
Chris@683 126 // results (an AlignmentModel)
Chris@683 127 std::map<QProcess *, ModelId> m_pendingProcesses;
Chris@420 128 };
Chris@420 129
Chris@420 130 #endif
Chris@420 131