RangeSummarisableTimeValueModel.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2007 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H
17 #define SV_RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H
18 
19 #include <QObject>
20 
21 #include "DenseTimeValueModel.h"
22 
23 #include <stdint.h>
24 
33 {
34  Q_OBJECT
35 
36 public:
38 
39  class Range
40  {
41  public:
42  Range() :
43  m_new(true), m_min(0.f), m_max(0.f), m_absmean(0.f) { }
44  Range(float min, float max, float absmean) :
45  m_new(false), m_min(min), m_max(max), m_absmean(absmean) { }
46 
47  Range(const Range &r) =default;
48  Range &operator=(const Range &) =default;
49 
50  float min() const { return m_min; }
51  float max() const { return m_max; }
52  float absmean() const { return m_absmean; }
53 
54  void setMin(float min) { m_min = min; m_new = false; }
55  void setMax(float max) { m_max = max; m_new = false; }
56  void setAbsmean(float absmean) { m_absmean = absmean; }
57 
58  void sample(float s) {
59  if (m_new) {
60  m_min = s;
61  m_max = s;
62  m_new = false;
63  } else {
64  if (s < m_min) m_min = s;
65  if (s > m_max) m_max = s;
66  }
67  }
68 
69  private:
70  bool m_new;
71  float m_min;
72  float m_max;
73  float m_absmean;
74  };
75 
76  typedef std::vector<Range> RangeBlock;
77 
89  virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
90  RangeBlock &ranges,
91  int &blockSize) const = 0;
92 
98  virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const = 0;
99 
100  virtual int getSummaryBlockSize(int desired) const = 0;
101 
102  QString getTypeName() const override { return tr("Range-Summarisable Time-Value"); }
103 };
104 
105 #endif
106 
virtual int getSummaryBlockSize(int desired) const =0
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
Range(float min, float max, float absmean)
QString getTypeName() const override
Return the type of the model.
virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, RangeBlock &ranges, int &blockSize) const =0
Return ranges from the given start frame, corresponding to the given number of underlying sample fram...
Range & operator=(const Range &)=default
Base class for models containing dense two-dimensional data (value against time). ...
Base class for models containing dense two-dimensional data (value against time) that may be meaningf...
virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const =0
Return the range from the given start frame, corresponding to the given number of underlying sample f...