comparison framework/Align.h @ 673:d62fd61082a1

Merge from branch tuning-difference
author Chris Cannam
date Fri, 17 May 2019 09:46:22 +0100
parents b6cafe05017d
children 4d26b66931f8
comparison
equal deleted inserted replaced
665:e19c609a7bec 673:d62fd61082a1
17 #define ALIGN_H 17 #define ALIGN_H
18 18
19 #include <QString> 19 #include <QString>
20 #include <QObject> 20 #include <QObject>
21 #include <QProcess> 21 #include <QProcess>
22 #include <QMutex>
22 #include <set> 23 #include <set>
23 24
24 class Model; 25 class Model;
25 class AlignmentModel; 26 class AlignmentModel;
27 class SparseTimeValueModel;
28 class AggregateWaveModel;
26 class Document; 29 class Document;
27 30
28 class Align : public QObject 31 class Align : public QObject
29 { 32 {
30 Q_OBJECT 33 Q_OBJECT
31 34
32 public: 35 public:
33 Align() : m_error("") { } 36 Align() { }
34 37
35 /** 38 /**
36 * Align the "other" model to the reference, attaching an 39 * Align the "other" model to the reference, attaching an
37 * AlignmentModel to it. Alignment is carried out by the method 40 * AlignmentModel to it. Alignment is carried out by the method
38 * configured in the user preferences (either a plugin transform 41 * configured in the user preferences (either a plugin transform
39 * or an external process) and is done asynchronously. 42 * or an external process) and is done asynchronously.
43 *
44 * The return value indicates whether the alignment procedure
45 * started successfully. If it is true, then an AlignmentModel has
46 * been constructed and attached to the toAlign model, and you can
47 * query that model to discover the alignment progress, eventual
48 * outcome, and any error message generated during alignment. (The
49 * AlignmentModel is subsequently owned by the toAlign model.)
50 * Conversely if alignModel returns false, no AlignmentModel has
51 * been created, and the error return argument will contain an
52 * error report about whatever problem prevented this from
53 * happening.
40 * 54 *
41 * A single Align object may carry out many simultanous alignment 55 * A single Align object may carry out many simultanous alignment
42 * calls -- you do not need to create a new Align object each 56 * calls -- you do not need to create a new Align object each
43 * time, nor to wait for an alignment to be complete before 57 * time, nor to wait for an alignment to be complete before
44 * starting a new one. 58 * starting a new one.
48 * Align object will simply share the process or document 62 * Align object will simply share the process or document
49 * lifespan. 63 * lifespan.
50 */ 64 */
51 bool alignModel(Document *doc, 65 bool alignModel(Document *doc,
52 Model *reference, 66 Model *reference,
53 Model *other); // via user preference 67 Model *toAlign,
68 QString &error);
54 69
55 bool alignModelViaTransform(Document *doc, 70 bool alignModelViaTransform(Document *doc,
56 Model *reference, 71 Model *reference,
57 Model *other); 72 Model *toAlign,
73 QString &error);
58 74
59 bool alignModelViaProgram(Document *doc, 75 bool alignModelViaProgram(Document *doc,
60 Model *reference, 76 Model *reference,
61 Model *other, 77 Model *toAlign,
62 QString program); 78 QString program,
79 QString &error);
63 80
64 /** 81 /**
65 * Return true if the alignment facility is available (relevant 82 * Return true if the alignment facility is available (relevant
66 * plugin installed, etc). 83 * plugin installed, etc).
67 */ 84 */
68 static bool canAlign(); 85 static bool canAlign();
69
70 QString getError() const { return m_error; }
71 86
72 signals: 87 signals:
73 /** 88 /**
74 * Emitted when an alignment is successfully completed. The 89 * Emitted when an alignment is successfully completed. The
75 * reference and other models can be queried from the alignment 90 * reference and other models can be queried from the alignment
77 */ 92 */
78 void alignmentComplete(AlignmentModel *alignment); 93 void alignmentComplete(AlignmentModel *alignment);
79 94
80 private slots: 95 private slots:
81 void alignmentCompletionChanged(); 96 void alignmentCompletionChanged();
97 void tuningDifferenceCompletionChanged();
82 void alignmentProgramFinished(int, QProcess::ExitStatus); 98 void alignmentProgramFinished(int, QProcess::ExitStatus);
83 99
84 private: 100 private:
85 static QString getAlignmentTransformName(); 101 static QString getAlignmentTransformName();
86 102 static QString getTuningDifferenceTransformName();
87 QString m_error; 103
88 std::map<QProcess *, AlignmentModel *> m_processModels; 104 bool beginTransformDrivenAlignment(AggregateWaveModel *,
105 AlignmentModel *,
106 float tuningFrequency = 0.f);
107
108 QMutex m_mutex;
109
110 struct TuningDiffRec {
111 AggregateWaveModel *input;
112 AlignmentModel *alignment;
113 SparseTimeValueModel *preparatory;
114 };
115
116 // tuning-difference output model -> data needed for subsequent alignment
117 std::map<SparseTimeValueModel *, TuningDiffRec> m_pendingTuningDiffs;
118
119 // external alignment subprocess -> model into which to stuff the results
120 std::map<QProcess *, AlignmentModel *> m_pendingProcesses;
89 }; 121 };
90 122
91 #endif 123 #endif
92 124