comparison layer/SpectrogramLayer.h @ 119:508276c923ba

* Various experiments in spectrogram colour scaling, etc. Nothing final here yet, but some promising developments.
author Chris Cannam
date Fri, 14 Jul 2006 17:12:16 +0000
parents 47cb32bb35ab
children 8dfa20f1c70a
comparison
equal deleted inserted replaced
118:853a7fc542d0 119:508276c923ba
127 127
128 enum ColourScale { 128 enum ColourScale {
129 LinearColourScale, 129 LinearColourScale,
130 MeterColourScale, 130 MeterColourScale,
131 dBColourScale, 131 dBColourScale,
132 OtherColourScale,
132 PhaseColourScale 133 PhaseColourScale
133 }; 134 };
134 135
135 /** 136 /**
136 * Specify the scale for sample levels. See WaveformLayer for 137 * Specify the scale for sample levels. See WaveformLayer for
275 size_t sampleRate, 276 size_t sampleRate,
276 float previousPhase, 277 float previousPhase,
277 float currentPhase, 278 float currentPhase,
278 bool &steadyState); 279 bool &steadyState);
279 280
280 unsigned char getDisplayValue(float input) const; 281 unsigned char getDisplayValue(View *v, float input) const;
281 float getInputForDisplayValue(unsigned char uc) const; 282 float getInputForDisplayValue(unsigned char uc) const;
282 283
283 int getColourScaleWidth(QPainter &) const; 284 int getColourScaleWidth(QPainter &) const;
284 285
285 float getEffectiveMinFrequency() const; 286 float getEffectiveMinFrequency() const;
313 FFTFuzzyAdapter *getFFTAdapter(const View *v) const; 314 FFTFuzzyAdapter *getFFTAdapter(const View *v) const;
314 void invalidateFFTAdapters(); 315 void invalidateFFTAdapters();
315 316
316 typedef std::pair<FFTFuzzyAdapter *, int> FFTFillPair; // adapter, last fill 317 typedef std::pair<FFTFuzzyAdapter *, int> FFTFillPair; // adapter, last fill
317 typedef std::map<const View *, FFTFillPair> ViewFFTMap; 318 typedef std::map<const View *, FFTFillPair> ViewFFTMap;
319 typedef std::vector<float> FloatVector;
318 mutable ViewFFTMap m_fftAdapters; 320 mutable ViewFFTMap m_fftAdapters;
321
322 class MagnitudeRange {
323 public:
324 MagnitudeRange() : m_min(0), m_max(0) { }
325 bool operator==(const MagnitudeRange &r) {
326 return r.m_min == m_min && r.m_max == m_max;
327 }
328 bool isSet() const { return (m_min != 0 || m_max != 0); }
329 void set(float min, float max) {
330 m_min = convert(min);
331 m_max = convert(max);
332 if (m_max < m_min) m_max = m_min;
333 }
334 bool sample(float f) {
335 unsigned int ui = convert(f);
336 bool changed = false;
337 if (isSet()) {
338 if (ui < m_min) { m_min = ui; changed = true; }
339 if (ui > m_max) { m_max = ui; changed = true; }
340 } else {
341 m_max = m_min = ui;
342 changed = true;
343 }
344 return changed;
345 }
346 bool sample(const MagnitudeRange &r) {
347 bool changed = false;
348 if (isSet()) {
349 if (r.m_min < m_min) { m_min = r.m_min; changed = true; }
350 if (r.m_max > m_max) { m_max = r.m_max; changed = true; }
351 } else {
352 m_min = r.m_min;
353 m_max = r.m_max;
354 changed = true;
355 }
356 return changed;
357 }
358 float getMin() const { return float(m_min) / UINT_MAX; }
359 float getMax() const { return float(m_max) / UINT_MAX; }
360 private:
361 unsigned int m_min;
362 unsigned int m_max;
363 unsigned int convert(float f) {
364 if (f < 0.f) f = 0.f;
365 if (f > 1.f) f = 1.f;
366 return (unsigned int)(f * UINT_MAX);
367 }
368 };
369
370 typedef std::map<const View *, MagnitudeRange> ViewMagMap;
371 mutable ViewMagMap m_viewMags;
372 mutable std::vector<MagnitudeRange> m_columnMags;
373 void invalidateMagnitudes();
374 bool updateViewMagnitudes(View *v) const;
319 }; 375 };
320 376
321 #endif 377 #endif