annotate align/Align.cpp @ 756:39808338e771 pitch-align

Fix argument passing mistake
author Chris Cannam
date Mon, 27 Apr 2020 14:59:50 +0100
parents 31289e8592c7
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@420 15 #include "Align.h"
Chris@753 16 #include "TransformAligner.h"
Chris@753 17 #include "ExternalProgramAligner.h"
Chris@744 18 #include "framework/Document.h"
Chris@420 19
Chris@422 20 #include <QSettings>
Chris@422 21
Chris@422 22 bool
Chris@753 23 Align::alignModel(Document *doc,
Chris@753 24 ModelId reference,
Chris@753 25 ModelId toAlign,
Chris@753 26 QString &error)
Chris@753 27 {
Chris@753 28 bool useProgram;
Chris@753 29 QString program;
Chris@753 30 getAlignerPreference(useProgram, program);
Chris@753 31
Chris@753 32 std::shared_ptr<Aligner> aligner;
Chris@753 33
Chris@753 34 {
Chris@753 35 // Replace the aligner with a new one. This also stops any
Chris@753 36 // previously-running alignment, when the old entry is
Chris@753 37 // replaced and its aligner destroyed.
Chris@753 38
Chris@753 39 QMutexLocker locker(&m_mutex);
Chris@753 40
Chris@753 41 if (useProgram && (program != "")) {
Chris@753 42 m_aligners[toAlign] =
Chris@753 43 std::make_shared<ExternalProgramAligner>(doc,
Chris@753 44 reference,
Chris@753 45 toAlign,
Chris@753 46 program);
Chris@753 47 } else {
Chris@753 48 m_aligners[toAlign] =
Chris@753 49 std::make_shared<TransformAligner>(doc,
Chris@753 50 reference,
Chris@753 51 toAlign);
Chris@753 52 }
Chris@753 53
Chris@753 54 aligner = m_aligners[toAlign];
Chris@753 55 }
Chris@753 56
Chris@753 57 connect(aligner.get(), SIGNAL(complete(ModelId)),
Chris@753 58 this, SLOT(alignerComplete(ModelId)));
Chris@753 59
Chris@753 60 return aligner->begin(error);
Chris@753 61 }
Chris@753 62
Chris@753 63 void
Chris@756 64 Align::getAlignerPreference(bool &useProgram, QString &program)
Chris@422 65 {
Chris@422 66 QSettings settings;
Chris@422 67 settings.beginGroup("Preferences");
Chris@753 68 useProgram = settings.value("use-external-alignment", false).toBool();
Chris@753 69 program = settings.value("external-alignment-program", "").toString();
Chris@422 70 settings.endGroup();
Chris@670 71 }
Chris@670 72
Chris@428 73 bool
Chris@428 74 Align::canAlign()
Chris@428 75 {
Chris@753 76 bool useProgram;
Chris@753 77 QString program;
Chris@753 78 getAlignerPreference(useProgram, program);
Chris@753 79
Chris@753 80 if (useProgram) {
Chris@753 81 return ExternalProgramAligner::isAvailable(program);
Chris@753 82 } else {
Chris@753 83 return TransformAligner::isAvailable();
Chris@753 84 }
Chris@428 85 }
Chris@428 86
Chris@702 87 void
Chris@753 88 Align::alignerComplete(ModelId alignmentModel)
Chris@702 89 {
Chris@753 90 Aligner *aligner = qobject_cast<Aligner *>(sender());
Chris@753 91 if (!aligner) {
Chris@753 92 SVCERR << "ERROR: Align::alignerComplete: Caller is not an Aligner"
Chris@753 93 << endl;
Chris@702 94 return;
Chris@702 95 }
Chris@702 96
Chris@753 97 {
Chris@753 98 QMutexLocker locker (&m_mutex);
Chris@702 99
Chris@753 100 for (auto p: m_aligners) {
Chris@753 101 if (aligner == p.second.get()) {
Chris@753 102 m_aligners.erase(p.first);
Chris@753 103 break;
Chris@753 104 }
Chris@702 105 }
Chris@702 106 }
Chris@702 107
Chris@753 108 emit alignmentComplete(alignmentModel);
Chris@702 109 }