comparison view/View.cpp @ 1486:ac0a8addabcf

Merge from branch by-id
author Chris Cannam
date Wed, 17 Jul 2019 14:25:16 +0100
parents 0e971e3d93e2
children c3cc36c014b8
comparison
equal deleted inserted replaced
1468:de41a11cabc2 1486:ac0a8addabcf
630 bool widgetLight = 630 bool widgetLight =
631 (widgetbg.red() + widgetbg.green() + widgetbg.blue()) > 384; 631 (widgetbg.red() + widgetbg.green() + widgetbg.blue()) > 384;
632 632
633 if (widgetLight == light) { 633 if (widgetLight == light) {
634 if (widgetLight) { 634 if (widgetLight) {
635 return widgetbg.light(); 635 return widgetbg.lighter();
636 } else { 636 } else {
637 return widgetbg.dark(); 637 return widgetbg.darker();
638 } 638 }
639 } 639 }
640 else if (light) return Qt::white; 640 else if (light) return Qt::white;
641 else return Qt::black; 641 else return Qt::black;
642 } 642 }
704 this, SLOT(layerParameterRangesChanged())); 704 this, SLOT(layerParameterRangesChanged()));
705 connect(layer, SIGNAL(layerMeasurementRectsChanged()), 705 connect(layer, SIGNAL(layerMeasurementRectsChanged()),
706 this, SLOT(layerMeasurementRectsChanged())); 706 this, SLOT(layerMeasurementRectsChanged()));
707 connect(layer, SIGNAL(layerNameChanged()), 707 connect(layer, SIGNAL(layerNameChanged()),
708 this, SLOT(layerNameChanged())); 708 this, SLOT(layerNameChanged()));
709 connect(layer, SIGNAL(modelChanged()), 709 connect(layer, SIGNAL(modelChanged(ModelId)),
710 this, SLOT(modelChanged())); 710 this, SLOT(modelChanged(ModelId)));
711 connect(layer, SIGNAL(modelCompletionChanged()), 711 connect(layer, SIGNAL(modelCompletionChanged(ModelId)),
712 this, SLOT(modelCompletionChanged())); 712 this, SLOT(modelCompletionChanged(ModelId)));
713 connect(layer, SIGNAL(modelAlignmentCompletionChanged()), 713 connect(layer, SIGNAL(modelAlignmentCompletionChanged(ModelId)),
714 this, SLOT(modelAlignmentCompletionChanged())); 714 this, SLOT(modelAlignmentCompletionChanged(ModelId)));
715 connect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), 715 connect(layer, SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)),
716 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); 716 this, SLOT(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)));
717 connect(layer, SIGNAL(modelReplaced()), 717 connect(layer, SIGNAL(modelReplaced()),
718 this, SLOT(modelReplaced())); 718 this, SLOT(modelReplaced()));
719 719
720 update(); 720 update();
721 721
759 this, SLOT(layerParametersChanged())); 759 this, SLOT(layerParametersChanged()));
760 disconnect(layer, SIGNAL(layerParameterRangesChanged()), 760 disconnect(layer, SIGNAL(layerParameterRangesChanged()),
761 this, SLOT(layerParameterRangesChanged())); 761 this, SLOT(layerParameterRangesChanged()));
762 disconnect(layer, SIGNAL(layerNameChanged()), 762 disconnect(layer, SIGNAL(layerNameChanged()),
763 this, SLOT(layerNameChanged())); 763 this, SLOT(layerNameChanged()));
764 disconnect(layer, SIGNAL(modelChanged()), 764 disconnect(layer, SIGNAL(modelChanged(ModelId)),
765 this, SLOT(modelChanged())); 765 this, SLOT(modelChanged(ModelId)));
766 disconnect(layer, SIGNAL(modelCompletionChanged()), 766 disconnect(layer, SIGNAL(modelCompletionChanged(ModelId)),
767 this, SLOT(modelCompletionChanged())); 767 this, SLOT(modelCompletionChanged(ModelId)));
768 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()), 768 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged(ModelId)),
769 this, SLOT(modelAlignmentCompletionChanged())); 769 this, SLOT(modelAlignmentCompletionChanged(ModelId)));
770 disconnect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), 770 disconnect(layer, SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)),
771 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); 771 this, SLOT(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)));
772 disconnect(layer, SIGNAL(modelReplaced()), 772 disconnect(layer, SIGNAL(modelReplaced()),
773 this, SLOT(modelReplaced())); 773 this, SLOT(modelReplaced()));
774 774
775 update(); 775 update();
776 776
920 m_followPlay = m; 920 m_followPlay = m;
921 emit propertyContainerPropertyChanged(m_propertyContainer); 921 emit propertyContainerPropertyChanged(m_propertyContainer);
922 } 922 }
923 923
924 void 924 void
925 View::modelChanged() 925 View::modelChanged(ModelId modelId)
926 { 926 {
927 QObject *obj = sender();
928
929 #ifdef DEBUG_VIEW_WIDGET_PAINT 927 #ifdef DEBUG_VIEW_WIDGET_PAINT
930 cerr << "View(" << this << ")::modelChanged()" << endl; 928 cerr << "View(" << this << ")::modelChanged()" << endl;
931 #endif 929 #endif
932 930
933 // If the model that has changed is not used by any of the cached 931 // If the model that has changed is not used by any of the cached
934 // layers, we won't need to recreate the cache 932 // layers, we won't need to recreate the cache
935 933
936 bool recreate = false; 934 bool recreate = false;
937 935
938 bool discard; 936 bool discard;
939 LayerList scrollables = getScrollableBackLayers(false, discard); 937 LayerList scrollables = getScrollableBackLayers(false, discard);
940 for (LayerList::const_iterator i = scrollables.begin(); 938 for (LayerList::const_iterator i = scrollables.begin();
941 i != scrollables.end(); ++i) { 939 i != scrollables.end(); ++i) {
942 if (*i == obj || (*i)->getModel() == obj) { 940 if ((*i)->getModel() == modelId) {
943 recreate = true; 941 recreate = true;
944 break; 942 break;
945 } 943 }
946 } 944 }
947 945
949 m_cacheValid = false; 947 m_cacheValid = false;
950 } 948 }
951 949
952 emit layerModelChanged(); 950 emit layerModelChanged();
953 951
954 checkProgress(obj); 952 checkProgress(modelId);
955 953
956 update(); 954 update();
957 } 955 }
958 956
959 void 957 void
960 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) 958 View::modelChangedWithin(ModelId modelId,
961 { 959 sv_frame_t startFrame, sv_frame_t endFrame)
962 QObject *obj = sender(); 960 {
963
964 sv_frame_t myStartFrame = getStartFrame(); 961 sv_frame_t myStartFrame = getStartFrame();
965 sv_frame_t myEndFrame = getEndFrame(); 962 sv_frame_t myEndFrame = getEndFrame();
966 963
967 #ifdef DEBUG_VIEW_WIDGET_PAINT 964 #ifdef DEBUG_VIEW_WIDGET_PAINT
968 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl; 965 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl;
969 #endif 966 #endif
970 967
971 if (myStartFrame > 0 && endFrame < myStartFrame) { 968 if (myStartFrame > 0 && endFrame < myStartFrame) {
972 checkProgress(obj); 969 checkProgress(modelId);
973 return; 970 return;
974 } 971 }
975 if (startFrame > myEndFrame) { 972 if (startFrame > myEndFrame) {
976 checkProgress(obj); 973 checkProgress(modelId);
977 return; 974 return;
978 } 975 }
979 976
980 // If the model that has changed is not used by any of the cached 977 // If the model that has changed is not used by any of the cached
981 // layers, we won't need to recreate the cache 978 // layers, we won't need to recreate the cache
984 981
985 bool discard; 982 bool discard;
986 LayerList scrollables = getScrollableBackLayers(false, discard); 983 LayerList scrollables = getScrollableBackLayers(false, discard);
987 for (LayerList::const_iterator i = scrollables.begin(); 984 for (LayerList::const_iterator i = scrollables.begin();
988 i != scrollables.end(); ++i) { 985 i != scrollables.end(); ++i) {
989 if (*i == obj || (*i)->getModel() == obj) { 986 if ((*i)->getModel() == modelId) {
990 recreate = true; 987 recreate = true;
991 break; 988 break;
992 } 989 }
993 } 990 }
994 991
997 } 994 }
998 995
999 if (startFrame < myStartFrame) startFrame = myStartFrame; 996 if (startFrame < myStartFrame) startFrame = myStartFrame;
1000 if (endFrame > myEndFrame) endFrame = myEndFrame; 997 if (endFrame > myEndFrame) endFrame = myEndFrame;
1001 998
1002 checkProgress(obj); 999 checkProgress(modelId);
1003 1000
1004 update(); 1001 update();
1005 } 1002 }
1006 1003
1007 void 1004 void
1008 View::modelCompletionChanged() 1005 View::modelCompletionChanged(ModelId modelId)
1009 { 1006 {
1010 // cerr << "View(" << this << ")::modelCompletionChanged()" << endl; 1007 checkProgress(modelId);
1011 1008 }
1012 QObject *obj = sender(); 1009
1013 checkProgress(obj); 1010 void
1014 } 1011 View::modelAlignmentCompletionChanged(ModelId modelId)
1015 1012 {
1016 void 1013 checkProgress(modelId);
1017 View::modelAlignmentCompletionChanged()
1018 {
1019 // cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << endl;
1020
1021 QObject *obj = sender();
1022 checkProgress(obj);
1023 } 1014 }
1024 1015
1025 void 1016 void
1026 View::modelReplaced() 1017 View::modelReplaced()
1027 { 1018 {
1268 View::getModelsStartFrame() const 1259 View::getModelsStartFrame() const
1269 { 1260 {
1270 bool first = true; 1261 bool first = true;
1271 sv_frame_t startFrame = 0; 1262 sv_frame_t startFrame = 0;
1272 1263
1273 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1264 for (Layer *layer: m_layerStack) {
1274 1265
1275 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1266 auto model = ModelById::get(layer->getModel());
1276 1267
1277 sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame(); 1268 if (model && model->isOK()) {
1269
1270 sv_frame_t thisStartFrame = model->getStartFrame();
1278 1271
1279 if (first || thisStartFrame < startFrame) { 1272 if (first || thisStartFrame < startFrame) {
1280 startFrame = thisStartFrame; 1273 startFrame = thisStartFrame;
1281 } 1274 }
1282 first = false; 1275 first = false;
1283 } 1276 }
1284 } 1277 }
1278
1285 return startFrame; 1279 return startFrame;
1286 } 1280 }
1287 1281
1288 sv_frame_t 1282 sv_frame_t
1289 View::getModelsEndFrame() const 1283 View::getModelsEndFrame() const
1290 { 1284 {
1291 bool first = true; 1285 bool first = true;
1292 sv_frame_t endFrame = 0; 1286 sv_frame_t endFrame = 0;
1293 1287
1294 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1288 for (Layer *layer: m_layerStack) {
1295 1289
1296 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1290 auto model = ModelById::get(layer->getModel());
1297 1291
1298 sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame(); 1292 if (model && model->isOK()) {
1293
1294 sv_frame_t thisEndFrame = model->getEndFrame();
1299 1295
1300 if (first || thisEndFrame > endFrame) { 1296 if (first || thisEndFrame > endFrame) {
1301 endFrame = thisEndFrame; 1297 endFrame = thisEndFrame;
1302 } 1298 }
1303 first = false; 1299 first = false;
1315 // multiple samplerates, we'd probably want to do frame/time 1311 // multiple samplerates, we'd probably want to do frame/time
1316 // conversion in the model 1312 // conversion in the model
1317 1313
1318 //!!! nah, this wants to always return the sr of the main model! 1314 //!!! nah, this wants to always return the sr of the main model!
1319 1315
1320 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1316 for (Layer *layer: m_layerStack) {
1321 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1317
1322 return (*i)->getModel()->getSampleRate(); 1318 auto model = ModelById::get(layer->getModel());
1323 } 1319
1324 } 1320 if (model && model->isOK()) {
1321 return model->getSampleRate();
1322 }
1323 }
1324
1325 return 0; 1325 return 0;
1326 } 1326 }
1327 1327
1328 View::ModelSet 1328 View::ModelSet
1329 View::getModels() 1329 View::getModels()
1336 1336
1337 if (dynamic_cast<TimeRulerLayer *>(layer)) { 1337 if (dynamic_cast<TimeRulerLayer *>(layer)) {
1338 continue; 1338 continue;
1339 } 1339 }
1340 1340
1341 if (layer && layer->getModel()) { 1341 if (layer && !layer->getModel().isNone()) {
1342 Model *model = layer->getModel(); 1342 models.insert(layer->getModel());
1343 models.insert(model);
1344 } 1343 }
1345 } 1344 }
1346 1345
1347 return models; 1346 return models;
1348 } 1347 }
1349 1348
1350 Model * 1349 ModelId
1351 View::getAligningModel() const 1350 View::getAligningModel() const
1352 { 1351 {
1353 if (!m_manager || 1352 if (!m_manager ||
1354 !m_manager->getAlignMode() || 1353 !m_manager->getAlignMode() ||
1355 !m_manager->getPlaybackModel()) { 1354 m_manager->getPlaybackModel().isNone()) {
1356 return nullptr; 1355 return {};
1357 } 1356 }
1358 1357
1359 Model *anyModel = nullptr; 1358 ModelId anyModel;
1360 Model *alignedModel = nullptr; 1359 ModelId alignedModel;
1361 Model *goodModel = nullptr; 1360 ModelId goodModel;
1362 1361
1363 for (LayerList::const_iterator i = m_layerStack.begin(); 1362 for (auto layer: m_layerStack) {
1364 i != m_layerStack.end(); ++i) {
1365
1366 Layer *layer = *i;
1367 1363
1368 if (!layer) continue; 1364 if (!layer) continue;
1369 if (dynamic_cast<TimeRulerLayer *>(layer)) continue; 1365 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
1370 1366
1371 Model *model = (*i)->getModel(); 1367 ModelId thisId = layer->getModel();
1368 auto model = ModelById::get(thisId);
1372 if (!model) continue; 1369 if (!model) continue;
1373 1370
1374 anyModel = model; 1371 anyModel = thisId;
1375 1372
1376 if (model->getAlignmentReference()) { 1373 if (!model->getAlignmentReference().isNone()) {
1377 alignedModel = model; 1374 alignedModel = thisId;
1378 if (layer->isLayerOpaque() || 1375 if (layer->isLayerOpaque() ||
1379 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { 1376 std::dynamic_pointer_cast
1380 goodModel = model; 1377 <RangeSummarisableTimeValueModel>(model)) {
1381 } 1378 goodModel = thisId;
1382 } 1379 }
1383 } 1380 }
1384 1381 }
1385 if (goodModel) return goodModel; 1382
1386 else if (alignedModel) return alignedModel; 1383 if (!goodModel.isNone()) return goodModel;
1384 else if (!alignedModel.isNone()) return alignedModel;
1387 else return anyModel; 1385 else return anyModel;
1388 } 1386 }
1389 1387
1390 sv_frame_t 1388 sv_frame_t
1391 View::alignFromReference(sv_frame_t f) const 1389 View::alignFromReference(sv_frame_t f) const
1392 { 1390 {
1393 if (!m_manager || !m_manager->getAlignMode()) return f; 1391 if (!m_manager || !m_manager->getAlignMode()) return f;
1394 Model *aligningModel = getAligningModel(); 1392 auto aligningModel = ModelById::get(getAligningModel());
1395 if (!aligningModel) return f; 1393 if (!aligningModel) return f;
1396 return aligningModel->alignFromReference(f); 1394 return aligningModel->alignFromReference(f);
1397 } 1395 }
1398 1396
1399 sv_frame_t 1397 sv_frame_t
1400 View::alignToReference(sv_frame_t f) const 1398 View::alignToReference(sv_frame_t f) const
1401 { 1399 {
1402 if (!m_manager->getAlignMode()) return f; 1400 if (!m_manager->getAlignMode()) return f;
1403 Model *aligningModel = getAligningModel(); 1401 auto aligningModel = ModelById::get(getAligningModel());
1404 if (!aligningModel) return f; 1402 if (!aligningModel) return f;
1405 return aligningModel->alignToReference(f); 1403 return aligningModel->alignToReference(f);
1406 } 1404 }
1407 1405
1408 sv_frame_t 1406 sv_frame_t
1410 { 1408 {
1411 if (!m_manager) return 0; 1409 if (!m_manager) return 0;
1412 sv_frame_t pf = m_manager->getPlaybackFrame(); 1410 sv_frame_t pf = m_manager->getPlaybackFrame();
1413 if (!m_manager->getAlignMode()) return pf; 1411 if (!m_manager->getAlignMode()) return pf;
1414 1412
1415 Model *aligningModel = getAligningModel(); 1413 auto aligningModel = ModelById::get(getAligningModel());
1416 if (!aligningModel) return pf; 1414 if (!aligningModel) return pf;
1417 1415
1418 sv_frame_t af = aligningModel->alignFromReference(pf); 1416 sv_frame_t af = aligningModel->alignFromReference(pf);
1419 1417
1420 return af; 1418 return af;
1719 View::cancelClicked() 1717 View::cancelClicked()
1720 { 1718 {
1721 QPushButton *cancel = qobject_cast<QPushButton *>(sender()); 1719 QPushButton *cancel = qobject_cast<QPushButton *>(sender());
1722 if (!cancel) return; 1720 if (!cancel) return;
1723 1721
1722 Layer *layer = nullptr;
1723
1724 for (ProgressMap::iterator i = m_progressBars.begin(); 1724 for (ProgressMap::iterator i = m_progressBars.begin();
1725 i != m_progressBars.end(); ++i) { 1725 i != m_progressBars.end(); ++i) {
1726
1727 if (i->second.cancel == cancel) { 1726 if (i->second.cancel == cancel) {
1728 1727 layer = i->first;
1729 Layer *layer = i->first; 1728 break;
1730 Model *model = layer->getModel(); 1729 }
1731 1730 }
1732 if (model) model->abandon(); 1731
1733 } 1732 if (layer) {
1734 } 1733 emit cancelButtonPressed(layer);
1735 } 1734 }
1736 1735 }
1737 void 1736
1738 View::checkProgress(void *object) 1737 void
1738 View::checkProgress(ModelId modelId)
1739 { 1739 {
1740 if (!m_showProgress) { 1740 if (!m_showProgress) {
1741 #ifdef DEBUG_PROGRESS_STUFF 1741 #ifdef DEBUG_PROGRESS_STUFF
1742 SVCERR << "View[" << this << "]::checkProgress(" << object << "): " 1742 SVCERR << "View[" << this << "]::checkProgress(" << modelId << "): "
1743 << "m_showProgress is off" << endl; 1743 << "m_showProgress is off" << endl;
1744 #endif 1744 #endif
1745 return; 1745 return;
1746 } 1746 }
1747 1747
1757 i != m_progressBars.end(); ++i) { 1757 i != m_progressBars.end(); ++i) {
1758 1758
1759 QProgressBar *pb = i->second.bar; 1759 QProgressBar *pb = i->second.bar;
1760 QPushButton *cancel = i->second.cancel; 1760 QPushButton *cancel = i->second.cancel;
1761 1761
1762 if (i->first == object) { 1762 if (i->first && i->first->getModel() == modelId) {
1763 1763
1764 found = true; 1764 found = true;
1765 1765
1766 if (i->first->isLayerDormant(this)) { 1766 if (i->first->isLayerDormant(this)) {
1767 // A dormant (invisible) layer can still be busy 1767 // A dormant (invisible) layer can still be busy
1791 if (error != "" && error != m_lastError) { 1791 if (error != "" && error != m_lastError) {
1792 QMessageBox::critical(this, tr("Layer rendering error"), error); 1792 QMessageBox::critical(this, tr("Layer rendering error"), error);
1793 m_lastError = error; 1793 m_lastError = error;
1794 } 1794 }
1795 1795
1796 Model *model = i->first->getModel(); 1796 auto model = ModelById::get(modelId);
1797 RangeSummarisableTimeValueModel *wfm = 1797 auto wfm = std::dynamic_pointer_cast
1798 dynamic_cast<RangeSummarisableTimeValueModel *>(model); 1798 <RangeSummarisableTimeValueModel>(model);
1799 1799
1800 if (completion > 0) { 1800 if (completion > 0) {
1801 pb->setMaximum(100); // was 0, for indeterminate start 1801 pb->setMaximum(100); // was 0, for indeterminate start
1802 } 1802 }
1803 1803
1804 if (completion >= 100) { 1804 if (completion >= 100) {
1805 1805
1806 //!!!
1807 if (wfm || 1806 if (wfm ||
1808 (model && 1807 (model &&
1809 (wfm = dynamic_cast<RangeSummarisableTimeValueModel *> 1808 (wfm = ModelById::getAs<RangeSummarisableTimeValueModel>
1810 (model->getSourceModel())))) { 1809 (model->getSourceModel())))) {
1810
1811 completion = wfm->getAlignmentCompletion(); 1811 completion = wfm->getAlignmentCompletion();
1812
1813 // We don't allow cancelling alignment operations
1814 // - they aren't usually all that expensive, and
1815 // it would leave things in a very uncertain state
1816 showCancelButton = false;
1812 1817
1813 #ifdef DEBUG_PROGRESS_STUFF 1818 #ifdef DEBUG_PROGRESS_STUFF
1814 SVCERR << "View[" << this << "]::checkProgress(" << object << "): " 1819 SVCERR << "View[" << this << "]::checkProgress(" << object << "): "
1815 << "alignment completion = " << completion << endl; 1820 << "alignment completion = " << completion << endl;
1816 #endif 1821 #endif
2338 .arg(QString::fromStdString 2343 .arg(QString::fromStdString
2339 (RealTime::frame2RealTime 2344 (RealTime::frame2RealTime
2340 (i->getEndFrame() - i->getStartFrame(), sampleRate) 2345 (i->getEndFrame() - i->getStartFrame(), sampleRate)
2341 .toText(true))) 2346 .toText(true)))
2342 .arg(i->getEndFrame() - i->getStartFrame()); 2347 .arg(i->getEndFrame() - i->getStartFrame());
2348
2349 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
2350 // replacement (horizontalAdvance) was only added in Qt 5.11
2351 // which is too new for us
2352 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2343 2353
2344 int sw = metrics.width(startText), 2354 int sw = metrics.width(startText),
2345 ew = metrics.width(endText), 2355 ew = metrics.width(endText),
2346 dw = metrics.width(durationText); 2356 dw = metrics.width(durationText);
2347 2357