d308bb68654d10f0c7d914dc99ccdd69f1683661
[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   }
141   
142   public void playback_ending_callback(Object sender) {
143     btn_active.set_sensitive(true);
144     btn_delete.set_sensitive(true);
145   }
146   
147   public void recording_starting_callback(Object sender) {
148     btn_active.set_sensitive(false);
149     btn_delete.set_sensitive(false);
150   }
151   
152   public void recording_ending_callback(Object sender) {
153     btn_active.set_sensitive(true);
154     btn_delete.set_sensitive(true);
155   }
156   
157   private void eq_updated_callback(EqualizerPopUp sender, int band, double val) {
158     eq_updated(band, val);
159   }
160   
161   private void mute_toggled(bool mute_on) {
162     volume_updated((mute_on) ? 0.0 : this.volume);
163   }
164   
165   private void volume_updated_callback(VolumeAndPanPopUp sender, double volume)
166   {
167     this.volume = volume;
168     volume_updated(this.volume);
169   }
170   
171   private void set_track_active(bool active) {
172     btn_mute.set_sensitive(active);
173     btn_volume.set_sensitive(active);
174     btn_eq.set_sensitive(active);
175     btn_effects.set_sensitive(active);
176     btn_active.set_image(new Gtk.Image.from_icon_name((active ? "general_presence_online" : "general_presence_invisible"), Gtk.IconSize.SMALL_TOOLBAR));
177     //track.active = active;
178     active_toggled(active);
179   }
180   
181   private void panorama_updated_callback(VolumeAndPanPopUp sender, double panorama)
182   {
183     this.panorama = panorama;
184     panorama_updated(this.panorama);
185   }
186   
187   /* Constructor */
188   construct {
189     this.volume = 1.0;
190     this.panorama = 0.0;
191     lbl_title = new Gtk.Label("<b>New Track</b>");
192     lbl_title.use_markup = true;
193     lbl_title.set_alignment(0.1f, 0.4f);
194     lbl_title.set_ellipsize(Pango.EllipsizeMode.START);
195     this.pack_start(lbl_title, true, true, 2);
196     Gtk.HButtonBox buttons = new Gtk.HButtonBox();
197     btn_active = new Gtk.ToggleButton(); //.with_label("Active");
198     btn_mute.set_image(new Gtk.Image.from_icon_name("general_presence_online", Gtk.IconSize.SMALL_TOOLBAR));
199     btn_active.toggled.connect((b) => { set_track_active(b.get_active()); });
200     buttons.add(btn_active);
201     btn_mute = new Gtk.ToggleButton(); //.with_label("Mute");
202     btn_mute.set_image(new Gtk.Image.from_icon_name("statusarea_volume_mute", Gtk.IconSize.SMALL_TOOLBAR));
203     btn_mute.toggled.connect((b) => { mute_toggled(b.get_active()); });
204     buttons.add(btn_mute);
205     btn_volume = new Gtk.Button(); //.with_label("Vol");
206     btn_volume.set_image(new Gtk.Image.from_icon_name("statusarea_volumelevel4", Gtk.IconSize.SMALL_TOOLBAR));
207     btn_volume.clicked.connect((b) => { show_volume_and_pan(); });
208     buttons.add(btn_volume);
209     btn_eq = new Gtk.Button.with_label("EQ");
210     btn_eq.clicked.connect((b) => { show_equalizer(); });
211     buttons.add(btn_eq);
212     btn_effects = new Gtk.Button.with_label("FX");
213     btn_effects.clicked.connect((b) => { show_effects(); });
214     buttons.add(btn_effects);
215     btn_delete = new Gtk.Button();    
216     btn_delete.set_image(new Gtk.Image.from_icon_name("camera_delete", Gtk.IconSize.SMALL_TOOLBAR));
217     btn_delete.clicked.connect((b) => { delete_clicked(); });
218     buttons.add(btn_delete);
219     this.pack_start(buttons, false, false, 0);
220   }  
221   
222   /* Overrides */
223   private override void add(Gtk.Widget w) {
224     base.add(w);
225   }
226   
227   /* Hidden inherited methods */
228   private new void pack_start(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
229     base.pack_start(w, expand, fill, padding);
230   }
231   
232   private new void pack_end(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
233     base.pack_start(w, expand, fill, padding);
234   }
235   
236   /* Public Methods */
237
238 }
239
240 }