UI fixes regarding button states.
[demorecorder] / src / TrackTransport.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 TrackTransport : Gtk.HBox {
21   
22   public TrackBin track_bin;
23   public Track track;
24   public Gtk.Window window;
25
26   /*Gst.Element audio_src;
27   public void set_audio_src(Gst.Element src) {
28     audio_src = src;
29   }
30
31   Gst.Element audio_sink;
32   public Gst.Element get_audio_sink()
33   {
34     return audio_sink;
35   }*/
36   
37   /* Widgets */
38   Gtk.Button btn_volume;
39   Gtk.Button btn_eq;
40   Gtk.Button btn_delete;
41   
42   Gtk.Label lbl_title;
43   string _title;
44   public string title {
45     get { return _title; /*lbl_title.get_text();*/ } 
46     set { _title = value; lbl_title.set_markup("<b>" + _title + "</b>"); }
47   }
48   
49   Gtk.ToggleButton btn_active;
50   public void set_active_state(bool state) {
51     btn_active.set_active(state);
52   }
53   public bool get_active_state() {
54     return btn_active.get_active();
55   }
56   
57   Gtk.ToggleButton btn_mute;
58   public void set_mute_state(bool state) {
59     btn_mute.set_active(state);
60   }
61   public bool get_mute_state() {
62     return btn_mute.get_active();
63   }
64   
65   Gtk.Button btn_effects;
66   /*public void set_effects_state(bool state) {
67     btn_effects.set_active(state);
68   }
69   public bool get_effects_state() {
70     return btn_effects.get_active();
71   }*/
72   
73   private double volume;
74   private double panorama;
75   
76   /* Signals */
77   public signal void active_toggled(bool state);
78   //public signal void mute_toggled(bool state);
79   //public signal void effects_toggled(bool state);
80   public signal void eq_updated(int band, double val);
81   public signal void delete_clicked();
82   public signal void volume_updated(double volume);
83   public signal void panorama_updated(double panorama);
84   
85   public signal void dynamics_toggled(bool state);
86   public signal void dynamics_mode_updated(string val);
87   public signal void dynamics_characteristics_updated(string val);
88   public signal void dynamics_ratio_updated(double val);
89   public signal void dynamics_threshold_updated(double val);
90   
91   public signal void echo_toggled(bool val);
92   public signal void echo_max_delay_updated(uint64 val);
93   public signal void echo_delay_updated(uint64 val);
94   public signal void echo_feedback_updated(double val);
95   public signal void echo_intensity_updated(double val);
96   
97   private void show_volume_and_pan() {
98     VolumeAndPanPopUp dlg = new VolumeAndPanPopUp("Mixer Volume", this);
99     dlg.set_transient_for(this.window);
100     dlg.set_volume(this.volume);
101     dlg.set_panorama(this.panorama);
102     dlg.volume_updated.connect(volume_updated_callback);
103     dlg.panorama_updated.connect(panorama_updated_callback);
104     dlg.run();
105     dlg.destroy();
106     dlg = null;
107   }
108   
109   private void show_equalizer() {
110     EqualizerPopUp dlg = new EqualizerPopUp("Track EQ", this);
111     dlg.set_transient_for(this.window);
112     dlg.eq_updated.connect(eq_updated_callback);
113     dlg.run();
114     dlg.destroy();
115     dlg = null;
116   }
117   
118   private void show_effects() {
119     TrackEffectsPopUp dlg = new TrackEffectsPopUp.with_settings("Track Effects", this, SettingsStructures.EchoSettings(), SettingsStructures.DynamicsSettings());
120     dlg.set_transient_for(this.window);
121     // connect up callbacks dlg.blah.connect
122     dlg.echo_toggled.connect((val) => {this.echo_toggled(val);});
123     dlg.echo_max_delay_updated.connect((val) => {this.echo_max_delay_updated(val);});
124     dlg.echo_delay_updated.connect((val) => {this.echo_delay_updated(val);});
125     dlg.echo_feedback_updated.connect((val) => {this.echo_feedback_updated(val);});
126     dlg.echo_intensity_updated.connect((val) => {this.echo_intensity_updated(val);});
127     dlg.dynamics_toggled.connect((val) => {this.dynamics_toggled(val);});
128     dlg.dynamics_mode_updated.connect((val) => {this.dynamics_mode_updated(val);});
129     dlg.dynamics_characteristics_updated.connect((val) => {this.dynamics_characteristics_updated(val);});
130     dlg.dynamics_ratio_updated.connect((val) => {this.dynamics_ratio_updated(val);});
131     dlg.dynamics_threshold_updated.connect((val) => {this.dynamics_threshold_updated(val);});
132     dlg.run();
133     dlg.destroy();
134     dlg = null;
135   }
136   
137   public void playback_starting_callback(Object sender) {
138     btn_active.set_sensitive(false);
139     btn_delete.set_sensitive(false);
140     btn_effects.set_sensitive(false);
141   }
142   
143   public void playback_ending_callback(Object sender) {
144     btn_active.set_sensitive(true);
145     btn_delete.set_sensitive(true);
146     btn_effects.set_sensitive(get_active_state());
147   }
148   
149   public void recording_starting_callback(Object sender) {
150     btn_active.set_sensitive(false);
151     btn_delete.set_sensitive(false);
152     btn_effects.set_sensitive(false);
153   }
154   
155   public void recording_ending_callback(Object sender) {
156     btn_active.set_sensitive(true);
157     btn_delete.set_sensitive(true);
158     btn_effects.set_sensitive(get_active_state());
159   }
160   
161   private void eq_updated_callback(EqualizerPopUp sender, int band, double val) {
162     eq_updated(band, val);
163   }
164   
165   private void mute_toggled(bool mute_on) {
166     volume_updated((mute_on) ? 0.0 : this.volume);
167   }
168   
169   private void volume_updated_callback(VolumeAndPanPopUp sender, double volume)
170   {
171     this.volume = volume;
172     volume_updated(this.volume);
173   }
174   
175   private void set_track_active(bool active) {
176     btn_mute.set_sensitive(active);
177     btn_volume.set_sensitive(active);
178     btn_eq.set_sensitive(active);
179     btn_effects.set_sensitive(active);
180     btn_active.set_image(new Gtk.Image.from_icon_name((active ? "general_presence_online" : "general_presence_invisible"), Gtk.IconSize.SMALL_TOOLBAR));
181     //track.active = active;
182     active_toggled(active);
183   }
184   
185   private void panorama_updated_callback(VolumeAndPanPopUp sender, double panorama)
186   {
187     this.panorama = panorama;
188     panorama_updated(this.panorama);
189   }
190   
191   /* Constructor */
192   construct {
193     this.volume = 1.0;
194     this.panorama = 0.0;
195     lbl_title = new Gtk.Label("<b>New Track</b>");
196     lbl_title.use_markup = true;
197     lbl_title.set_alignment(0.1f, 0.4f);
198     lbl_title.set_ellipsize(Pango.EllipsizeMode.START);
199     this.pack_start(lbl_title, true, true, 2);
200     Gtk.HButtonBox buttons = new Gtk.HButtonBox();
201     btn_active = new Gtk.ToggleButton(); //.with_label("Active");
202     btn_mute.set_image(new Gtk.Image.from_icon_name("general_presence_online", Gtk.IconSize.SMALL_TOOLBAR));
203     btn_active.toggled.connect((b) => { set_track_active(b.get_active()); });
204     buttons.add(btn_active);
205     btn_mute = new Gtk.ToggleButton(); //.with_label("Mute");
206     btn_mute.set_image(new Gtk.Image.from_icon_name("statusarea_volume_mute", Gtk.IconSize.SMALL_TOOLBAR));
207     btn_mute.toggled.connect((b) => { mute_toggled(b.get_active()); });
208     buttons.add(btn_mute);
209     btn_volume = new Gtk.Button(); //.with_label("Vol");
210     btn_volume.set_image(new Gtk.Image.from_icon_name("statusarea_volumelevel4", Gtk.IconSize.SMALL_TOOLBAR));
211     btn_volume.clicked.connect((b) => { show_volume_and_pan(); });
212     buttons.add(btn_volume);
213     btn_eq = new Gtk.Button.with_label("EQ");
214     btn_eq.clicked.connect((b) => { show_equalizer(); });
215     buttons.add(btn_eq);
216     btn_effects = new Gtk.Button.with_label("FX");
217     btn_effects.clicked.connect((b) => { show_effects(); });
218     buttons.add(btn_effects);
219     btn_delete = new Gtk.Button();    
220     btn_delete.set_image(new Gtk.Image.from_icon_name("camera_delete", Gtk.IconSize.SMALL_TOOLBAR));
221     btn_delete.clicked.connect((b) => { delete_clicked(); });
222     buttons.add(btn_delete);
223     this.pack_start(buttons, false, false, 0);
224   }  
225   
226   /* Overrides */
227   private override void add(Gtk.Widget w) {
228     base.add(w);
229   }
230   
231   /* Hidden inherited methods */
232   private new void pack_start(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
233     base.pack_start(w, expand, fill, padding);
234   }
235   
236   private new void pack_end(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
237     base.pack_start(w, expand, fill, padding);
238   }
239   
240   /* Public Methods */
241
242 }
243
244 }