Adding first code drop
[demorecorder] / src / PlayerTransport.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 namespace IdWorks {
19
20 public class PlayerTransport : Gtk.HBox {
21   
22   public Gtk.Window window;
23   
24   //Gtk.HScale progress;
25   Gtk.Label label_position;
26   Gtk.Label label_duration;
27   Gtk.ToggleButton record;
28   Gtk.Button play;
29   Gtk.ToggleButton pause;
30   Gtk.Button stop;
31   
32   double volume;
33   public double get_volume() {
34     return volume;
35   }
36   public void set_volume(double volume) {
37     this.volume = volume;
38   }
39   
40   double panorama;
41   public double get_panorama() {
42     return panorama;
43   }
44   public void set_panorama(double panorama) {
45     this.panorama = panorama;
46   }
47   /*
48   bool record_state;
49   public bool get_record_state() {
50     return record_state;
51   }
52   public void set_record_state(bool state) {
53     this.record_state = state;
54   }
55   
56   bool pause_state;
57   public bool get_pause_state() {
58     return pause_state;
59   }
60   public void set_pause_state(bool state) {
61     this.pause_state = state;
62   }
63   */
64   public signal void record_toggled(bool val);
65   public signal void play_clicked();
66   public signal void stop_clicked();
67   public signal void pause_toggled(bool val);
68   public signal void volume_updated(double val);
69   public signal void panorama_updated(double val);
70   public signal void eq_updated(int band, double val);
71   
72   private void show_volume_and_pan() {
73     VolumeAndPanPopUp dlg = new VolumeAndPanPopUp("Mixer Volume", this);
74     dlg.set_transient_for(this.window);
75     dlg.set_volume(this.volume);
76     dlg.set_panorama(this.panorama);
77     dlg.volume_updated.connect(volume_updated_callback);
78     dlg.panorama_updated.connect(panorama_updated_callback);
79     dlg.run();
80     dlg.destroy();
81     dlg = null;
82   }
83   
84   private void show_equalizer() {
85     EqualizerPopUp dlg = new EqualizerPopUp("Mixer EQ", this);
86     dlg.set_transient_for(this.window);
87     dlg.eq_updated.connect(eq_updated_callback);
88     dlg.run();
89     dlg.destroy();
90     dlg = null;
91   }
92   
93   private void volume_updated_callback(VolumeAndPanPopUp sender, double volume)
94   {
95     this.volume = volume;
96     volume_updated(this.volume);
97   }
98   
99   private void panorama_updated_callback(VolumeAndPanPopUp sender, double panorama)
100   {
101     this.panorama = panorama;
102     panorama_updated(this.panorama);
103   }
104   
105   private void eq_updated_callback(EqualizerPopUp sender, int band, double val)
106   {
107     eq_updated(band, val);
108   }
109   
110   /*private static string time_to_string(int64 t) {
111     uint64 ut = (uint64)t / Time.Nanoseconds.MILLISECOND;
112     return Time.CLOCK_FORMAT.printf((ut / Time.Milliseconds.MINUTE), (ut / Time.Milliseconds.SECOND) % Time.Seconds.MINUTE, (ut % Time.Milliseconds.SECOND) / 100);
113   }*/
114   public void position_duration_callback(int64 position, int64 duration) {
115     label_position.set_text("%s\n%s".printf(Time.time_to_string(position), Time.time_to_string(duration)));
116   }
117   
118   construct {
119     //record_state = false;
120     //pause_state = false;
121     volume = 1.0;
122     panorama = 0.0;
123     Gtk.HBox transport = new Gtk.HBox(true, 0);
124     //transport.add(new Gtk.Label("Test"));
125     label_position = new Gtk.Label((Time.CLOCK_FORMAT + "\n" + Time.CLOCK_FORMAT).printf((uint64)0,(uint64)0,(uint64)0,(uint64)0,(uint64)0,(uint64)0));
126     transport.pack_end(label_position, false, false, 0);
127     /*progress = new Gtk.HScale.with_range(0.0, 100.0, 0.1);
128     progress.set_draw_value(false);
129     progress.value_changed.connect((s) => { label_position.set_text("%02.2f".printf(s.get_value())); });
130     transport.pack_start(progress, true, true, 2);
131     label_duration = new Gtk.Label("100.0");
132     transport.pack_start(label_duration, false, false, 0);*/
133     Gtk.HButtonBox buttons = new Gtk.HButtonBox();
134     record = new Gtk.ToggleButton(); //.with_label("Re");
135     record.set_image(new Gtk.Image.from_icon_name("camera_video_recording", Gtk.IconSize.BUTTON));
136     record.toggled.connect((b) => { record_toggled(b.active); set_recording(); });
137     buttons.add(record);
138     play = new Gtk.Button(); //.with_label("Pl");
139     play.set_image(new Gtk.Image.from_icon_name("camera_playback", Gtk.IconSize.BUTTON));
140     play.clicked.connect((b) => { play_clicked(); set_playing(); });
141     buttons.add(play);
142     pause = new Gtk.ToggleButton(); //.with_label("Pa");
143     pause.set_image(new Gtk.Image.from_icon_name("camera_video_pause", Gtk.IconSize.BUTTON));
144     pause.toggled.connect((b) => { pause_toggled(b.active); set_paused(); });
145     buttons.add(pause);
146     stop = new Gtk.Button(); //.with_label("St");
147     stop.set_image(new Gtk.Image.from_icon_name("camera_video_stop", Gtk.IconSize.BUTTON));
148     stop.clicked.connect((b) => { stop_clicked(); set_idle(); });
149     buttons.add(stop);
150     Gtk.Button vol = new Gtk.Button(); //.with_label("Vo");
151     //Gtk.Image vol_img = new Gtk.Image.from_icon_name("general_gtalk", Gtk.IconSize.BUTTON);
152     vol.set_image(new Gtk.Image.from_icon_name("statusarea_volumelevel4", Gtk.IconSize.BUTTON));
153     vol.clicked.connect(show_volume_and_pan);
154     buttons.add(vol);
155     Gtk.Button eq = new Gtk.Button.with_label("EQ");
156     eq.clicked.connect(show_equalizer);
157     buttons.add(eq);
158     this.pack_start(buttons, false, false, 0);
159     this.pack_start(transport, true, true, 0);
160     set_idle();
161   }
162   
163   private void set_recording() {
164     play.set_sensitive(true);
165     record.set_sensitive(true);
166     pause.set_sensitive(false);
167     stop.set_sensitive(false);
168   }
169   private void set_playing() {
170     play.set_sensitive(false);
171     record.set_sensitive(false);
172     pause.set_sensitive(true);
173     stop.set_sensitive(true);
174   }
175   private void set_idle() {
176     play.set_sensitive(true);
177     record.set_sensitive(true);
178     record.set_active(false);
179     pause.set_sensitive(false);
180     stop.set_sensitive(false);
181   }
182   private void set_paused() {
183     play.set_sensitive(false);
184     record.set_sensitive(false);
185     pause.set_sensitive(true);
186     stop.set_sensitive(true);
187   }
188
189   private override void add(Gtk.Widget w) {
190     base.add(w);
191   }
192
193   private new void pack_start(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
194     base.pack_start(w, expand, fill, padding);
195   }
196   
197   private new void pack_end(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
198     base.pack_start(w, expand, fill, padding);
199   }
200   
201   
202
203 }
204
205 }