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