comparison layer/TimeRulerLayer.cpp @ 1474:36ad3cdabf55 by-id

Further layer updates for ModelById
author Chris Cannam
date Tue, 02 Jul 2019 14:08:44 +0100
parents f2525e6cbdf1
children e6362cf5ff1d
comparison
equal deleted inserted replaced
1473:886c1cd48f9d 1474:36ad3cdabf55
34 //#define DEBUG_TIME_RULER_LAYER 1 34 //#define DEBUG_TIME_RULER_LAYER 1
35 35
36 36
37 TimeRulerLayer::TimeRulerLayer() : 37 TimeRulerLayer::TimeRulerLayer() :
38 SingleColourLayer(), 38 SingleColourLayer(),
39 m_model(nullptr),
40 m_labelHeight(LabelTop) 39 m_labelHeight(LabelTop)
41 { 40 {
42 41
43 } 42 }
44 43
52 51
53 bool 52 bool
54 TimeRulerLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 53 TimeRulerLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
55 int &resolution, SnapType snap) const 54 int &resolution, SnapType snap) const
56 { 55 {
57 if (!m_model) { 56 auto model = ModelById::get(m_model);
57 if (!model) {
58 resolution = 1; 58 resolution = 1;
59 return false; 59 return false;
60 } 60 }
61 61
62 bool q; 62 bool q;
63 int64_t tickUSec = getMajorTickUSec(v, q); 63 int64_t tickUSec = getMajorTickUSec(v, q);
64 RealTime rtick = RealTime::fromMicroseconds(tickUSec); 64 RealTime rtick = RealTime::fromMicroseconds(tickUSec);
65 sv_samplerate_t rate = m_model->getSampleRate(); 65 sv_samplerate_t rate = model->getSampleRate();
66 66
67 RealTime rt = RealTime::frame2RealTime(frame, rate); 67 RealTime rt = RealTime::frame2RealTime(frame, rate);
68 double ratio = rt / rtick; 68 double ratio = rt / rtick;
69 69
70 int rounded = int(ratio); 70 int rounded = int(ratio);
135 int64_t 135 int64_t
136 TimeRulerLayer::getMajorTickUSec(LayerGeometryProvider *v, 136 TimeRulerLayer::getMajorTickUSec(LayerGeometryProvider *v,
137 bool &quarterTicks) const 137 bool &quarterTicks) const
138 { 138 {
139 // return value is in microseconds 139 // return value is in microseconds
140 if (!m_model || !v) return 1000 * 1000; 140 auto model = ModelById::get(m_model);
141 141 if (!model || !v) return 1000 * 1000;
142 sv_samplerate_t sampleRate = m_model->getSampleRate(); 142
143 sv_samplerate_t sampleRate = model->getSampleRate();
143 if (!sampleRate) return 1000 * 1000; 144 if (!sampleRate) return 1000 * 1000;
144 145
145 sv_frame_t startFrame = v->getStartFrame(); 146 sv_frame_t startFrame = v->getStartFrame();
146 sv_frame_t endFrame = v->getEndFrame(); 147 sv_frame_t endFrame = v->getEndFrame();
147 if (endFrame == startFrame) { 148 if (endFrame == startFrame) {
148 endFrame = startFrame + 1; 149 endFrame = startFrame + 1;
149 } 150 }
151
152 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
153 // replacement (horizontalAdvance) was only added in Qt 5.11
154 // which is too new for us
155 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
150 156
151 int exampleWidth = QFontMetrics(QFont()).width("10:42.987654"); 157 int exampleWidth = QFontMetrics(QFont()).width("10:42.987654");
152 int minPixelSpacing = v->getXForViewX(exampleWidth); 158 int minPixelSpacing = v->getXForViewX(exampleWidth);
153 159
154 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); 160 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate);
208 } 214 }
209 215
210 int 216 int
211 TimeRulerLayer::getXForUSec(LayerGeometryProvider *v, double us) const 217 TimeRulerLayer::getXForUSec(LayerGeometryProvider *v, double us) const
212 { 218 {
213 sv_samplerate_t sampleRate = m_model->getSampleRate(); 219 auto model = ModelById::get(m_model);
220 sv_samplerate_t sampleRate = model->getSampleRate();
214 double dframe = (us * sampleRate) / 1000000.0; 221 double dframe = (us * sampleRate) / 1000000.0;
215 double eps = 1e-7; 222 double eps = 1e-7;
216 sv_frame_t frame = sv_frame_t(floor(dframe + eps)); 223 sv_frame_t frame = sv_frame_t(floor(dframe + eps));
217 int x; 224 int x;
218 225
247 #ifdef DEBUG_TIME_RULER_LAYER 254 #ifdef DEBUG_TIME_RULER_LAYER
248 SVCERR << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y() 255 SVCERR << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y()
249 << ") [" << rect.width() << "x" << rect.height() << "]" << endl; 256 << ") [" << rect.width() << "x" << rect.height() << "]" << endl;
250 #endif 257 #endif
251 258
252 if (!m_model || !m_model->isOK()) return; 259 auto model = ModelById::get(m_model);
253 260 if (!model || !model->isOK()) return;
254 sv_samplerate_t sampleRate = m_model->getSampleRate(); 261
262 sv_samplerate_t sampleRate = model->getSampleRate();
255 if (!sampleRate) return; 263 if (!sampleRate) return;
256 264
257 sv_frame_t startFrame = v->getFrameForX(rect.x() - 50); 265 sv_frame_t startFrame = v->getFrameForX(rect.x() - 50);
258 266
259 #ifdef DEBUG_TIME_RULER_LAYER 267 #ifdef DEBUG_TIME_RULER_LAYER