comparison align/Align.h @ 744:36772d79cf44 pitch-align

Move Align to new align directory
author Chris Cannam
date Fri, 03 Apr 2020 10:17:46 +0100
parents framework/Align.h@e4d92aaa689c
children 31289e8592c7
comparison
equal deleted inserted replaced
743:7b1d30af4b38 744:36772d79cf44
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #ifndef ALIGN_H
16 #define ALIGN_H
17
18 #include <QString>
19 #include <QObject>
20 #include <QProcess>
21 #include <QMutex>
22 #include <set>
23
24 #include "data/model/Model.h"
25
26 class AlignmentModel;
27 class SparseTimeValueModel;
28 class AggregateWaveModel;
29 class Document;
30
31 class Align : public QObject
32 {
33 Q_OBJECT
34
35 public:
36 Align() { }
37
38 /**
39 * Align the "other" model to the reference, attaching an
40 * AlignmentModel to it. Alignment is carried out by the method
41 * configured in the user preferences (either a plugin transform
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.
54 *
55 * A single Align object may carry out many simultanous alignment
56 * calls -- you do not need to create a new Align object each
57 * time, nor to wait for an alignment to be complete before
58 * starting a new one.
59 *
60 * The Align object must survive after this call, for at least as
61 * long as the alignment takes. The usual expectation is that the
62 * Align object will simply share the process or document
63 * lifespan.
64 */
65 bool alignModel(Document *doc,
66 ModelId reference,
67 ModelId toAlign,
68 QString &error);
69
70 bool alignModelViaTransform(Document *doc,
71 ModelId reference,
72 ModelId toAlign,
73 QString &error);
74
75 bool alignModelViaProgram(Document *doc,
76 ModelId reference,
77 ModelId toAlign,
78 QString program,
79 QString &error);
80
81 /**
82 * Return true if the alignment facility is available (relevant
83 * plugin installed, etc).
84 */
85 static bool canAlign();
86
87 signals:
88 /**
89 * Emitted when an alignment is successfully completed. The
90 * reference and other models can be queried from the alignment
91 * model.
92 */
93 void alignmentComplete(ModelId alignmentModel); // an AlignmentModel
94
95 private slots:
96 void alignmentCompletionChanged(ModelId);
97 void tuningDifferenceCompletionChanged(ModelId);
98 void alignmentProgramFinished(int, QProcess::ExitStatus);
99
100 private:
101 static QString getAlignmentTransformName();
102 static QString getTuningDifferenceTransformName();
103
104 bool beginTransformDrivenAlignment(ModelId, // an AggregateWaveModel
105 ModelId, // an AlignmentModel
106 float tuningFrequency = 0.f);
107
108 void abandonOngoingAlignment(ModelId otherId);
109
110 QMutex m_mutex;
111
112 struct TuningDiffRec {
113 ModelId input; // an AggregateWaveModel
114 ModelId alignment; // an AlignmentModel
115 ModelId preparatory; // a SparseTimeValueModel
116 };
117
118 // tuning-difference output model (a SparseTimeValueModel) -> data
119 // needed for subsequent alignment
120 std::map<ModelId, TuningDiffRec> m_pendingTuningDiffs;
121
122 // alignment model id -> path output model id
123 std::map<ModelId, ModelId> m_pendingAlignments;
124
125 // external alignment subprocess -> model into which to stuff the
126 // results (an AlignmentModel)
127 std::map<QProcess *, ModelId> m_pendingProcesses;
128 };
129
130 #endif
131