merge with master, with minor conflict fixes
[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/libardour_visibility.h"
24 #include "ardour/types.h"
25 #include "ardour/processor.h"
26 #include "pbd/fastlog.h"
27
28 #include "ardour/kmeterdsp.h"
29 #include "ardour/iec1ppmdsp.h"
30 #include "ardour/iec2ppmdsp.h"
31 #include "ardour/vumeterdsp.h"
32
33 namespace ARDOUR {
34
35 class BufferSet;
36 class ChanCount;
37 class Session;
38
39 class LIBARDOUR_API Metering {
40   public:
41         static void               update_meters ();
42         static PBD::Signal0<void> Meter;
43
44   private:
45         /* this object is not meant to be instantiated */
46         Metering();
47 };
48
49 /** Meters peaks on the input and stores them for access.
50  */
51 class LIBARDOUR_API PeakMeter : public Processor {
52 public:
53         PeakMeter(Session& s, const std::string& name);
54         ~PeakMeter();
55
56         void meter();
57         void reset ();
58         void reset_max ();
59
60         bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
61         bool configure_io (ChanCount in, ChanCount out);
62
63         /* special method for meter, to ensure that it can always handle the maximum
64            number of streams in the route, no matter where we put it.
65         */
66
67         void reset_max_channels (const ChanCount&);
68
69         /* tell the meter than no matter how many channels it can handle,
70            `in' is the number it is actually going be handling from
71            now on.
72         */
73
74         void reflect_inputs (const ChanCount& in);
75
76         /** Compute peaks */
77         void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
78
79         void activate ()   { }
80         void deactivate () { }
81
82         ChanCount input_streams () const { return current_meters; }
83         ChanCount output_streams () const { return current_meters; }
84
85         float peak_power (uint32_t n) {
86                 if (n < _visible_peak_power.size()) {
87                         return _visible_peak_power[n];
88                 } else {
89                         return minus_infinity();
90                 }
91         }
92
93         float meter_level (uint32_t n, MeterType type);
94
95         void set_type(MeterType t);
96         MeterType get_type() { return _meter_type; }
97
98         XMLNode& state (bool full);
99
100         PBD::Signal1<void, MeterType> TypeChanged;
101
102 private:
103         friend class IO;
104
105         /** The number of meters that we are currently handling;
106          *  may be different to _configured_input and _configured_output
107          *  as it can be altered outside a ::configure_io by ::reflect_inputs.
108          */
109         ChanCount current_meters;
110
111         std::vector<float> _peak_signal;
112         std::vector<float> _visible_peak_power;
113         std::vector<float> _max_peak_signal;
114         std::vector<float> _max_peak_power;
115
116         std::vector<Kmeterdsp *> _kmeter;
117         std::vector<Iec1ppmdsp *> _iec1meter;
118         std::vector<Iec2ppmdsp *> _iec2meter;
119         std::vector<Vumeterdsp *> _vumeter;
120
121         MeterType _meter_type;
122 };
123
124 } // namespace ARDOUR
125
126 #endif // __ardour_meter_h__