Mercurial > hg > svapp
comparison framework/Align.cpp @ 665:e19c609a7bec
Update so Document owns the alignment model's input aggregate model
author | Chris Cannam |
---|---|
date | Thu, 04 Apr 2019 16:17:11 +0100 |
parents | e2715204feaa |
children | 21673429dba5 |
comparison
equal
deleted
inserted
replaced
644:6fd0ebfd2bbe | 665:e19c609a7bec |
---|---|
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "Align.h" | 16 #include "Align.h" |
17 #include "Document.h" | |
17 | 18 |
18 #include "data/model/WaveFileModel.h" | 19 #include "data/model/WaveFileModel.h" |
19 #include "data/model/ReadOnlyWaveFileModel.h" | 20 #include "data/model/ReadOnlyWaveFileModel.h" |
20 #include "data/model/AggregateWaveModel.h" | 21 #include "data/model/AggregateWaveModel.h" |
21 #include "data/model/RangeSummarisableTimeValueModel.h" | 22 #include "data/model/RangeSummarisableTimeValueModel.h" |
31 #include <QProcess> | 32 #include <QProcess> |
32 #include <QSettings> | 33 #include <QSettings> |
33 #include <QApplication> | 34 #include <QApplication> |
34 | 35 |
35 bool | 36 bool |
36 Align::alignModel(Model *ref, Model *other) | 37 Align::alignModel(Document *doc, Model *ref, Model *other) |
37 { | 38 { |
38 QSettings settings; | 39 QSettings settings; |
39 settings.beginGroup("Preferences"); | 40 settings.beginGroup("Preferences"); |
40 bool useProgram = settings.value("use-external-alignment", false).toBool(); | 41 bool useProgram = settings.value("use-external-alignment", false).toBool(); |
41 QString program = settings.value("external-alignment-program", "").toString(); | 42 QString program = settings.value("external-alignment-program", "").toString(); |
42 settings.endGroup(); | 43 settings.endGroup(); |
43 | 44 |
44 if (useProgram && (program != "")) { | 45 if (useProgram && (program != "")) { |
45 return alignModelViaProgram(ref, other, program); | 46 return alignModelViaProgram(doc, ref, other, program); |
46 } else { | 47 } else { |
47 return alignModelViaTransform(ref, other); | 48 return alignModelViaTransform(doc, ref, other); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 QString | 52 QString |
52 Align::getAlignmentTransformName() | 53 Align::getAlignmentTransformName() |
67 TransformFactory *factory = TransformFactory::getInstance(); | 68 TransformFactory *factory = TransformFactory::getInstance(); |
68 return factory->haveTransform(id); | 69 return factory->haveTransform(id); |
69 } | 70 } |
70 | 71 |
71 bool | 72 bool |
72 Align::alignModelViaTransform(Model *ref, Model *other) | 73 Align::alignModelViaTransform(Document *doc, Model *ref, Model *other) |
73 { | 74 { |
74 RangeSummarisableTimeValueModel *reference = qobject_cast | 75 RangeSummarisableTimeValueModel *reference = qobject_cast |
75 <RangeSummarisableTimeValueModel *>(ref); | 76 <RangeSummarisableTimeValueModel *>(ref); |
76 | 77 |
77 RangeSummarisableTimeValueModel *rm = qobject_cast | 78 RangeSummarisableTimeValueModel *rm = qobject_cast |
104 (reference, -1)); | 105 (reference, -1)); |
105 | 106 |
106 components.push_back(AggregateWaveModel::ModelChannelSpec | 107 components.push_back(AggregateWaveModel::ModelChannelSpec |
107 (rm, -1)); | 108 (rm, -1)); |
108 | 109 |
109 Model *aggregateModel = new AggregateWaveModel(components); | 110 AggregateWaveModel *aggregateModel = new AggregateWaveModel(components); |
111 doc->addAggregateModel(aggregateModel); | |
112 | |
110 ModelTransformer::Input aggregate(aggregateModel); | 113 ModelTransformer::Input aggregate(aggregateModel); |
111 | 114 |
112 TransformId id = getAlignmentTransformName(); | 115 TransformId id = getAlignmentTransformName(); |
113 | 116 |
114 TransformFactory *tf = TransformFactory::getInstance(); | 117 TransformFactory *tf = TransformFactory::getInstance(); |
144 } | 147 } |
145 | 148 |
146 path->setCompletion(0); | 149 path->setCompletion(0); |
147 | 150 |
148 AlignmentModel *alignmentModel = new AlignmentModel | 151 AlignmentModel *alignmentModel = new AlignmentModel |
149 (reference, other, aggregateModel, path); | 152 (reference, other, path); |
150 | 153 |
151 connect(alignmentModel, SIGNAL(completionChanged()), | 154 connect(alignmentModel, SIGNAL(completionChanged()), |
152 this, SLOT(alignmentCompletionChanged())); | 155 this, SLOT(alignmentCompletionChanged())); |
153 | 156 |
154 rm->setAlignment(alignmentModel); | 157 rm->setAlignment(alignmentModel); |
167 emit alignmentComplete(am); | 170 emit alignmentComplete(am); |
168 } | 171 } |
169 } | 172 } |
170 | 173 |
171 bool | 174 bool |
172 Align::alignModelViaProgram(Model *ref, Model *other, QString program) | 175 Align::alignModelViaProgram(Document *, Model *ref, Model *other, QString program) |
173 { | 176 { |
174 WaveFileModel *reference = qobject_cast<WaveFileModel *>(ref); | 177 WaveFileModel *reference = qobject_cast<WaveFileModel *>(ref); |
175 WaveFileModel *rm = qobject_cast<WaveFileModel *>(other); | 178 WaveFileModel *rm = qobject_cast<WaveFileModel *>(other); |
176 | 179 |
177 if (!reference || !rm) { | 180 if (!reference || !rm) { |
201 return false; | 204 return false; |
202 } | 205 } |
203 | 206 |
204 m_error = ""; | 207 m_error = ""; |
205 | 208 |
206 AlignmentModel *alignmentModel = new AlignmentModel(reference, other, nullptr, nullptr); | 209 AlignmentModel *alignmentModel = |
210 new AlignmentModel(reference, other, nullptr); | |
207 rm->setAlignment(alignmentModel); | 211 rm->setAlignment(alignmentModel); |
208 | 212 |
209 QProcess *process = new QProcess; | 213 QProcess *process = new QProcess; |
210 QStringList args; | 214 QStringList args; |
211 args << refPath << otherPath; | 215 args << refPath << otherPath; |