comparison layer/TimeRulerLayer.cpp @ 944:78c152e4db95

Merge from branch tonioni
author Chris Cannam
date Mon, 20 Apr 2015 09:12:17 +0100
parents 4a578a360011
children 94e4952a6774 3871dffc31bd
comparison
equal deleted inserted replaced
896:78e041e45ff0 944:78c152e4db95
47 m_model = model; 47 m_model = model;
48 emit modelReplaced(); 48 emit modelReplaced();
49 } 49 }
50 50
51 bool 51 bool
52 TimeRulerLayer::snapToFeatureFrame(View *v, int &frame, 52 TimeRulerLayer::snapToFeatureFrame(View *v, sv_frame_t &frame,
53 int &resolution, SnapType snap) const 53 int &resolution, SnapType snap) const
54 { 54 {
55 if (!m_model) { 55 if (!m_model) {
56 resolution = 1; 56 resolution = 1;
57 return false; 57 return false;
58 } 58 }
59 59
60 bool q; 60 bool q;
61 int tick = getMajorTickSpacing(v, q); 61 int tick = getMajorTickSpacing(v, q);
62 RealTime rtick = RealTime::fromMilliseconds(tick); 62 RealTime rtick = RealTime::fromMilliseconds(tick);
63 int rate = m_model->getSampleRate(); 63 sv_samplerate_t rate = m_model->getSampleRate();
64 64
65 RealTime rt = RealTime::frame2RealTime(frame, rate); 65 RealTime rt = RealTime::frame2RealTime(frame, rate);
66 double ratio = rt / rtick; 66 double ratio = rt / rtick;
67 67
68 int rounded = int(ratio); 68 int rounded = int(ratio);
69 RealTime rdrt = rtick * rounded; 69 RealTime rdrt = rtick * rounded;
70 70
71 int left = RealTime::realTime2Frame(rdrt, rate); 71 sv_frame_t left = RealTime::realTime2Frame(rdrt, rate);
72 resolution = RealTime::realTime2Frame(rtick, rate); 72 resolution = int(RealTime::realTime2Frame(rtick, rate));
73 int right = left + resolution; 73 sv_frame_t right = left + resolution;
74 74
75 // SVDEBUG << "TimeRulerLayer::snapToFeatureFrame: type " 75 // SVDEBUG << "TimeRulerLayer::snapToFeatureFrame: type "
76 // << int(snap) << ", frame " << frame << " (time " 76 // << int(snap) << ", frame " << frame << " (time "
77 // << rt << ", tick " << rtick << ", rounded " << rdrt << ") "; 77 // << rt << ", tick " << rtick << ", rounded " << rdrt << ") ";
78 78
86 frame = right; 86 frame = right;
87 break; 87 break;
88 88
89 case SnapNearest: 89 case SnapNearest:
90 { 90 {
91 if (abs(frame - left) > abs(right - frame)) { 91 if (labs(frame - left) > labs(right - frame)) {
92 frame = right; 92 frame = right;
93 } else { 93 } else {
94 frame = left; 94 frame = left;
95 } 95 }
96 break; 96 break;
145 { 145 {
146 // return value is in milliseconds 146 // return value is in milliseconds
147 147
148 if (!m_model || !v) return 1000; 148 if (!m_model || !v) return 1000;
149 149
150 int sampleRate = m_model->getSampleRate(); 150 sv_samplerate_t sampleRate = m_model->getSampleRate();
151 if (!sampleRate) return 1000; 151 if (!sampleRate) return 1000;
152 152
153 long startFrame = v->getStartFrame(); 153 sv_frame_t startFrame = v->getStartFrame();
154 long endFrame = v->getEndFrame(); 154 sv_frame_t endFrame = v->getEndFrame();
155 155
156 int minPixelSpacing = 50; 156 int minPixelSpacing = 50;
157 157
158 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); 158 RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate);
159 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); 159 RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate);
199 << ") [" << rect.width() << "x" << rect.height() << "]" << endl; 199 << ") [" << rect.width() << "x" << rect.height() << "]" << endl;
200 #endif 200 #endif
201 201
202 if (!m_model || !m_model->isOK()) return; 202 if (!m_model || !m_model->isOK()) return;
203 203
204 int sampleRate = m_model->getSampleRate(); 204 sv_samplerate_t sampleRate = m_model->getSampleRate();
205 if (!sampleRate) return; 205 if (!sampleRate) return;
206 206
207 long startFrame = v->getFrameForX(rect.x() - 50); 207 sv_frame_t startFrame = v->getFrameForX(rect.x() - 50);
208 208
209 #ifdef DEBUG_TIME_RULER_LAYER 209 #ifdef DEBUG_TIME_RULER_LAYER
210 cerr << "start frame = " << startFrame << endl; 210 cerr << "start frame = " << startFrame << endl;
211 #endif 211 #endif
212 212
213 bool quarter = false; 213 bool quarter = false;
214 int incms = getMajorTickSpacing(v, quarter); 214 int incms = getMajorTickSpacing(v, quarter);
215 215
216 int ms = lrint(1000.0 * (double(startFrame) / double(sampleRate))); 216 int ms = int(lrint(1000.0 * (double(startFrame) / double(sampleRate))));
217 ms = (ms / incms) * incms - incms; 217 ms = (ms / incms) * incms - incms;
218 218
219 #ifdef DEBUG_TIME_RULER_LAYER 219 #ifdef DEBUG_TIME_RULER_LAYER
220 cerr << "start ms = " << ms << " at step " << incms << endl; 220 cerr << "start ms = " << ms << " at step " << incms << endl;
221 #endif 221 #endif
224 // values for x and frame counts here will do, no rounding issue. 224 // values for x and frame counts here will do, no rounding issue.
225 // We always use the exact incms in our calculations for where to 225 // We always use the exact incms in our calculations for where to
226 // draw the actual ticks or lines. 226 // draw the actual ticks or lines.
227 227
228 int minPixelSpacing = 50; 228 int minPixelSpacing = 50;
229 long incFrame = (incms * sampleRate) / 1000; 229 sv_frame_t incFrame = lrint((incms * sampleRate) / 1000);
230 int incX = incFrame / v->getZoomLevel(); 230 int incX = int(incFrame / v->getZoomLevel());
231 int ticks = 10; 231 int ticks = 10;
232 if (incX < minPixelSpacing * 2) { 232 if (incX < minPixelSpacing * 2) {
233 ticks = quarter ? 4 : 5; 233 ticks = quarter ? 4 : 5;
234 } 234 }
235 235
247 // needs to correspond to an exact pixel (so that we don't get 247 // needs to correspond to an exact pixel (so that we don't get
248 // a different pixel when scrolling a small amount and 248 // a different pixel when scrolling a small amount and
249 // re-drawing with a different start frame). 249 // re-drawing with a different start frame).
250 250
251 double dms = ms; 251 double dms = ms;
252 long frame = lrint((dms * sampleRate) / 1000.0); 252 sv_frame_t frame = lrint((dms * sampleRate) / 1000.0);
253 frame /= v->getZoomLevel(); 253 frame /= v->getZoomLevel();
254 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel 254 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel
255 255
256 int x = v->getXForFrame(frame); 256 int x = v->getXForFrame(frame);
257 257