Mercurial > hg > svgui
comparison layer/ScrollableMagRangeCache.cpp @ 1122:94370157b265 spectrogram-minor-refactor
Fixes and debug output for mag range calculations
author | Chris Cannam |
---|---|
date | Fri, 22 Jul 2016 13:56:24 +0100 |
parents | 65cdaf8d6b50 |
children | 745a868f0abf |
comparison
equal
deleted
inserted
replaced
1121:d930ff725f64 | 1122:94370157b265 |
---|---|
20 #define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1 | 20 #define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1 |
21 | 21 |
22 void | 22 void |
23 ScrollableMagRangeCache::scrollTo(const LayerGeometryProvider *v, | 23 ScrollableMagRangeCache::scrollTo(const LayerGeometryProvider *v, |
24 sv_frame_t newStartFrame) | 24 sv_frame_t newStartFrame) |
25 { | 25 { |
26 if (m_startFrame == newStartFrame) { | |
27 // haven't moved | |
28 return; | |
29 } | |
30 | |
31 int dx = (v->getXForFrame(m_startFrame) - | 26 int dx = (v->getXForFrame(m_startFrame) - |
32 v->getXForFrame(newStartFrame)); | 27 v->getXForFrame(newStartFrame)); |
33 | 28 |
34 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | 29 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE |
35 cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame | 30 cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame |
36 << " -> " << newStartFrame << ", dx = " << dx << endl; | 31 << " -> " << newStartFrame << ", dx = " << dx << endl; |
37 #endif | 32 #endif |
33 | |
34 if (m_startFrame == newStartFrame) { | |
35 // haven't moved | |
36 return; | |
37 } | |
38 | 38 |
39 m_startFrame = newStartFrame; | 39 m_startFrame = newStartFrame; |
40 | 40 |
41 if (dx == 0) { | 41 if (dx == 0) { |
42 // haven't moved visibly (even though start frame may have changed) | 42 // haven't moved visibly (even though start frame may have changed) |
59 // end and clip the right end. Assemble -dx new values, then | 59 // end and clip the right end. Assemble -dx new values, then |
60 // w+dx old values starting at index 0. | 60 // w+dx old values starting at index 0. |
61 | 61 |
62 auto newRanges = vector<MagnitudeRange>(-dx); | 62 auto newRanges = vector<MagnitudeRange>(-dx); |
63 newRanges.insert(newRanges.end(), | 63 newRanges.insert(newRanges.end(), |
64 m_ranges.begin(), m_ranges.begin() + w + dx); | 64 m_ranges.begin(), m_ranges.begin() + (w + dx)); |
65 m_ranges = newRanges; | 65 m_ranges = newRanges; |
66 | 66 |
67 } else { | 67 } else { |
68 // The new start frame is to the right of the old start | 68 // The new start frame is to the right of the old start |
69 // frame. We want to clip the left (start) end and add some | 69 // frame. We want to clip the left (start) end and add some |
73 auto newRanges = vector<MagnitudeRange>(dx); | 73 auto newRanges = vector<MagnitudeRange>(dx); |
74 newRanges.insert(newRanges.begin(), | 74 newRanges.insert(newRanges.begin(), |
75 m_ranges.begin() + dx, m_ranges.end()); | 75 m_ranges.begin() + dx, m_ranges.end()); |
76 m_ranges = newRanges; | 76 m_ranges = newRanges; |
77 } | 77 } |
78 | |
79 cerr << "maxes now: "; | |
80 for (int i = 0; in_range_for(m_ranges, i); ++i) { | |
81 cerr << m_ranges[i].getMax() << " "; | |
82 } | |
83 cerr << endl; | |
84 } | |
85 | |
86 MagnitudeRange | |
87 ScrollableMagRangeCache::getRange(int x, int count) const | |
88 { | |
89 MagnitudeRange r; | |
90 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | |
91 cerr << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; | |
92 #endif | |
93 for (int i = 0; i < count; ++i) { | |
94 r.sample(m_ranges.at(x + i)); | |
95 } | |
96 return r; | |
78 } | 97 } |
79 | 98 |
80 void | 99 void |
81 ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r) | 100 ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r) |
82 { | 101 { |
88 } else { | 107 } else { |
89 m_ranges[column].sample(r); | 108 m_ranges[column].sample(r); |
90 } | 109 } |
91 } | 110 } |
92 | 111 |
112 //!!! unneeded? | |
93 void | 113 void |
94 ScrollableMagRangeCache::sampleColumn(const LayerGeometryProvider *v, | 114 ScrollableMagRangeCache::sampleColumn(const LayerGeometryProvider *v, |
95 sv_frame_t frame, | 115 sv_frame_t frame, |
96 const MagnitudeRange &r) | 116 const MagnitudeRange &r) |
97 { | 117 { |