comparison framework/Align.cpp @ 423:f32a64149602 alignment_view

Make alignment using an external program asynchronous
author Chris Cannam
date Thu, 20 Nov 2014 15:46:19 +0000
parents 33fae747db7e
children d044682967ca
comparison
equal deleted inserted replaced
422:33fae747db7e 423:f32a64149602
149 if (refPath == "" || otherPath == "") { 149 if (refPath == "" || otherPath == "") {
150 m_error = "Failed to find local filepath for wave-file model"; 150 m_error = "Failed to find local filepath for wave-file model";
151 return false; 151 return false;
152 } 152 }
153 153
154 QProcess process; 154 m_error = "";
155
156 AlignmentModel *alignmentModel = new AlignmentModel(reference, other, 0, 0);
157 rm->setAlignment(alignmentModel);
158
159 QProcess *process = new QProcess;
155 QStringList args; 160 QStringList args;
156 args << refPath << otherPath; 161 args << refPath << otherPath;
157 process.start(program, args); 162
158 163 connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
159 process.waitForFinished(60000); //!!! nb timeout, but we can do better than blocking anyway 164 this, SLOT(alignmentProgramFinished(int, QProcess::ExitStatus)));
160 165
161 if (process.exitStatus() == 0) { 166 m_processModels[process] = alignmentModel;
167 process->start(program, args);
168
169 bool success = process->waitForStarted();
170
171 if (!success) {
172 cerr << "ERROR: Align::alignModelViaProgram: Program did not start"
173 << endl;
174 m_error = "Alignment program could not be started";
175 m_processModels.erase(process);
176 delete alignmentModel;
177 delete process;
178 }
179
180 return success;
181 }
182
183 void
184 Align::alignmentProgramFinished(int exitCode, QProcess::ExitStatus status)
185 {
186 cerr << "Align::alignmentProgramFinished" << endl;
187
188 QProcess *process = qobject_cast<QProcess *>(sender());
189
190 if (m_processModels.find(process) == m_processModels.end()) {
191 cerr << "ERROR: Align::alignmentProgramFinished: Process " << process
192 << " not found in process model map!" << endl;
193 return;
194 }
195
196 AlignmentModel *alignmentModel = m_processModels[process];
197
198 if (exitCode == 0 && status == 0) {
162 199
163 CSVFormat format; 200 CSVFormat format;
164 format.setModelType(CSVFormat::TwoDimensionalModel); 201 format.setModelType(CSVFormat::TwoDimensionalModel);
165 format.setTimingType(CSVFormat::ExplicitTiming); 202 format.setTimingType(CSVFormat::ExplicitTiming);
166 format.setTimeUnits(CSVFormat::TimeSeconds); 203 format.setTimeUnits(CSVFormat::TimeSeconds);
168 format.setColumnPurpose(0, CSVFormat::ColumnStartTime); 205 format.setColumnPurpose(0, CSVFormat::ColumnStartTime);
169 format.setColumnPurpose(1, CSVFormat::ColumnValue); 206 format.setColumnPurpose(1, CSVFormat::ColumnValue);
170 format.setAllowQuoting(false); 207 format.setAllowQuoting(false);
171 format.setSeparator(','); 208 format.setSeparator(',');
172 209
173 CSVFileReader reader(&process, format, reference->getSampleRate()); 210 CSVFileReader reader(process, format, alignmentModel->getSampleRate());
174 if (!reader.isOK()) { 211 if (!reader.isOK()) {
212 cerr << "ERROR: Align::alignmentProgramFinished: Failed to parse output"
213 << endl;
175 m_error = QString("Failed to parse output of program: %1") 214 m_error = QString("Failed to parse output of program: %1")
176 .arg(reader.getError()); 215 .arg(reader.getError());
177 return false; 216 goto done;
178 } 217 }
179 218
180 Model *csvOutput = reader.load(); 219 Model *csvOutput = reader.load();
181 220
182 SparseTimeValueModel *path = qobject_cast<SparseTimeValueModel *>(csvOutput); 221 SparseTimeValueModel *path = qobject_cast<SparseTimeValueModel *>(csvOutput);
183 if (!path) { 222 if (!path) {
223 cerr << "ERROR: Align::alignmentProgramFinished: Output did not convert to sparse time-value model"
224 << endl;
184 m_error = QString("Output of program did not produce sparse time-value model"); 225 m_error = QString("Output of program did not produce sparse time-value model");
185 return false; 226 goto done;
186 } 227 }
187 228
188 if (path->getPoints().empty()) { 229 if (path->getPoints().empty()) {
230 cerr << "ERROR: Align::alignmentProgramFinished: Output contained no mappings"
231 << endl;
189 m_error = QString("Output of alignment program contained no mappings"); 232 m_error = QString("Output of alignment program contained no mappings");
190 return false; 233 goto done;
191 } 234 }
192 235
193 AlignmentModel *alignmentModel = new AlignmentModel 236 cerr << "Align::alignmentProgramFinished: Setting alignment path ("
194 (reference, other, 0, path); 237 << path->getPoints().size() << " point(s))" << endl;
195 238
196 rm->setAlignment(alignmentModel); 239 alignmentModel->setPathFrom(path);
197 240
198 } else { 241 } else {
242 cerr << "ERROR: Align::alignmentProgramFinished: Aligner program "
243 << "failed: exit code " << exitCode << ", status " << status
244 << endl;
199 m_error = "Aligner process returned non-zero exit status"; 245 m_error = "Aligner process returned non-zero exit status";
200 return false; 246 }
201 } 247
202 248 done:
203 cerr << "Align: success" << endl; 249 m_processModels.erase(process);
204 250 delete process;
205 return true; 251 }
206 } 252
207