Chris@420: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@420: Chris@420: /* Chris@420: Sonic Visualiser Chris@420: An audio file viewer and annotation editor. Chris@420: Centre for Digital Music, Queen Mary, University of London. Chris@420: Chris@420: This program is free software; you can redistribute it and/or Chris@420: modify it under the terms of the GNU General Public License as Chris@420: published by the Free Software Foundation; either version 2 of the Chris@420: License, or (at your option) any later version. See the file Chris@420: COPYING included with this distribution for more information. Chris@420: */ Chris@420: Chris@420: #include "Align.h" Chris@753: #include "TransformAligner.h" Chris@753: #include "ExternalProgramAligner.h" Chris@744: #include "framework/Document.h" Chris@420: Chris@422: #include Chris@422: Chris@422: bool Chris@753: Align::alignModel(Document *doc, Chris@753: ModelId reference, Chris@753: ModelId toAlign, Chris@753: QString &error) Chris@753: { Chris@753: bool useProgram; Chris@753: QString program; Chris@753: getAlignerPreference(useProgram, program); Chris@753: Chris@753: std::shared_ptr aligner; Chris@753: Chris@753: { Chris@753: // Replace the aligner with a new one. This also stops any Chris@753: // previously-running alignment, when the old entry is Chris@753: // replaced and its aligner destroyed. Chris@753: Chris@753: QMutexLocker locker(&m_mutex); Chris@753: Chris@753: if (useProgram && (program != "")) { Chris@753: m_aligners[toAlign] = Chris@753: std::make_shared(doc, Chris@753: reference, Chris@753: toAlign, Chris@753: program); Chris@753: } else { Chris@753: m_aligners[toAlign] = Chris@753: std::make_shared(doc, Chris@753: reference, Chris@753: toAlign); Chris@753: } Chris@753: Chris@753: aligner = m_aligners[toAlign]; Chris@753: } Chris@753: Chris@753: connect(aligner.get(), SIGNAL(complete(ModelId)), Chris@753: this, SLOT(alignerComplete(ModelId))); Chris@753: Chris@753: return aligner->begin(error); Chris@753: } Chris@753: Chris@753: void Chris@756: Align::getAlignerPreference(bool &useProgram, QString &program) Chris@422: { Chris@422: QSettings settings; Chris@422: settings.beginGroup("Preferences"); Chris@753: useProgram = settings.value("use-external-alignment", false).toBool(); Chris@753: program = settings.value("external-alignment-program", "").toString(); Chris@422: settings.endGroup(); Chris@670: } Chris@670: Chris@428: bool Chris@428: Align::canAlign() Chris@428: { Chris@753: bool useProgram; Chris@753: QString program; Chris@753: getAlignerPreference(useProgram, program); Chris@753: Chris@753: if (useProgram) { Chris@753: return ExternalProgramAligner::isAvailable(program); Chris@753: } else { Chris@753: return TransformAligner::isAvailable(); Chris@753: } Chris@428: } Chris@428: Chris@702: void Chris@753: Align::alignerComplete(ModelId alignmentModel) Chris@702: { Chris@753: Aligner *aligner = qobject_cast(sender()); Chris@753: if (!aligner) { Chris@753: SVCERR << "ERROR: Align::alignerComplete: Caller is not an Aligner" Chris@753: << endl; Chris@702: return; Chris@702: } Chris@702: Chris@753: { Chris@753: QMutexLocker locker (&m_mutex); Chris@702: Chris@753: for (auto p: m_aligners) { Chris@753: if (aligner == p.second.get()) { Chris@753: m_aligners.erase(p.first); Chris@753: break; Chris@753: } Chris@702: } Chris@702: } Chris@702: Chris@753: emit alignmentComplete(alignmentModel); Chris@702: }