Initial project commit
[decibelmeter] / src / MeterWidget.vala
1 /*  Demo Recorder for MAEMO 5
2 *   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18
19 namespace IdWorks {
20
21 public class MeterWidget : Gtk.VBox {
22   
23   private Gtk.Label title_label;
24   private Gtk.Label peak_label;
25   private Gtk.Label decay_label;
26   private DbMonitorWidget meter;  
27   
28   private static const int BORDER_WIDTH = 4;
29   private static const int BORDER_HEIGHT = 4;
30   //private Pango.Layout layout;
31   private static const double MIN_VALUE = 0.0;
32   private static const double MAX_VALUE = 1.5;
33   
34   private static const double ZERO_VALUE = 1.0;
35   
36   private double peak;
37   private double decay;
38   public void set_peak(double val) {
39     this.peak = (MAX_VALUE > val) ? val : MAX_VALUE;
40     this.peak_label.set_text("%02.2f".printf(val));
41     meter.set_peak(Math.pow (10, val / 20));
42   }
43   public void set_decay(double val) {
44     this.decay = (MAX_VALUE > val) ? val : MAX_VALUE;
45     this.decay_label.set_text("%02.2f".printf(val));
46     meter.set_decay(Math.pow (10, val / 20));
47   }
48   private DbMonitorWidget.Layout layout = DbMonitorWidget.Layout.VERTICAL;
49   public void set_layout(DbMonitorWidget.Layout layout) {
50     this.layout = layout;
51     meter.set_layout(layout);
52   }
53   
54   public string title {
55     get {
56       return title_label.get_text();
57     }
58     set {
59       title_label.set_text(value);
60     }
61   }
62   
63   construct {
64     title_label = new Gtk.Label("");
65     title_label.modify_font(Pango.FontDescription.from_string("Sans 20"));
66     title_label.set_padding(4, 2);
67     //title_label.set_alignment(0,0);
68     
69     this.pack_start(title_label, false, true, 4);    
70     
71     meter = new DbMonitorWidget();
72     meter.set_layout(layout);
73     meter.set_peak(0.0);
74     meter.set_decay(0.0);
75     this.pack_start(meter, true, true, 0);
76   
77     Gtk.HBox display = new Gtk.HBox(true, 8);
78     
79     peak_label = new Gtk.Label("0.0");
80     peak_label.modify_font(Pango.FontDescription.from_string("Sans 40"));
81     peak_label.set_padding(4, 2);
82     //peak_label.set_alignment(0,0);
83     decay_label = new Gtk.Label("0.0");
84     decay_label.modify_font(Pango.FontDescription.from_string("Sans 40"));
85     decay_label.set_padding(4, 2);
86     //decay_label.set_alignment(0,0);
87     
88     display.add(peak_label);
89     display.add(decay_label);
90     
91     this.pack_start(display, false, true, 0);    
92     
93     Gtk.HBox display2 = new Gtk.HBox(true, 0);
94     
95     Gtk.Label peak_label2 = new Gtk.Label("dB Peak");
96     peak_label2.modify_font(Pango.FontDescription.from_string("Sans 16"));
97     peak_label2.set_padding(0, 0);
98     //peak_label2.set_alignment(0,0);
99     Gtk.Label decay_label2 = new Gtk.Label("dB Decay");
100     decay_label2.modify_font(Pango.FontDescription.from_string("Sans 16"));
101     decay_label2.set_padding(0, 0);
102     //decay_label2.set_alignment(0,0);
103     
104     display2.add(peak_label2);
105     display2.add(decay_label2);
106     
107     this.pack_start(display2, false, true, 0);    
108     
109   }  
110   
111 }
112
113 }