merge from 2.0-ongoing @ 3581
[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 <ardour/processor.h>
25 #include <pbd/fastlog.h>
26
27 namespace ARDOUR {
28
29 class BufferSet;
30 class ChanCount;
31 class Session;
32
33
34 /** Meters peaks on the input and stores them for access.
35  */
36 class PeakMeter : public Processor {
37 public:
38         PeakMeter(Session& s) : Processor(s, "meter", PreFader) {}
39
40         void reset ();
41         void reset_max ();
42         
43         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const { return true; }
44         bool configure_io (ChanCount in, ChanCount out);
45         
46         /** Compute peaks */
47         void run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset);
48         
49         float peak_power (uint32_t n) { 
50                 if (n < _visible_peak_power.size()) {
51                         return _visible_peak_power[n];
52                 } else {
53                         return minus_infinity();
54                 }
55         }
56         
57         float max_peak_power (uint32_t n) {
58                 if (n < _max_peak_power.size()) {
59                         return _max_peak_power[n];
60                 } else {
61                         return minus_infinity();
62                 }
63         }
64
65 private:
66         
67         friend class IO;
68         void meter();
69
70         std::vector<float> _peak_power;
71         std::vector<float> _visible_peak_power;
72         std::vector<float> _max_peak_power;
73 };
74
75
76 } // namespace ARDOUR
77
78 #endif // __ardour_meter_h__