comparison view/View.cpp @ 835:7792b7667f74

Introduce (but don't yet populate) the fixed layers vector; rename m_layers to m_layerStack to reflect its ordering by stacking
author Chris Cannam
date Tue, 02 Sep 2014 14:47:04 +0100
parents 9ad718fdc369
children 1384485650e3
comparison
equal deleted inserted replaced
834:9ad718fdc369 835:7792b7667f74
162 } 162 }
163 163
164 int 164 int
165 View::getPropertyContainerCount() const 165 View::getPropertyContainerCount() const
166 { 166 {
167 return m_layers.size() + 1; // the 1 is for me 167 return m_layerStack.size() + 1; // the 1 is for me
168 } 168 }
169 169
170 const PropertyContainer * 170 const PropertyContainer *
171 View::getPropertyContainer(int i) const 171 View::getPropertyContainer(int i) const
172 { 172 {
176 176
177 PropertyContainer * 177 PropertyContainer *
178 View::getPropertyContainer(int i) 178 View::getPropertyContainer(int i)
179 { 179 {
180 if (i == 0) return m_propertyContainer; 180 if (i == 0) return m_propertyContainer;
181 return m_layers[i-1]; 181 return m_layerStack[i-1];
182 } 182 }
183 183
184 bool 184 bool
185 View::getValueExtents(QString unit, float &min, float &max, bool &log) const 185 View::getValueExtents(QString unit, float &min, float &max, bool &log) const
186 { 186 {
187 bool have = false; 187 bool have = false;
188 188
189 for (LayerList::const_iterator i = m_layers.begin(); 189 for (LayerList::const_iterator i = m_layerStack.begin();
190 i != m_layers.end(); ++i) { 190 i != m_layerStack.end(); ++i) {
191 191
192 QString layerUnit; 192 QString layerUnit;
193 float layerMin = 0.0, layerMax = 0.0; 193 float layerMin = 0.0, layerMax = 0.0;
194 float displayMin = 0.0, displayMax = 0.0; 194 float displayMin = 0.0, displayMax = 0.0;
195 bool layerLog = false; 195 bool layerLog = false;
221 int 221 int
222 View::getTextLabelHeight(const Layer *layer, QPainter &paint) const 222 View::getTextLabelHeight(const Layer *layer, QPainter &paint) const
223 { 223 {
224 std::map<int, Layer *> sortedLayers; 224 std::map<int, Layer *> sortedLayers;
225 225
226 for (LayerList::const_iterator i = m_layers.begin(); 226 for (LayerList::const_iterator i = m_layerStack.begin();
227 i != m_layers.end(); ++i) { 227 i != m_layerStack.end(); ++i) {
228 if ((*i)->needsTextLabelHeight()) { 228 if ((*i)->needsTextLabelHeight()) {
229 sortedLayers[getObjectExportId(*i)] = *i; 229 sortedLayers[getObjectExportId(*i)] = *i;
230 } 230 }
231 } 231 }
232 232
257 delete m_cache; 257 delete m_cache;
258 m_cache = 0; 258 m_cache = 0;
259 259
260 Layer *selectedLayer = 0; 260 Layer *selectedLayer = 0;
261 261
262 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 262 for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
263 if (*i == pc) { 263 if (*i == pc) {
264 selectedLayer = *i; 264 selectedLayer = *i;
265 m_layers.erase(i); 265 m_layerStack.erase(i);
266 break; 266 break;
267 } 267 }
268 } 268 }
269 269
270 if (selectedLayer) { 270 if (selectedLayer) {
271 m_haveSelectedLayer = true; 271 m_haveSelectedLayer = true;
272 m_layers.push_back(selectedLayer); 272 m_layerStack.push_back(selectedLayer);
273 update(); 273 update();
274 } else { 274 } else {
275 m_haveSelectedLayer = false; 275 m_haveSelectedLayer = false;
276 } 276 }
277 277
466 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground(); 466 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
467 467
468 Layer::ColourSignificance maxSignificance = Layer::ColourAbsent; 468 Layer::ColourSignificance maxSignificance = Layer::ColourAbsent;
469 bool mostSignificantHasDarkBackground = false; 469 bool mostSignificantHasDarkBackground = false;
470 470
471 for (LayerList::const_iterator i = m_layers.begin(); 471 for (LayerList::const_iterator i = m_layerStack.begin();
472 i != m_layers.end(); ++i) { 472 i != m_layerStack.end(); ++i) {
473 473
474 Layer::ColourSignificance s = (*i)->getLayerColourSignificance(); 474 Layer::ColourSignificance s = (*i)->getLayerColourSignificance();
475 bool light = (*i)->hasLightBackground(); 475 bool light = (*i)->hasLightBackground();
476 476
477 if (int(s) > int(maxSignificance)) { 477 if (int(s) > int(maxSignificance)) {
530 m_cache = 0; 530 m_cache = 0;
531 531
532 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer); 532 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer);
533 if (scl) scl->setDefaultColourFor(this); 533 if (scl) scl->setDefaultColourFor(this);
534 534
535 m_layers.push_back(layer); 535 m_layerStack.push_back(layer);
536 536
537 QProgressBar *pb = new QProgressBar(this); 537 QProgressBar *pb = new QProgressBar(this);
538 pb->setMinimum(0); 538 pb->setMinimum(0);
539 pb->setMaximum(0); 539 pb->setMaximum(0);
540 pb->setFixedWidth(80); 540 pb->setFixedWidth(80);
597 } 597 }
598 598
599 delete m_cache; 599 delete m_cache;
600 m_cache = 0; 600 m_cache = 0;
601 601
602 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 602 for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
603 if (*i == layer) { 603 if (*i == layer) {
604 m_layers.erase(i); 604 m_layerStack.erase(i);
605 if (m_progressBars.find(layer) != m_progressBars.end()) { 605 if (m_progressBars.find(layer) != m_progressBars.end()) {
606 delete m_progressBars[layer].bar; 606 delete m_progressBars[layer].bar;
607 delete m_progressBars[layer].cancel; 607 delete m_progressBars[layer].cancel;
608 delete m_progressBars[layer].checkTimer; 608 delete m_progressBars[layer].checkTimer;
609 m_progressBars.erase(layer); 609 m_progressBars.erase(layer);
639 { 639 {
640 Layer *sl = getSelectedLayer(); 640 Layer *sl = getSelectedLayer();
641 if (sl && !(sl->isLayerDormant(this))) { 641 if (sl && !(sl->isLayerDormant(this))) {
642 return sl; 642 return sl;
643 } 643 }
644 if (!m_layers.empty()) { 644 if (!m_layerStack.empty()) {
645 int n = getLayerCount(); 645 int n = getLayerCount();
646 while (n > 0) { 646 while (n > 0) {
647 --n; 647 --n;
648 Layer *layer = getLayer(n); 648 Layer *layer = getLayer(n);
649 if (!(layer->isLayerDormant(this))) { 649 if (!(layer->isLayerDormant(this))) {
655 } 655 }
656 656
657 Layer * 657 Layer *
658 View::getSelectedLayer() 658 View::getSelectedLayer()
659 { 659 {
660 if (m_haveSelectedLayer && !m_layers.empty()) { 660 if (m_haveSelectedLayer && !m_layerStack.empty()) {
661 int n = getLayerCount(); 661 int n = getLayerCount();
662 while (n > 0) { 662 while (n > 0) {
663 --n; 663 --n;
664 Layer *layer = getLayer(n); 664 Layer *layer = getLayer(n);
665 if (!(layer->isLayerDormant(this))) { 665 if (!(layer->isLayerDormant(this))) {
1180 View::getModelsStartFrame() const 1180 View::getModelsStartFrame() const
1181 { 1181 {
1182 bool first = true; 1182 bool first = true;
1183 int startFrame = 0; 1183 int startFrame = 0;
1184 1184
1185 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1185 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1186 1186
1187 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1187 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1188 1188
1189 int thisStartFrame = (*i)->getModel()->getStartFrame(); 1189 int thisStartFrame = (*i)->getModel()->getStartFrame();
1190 1190
1201 View::getModelsEndFrame() const 1201 View::getModelsEndFrame() const
1202 { 1202 {
1203 bool first = true; 1203 bool first = true;
1204 int endFrame = 0; 1204 int endFrame = 0;
1205 1205
1206 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1206 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1207 1207
1208 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1208 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1209 1209
1210 int thisEndFrame = (*i)->getModel()->getEndFrame(); 1210 int thisEndFrame = (*i)->getModel()->getEndFrame();
1211 1211
1227 // multiple samplerates, we'd probably want to do frame/time 1227 // multiple samplerates, we'd probably want to do frame/time
1228 // conversion in the model 1228 // conversion in the model
1229 1229
1230 //!!! nah, this wants to always return the sr of the main model! 1230 //!!! nah, this wants to always return the sr of the main model!
1231 1231
1232 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1232 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1233 if ((*i)->getModel() && (*i)->getModel()->isOK()) { 1233 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
1234 return (*i)->getModel()->getSampleRate(); 1234 return (*i)->getModel()->getSampleRate();
1235 } 1235 }
1236 } 1236 }
1237 return 0; 1237 return 0;
1270 1270
1271 Model *anyModel = 0; 1271 Model *anyModel = 0;
1272 Model *alignedModel = 0; 1272 Model *alignedModel = 0;
1273 Model *goodModel = 0; 1273 Model *goodModel = 0;
1274 1274
1275 for (LayerList::const_iterator i = m_layers.begin(); 1275 for (LayerList::const_iterator i = m_layerStack.begin();
1276 i != m_layers.end(); ++i) { 1276 i != m_layerStack.end(); ++i) {
1277 1277
1278 Layer *layer = *i; 1278 Layer *layer = *i;
1279 1279
1280 if (!layer) continue; 1280 if (!layer) continue;
1281 if (dynamic_cast<TimeRulerLayer *>(layer)) continue; 1281 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
1333 1333
1334 bool 1334 bool
1335 View::areLayersScrollable() const 1335 View::areLayersScrollable() const
1336 { 1336 {
1337 // True iff all views are scrollable 1337 // True iff all views are scrollable
1338 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1338 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1339 if (!(*i)->isLayerScrollable(this)) return false; 1339 if (!(*i)->isLayerScrollable(this)) return false;
1340 } 1340 }
1341 return true; 1341 return true;
1342 } 1342 }
1343 1343
1350 // backmost non-scrollable layer. 1350 // backmost non-scrollable layer.
1351 1351
1352 LayerList scrollables; 1352 LayerList scrollables;
1353 bool metUnscrollable = false; 1353 bool metUnscrollable = false;
1354 1354
1355 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1355 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1356 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl; 1356 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl;
1357 // cerr << "(name is " << (*i)->objectName() << ")" 1357 // cerr << "(name is " << (*i)->objectName() << ")"
1358 // << endl; 1358 // << endl;
1359 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl; 1359 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl;
1360 if ((*i)->isLayerDormant(this)) continue; 1360 if ((*i)->isLayerDormant(this)) continue;
1386 // Everything in front of the first non-scrollable from the back 1386 // Everything in front of the first non-scrollable from the back
1387 // should also be considered non-scrollable 1387 // should also be considered non-scrollable
1388 1388
1389 bool started = false; 1389 bool started = false;
1390 1390
1391 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1391 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1392 if ((*i)->isLayerDormant(this)) continue; 1392 if ((*i)->isLayerDormant(this)) continue;
1393 if (!started && (*i)->isLayerScrollable(this)) { 1393 if (!started && (*i)->isLayerScrollable(this)) {
1394 continue; 1394 continue;
1395 } 1395 }
1396 started = true; 1396 started = true;
1417 int candidate = blockSize; 1417 int candidate = blockSize;
1418 bool haveCandidate = false; 1418 bool haveCandidate = false;
1419 1419
1420 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint; 1420 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint;
1421 1421
1422 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1422 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1423 1423
1424 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint(); 1424 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint();
1425 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint; 1425 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint;
1426 1426
1427 int thisBlockSize = 1427 int thisBlockSize =
1441 } 1441 }
1442 1442
1443 bool 1443 bool
1444 View::areLayerColoursSignificant() const 1444 View::areLayerColoursSignificant() const
1445 { 1445 {
1446 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1446 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
1447 if ((*i)->getLayerColourSignificance() == 1447 if ((*i)->getLayerColourSignificance() ==
1448 Layer::ColourHasMeaningfulValue) return true; 1448 Layer::ColourHasMeaningfulValue) return true;
1449 if ((*i)->isLayerOpaque()) break; 1449 if ((*i)->isLayerOpaque()) break;
1450 } 1450 }
1451 return false; 1451 return false;
1452 } 1452 }
1453 1453
1454 bool 1454 bool
1455 View::hasTopLayerTimeXAxis() const 1455 View::hasTopLayerTimeXAxis() const
1456 { 1456 {
1457 LayerList::const_iterator i = m_layers.end(); 1457 LayerList::const_iterator i = m_layerStack.end();
1458 if (i == m_layers.begin()) return false; 1458 if (i == m_layerStack.begin()) return false;
1459 --i; 1459 --i;
1460 return (*i)->hasTimeXAxis(); 1460 return (*i)->hasTimeXAxis();
1461 } 1461 }
1462 1462
1463 void 1463 void
1651 View::paintEvent(QPaintEvent *e) 1651 View::paintEvent(QPaintEvent *e)
1652 { 1652 {
1653 // Profiler prof("View::paintEvent", false); 1653 // Profiler prof("View::paintEvent", false);
1654 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl; 1654 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl;
1655 1655
1656 if (m_layers.empty()) { 1656 if (m_layerStack.empty()) {
1657 QFrame::paintEvent(e); 1657 QFrame::paintEvent(e);
1658 return; 1658 return;
1659 } 1659 }
1660 1660
1661 // ensure our constraints are met 1661 // ensure our constraints are met
2331 2331
2332 int origCentreFrame = m_centreFrame; 2332 int origCentreFrame = m_centreFrame;
2333 2333
2334 bool someLayersIncomplete = false; 2334 bool someLayersIncomplete = false;
2335 2335
2336 for (LayerList::iterator i = m_layers.begin(); 2336 for (LayerList::iterator i = m_layerStack.begin();
2337 i != m_layers.end(); ++i) { 2337 i != m_layerStack.end(); ++i) {
2338 2338
2339 int c = (*i)->getCompletion(this); 2339 int c = (*i)->getCompletion(this);
2340 if (c < 100) { 2340 if (c < 100) {
2341 someLayersIncomplete = true; 2341 someLayersIncomplete = true;
2342 break; 2342 break;
2350 2350
2351 int layerCompletion = 0; 2351 int layerCompletion = 0;
2352 2352
2353 while (layerCompletion < 100) { 2353 while (layerCompletion < 100) {
2354 2354
2355 for (LayerList::iterator i = m_layers.begin(); 2355 for (LayerList::iterator i = m_layerStack.begin();
2356 i != m_layers.end(); ++i) { 2356 i != m_layerStack.end(); ++i) {
2357 2357
2358 int c = (*i)->getCompletion(this); 2358 int c = (*i)->getCompletion(this);
2359 if (i == m_layers.begin() || c < layerCompletion) { 2359 if (i == m_layerStack.begin() || c < layerCompletion) {
2360 layerCompletion = c; 2360 layerCompletion = c;
2361 } 2361 }
2362 } 2362 }
2363 2363
2364 if (layerCompletion >= 100) break; 2364 if (layerCompletion >= 100) break;
2397 paint.drawRect(QRect(xorigin + x, 0, width(), height())); 2397 paint.drawRect(QRect(xorigin + x, 0, width(), height()));
2398 2398
2399 paint.setPen(getForeground()); 2399 paint.setPen(getForeground());
2400 paint.setBrush(Qt::NoBrush); 2400 paint.setBrush(Qt::NoBrush);
2401 2401
2402 for (LayerList::iterator i = m_layers.begin(); 2402 for (LayerList::iterator i = m_layerStack.begin();
2403 i != m_layers.end(); ++i) { 2403 i != m_layerStack.end(); ++i) {
2404 if(!((*i)->isLayerDormant(this))){ 2404 if(!((*i)->isLayerDormant(this))){
2405 2405
2406 paint.setRenderHint(QPainter::Antialiasing, false); 2406 paint.setRenderHint(QPainter::Antialiasing, false);
2407 2407
2408 paint.save(); 2408 paint.save();
2493 m_followPlay == PlaybackScrollPageWithCentre ? "page" : 2493 m_followPlay == PlaybackScrollPageWithCentre ? "page" :
2494 m_followPlay == PlaybackScrollPage ? "daw" : 2494 m_followPlay == PlaybackScrollPage ? "daw" :
2495 "ignore") 2495 "ignore")
2496 .arg(extraAttributes); 2496 .arg(extraAttributes);
2497 2497
2498 for (int i = 0; i < (int)m_layers.size(); ++i) { 2498 for (int i = 0; i < (int)m_layerStack.size(); ++i) {
2499 bool visible = !m_layers[i]->isLayerDormant(this); 2499 bool visible = !m_layerStack[i]->isLayerDormant(this);
2500 m_layers[i]->toBriefXml(stream, indent + " ", 2500 m_layerStack[i]->toBriefXml(stream, indent + " ",
2501 QString("visible=\"%1\"") 2501 QString("visible=\"%1\"")
2502 .arg(visible ? "true" : "false")); 2502 .arg(visible ? "true" : "false"));
2503 } 2503 }
2504 2504
2505 stream << indent + "</view>\n"; 2505 stream << indent + "</view>\n";