Towards MIDI:
[ardour.git] / libs / ardour / ardour / meter.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3     
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8     
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13     
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_meter_h__
20 #define __ardour_meter_h__
21
22 #include <vector>
23 #include <ardour/types.h>
24 #include <pbd/fastlog.h>
25
26 namespace ARDOUR {
27
28 class BufferSet;
29 class ChanCount;
30 class Session;
31
32
33 /** Meters peaks on the input and stores them for access.
34  */
35 class PeakMeter {
36 public:
37         PeakMeter(Session& s) : _session(s) {}
38
39         void setup (const ChanCount& in);
40         void reset ();
41
42         /** Compute peaks */
43         void run (BufferSet& bufs, jack_nframes_t nframes, jack_nframes_t offset=0);
44         
45         float peak_power (uint32_t n) { 
46                 if (n < _visible_peak_power.size()) {
47                         return _visible_peak_power[n];
48                 } else {
49                         return minus_infinity();
50                 }
51         }
52
53 private:
54         
55         friend class IO;
56         void meter();
57
58         Session&           _session;
59         std::vector<float> _peak_power;
60         std::vector<float> _visible_peak_power;
61 };
62
63
64 } // namespace ARDOUR
65
66 #endif // __ardour_meter_h__