comparison framework/Document.cpp @ 679:1f18e0f64af8

Defer alignment for recorded audio until recording is complete
author Chris Cannam
date Thu, 13 Jun 2019 20:36:10 +0100
parents 0d4236961c97
children 0736beb8b852
comparison
equal deleted inserted replaced
678:16c1077da62c 679:1f18e0f64af8
41 #include "data/model/AlignmentModel.h" 41 #include "data/model/AlignmentModel.h"
42 #include "Align.h" 42 #include "Align.h"
43 43
44 using std::vector; 44 using std::vector;
45 45
46 //#define DEBUG_DOCUMENT 1 46 #define DEBUG_DOCUMENT 1
47 47
48 //!!! still need to handle command history, documentRestored/documentModified 48 //!!! still need to handle command history, documentRestored/documentModified
49 49
50 Document::Document() : 50 Document::Document() :
51 m_mainModel(nullptr), 51 m_mainModel(nullptr),
1119 void 1119 void
1120 Document::alignModel(Model *model, bool forceRecalculate) 1120 Document::alignModel(Model *model, bool forceRecalculate)
1121 { 1121 {
1122 SVDEBUG << "Document::alignModel(" << model << ", " << forceRecalculate 1122 SVDEBUG << "Document::alignModel(" << model << ", " << forceRecalculate
1123 << ") (main model is " << m_mainModel << ")" << endl; 1123 << ") (main model is " << m_mainModel << ")" << endl;
1124 1124
1125 RangeSummarisableTimeValueModel *rm = 1125 RangeSummarisableTimeValueModel *rm =
1126 dynamic_cast<RangeSummarisableTimeValueModel *>(model); 1126 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
1127 if (!rm) { 1127 if (!rm) {
1128 SVDEBUG << "(model " << rm << " is not an alignable sort)" << endl; 1128 SVDEBUG << "(model " << rm << " is not an alignable sort)" << endl;
1129 return; 1129 return;
1159 << "): is main model, setting alignment to itself" << endl; 1159 << "): is main model, setting alignment to itself" << endl;
1160 rm->setAlignment(new AlignmentModel(model, model, nullptr)); 1160 rm->setAlignment(new AlignmentModel(model, model, nullptr));
1161 return; 1161 return;
1162 } 1162 }
1163 1163
1164 WritableWaveFileModel *w =
1165 dynamic_cast<WritableWaveFileModel *>(model);
1166 if (w && w->getWriteProportion() < 100) {
1167 SVDEBUG << "Document::alignModel(" << model
1168 << "): model write is not complete, deferring"
1169 << endl;
1170 connect(w, SIGNAL(writeCompleted()),
1171 this, SLOT(performDeferredAlignment()));
1172 return;
1173 }
1174
1164 SVDEBUG << "Document::alignModel: aligning..." << endl; 1175 SVDEBUG << "Document::alignModel: aligning..." << endl;
1165 if (rm->getAlignmentReference() != nullptr) { 1176 if (rm->getAlignmentReference() != nullptr) {
1166 SVDEBUG << "(Note: model " << rm << " is currently aligned to model " 1177 SVDEBUG << "(Note: model " << rm << " is currently aligned to model "
1167 << rm->getAlignmentReference() << "; this will replace that)" 1178 << rm->getAlignmentReference() << "; this will replace that)"
1168 << endl; 1179 << endl;
1170 1181
1171 QString err; 1182 QString err;
1172 if (!m_align->alignModel(this, m_mainModel, rm, err)) { 1183 if (!m_align->alignModel(this, m_mainModel, rm, err)) {
1173 SVCERR << "Alignment failed: " << err << endl; 1184 SVCERR << "Alignment failed: " << err << endl;
1174 emit alignmentFailed(err); 1185 emit alignmentFailed(err);
1186 }
1187 }
1188
1189 void
1190 Document::performDeferredAlignment()
1191 {
1192 QObject *s = sender();
1193 Model *m = dynamic_cast<Model *>(s);
1194 if (!m) {
1195 SVDEBUG << "Document::performDeferredAlignment: sender is not a Model" << endl;
1196 } else {
1197 SVDEBUG << "Document::performDeferredAlignment: aligning..." << endl;
1198 alignModel(m);
1175 } 1199 }
1176 } 1200 }
1177 1201
1178 void 1202 void
1179 Document::alignModels() 1203 Document::alignModels()