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@754
|
15 #ifndef SV_ALIGN_H
|
Chris@754
|
16 #define SV_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@753
|
24 #include "Aligner.h"
|
Chris@683
|
25
|
Chris@423
|
26 class AlignmentModel;
|
Chris@664
|
27 class Document;
|
Chris@420
|
28
|
Chris@423
|
29 class Align : public QObject
|
Chris@420
|
30 {
|
Chris@423
|
31 Q_OBJECT
|
Chris@423
|
32
|
Chris@420
|
33 public:
|
Chris@670
|
34 Align() { }
|
Chris@420
|
35
|
Chris@423
|
36 /**
|
Chris@423
|
37 * Align the "other" model to the reference, attaching an
|
Chris@423
|
38 * AlignmentModel to it. Alignment is carried out by the method
|
Chris@423
|
39 * configured in the user preferences (either a plugin transform
|
Chris@423
|
40 * or an external process) and is done asynchronously.
|
Chris@423
|
41 *
|
Chris@761
|
42 * Any errors are reported by firing the alignmentFailed
|
Chris@761
|
43 * signal. Note that the signal may be fired during the call to
|
Chris@761
|
44 * this function, if the aligner fails to start at all.
|
Chris@761
|
45 *
|
Chris@761
|
46 * If alignment starts successfully, then an AlignmentModel has
|
Chris@670
|
47 * been constructed and attached to the toAlign model, and you can
|
Chris@670
|
48 * query that model to discover the alignment progress, eventual
|
Chris@761
|
49 * outcome, and also (separately from the alignmentFailed signal
|
Chris@761
|
50 * here) any error message generated during alignment.
|
Chris@670
|
51 *
|
Chris@423
|
52 * A single Align object may carry out many simultanous alignment
|
Chris@423
|
53 * calls -- you do not need to create a new Align object each
|
Chris@423
|
54 * time, nor to wait for an alignment to be complete before
|
Chris@423
|
55 * starting a new one.
|
Chris@423
|
56 *
|
Chris@423
|
57 * The Align object must survive after this call, for at least as
|
Chris@428
|
58 * long as the alignment takes. The usual expectation is that the
|
Chris@428
|
59 * Align object will simply share the process or document
|
Chris@428
|
60 * lifespan.
|
Chris@423
|
61 */
|
Chris@761
|
62 void alignModel(Document *doc,
|
Chris@683
|
63 ModelId reference,
|
Chris@761
|
64 ModelId toAlign);
|
Chris@420
|
65
|
Chris@428
|
66 /**
|
Chris@761
|
67 * As alignModel, except that the alignment does not begin
|
Chris@761
|
68 * immediately, but is instead placed behind an event callback
|
Chris@761
|
69 * with a small delay. Useful to avoid an unresponsive GUI when
|
Chris@761
|
70 * firing off alignments while doing something else as well. Any
|
Chris@761
|
71 * error is reported by firing the alignmentFailed signal.
|
Chris@761
|
72 *
|
Chris@761
|
73 * Scheduled alignments are not queued or serialised - many could
|
Chris@761
|
74 * happen at once. They are just delayed a little for UI
|
Chris@761
|
75 * responsiveness.
|
Chris@761
|
76 */
|
Chris@761
|
77 void scheduleAlignment(Document *doc,
|
Chris@761
|
78 ModelId reference,
|
Chris@761
|
79 ModelId toAlign);
|
Chris@761
|
80
|
Chris@761
|
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@761
|
95 /**
|
Chris@761
|
96 * Emitted when an alignment fails. The model is the toAlign model
|
Chris@761
|
97 * that was passed to the call to alignModel or scheduleAlignment.
|
Chris@761
|
98 */
|
Chris@761
|
99 void alignmentFailed(ModelId toAlign, QString errorText);
|
Chris@761
|
100
|
Chris@423
|
101 private slots:
|
Chris@753
|
102 void alignerComplete(ModelId alignmentModel); // an AlignmentModel
|
Chris@761
|
103 void alignerFailed(ModelId toAlign, QString errorText);
|
Chris@423
|
104
|
Chris@420
|
105 private:
|
Chris@670
|
106 QMutex m_mutex;
|
Chris@671
|
107
|
Chris@753
|
108 // maps toAlign -> aligner for ongoing alignment - note that
|
Chris@753
|
109 // although we can calculate alignments with different references,
|
Chris@753
|
110 // we can only have one alignment on any given toAlign model, so
|
Chris@753
|
111 // we don't key this on the whole (reference, toAlign) pair
|
Chris@753
|
112 std::map<ModelId, std::shared_ptr<Aligner>> m_aligners;
|
Chris@671
|
113
|
Chris@761
|
114 void addAligner(Document *doc, ModelId reference, ModelId toAlign);
|
Chris@761
|
115 void removeAligner(QObject *);
|
Chris@761
|
116
|
Chris@756
|
117 static void getAlignerPreference(bool &useProgram, QString &program);
|
Chris@420
|
118 };
|
Chris@420
|
119
|
Chris@420
|
120 #endif
|
Chris@420
|
121
|