comparison align/Align.h @ 763:da57ab54f0e8

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