annotate align/Align.h @ 757:f32df46d0c84 pitch-align

Flesh out DTW
author Chris Cannam
date Mon, 27 Apr 2020 14:59:56 +0100
parents 39808338e771
children 6429a164b7e1
rev   line source
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@670 42 * The return value indicates whether the alignment procedure
Chris@670 43 * started successfully. If it is true, then an AlignmentModel has
Chris@670 44 * been constructed and attached to the toAlign model, and you can
Chris@670 45 * query that model to discover the alignment progress, eventual
Chris@670 46 * outcome, and any error message generated during alignment. (The
Chris@670 47 * AlignmentModel is subsequently owned by the toAlign model.)
Chris@670 48 * Conversely if alignModel returns false, no AlignmentModel has
Chris@670 49 * been created, and the error return argument will contain an
Chris@670 50 * error report about whatever problem prevented this from
Chris@670 51 * happening.
Chris@670 52 *
Chris@423 53 * A single Align object may carry out many simultanous alignment
Chris@423 54 * calls -- you do not need to create a new Align object each
Chris@423 55 * time, nor to wait for an alignment to be complete before
Chris@423 56 * starting a new one.
Chris@423 57 *
Chris@423 58 * The Align object must survive after this call, for at least as
Chris@428 59 * long as the alignment takes. The usual expectation is that the
Chris@428 60 * Align object will simply share the process or document
Chris@428 61 * lifespan.
Chris@423 62 */
Chris@664 63 bool alignModel(Document *doc,
Chris@683 64 ModelId reference,
Chris@683 65 ModelId toAlign,
Chris@670 66 QString &error);
Chris@420 67
Chris@428 68 /**
Chris@428 69 * Return true if the alignment facility is available (relevant
Chris@428 70 * plugin installed, etc).
Chris@428 71 */
Chris@428 72 static bool canAlign();
Chris@428 73
Chris@428 74 signals:
Chris@428 75 /**
Chris@428 76 * Emitted when an alignment is successfully completed. The
Chris@428 77 * reference and other models can be queried from the alignment
Chris@428 78 * model.
Chris@428 79 */
Chris@683 80 void alignmentComplete(ModelId alignmentModel); // an AlignmentModel
Chris@428 81
Chris@423 82 private slots:
Chris@753 83 void alignerComplete(ModelId alignmentModel); // an AlignmentModel
Chris@423 84
Chris@420 85 private:
Chris@670 86 QMutex m_mutex;
Chris@671 87
Chris@753 88 // maps toAlign -> aligner for ongoing alignment - note that
Chris@753 89 // although we can calculate alignments with different references,
Chris@753 90 // we can only have one alignment on any given toAlign model, so
Chris@753 91 // we don't key this on the whole (reference, toAlign) pair
Chris@753 92 std::map<ModelId, std::shared_ptr<Aligner>> m_aligners;
Chris@671 93
Chris@756 94 static void getAlignerPreference(bool &useProgram, QString &program);
Chris@420 95 };
Chris@420 96
Chris@420 97 #endif
Chris@420 98