comparison layer/TimeRulerLayer.cpp @ 1148:c0d841cb8ab9 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents ee01a4062747
children a34a2a25907c
comparison
equal deleted inserted replaced
1009:96cf499fad62 1148:c0d841cb8ab9
17 17
18 #include "LayerFactory.h" 18 #include "LayerFactory.h"
19 19
20 #include "data/model/Model.h" 20 #include "data/model/Model.h"
21 #include "base/RealTime.h" 21 #include "base/RealTime.h"
22 #include "view/View.h"
23
22 #include "ColourDatabase.h" 24 #include "ColourDatabase.h"
23 #include "view/View.h" 25 #include "PaintAssistant.h"
24 26
25 #include <QPainter> 27 #include <QPainter>
26 28
27 #include <iostream> 29 #include <iostream>
28 #include <cmath> 30 #include <cmath>
31 #include <stdexcept>
29 32
30 //#define DEBUG_TIME_RULER_LAYER 1 33 //#define DEBUG_TIME_RULER_LAYER 1
31
32
33 34
34 35
35 TimeRulerLayer::TimeRulerLayer() : 36 TimeRulerLayer::TimeRulerLayer() :
36 SingleColourLayer(), 37 SingleColourLayer(),
37 m_model(0), 38 m_model(0),
180 quarterTicks = false; 181 quarterTicks = false;
181 } 182 }
182 } else { 183 } else {
183 incms = 1; 184 incms = 1;
184 int ms = rtGap.msec(); 185 int ms = rtGap.msec();
186 // cerr << "rtGap.msec = " << ms << ", rtGap = " << rtGap << ", count = " << count << endl;
187 // cerr << "startFrame = " << startFrame << ", endFrame = " << endFrame << " rtStart = " << rtStart << ", rtEnd = " << rtEnd << endl;
185 if (ms > 0) { incms *= 10; ms /= 10; } 188 if (ms > 0) { incms *= 10; ms /= 10; }
186 if (ms > 0) { incms *= 10; ms /= 10; } 189 if (ms > 0) { incms *= 10; ms /= 10; }
187 if (ms > 0) { incms *= 5; ms /= 5; } 190 if (ms > 0) { incms *= 5; ms /= 5; }
188 if (ms > 0) { incms *= 2; ms /= 2; } 191 if (ms > 0) { incms *= 2; ms /= 2; }
189 } 192 }
239 242
240 // Do not label time zero - we now overlay an opaque area over 243 // Do not label time zero - we now overlay an opaque area over
241 // time < 0 which would cut it in half 244 // time < 0 which would cut it in half
242 int minlabel = 1; // ms 245 int minlabel = 1; // ms
243 246
247 // used for a sanity check
248 sv_frame_t prevframe = 0;
249
244 while (1) { 250 while (1) {
245 251
246 // frame is used to determine where to draw the lines, so it 252 // frame is used to determine where to draw the lines, so it
247 // needs to correspond to an exact pixel (so that we don't get 253 // needs to correspond to an exact pixel (so that we don't get
248 // a different pixel when scrolling a small amount and 254 // a different pixel when scrolling a small amount and
251 double dms = ms; 257 double dms = ms;
252 sv_frame_t frame = lrint((dms * sampleRate) / 1000.0); 258 sv_frame_t frame = lrint((dms * sampleRate) / 1000.0);
253 frame /= v->getZoomLevel(); 259 frame /= v->getZoomLevel();
254 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel 260 frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel
255 261
262 if (frame == prevframe && prevframe != 0) {
263 cerr << "ERROR: frame == prevframe (== " << frame
264 << ") in TimeRulerLayer::paint" << endl;
265 throw std::logic_error("frame == prevframe in TimeRulerLayer::paint");
266 }
267 prevframe = frame;
268
256 int x = v->getXForFrame(frame); 269 int x = v->getXForFrame(frame);
257 270
258 #ifdef DEBUG_TIME_RULER_LAYER 271 #ifdef DEBUG_TIME_RULER_LAYER
259 SVDEBUG << "Considering frame = " << frame << ", x = " << x << endl; 272 cerr << "Considering frame = " << frame << ", x = " << x << endl;
260 #endif 273 #endif
261 274
262 if (x >= rect.x() + rect.width() + 50) { 275 if (x >= rect.x() + rect.width() + 50) {
263 #ifdef DEBUG_TIME_RULER_LAYER 276 #ifdef DEBUG_TIME_RULER_LAYER
264 cerr << "X well out of range, ending here" << endl; 277 cerr << "X well out of range, ending here" << endl;
311 324
312 if (v->getView()->getLayer(0) == this) { 325 if (v->getView()->getLayer(0) == this) {
313 // backmost layer, don't worry about outlining the text 326 // backmost layer, don't worry about outlining the text
314 paint.drawText(x+2 - tw/2, y, text); 327 paint.drawText(x+2 - tw/2, y, text);
315 } else { 328 } else {
316 v->drawVisibleText(paint, x+2 - tw/2, y, text, View::OutlinedText); 329 PaintAssistant::drawVisibleText(v, paint, x+2 - tw/2, y, text, PaintAssistant::OutlinedText);
317 } 330 }
318 } 331 }
319 } 332 }
320 333
321 paint.setPen(greyColour); 334 paint.setPen(greyColour);