comparison view/View.cpp @ 320:984c1975f1ff

* Some tidying up to handling of alignment; add alignment status label to pane; ensure alignment when dragging with mouse as well as when playing
author Chris Cannam
date Thu, 25 Oct 2007 14:32:23 +0000
parents c0b9eec70639
children 973a0272b712
comparison
equal deleted inserted replaced
319:2a50c1ecc990 320:984c1975f1ff
324 update(); 324 update();
325 325
326 changeVisible = true; 326 changeVisible = true;
327 } 327 }
328 328
329 if (e) emit centreFrameChanged(f, m_followPan, m_followPlay); 329 if (e) emit centreFrameChanged(alignFromReference(f),
330 m_followPan, m_followPlay);
330 } 331 }
331 332
332 return changeVisible; 333 return changeVisible;
333 } 334 }
334 335
529 this, SLOT(layerNameChanged())); 530 this, SLOT(layerNameChanged()));
530 connect(layer, SIGNAL(modelChanged()), 531 connect(layer, SIGNAL(modelChanged()),
531 this, SLOT(modelChanged())); 532 this, SLOT(modelChanged()));
532 connect(layer, SIGNAL(modelCompletionChanged()), 533 connect(layer, SIGNAL(modelCompletionChanged()),
533 this, SLOT(modelCompletionChanged())); 534 this, SLOT(modelCompletionChanged()));
535 connect(layer, SIGNAL(modelAlignmentCompletionChanged()),
536 this, SLOT(modelAlignmentCompletionChanged()));
534 connect(layer, SIGNAL(modelChanged(size_t, size_t)), 537 connect(layer, SIGNAL(modelChanged(size_t, size_t)),
535 this, SLOT(modelChanged(size_t, size_t))); 538 this, SLOT(modelChanged(size_t, size_t)));
536 connect(layer, SIGNAL(modelReplaced()), 539 connect(layer, SIGNAL(modelReplaced()),
537 this, SLOT(modelReplaced())); 540 this, SLOT(modelReplaced()));
538 541
570 this, SLOT(layerNameChanged())); 573 this, SLOT(layerNameChanged()));
571 disconnect(layer, SIGNAL(modelChanged()), 574 disconnect(layer, SIGNAL(modelChanged()),
572 this, SLOT(modelChanged())); 575 this, SLOT(modelChanged()));
573 disconnect(layer, SIGNAL(modelCompletionChanged()), 576 disconnect(layer, SIGNAL(modelCompletionChanged()),
574 this, SLOT(modelCompletionChanged())); 577 this, SLOT(modelCompletionChanged()));
578 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()),
579 this, SLOT(modelAlignmentCompletionChanged()));
575 disconnect(layer, SIGNAL(modelChanged(size_t, size_t)), 580 disconnect(layer, SIGNAL(modelChanged(size_t, size_t)),
576 this, SLOT(modelChanged(size_t, size_t))); 581 this, SLOT(modelChanged(size_t, size_t)));
577 disconnect(layer, SIGNAL(modelReplaced()), 582 disconnect(layer, SIGNAL(modelReplaced()),
578 this, SLOT(modelReplaced())); 583 this, SLOT(modelReplaced()));
579 584
802 QObject *obj = sender(); 807 QObject *obj = sender();
803 checkProgress(obj); 808 checkProgress(obj);
804 } 809 }
805 810
806 void 811 void
812 View::modelAlignmentCompletionChanged()
813 {
814 std::cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << std::endl;
815
816 QObject *obj = sender();
817 checkProgress(obj);
818 }
819
820 void
807 View::modelReplaced() 821 View::modelReplaced()
808 { 822 {
809 #ifdef DEBUG_VIEW_WIDGET_PAINT 823 #ifdef DEBUG_VIEW_WIDGET_PAINT
810 std::cerr << "View(" << this << ")::modelReplaced()" << std::endl; 824 std::cerr << "View(" << this << ")::modelReplaced()" << std::endl;
811 #endif 825 #endif
856 870
857 void 871 void
858 View::globalCentreFrameChanged(unsigned long f) 872 View::globalCentreFrameChanged(unsigned long f)
859 { 873 {
860 if (m_followPan) { 874 if (m_followPan) {
861 setCentreFrame(f, false); 875 setCentreFrame(alignToReference(f), false);
862 } 876 }
863 } 877 }
864 878
865 void 879 void
866 View::viewCentreFrameChanged(View *, unsigned long ) 880 View::viewCentreFrameChanged(View *, unsigned long )
1072 } 1086 }
1073 1087
1074 return models; 1088 return models;
1075 } 1089 }
1076 1090
1091 Model *
1092 View::getAligningModel() const
1093 {
1094 if (!m_manager ||
1095 !m_manager->getAlignMode() ||
1096 !m_manager->getPlaybackModel()) {
1097 return 0;
1098 }
1099
1100 Model *anyModel = 0;
1101 Model *goodModel = 0;
1102
1103 for (LayerList::const_iterator i = m_layers.begin();
1104 i != m_layers.end(); ++i) {
1105
1106 Layer *layer = *i;
1107
1108 if (!layer) continue;
1109 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
1110
1111 Model *model = (*i)->getModel();
1112 if (!model) continue;
1113
1114 if (model->getAlignmentReference()) {
1115 anyModel = model;
1116 if (layer->isLayerOpaque() ||
1117 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
1118 goodModel = model;
1119 }
1120 }
1121 }
1122
1123 if (goodModel) return goodModel;
1124 else return anyModel;
1125 }
1126
1127 size_t
1128 View::alignFromReference(size_t f) const
1129 {
1130 Model *aligningModel = getAligningModel();
1131 if (!aligningModel) return f;
1132 return aligningModel->alignFromReference(f);
1133 }
1134
1135 size_t
1136 View::alignToReference(size_t f) const
1137 {
1138 Model *aligningModel = getAligningModel();
1139 if (!aligningModel) return f;
1140 return aligningModel->alignToReference(f);
1141 }
1142
1077 int 1143 int
1078 View::getAlignedPlaybackFrame() const 1144 View::getAlignedPlaybackFrame() const
1079 { 1145 {
1080 if (!m_manager) return 0; 1146 Model *aligningModel = getAligningModel();
1081 if (!m_manager->getAlignMode() ||
1082 !m_manager->getPlaybackModel()) {
1083 return m_manager->getPlaybackFrame();
1084 }
1085
1086 RangeSummarisableTimeValueModel *waveformModel = 0;
1087 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
1088
1089 if (!*i) continue;
1090 if (dynamic_cast<TimeRulerLayer *>(*i)) continue;
1091
1092 Model *model = (*i)->getModel();
1093 if (!model) continue;
1094
1095 waveformModel = dynamic_cast<RangeSummarisableTimeValueModel *>(model);
1096 if (!waveformModel) {
1097 waveformModel = dynamic_cast<RangeSummarisableTimeValueModel *>
1098 (model->getSourceModel());
1099 }
1100
1101 if (waveformModel) break;
1102 }
1103 1147
1104 int pf = m_manager->getPlaybackFrame(); 1148 int pf = m_manager->getPlaybackFrame();
1105 1149
1106 if (!waveformModel) return pf; 1150 if (!aligningModel) return pf;
1107 1151
1108 RangeSummarisableTimeValueModel *pm = 1152 Model *pm = m_manager->getPlaybackModel();
1109 dynamic_cast<RangeSummarisableTimeValueModel *>
1110 (m_manager->getPlaybackModel());
1111 1153
1112 // std::cerr << "View[" << this << "]::getAlignedPlaybackFrame: pf = " << pf; 1154 // std::cerr << "View[" << this << "]::getAlignedPlaybackFrame: pf = " << pf;
1113 1155
1114 if (pm) { 1156 if (pm) {
1115 pf = pm->alignFromReference(pf); 1157 pf = pm->alignFromReference(pf);
1116 // std::cerr << " -> " << pf; 1158 // std::cerr << " -> " << pf;
1117 } 1159 }
1118 1160
1119 int af = waveformModel->alignToReference(pf); 1161 int af = aligningModel->alignToReference(pf);
1120 1162
1121 // std::cerr << ", aligned = " << af << std::endl; 1163 // std::cerr << ", aligned = " << af << std::endl;
1122 return af; 1164 return af;
1123 } 1165 }
1124 1166