comparison align/Align.h @ 761:6429a164b7e1 pitch-align

Schedule alignments with a small delay to avoid too much UI unresponsiveness. Also overhaul error reporting to use signals throughout.
author Chris Cannam
date Wed, 06 May 2020 11:45:27 +0100
parents 39808338e771
children dd742e566e60
comparison
equal deleted inserted replaced
757:f32df46d0c84 761:6429a164b7e1
37 * Align the "other" model to the reference, attaching an 37 * Align the "other" model to the reference, attaching an
38 * AlignmentModel to it. Alignment is carried out by the method 38 * AlignmentModel to it. Alignment is carried out by the method
39 * configured in the user preferences (either a plugin transform 39 * configured in the user preferences (either a plugin transform
40 * or an external process) and is done asynchronously. 40 * or an external process) and is done asynchronously.
41 * 41 *
42 * The return value indicates whether the alignment procedure 42 * Any errors are reported by firing the alignmentFailed
43 * started successfully. If it is true, then an AlignmentModel has 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
44 * been constructed and attached to the toAlign model, and you can 47 * been constructed and attached to the toAlign model, and you can
45 * query that model to discover the alignment progress, eventual 48 * query that model to discover the alignment progress, eventual
46 * outcome, and any error message generated during alignment. (The 49 * outcome, and also (separately from the alignmentFailed signal
47 * AlignmentModel is subsequently owned by the toAlign model.) 50 * here) any error message generated during alignment.
48 * Conversely if alignModel returns false, no AlignmentModel has
49 * been created, and the error return argument will contain an
50 * error report about whatever problem prevented this from
51 * happening.
52 * 51 *
53 * A single Align object may carry out many simultanous alignment 52 * A single Align object may carry out many simultanous alignment
54 * calls -- you do not need to create a new Align object each 53 * calls -- you do not need to create a new Align object each
55 * time, nor to wait for an alignment to be complete before 54 * time, nor to wait for an alignment to be complete before
56 * starting a new one. 55 * starting a new one.
58 * The Align object must survive after this call, for at least as 57 * The Align object must survive after this call, for at least as
59 * long as the alignment takes. The usual expectation is that the 58 * long as the alignment takes. The usual expectation is that the
60 * Align object will simply share the process or document 59 * Align object will simply share the process or document
61 * lifespan. 60 * lifespan.
62 */ 61 */
63 bool alignModel(Document *doc, 62 void alignModel(Document *doc,
64 ModelId reference, 63 ModelId reference,
65 ModelId toAlign, 64 ModelId toAlign);
66 QString &error);
67 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
68 /** 81 /**
69 * Return true if the alignment facility is available (relevant 82 * Return true if the alignment facility is available (relevant
70 * plugin installed, etc). 83 * plugin installed, etc).
71 */ 84 */
72 static bool canAlign(); 85 static bool canAlign();
77 * reference and other models can be queried from the alignment 90 * reference and other models can be queried from the alignment
78 * model. 91 * model.
79 */ 92 */
80 void alignmentComplete(ModelId alignmentModel); // an AlignmentModel 93 void alignmentComplete(ModelId alignmentModel); // an AlignmentModel
81 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
82 private slots: 101 private slots:
83 void alignerComplete(ModelId alignmentModel); // an AlignmentModel 102 void alignerComplete(ModelId alignmentModel); // an AlignmentModel
103 void alignerFailed(ModelId toAlign, QString errorText);
84 104
85 private: 105 private:
86 QMutex m_mutex; 106 QMutex m_mutex;
87 107
88 // maps toAlign -> aligner for ongoing alignment - note that 108 // maps toAlign -> aligner for ongoing alignment - note that
89 // although we can calculate alignments with different references, 109 // although we can calculate alignments with different references,
90 // we can only have one alignment on any given toAlign model, so 110 // we can only have one alignment on any given toAlign model, so
91 // we don't key this on the whole (reference, toAlign) pair 111 // we don't key this on the whole (reference, toAlign) pair
92 std::map<ModelId, std::shared_ptr<Aligner>> m_aligners; 112 std::map<ModelId, std::shared_ptr<Aligner>> m_aligners;
93 113
114 void addAligner(Document *doc, ModelId reference, ModelId toAlign);
115 void removeAligner(QObject *);
116
94 static void getAlignerPreference(bool &useProgram, QString &program); 117 static void getAlignerPreference(bool &useProgram, QString &program);
95 }; 118 };
96 119
97 #endif 120 #endif
98 121