Chris@767: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@767: Chris@767: /* Chris@767: Sonic Visualiser Chris@767: An audio file viewer and annotation editor. Chris@767: Centre for Digital Music, Queen Mary, University of London. Chris@767: Chris@767: This program is free software; you can redistribute it and/or Chris@767: modify it under the terms of the GNU General Public License as Chris@767: published by the Free Software Foundation; either version 2 of the Chris@767: License, or (at your option) any later version. See the file Chris@767: COPYING included with this distribution for more information. Chris@767: */ Chris@767: Chris@767: #ifndef SV_TRANSFORM_DTW_ALIGNER_H Chris@767: #define SV_TRANSFORM_DTW_ALIGNER_H Chris@767: Chris@767: #include "Aligner.h" Chris@771: #include "DTW.h" Chris@767: Chris@767: #include "transform/Transform.h" Chris@771: #include "svcore/data/model/Path.h" Chris@767: Chris@768: #include Chris@768: Chris@771: #include Chris@771: Chris@767: class AlignmentModel; Chris@767: class Document; Chris@767: Chris@767: class TransformDTWAligner : public Aligner Chris@767: { Chris@767: Q_OBJECT Chris@767: Chris@767: public: Chris@767: enum DTWType { Chris@767: Magnitude, Chris@767: RiseFall Chris@767: }; Chris@771: Chris@771: /** Chris@771: * Create a TransformDTWAligner that runs the given transform on Chris@771: * both models and feeds the resulting values into the given DTW Chris@771: * type. If DTWType is Magnitude, the transform output values are Chris@771: * used unmodified; if RiseFall, the deltas between consecutive Chris@771: * values are used. Chris@771: */ Chris@767: TransformDTWAligner(Document *doc, Chris@767: ModelId reference, Chris@767: ModelId toAlign, Chris@781: bool subsequence, Chris@767: Transform transform, Chris@767: DTWType dtwType); Chris@771: Chris@771: typedef std::function MagnitudePreprocessor; Chris@771: Chris@771: /** Chris@771: * Create a TransformDTWAligner that runs the given transform on Chris@771: * both models, applies the supplied output preprocessor, and Chris@771: * feeds the resulting values into a Magnitude DTW type. Chris@771: */ Chris@768: TransformDTWAligner(Document *doc, Chris@768: ModelId reference, Chris@768: ModelId toAlign, Chris@781: bool subsequence, Chris@768: Transform transform, Chris@771: MagnitudePreprocessor outputPreprocessor); Chris@771: Chris@771: typedef std::function Chris@771: RiseFallPreprocessor; Chris@771: Chris@771: /** Chris@771: * Create a TransformDTWAligner that runs the given transform on Chris@771: * both models, applies the supplied output preprocessor, and Chris@771: * feeds the resulting values into a RiseFall DTW type. Chris@771: */ Chris@771: TransformDTWAligner(Document *doc, Chris@771: ModelId reference, Chris@771: ModelId toAlign, Chris@781: bool subsequence, Chris@771: Transform transform, Chris@771: RiseFallPreprocessor outputPreprocessor); Chris@767: Chris@767: // Destroy the aligner, cleanly cancelling any ongoing alignment Chris@767: ~TransformDTWAligner(); Chris@767: Chris@767: void begin() override; Chris@767: Chris@767: static bool isAvailable(); Chris@767: Chris@767: private slots: Chris@767: void completionChanged(ModelId); Chris@767: Chris@767: private: Chris@767: bool performAlignment(); Chris@767: bool performAlignmentMagnitude(); Chris@767: bool performAlignmentRiseFall(); Chris@771: Chris@771: bool getValuesFrom(ModelId modelId, Chris@771: std::vector &frames, Chris@771: std::vector &values, Chris@771: sv_frame_t &resolution); Chris@771: Chris@771: Path makePath(const std::vector &alignment, Chris@771: const std::vector &refFrames, Chris@771: const std::vector &otherFrames, Chris@771: sv_samplerate_t sampleRate, Chris@771: sv_frame_t resolution); Chris@767: Chris@767: Document *m_document; Chris@767: ModelId m_reference; Chris@767: ModelId m_toAlign; Chris@767: ModelId m_referenceOutputModel; Chris@767: ModelId m_toAlignOutputModel; Chris@767: ModelId m_alignmentModel; Chris@767: Transform m_transform; Chris@767: DTWType m_dtwType; Chris@781: bool m_subsequence; Chris@767: bool m_incomplete; Chris@771: MagnitudePreprocessor m_magnitudePreprocessor; Chris@771: RiseFallPreprocessor m_riseFallPreprocessor; Chris@771: Chris@771: static QMutex m_dtwMutex; Chris@767: }; Chris@767: Chris@767: #endif