comparison view/View.cpp @ 1475:84c4ddb38415 by-id

Further layer updates
author Chris Cannam
date Tue, 02 Jul 2019 15:29:17 +0100
parents 009f22e03bf6
children c268fe2ad597
comparison
equal deleted inserted replaced
1474:36ad3cdabf55 1475:84c4ddb38415
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 }
922 } 922 }
923 923
924 void 924 void
925 View::modelChanged() 925 View::modelChanged()
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
930
931 QObject *obj = sender();
932
933 ModelId model;
934 if (Model *modelPtr = qobject_cast<Model *>(obj)) {
935 model = modelPtr->getId();
936 } else if (Layer *layerPtr = qobject_cast<Layer *>(obj)) {
937 model = layerPtr->getModel();
938 } else {
939 return;
940 }
932 941
933 // If the model that has changed is not used by any of the cached 942 // If the model that has changed is not used by any of the cached
934 // layers, we won't need to recreate the cache 943 // layers, we won't need to recreate the cache
935 944
936 bool recreate = false; 945 bool recreate = false;
937 946
938 bool discard; 947 bool discard;
939 LayerList scrollables = getScrollableBackLayers(false, discard); 948 LayerList scrollables = getScrollableBackLayers(false, discard);
940 for (LayerList::const_iterator i = scrollables.begin(); 949 for (LayerList::const_iterator i = scrollables.begin();
941 i != scrollables.end(); ++i) { 950 i != scrollables.end(); ++i) {
942 if (*i == obj || (*i)->getModel() == obj) { 951 if ((*i)->getModel() == model) {
943 recreate = true; 952 recreate = true;
944 break; 953 break;
945 } 954 }
946 } 955 }
947 956
958 967
959 void 968 void
960 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) 969 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
961 { 970 {
962 QObject *obj = sender(); 971 QObject *obj = sender();
972
973 ModelId model;
974 if (Model *modelPtr = qobject_cast<Model *>(obj)) {
975 model = modelPtr->getId();
976 } else if (Layer *layerPtr = qobject_cast<Layer *>(obj)) {
977 model = layerPtr->getModel();
978 } else {
979 return;
980 }
963 981
964 sv_frame_t myStartFrame = getStartFrame(); 982 sv_frame_t myStartFrame = getStartFrame();
965 sv_frame_t myEndFrame = getEndFrame(); 983 sv_frame_t myEndFrame = getEndFrame();
966 984
967 #ifdef DEBUG_VIEW_WIDGET_PAINT 985 #ifdef DEBUG_VIEW_WIDGET_PAINT
984 1002
985 bool discard; 1003 bool discard;
986 LayerList scrollables = getScrollableBackLayers(false, discard); 1004 LayerList scrollables = getScrollableBackLayers(false, discard);
987 for (LayerList::const_iterator i = scrollables.begin(); 1005 for (LayerList::const_iterator i = scrollables.begin();
988 i != scrollables.end(); ++i) { 1006 i != scrollables.end(); ++i) {
989 if (*i == obj || (*i)->getModel() == obj) { 1007 if ((*i)->getModel() == model) {
990 recreate = true; 1008 recreate = true;
991 break; 1009 break;
992 } 1010 }
993 } 1011 }
994 1012
1268 View::getModelsStartFrame() const 1286 View::getModelsStartFrame() const
1269 { 1287 {
1270 bool first = true; 1288 bool first = true;
1271 sv_frame_t startFrame = 0; 1289 sv_frame_t startFrame = 0;
1272 1290
1273 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1291 for (Layer *layer: m_layerStack) {
1274 1292
1275 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1293 auto model = ModelById::get(layer->getModel());
1276 1294
1277 sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame(); 1295 if (model && model->isOK()) {
1296
1297 sv_frame_t thisStartFrame = model->getStartFrame();
1278 1298
1279 if (first || thisStartFrame < startFrame) { 1299 if (first || thisStartFrame < startFrame) {
1280 startFrame = thisStartFrame; 1300 startFrame = thisStartFrame;
1281 } 1301 }
1282 first = false; 1302 first = false;
1283 } 1303 }
1284 } 1304 }
1305
1285 return startFrame; 1306 return startFrame;
1286 } 1307 }
1287 1308
1288 sv_frame_t 1309 sv_frame_t
1289 View::getModelsEndFrame() const 1310 View::getModelsEndFrame() const
1290 { 1311 {
1291 bool first = true; 1312 bool first = true;
1292 sv_frame_t endFrame = 0; 1313 sv_frame_t endFrame = 0;
1293 1314
1294 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1315 for (Layer *layer: m_layerStack) {
1295 1316
1296 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1317 auto model = ModelById::get(layer->getModel());
1297 1318
1298 sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame(); 1319 if (model && model->isOK()) {
1320
1321 sv_frame_t thisEndFrame = model->getEndFrame();
1299 1322
1300 if (first || thisEndFrame > endFrame) { 1323 if (first || thisEndFrame > endFrame) {
1301 endFrame = thisEndFrame; 1324 endFrame = thisEndFrame;
1302 } 1325 }
1303 first = false; 1326 first = false;
1315 // multiple samplerates, we'd probably want to do frame/time 1338 // multiple samplerates, we'd probably want to do frame/time
1316 // conversion in the model 1339 // conversion in the model
1317 1340
1318 //!!! nah, this wants to always return the sr of the main model! 1341 //!!! nah, this wants to always return the sr of the main model!
1319 1342
1320 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { 1343 for (Layer *layer: m_layerStack) {
1321 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1344
1322 return (*i)->getModel()->getSampleRate(); 1345 auto model = ModelById::get(layer->getModel());
1323 } 1346
1324 } 1347 if (model && model->isOK()) {
1348 return model->getSampleRate();
1349 }
1350 }
1351
1325 return 0; 1352 return 0;
1326 } 1353 }
1327 1354
1328 View::ModelSet 1355 View::ModelSet
1329 View::getModels() 1356 View::getModels()
1336 1363
1337 if (dynamic_cast<TimeRulerLayer *>(layer)) { 1364 if (dynamic_cast<TimeRulerLayer *>(layer)) {
1338 continue; 1365 continue;
1339 } 1366 }
1340 1367
1341 if (layer && layer->getModel()) { 1368 if (layer && !layer->getModel().isNone()) {
1342 Model *model = layer->getModel(); 1369 models.insert(layer->getModel());
1343 models.insert(model);
1344 } 1370 }
1345 } 1371 }
1346 1372
1347 return models; 1373 return models;
1348 } 1374 }
1349 1375
1350 Model * 1376 ModelId
1351 View::getAligningModel() const 1377 View::getAligningModel() const
1352 { 1378 {
1353 if (!m_manager || 1379 if (!m_manager ||
1354 !m_manager->getAlignMode() || 1380 !m_manager->getAlignMode() ||
1355 !m_manager->getPlaybackModel()) { 1381 !m_manager->getPlaybackModel()) {
1356 return nullptr; 1382 return {};
1357 } 1383 }
1358 1384
1359 Model *anyModel = nullptr; 1385 ModelId anyModel;
1360 Model *alignedModel = nullptr; 1386 ModelId alignedModel;
1361 Model *goodModel = nullptr; 1387 ModelId goodModel;
1362 1388
1363 for (LayerList::const_iterator i = m_layerStack.begin(); 1389 for (auto layer: m_layerStack) {
1364 i != m_layerStack.end(); ++i) {
1365
1366 Layer *layer = *i;
1367 1390
1368 if (!layer) continue; 1391 if (!layer) continue;
1369 if (dynamic_cast<TimeRulerLayer *>(layer)) continue; 1392 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
1370 1393
1371 Model *model = (*i)->getModel(); 1394 auto model = ModelById::get(layer->getModel());
1372 if (!model) continue; 1395 if (!model) continue;
1373 1396
1374 anyModel = model; 1397 anyModel = model->getId();
1375 1398
1376 if (model->getAlignmentReference()) { 1399 if (!model->getAlignmentReference().isNone()) {
1377 alignedModel = model; 1400 alignedModel = model->getId();
1378 if (layer->isLayerOpaque() || 1401 if (layer->isLayerOpaque() ||
1379 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { 1402 std::dynamic_pointer_cast
1380 goodModel = model; 1403 <RangeSummarisableTimeValueModel>(model)) {
1381 } 1404 goodModel = model->getId();
1382 } 1405 }
1383 } 1406 }
1384 1407 }
1385 if (goodModel) return goodModel; 1408
1386 else if (alignedModel) return alignedModel; 1409 if (!goodModel.isNone()) return goodModel;
1410 else if (!alignedModel.isNone()) return alignedModel;
1387 else return anyModel; 1411 else return anyModel;
1388 } 1412 }
1389 1413
1390 sv_frame_t 1414 sv_frame_t
1391 View::alignFromReference(sv_frame_t f) const 1415 View::alignFromReference(sv_frame_t f) const
1392 { 1416 {
1393 if (!m_manager || !m_manager->getAlignMode()) return f; 1417 if (!m_manager || !m_manager->getAlignMode()) return f;
1394 Model *aligningModel = getAligningModel(); 1418 auto aligningModel = ModelById::get(getAligningModel());
1395 if (!aligningModel) return f; 1419 if (!aligningModel) return f;
1396 return aligningModel->alignFromReference(f); 1420 return aligningModel->alignFromReference(f);
1397 } 1421 }
1398 1422
1399 sv_frame_t 1423 sv_frame_t
1400 View::alignToReference(sv_frame_t f) const 1424 View::alignToReference(sv_frame_t f) const
1401 { 1425 {
1402 if (!m_manager->getAlignMode()) return f; 1426 if (!m_manager->getAlignMode()) return f;
1403 Model *aligningModel = getAligningModel(); 1427 auto aligningModel = ModelById::get(getAligningModel());
1404 if (!aligningModel) return f; 1428 if (!aligningModel) return f;
1405 return aligningModel->alignToReference(f); 1429 return aligningModel->alignToReference(f);
1406 } 1430 }
1407 1431
1408 sv_frame_t 1432 sv_frame_t
1410 { 1434 {
1411 if (!m_manager) return 0; 1435 if (!m_manager) return 0;
1412 sv_frame_t pf = m_manager->getPlaybackFrame(); 1436 sv_frame_t pf = m_manager->getPlaybackFrame();
1413 if (!m_manager->getAlignMode()) return pf; 1437 if (!m_manager->getAlignMode()) return pf;
1414 1438
1415 Model *aligningModel = getAligningModel(); 1439 auto aligningModel = ModelById::get(getAligningModel());
1416 if (!aligningModel) return pf; 1440 if (!aligningModel) return pf;
1417 1441
1418 sv_frame_t af = aligningModel->alignFromReference(pf); 1442 sv_frame_t af = aligningModel->alignFromReference(pf);
1419 1443
1420 return af; 1444 return af;
1725 i != m_progressBars.end(); ++i) { 1749 i != m_progressBars.end(); ++i) {
1726 1750
1727 if (i->second.cancel == cancel) { 1751 if (i->second.cancel == cancel) {
1728 1752
1729 Layer *layer = i->first; 1753 Layer *layer = i->first;
1730 Model *model = layer->getModel(); 1754 /*!!! Model *model = layer->getModel();
1731 1755
1756 //!!! todo: restore this behaviour
1732 if (model) model->abandon(); 1757 if (model) model->abandon();
1758 */
1733 } 1759 }
1734 } 1760 }
1735 } 1761 }
1736 1762
1737 void 1763 void