Fix assertion failure on dropping a track out of rec-arm.
[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/signals.h"
26 #include "pbd/fastlog.h"
27
28 namespace ARDOUR {
29
30 class BufferSet;
31 class ChanCount;
32 class Session;
33
34 class Metering {
35   public:
36         static void               update_meters ();
37         static PBD::Signal0<void> Meter;
38
39   private:
40         /* this object is not meant to be instantiated */
41         Metering();
42 };
43
44 /** Meters peaks on the input and stores them for access.
45  */
46 class PeakMeter : public Processor {
47 public:
48         PeakMeter(Session& s) : Processor(s, "Meter") {}
49         PeakMeter(Session&s, const XMLNode& node);
50
51         void meter();
52         void reset ();
53         void reset_max ();
54
55         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const;
56         bool configure_io (ChanCount in, ChanCount out);
57         
58         /* special method for meter, to ensure that it can always handle the maximum
59            number of streams in the route, no matter where we put it.
60         */
61
62         void reset_max_channels (const ChanCount&);
63
64         /* tell the meter than no matter how many channels it can handle,
65            `in' is the number it is actually going be handling from
66            now on.
67         */
68
69         void reflect_inputs (const ChanCount& in);
70
71         /** Compute peaks */
72         void run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes, bool);
73
74         ChanCount input_streams () const { return current_meters; }
75         ChanCount output_streams () const { return current_meters; }
76
77         float peak_power (uint32_t n) {
78                 if (n < _visible_peak_power.size()) {
79                         return _visible_peak_power[n];
80                 } else {
81                         return minus_infinity();
82                 }
83         }
84
85         float max_peak_power (uint32_t n) {
86                 if (n < _max_peak_power.size()) {
87                         return _max_peak_power[n];
88                 } else {
89                         return minus_infinity();
90                 }
91         }
92
93         XMLNode& state (bool full);
94         
95 private:
96         friend class IO;
97         
98         ChanCount current_meters;
99         
100         std::vector<float> _peak_power;
101         std::vector<float> _visible_peak_power;
102         std::vector<float> _max_peak_power;
103 };
104
105
106 } // namespace ARDOUR
107
108 #endif // __ardour_meter_h__