comparison layer/SpectrogramLayer.h @ 946:36cddc3de023 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:19:52 +0100
parents 28d05ae8741c
children 94e4952a6774 8053c0dfa919
comparison
equal deleted inserted replaced
897:499b637f2a26 946:36cddc3de023
67 std::vector<QRect> &extents) const; 67 std::vector<QRect> &extents) const;
68 virtual void paintCrosshairs(View *, QPainter &, QPoint) const; 68 virtual void paintCrosshairs(View *, QPainter &, QPoint) const;
69 69
70 virtual QString getFeatureDescription(View *v, QPoint &) const; 70 virtual QString getFeatureDescription(View *v, QPoint &) const;
71 71
72 virtual bool snapToFeatureFrame(View *v, int &frame, 72 virtual bool snapToFeatureFrame(View *v, sv_frame_t &frame,
73 int &resolution, 73 int &resolution,
74 SnapType snap) const; 74 SnapType snap) const;
75 75
76 virtual void measureDoubleClick(View *, QMouseEvent *); 76 virtual void measureDoubleClick(View *, QMouseEvent *);
77 77
208 208
209 virtual ColourSignificance getLayerColourSignificance() const { 209 virtual ColourSignificance getLayerColourSignificance() const {
210 return ColourHasMeaningfulValue; 210 return ColourHasMeaningfulValue;
211 } 211 }
212 212
213 float getYForFrequency(const View *v, float frequency) const; 213 double getYForFrequency(const View *v, double frequency) const;
214 float getFrequencyForY(const View *v, int y) const; 214 double getFrequencyForY(const View *v, int y) const;
215 215
216 virtual int getCompletion(View *v) const; 216 virtual int getCompletion(View *v) const;
217 virtual QString getError(View *v) const; 217 virtual QString getError(View *v) const;
218 218
219 virtual bool getValueExtents(float &min, float &max, 219 virtual bool getValueExtents(double &min, double &max,
220 bool &logarithmic, QString &unit) const; 220 bool &logarithmic, QString &unit) const;
221 221
222 virtual bool getDisplayExtents(float &min, float &max) const; 222 virtual bool getDisplayExtents(double &min, double &max) const;
223 223
224 virtual bool setDisplayExtents(float min, float max); 224 virtual bool setDisplayExtents(double min, double max);
225 225
226 virtual bool getYScaleValue(const View *, int, float &, QString &) const; 226 virtual bool getYScaleValue(const View *, int, double &, QString &) const;
227 227
228 virtual void toXml(QTextStream &stream, QString indent = "", 228 virtual void toXml(QTextStream &stream, QString indent = "",
229 QString extraAttributes = "") const; 229 QString extraAttributes = "") const;
230 230
231 void setProperties(const QXmlAttributes &attributes); 231 void setProperties(const QXmlAttributes &attributes);
241 241
242 virtual const Model *getSliceableModel() const; 242 virtual const Model *getSliceableModel() const;
243 243
244 protected slots: 244 protected slots:
245 void cacheInvalid(); 245 void cacheInvalid();
246 void cacheInvalid(int startFrame, int endFrame); 246 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
247 247
248 void preferenceChanged(PropertyContainer::PropertyName name); 248 void preferenceChanged(PropertyContainer::PropertyName name);
249 249
250 void fillTimerTimedOut(); 250 void fillTimerTimedOut();
251 251
308 */ 308 */
309 struct ImageCache 309 struct ImageCache
310 { 310 {
311 QImage image; 311 QImage image;
312 QRect validArea; 312 QRect validArea;
313 int startFrame; 313 sv_frame_t startFrame;
314 int zoomLevel; 314 int zoomLevel;
315 }; 315 };
316 typedef std::map<const View *, ImageCache> ViewImageCache; 316 typedef std::map<const View *, ImageCache> ViewImageCache;
317 void invalidateImageCaches(); 317 void invalidateImageCaches();
318 void invalidateImageCaches(int startFrame, int endFrame); 318 void invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame);
319 mutable ViewImageCache m_imageCaches; 319 mutable ViewImageCache m_imageCaches;
320 320
321 /** 321 /**
322 * When painting, we draw directly onto the draw buffer and then 322 * When painting, we draw directly onto the draw buffer and then
323 * copy this to the part of the image cache that needed refreshing 323 * copy this to the part of the image cache that needed refreshing
326 */ 326 */
327 mutable QImage m_drawBuffer; 327 mutable QImage m_drawBuffer;
328 328
329 mutable QTimer *m_updateTimer; 329 mutable QTimer *m_updateTimer;
330 330
331 mutable int m_candidateFillStartFrame; 331 mutable sv_frame_t m_candidateFillStartFrame;
332 bool m_exiting; 332 bool m_exiting;
333 333
334 void initialisePalette(); 334 void initialisePalette();
335 void rotatePalette(int distance); 335 void rotatePalette(int distance);
336 336
337 unsigned char getDisplayValue(View *v, float input) const; 337 unsigned char getDisplayValue(View *v, double input) const;
338 338
339 int getColourScaleWidth(QPainter &) const; 339 int getColourScaleWidth(QPainter &) const;
340 340
341 void illuminateLocalFeatures(View *v, QPainter &painter) const; 341 void illuminateLocalFeatures(View *v, QPainter &painter) const;
342 342
343 float getEffectiveMinFrequency() const; 343 double getEffectiveMinFrequency() const;
344 float getEffectiveMaxFrequency() const; 344 double getEffectiveMaxFrequency() const;
345
346 struct LayerRange {
347 int startFrame;
348 int zoomLevel;
349 int modelStart;
350 int modelEnd;
351 };
352 345
353 // Note that the getYBin... methods return the nominal bin in the 346 // Note that the getYBin... methods return the nominal bin in the
354 // un-smoothed spectrogram. This is not necessarily the same bin 347 // un-smoothed spectrogram. This is not necessarily the same bin
355 // as is pulled from the spectrogram and drawn at the given 348 // as is pulled from the spectrogram and drawn at the given
356 // position, if the spectrogram has oversampling smoothing. Use 349 // position, if the spectrogram has oversampling smoothing. Use
357 // getSmoothedYBinRange to obtain that. 350 // getSmoothedYBinRange to obtain that.
358 351
359 bool getXBinRange(View *v, int x, float &windowMin, float &windowMax) const; 352 bool getXBinRange(View *v, int x, double &windowMin, double &windowMax) const;
360 bool getYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; 353 bool getYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const;
361 bool getSmoothedYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; 354 bool getSmoothedYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const;
362 355
363 bool getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) const; 356 bool getYBinSourceRange(View *v, int y, double &freqMin, double &freqMax) const;
364 bool getAdjustedYBinSourceRange(View *v, int x, int y, 357 bool getAdjustedYBinSourceRange(View *v, int x, int y,
365 float &freqMin, float &freqMax, 358 double &freqMin, double &freqMax,
366 float &adjFreqMin, float &adjFreqMax) const; 359 double &adjFreqMin, double &adjFreqMax) const;
367 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const; 360 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const;
368 bool getXYBinSourceRange(View *v, int x, int y, float &min, float &max, 361 bool getXYBinSourceRange(View *v, int x, int y, double &min, double &max,
369 float &phaseMin, float &phaseMax) const; 362 double &phaseMin, double &phaseMax) const;
370 363
371 int getWindowIncrement() const { 364 int getWindowIncrement() const {
372 if (m_windowHopLevel == 0) return m_windowSize; 365 if (m_windowHopLevel == 0) return m_windowSize;
373 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; 366 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
374 else return m_windowSize / (1 << (m_windowHopLevel - 1)); 367 else return m_windowSize / (1 << (m_windowHopLevel - 1));
378 int getFFTSize(const View *v) const; 371 int getFFTSize(const View *v) const;
379 FFTModel *getFFTModel(const View *v) const; 372 FFTModel *getFFTModel(const View *v) const;
380 Dense3DModelPeakCache *getPeakCache(const View *v) const; 373 Dense3DModelPeakCache *getPeakCache(const View *v) const;
381 void invalidateFFTModels(); 374 void invalidateFFTModels();
382 375
383 typedef std::pair<FFTModel *, int> FFTFillPair; // model, last fill 376 typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill
384 typedef std::map<const View *, FFTFillPair> ViewFFTMap; 377 typedef std::map<const View *, FFTFillPair> ViewFFTMap;
385 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; 378 typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap;
386 mutable ViewFFTMap m_fftModels; 379 mutable ViewFFTMap m_fftModels;
387 mutable PeakCacheMap m_peakCaches; 380 mutable PeakCacheMap m_peakCaches;
388 mutable Model *m_sliceableModel; 381 mutable Model *m_sliceableModel;
391 public: 384 public:
392 MagnitudeRange() : m_min(0), m_max(0) { } 385 MagnitudeRange() : m_min(0), m_max(0) { }
393 bool operator==(const MagnitudeRange &r) { 386 bool operator==(const MagnitudeRange &r) {
394 return r.m_min == m_min && r.m_max == m_max; 387 return r.m_min == m_min && r.m_max == m_max;
395 } 388 }
396 bool isSet() const { return (m_min != 0 || m_max != 0); } 389 bool isSet() const { return (m_min != 0.f || m_max != 0.f); }
397 void set(float min, float max) { 390 void set(float min, float max) {
398 m_min = convert(min); 391 m_min = min;
399 m_max = convert(max); 392 m_max = max;
400 if (m_max < m_min) m_max = m_min; 393 if (m_max < m_min) m_max = m_min;
401 } 394 }
402 bool sample(float f) { 395 bool sample(float f) {
403 unsigned int ui = convert(f);
404 bool changed = false; 396 bool changed = false;
405 if (isSet()) { 397 if (isSet()) {
406 if (ui < m_min) { m_min = ui; changed = true; } 398 if (f < m_min) { m_min = f; changed = true; }
407 if (ui > m_max) { m_max = ui; changed = true; } 399 if (f > m_max) { m_max = f; changed = true; }
408 } else { 400 } else {
409 m_max = m_min = ui; 401 m_max = m_min = f;
410 changed = true; 402 changed = true;
411 } 403 }
412 return changed; 404 return changed;
413 } 405 }
414 bool sample(const MagnitudeRange &r) { 406 bool sample(const MagnitudeRange &r) {
421 m_max = r.m_max; 413 m_max = r.m_max;
422 changed = true; 414 changed = true;
423 } 415 }
424 return changed; 416 return changed;
425 } 417 }
426 float getMin() const { return float(m_min) / UINT_MAX; } 418 float getMin() const { return m_min; }
427 float getMax() const { return float(m_max) / UINT_MAX; } 419 float getMax() const { return m_max; }
428 private: 420 private:
429 unsigned int m_min; 421 float m_min;
430 unsigned int m_max; 422 float m_max;
431 unsigned int convert(float f) {
432 if (f < 0.f) f = 0.f;
433 if (f > 1.f) f = 1.f;
434 return (unsigned int)(f * UINT_MAX);
435 }
436 }; 423 };
437 424
438 typedef std::map<const View *, MagnitudeRange> ViewMagMap; 425 typedef std::map<const View *, MagnitudeRange> ViewMagMap;
439 mutable ViewMagMap m_viewMags; 426 mutable ViewMagMap m_viewMags;
440 mutable std::vector<MagnitudeRange> m_columnMags; 427 mutable std::vector<MagnitudeRange> m_columnMags;
441 void invalidateMagnitudes(); 428 void invalidateMagnitudes();
442 bool updateViewMagnitudes(View *v) const; 429 bool updateViewMagnitudes(View *v) const;
443 bool paintDrawBuffer(View *v, int w, int h, 430 bool paintDrawBuffer(View *v, int w, int h,
444 int *binforx, float *binfory, 431 const std::vector<int> &binforx,
432 const std::vector<double> &binfory,
445 bool usePeaksCache, 433 bool usePeaksCache,
446 MagnitudeRange &overallMag, 434 MagnitudeRange &overallMag,
447 bool &overallMagChanged) const; 435 bool &overallMagChanged) const;
448 bool paintDrawBufferPeakFrequencies(View *v, int w, int h, 436 bool paintDrawBufferPeakFrequencies(View *v, int w, int h,
449 int *binforx, 437 const std::vector<int> &binforx,
450 int minbin, 438 int minbin,
451 int maxbin, 439 int maxbin,
452 float displayMinFreq, 440 double displayMinFreq,
453 float displayMaxFreq, 441 double displayMaxFreq,
454 bool logarithmic, 442 bool logarithmic,
455 MagnitudeRange &overallMag, 443 MagnitudeRange &overallMag,
456 bool &overallMagChanged) const; 444 bool &overallMagChanged) const;
457 445
458 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; 446 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const;