ScrollableMagRangeCache.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 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef SCROLLABLE_MAG_RANGE_CACHE_H
16 #define SCROLLABLE_MAG_RANGE_CACHE_H
17 
18 #include "base/BaseTypes.h"
19 #include "base/MagnitudeRange.h"
20 
21 #include "LayerGeometryProvider.h"
22 
36 {
37 public:
39  m_startFrame(0)
40  {}
41 
42  void invalidate() {
43  m_ranges = std::vector<MagnitudeRange>(m_ranges.size());
44  }
45 
46  int getWidth() const {
47  return int(m_ranges.size());
48  }
49 
54  void resize(int newWidth) {
55  if (getWidth() != newWidth) {
56  m_ranges = std::vector<MagnitudeRange>(newWidth);
57  }
58  }
59 
60  ZoomLevel getZoomLevel() const {
61  return m_zoomLevel;
62  }
63 
70  void setZoomLevel(ZoomLevel zoom) {
71  using namespace std::rel_ops;
72  if (m_zoomLevel != zoom) {
73  m_zoomLevel = zoom;
74  invalidate();
75  }
76  }
77 
78  sv_frame_t getStartFrame() const {
79  return m_startFrame;
80  }
81 
88  void setStartFrame(sv_frame_t frame) {
89  if (m_startFrame != frame) {
90  m_startFrame = frame;
91  invalidate();
92  }
93  }
94 
95  bool isColumnSet(int column) const {
96  return in_range_for(m_ranges, column) && m_ranges.at(column).isSet();
97  }
98 
99  bool areColumnsSet(int x, int count) const {
100  for (int i = 0; i < count; ++i) {
101  if (!isColumnSet(x + i)) return false;
102  }
103  return true;
104  }
105 
109  MagnitudeRange getRange(int column) const {
110  return m_ranges.at(column);
111  }
112 
116  MagnitudeRange getRange(int x, int count) const;
117 
124  void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame);
125 
131  void sampleColumn(int column, const MagnitudeRange &r);
132 
133 private:
134  std::vector<MagnitudeRange> m_ranges;
135  sv_frame_t m_startFrame;
136  ZoomLevel m_zoomLevel;
137 };
138 
139 #endif
sv_frame_t getStartFrame() const
MagnitudeRange getRange(int column) const
Get the magnitude range for a single column.
bool isColumnSet(int column) const
void resize(int newWidth)
Set the width of the cache in columns.
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
bool areColumnsSet(int x, int count) const
void setStartFrame(sv_frame_t frame)
Set the start frame.
std::vector< MagnitudeRange > m_ranges
void sampleColumn(int column, const MagnitudeRange &r)
Update a column in the cache, by column index.
A cached set of magnitude range records for a view that scrolls horizontally, such as a spectrogram...
void setZoomLevel(ZoomLevel zoom)
Set the zoom level.
void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame)
Set the new start frame for the cache, according to the geometry of the supplied LayerGeometryProvide...