Fix broken meter style on MIDI tracks.
[ardour2.git] / gtk2_ardour / logmeter.h
blobd86150908002bcc60e060ab031cbbe3c084b91b8
1 /*
2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_gtk_log_meter_h__
21 #define __ardour_gtk_log_meter_h__
23 #if 1
24 static inline float
25 _log_meter (float power, double lower_db, double upper_db, double non_linearity)
27 return (power < lower_db ? 0.0 : pow((power-lower_db)/(upper_db-lower_db), non_linearity));
30 static inline float
31 alt_log_meter (float power)
33 return _log_meter (power, -192.0, 0.0, 8.0);
35 #endif
37 inline float
38 log_meter (float db)
40 gfloat def = 0.0f; /* Meter deflection %age */
42 if (db < -70.0f) {
43 def = 0.0f;
44 } else if (db < -60.0f) {
45 def = (db + 70.0f) * 0.25f;
46 } else if (db < -50.0f) {
47 def = (db + 60.0f) * 0.5f + 2.5f;
48 } else if (db < -40.0f) {
49 def = (db + 50.0f) * 0.75f + 7.5f;
50 } else if (db < -30.0f) {
51 def = (db + 40.0f) * 1.5f + 15.0f;
52 } else if (db < -20.0f) {
53 def = (db + 30.0f) * 2.0f + 30.0f;
54 } else if (db < 6.0f) {
55 def = (db + 20.0f) * 2.5f + 50.0f;
56 } else {
57 def = 115.0f;
60 /* 115 is the deflection %age that would be
61 when db=6.0. this is an arbitrary
62 endpoint for our scaling.
65 return def/115.0f;
68 #endif /* __ardour_gtk_log_meter_h__ */