comparison layer/SpectrogramLayer.h @ 905:b66fb15de477 cxx11

Working through the float/double and int/sv_frame_t fixes
author Chris Cannam
date Mon, 09 Mar 2015 14:35:21 +0000
parents 4c8ca536b54f
children 12ab113ca2b1
comparison
equal deleted inserted replaced
904:e0f08e108064 905:b66fb15de477
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);
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 345
346 struct LayerRange { 346 struct LayerRange {
347 int startFrame; 347 int startFrame;
348 int zoomLevel; 348 int zoomLevel;
349 int modelStart; 349 int modelStart;
354 // un-smoothed spectrogram. This is not necessarily the same bin 354 // un-smoothed spectrogram. This is not necessarily the same bin
355 // as is pulled from the spectrogram and drawn at the given 355 // as is pulled from the spectrogram and drawn at the given
356 // position, if the spectrogram has oversampling smoothing. Use 356 // position, if the spectrogram has oversampling smoothing. Use
357 // getSmoothedYBinRange to obtain that. 357 // getSmoothedYBinRange to obtain that.
358 358
359 bool getXBinRange(View *v, int x, float &windowMin, float &windowMax) const; 359 bool getXBinRange(View *v, int x, double &windowMin, double &windowMax) const;
360 bool getYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; 360 bool getYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const;
361 bool getSmoothedYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; 361 bool getSmoothedYBinRange(View *v, int y, double &freqBinMin, double &freqBinMax) const;
362 362
363 bool getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) const; 363 bool getYBinSourceRange(View *v, int y, double &freqMin, double &freqMax) const;
364 bool getAdjustedYBinSourceRange(View *v, int x, int y, 364 bool getAdjustedYBinSourceRange(View *v, int x, int y,
365 float &freqMin, float &freqMax, 365 double &freqMin, double &freqMax,
366 float &adjFreqMin, float &adjFreqMax) const; 366 double &adjFreqMin, double &adjFreqMax) const;
367 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const; 367 bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const;
368 bool getXYBinSourceRange(View *v, int x, int y, float &min, float &max, 368 bool getXYBinSourceRange(View *v, int x, int y, double &min, double &max,
369 float &phaseMin, float &phaseMax) const; 369 double &phaseMin, double &phaseMax) const;
370 370
371 int getWindowIncrement() const { 371 int getWindowIncrement() const {
372 if (m_windowHopLevel == 0) return m_windowSize; 372 if (m_windowHopLevel == 0) return m_windowSize;
373 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4; 373 else if (m_windowHopLevel == 1) return (m_windowSize * 3) / 4;
374 else return m_windowSize / (1 << (m_windowHopLevel - 1)); 374 else return m_windowSize / (1 << (m_windowHopLevel - 1));
391 public: 391 public:
392 MagnitudeRange() : m_min(0), m_max(0) { } 392 MagnitudeRange() : m_min(0), m_max(0) { }
393 bool operator==(const MagnitudeRange &r) { 393 bool operator==(const MagnitudeRange &r) {
394 return r.m_min == m_min && r.m_max == m_max; 394 return r.m_min == m_min && r.m_max == m_max;
395 } 395 }
396 bool isSet() const { return (m_min != 0 || m_max != 0); } 396 bool isSet() const { return (m_min != 0.f || m_max != 0.f); }
397 void set(float min, float max) { 397 void set(float min, float max) {
398 m_min = convert(min); 398 m_min = min;
399 m_max = convert(max); 399 m_max = max;
400 if (m_max < m_min) m_max = m_min; 400 if (m_max < m_min) m_max = m_min;
401 } 401 }
402 bool sample(float f) { 402 bool sample(float f) {
403 unsigned int ui = convert(f);
404 bool changed = false; 403 bool changed = false;
405 if (isSet()) { 404 if (isSet()) {
406 if (ui < m_min) { m_min = ui; changed = true; } 405 if (f < m_min) { m_min = f; changed = true; }
407 if (ui > m_max) { m_max = ui; changed = true; } 406 if (f > m_max) { m_max = f; changed = true; }
408 } else { 407 } else {
409 m_max = m_min = ui; 408 m_max = m_min = f;
410 changed = true; 409 changed = true;
411 } 410 }
412 return changed; 411 return changed;
413 } 412 }
414 bool sample(const MagnitudeRange &r) { 413 bool sample(const MagnitudeRange &r) {
421 m_max = r.m_max; 420 m_max = r.m_max;
422 changed = true; 421 changed = true;
423 } 422 }
424 return changed; 423 return changed;
425 } 424 }
426 float getMin() const { return float(m_min) / UINT_MAX; } 425 float getMin() const { return m_min; }
427 float getMax() const { return float(m_max) / UINT_MAX; } 426 float getMax() const { return m_max; }
428 private: 427 private:
429 unsigned int m_min; 428 float m_min;
430 unsigned int m_max; 429 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 }; 430 };
437 431
438 typedef std::map<const View *, MagnitudeRange> ViewMagMap; 432 typedef std::map<const View *, MagnitudeRange> ViewMagMap;
439 mutable ViewMagMap m_viewMags; 433 mutable ViewMagMap m_viewMags;
440 mutable std::vector<MagnitudeRange> m_columnMags; 434 mutable std::vector<MagnitudeRange> m_columnMags;
441 void invalidateMagnitudes(); 435 void invalidateMagnitudes();
442 bool updateViewMagnitudes(View *v) const; 436 bool updateViewMagnitudes(View *v) const;
443 bool paintDrawBuffer(View *v, int w, int h, 437 bool paintDrawBuffer(View *v, int w, int h,
444 int *binforx, float *binfory, 438 int *binforx, double *binfory,
445 bool usePeaksCache, 439 bool usePeaksCache,
446 MagnitudeRange &overallMag, 440 MagnitudeRange &overallMag,
447 bool &overallMagChanged) const; 441 bool &overallMagChanged) const;
448 bool paintDrawBufferPeakFrequencies(View *v, int w, int h, 442 bool paintDrawBufferPeakFrequencies(View *v, int w, int h,
449 int *binforx, 443 int *binforx,
450 int minbin, 444 int minbin,
451 int maxbin, 445 int maxbin,
452 float displayMinFreq, 446 double displayMinFreq,
453 float displayMaxFreq, 447 double displayMaxFreq,
454 bool logarithmic, 448 bool logarithmic,
455 MagnitudeRange &overallMag, 449 MagnitudeRange &overallMag,
456 bool &overallMagChanged) const; 450 bool &overallMagChanged) const;
457 451
458 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; 452 virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const;