Adding first code drop
[demorecorder] / src / TrackTransport.vala
diff --git a/src/TrackTransport.vala b/src/TrackTransport.vala
new file mode 100644 (file)
index 0000000..d308bb6
--- /dev/null
@@ -0,0 +1,240 @@
+/*  Demo Recorder for MAEMO 5
+*   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
+*   This program is free software; you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License version 2,
+*   or (at your option) any later version, as published by the Free
+*   Software Foundation
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details
+*
+*   You should have received a copy of the GNU General Public
+*   License along with this program; if not, write to the
+*   Free Software Foundation, Inc.,
+*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+namespace IdWorks {
+
+public class TrackTransport : Gtk.HBox {
+  
+  public TrackBin track_bin;
+  public Track track;
+  public Gtk.Window window;
+
+  /*Gst.Element audio_src;
+  public void set_audio_src(Gst.Element src) {
+    audio_src = src;
+  }
+
+  Gst.Element audio_sink;
+  public Gst.Element get_audio_sink()
+  {
+    return audio_sink;
+  }*/
+  
+  /* Widgets */
+  Gtk.Button btn_volume;
+  Gtk.Button btn_eq;
+  Gtk.Button btn_delete;
+  
+  Gtk.Label lbl_title;
+  string _title;
+  public string title {
+    get { return _title; /*lbl_title.get_text();*/ } 
+    set { _title = value; lbl_title.set_markup("<b>" + _title + "</b>"); }
+  }
+  
+  Gtk.ToggleButton btn_active;
+  public void set_active_state(bool state) {
+    btn_active.set_active(state);
+  }
+  public bool get_active_state() {
+    return btn_active.get_active();
+  }
+  
+  Gtk.ToggleButton btn_mute;
+  public void set_mute_state(bool state) {
+    btn_mute.set_active(state);
+  }
+  public bool get_mute_state() {
+    return btn_mute.get_active();
+  }
+  
+  Gtk.Button btn_effects;
+  /*public void set_effects_state(bool state) {
+    btn_effects.set_active(state);
+  }
+  public bool get_effects_state() {
+    return btn_effects.get_active();
+  }*/
+  
+  private double volume;
+  private double panorama;
+  
+  /* Signals */
+  public signal void active_toggled(bool state);
+  //public signal void mute_toggled(bool state);
+  //public signal void effects_toggled(bool state);
+  public signal void eq_updated(int band, double val);
+  public signal void delete_clicked();
+  public signal void volume_updated(double volume);
+  public signal void panorama_updated(double panorama);
+  
+  public signal void dynamics_toggled(bool state);
+  public signal void dynamics_mode_updated(string val);
+  public signal void dynamics_characteristics_updated(string val);
+  public signal void dynamics_ratio_updated(double val);
+  public signal void dynamics_threshold_updated(double val);
+  
+  public signal void echo_toggled(bool val);
+  public signal void echo_max_delay_updated(uint64 val);
+  public signal void echo_delay_updated(uint64 val);
+  public signal void echo_feedback_updated(double val);
+  public signal void echo_intensity_updated(double val);
+  
+  private void show_volume_and_pan() {
+    VolumeAndPanPopUp dlg = new VolumeAndPanPopUp("Mixer Volume", this);
+    dlg.set_transient_for(this.window);
+    dlg.set_volume(this.volume);
+    dlg.set_panorama(this.panorama);
+    dlg.volume_updated.connect(volume_updated_callback);
+    dlg.panorama_updated.connect(panorama_updated_callback);
+    dlg.run();
+    dlg.destroy();
+    dlg = null;
+  }
+  
+  private void show_equalizer() {
+    EqualizerPopUp dlg = new EqualizerPopUp("Track EQ", this);
+    dlg.set_transient_for(this.window);
+    dlg.eq_updated.connect(eq_updated_callback);
+    dlg.run();
+    dlg.destroy();
+    dlg = null;
+  }
+  
+  private void show_effects() {
+    TrackEffectsPopUp dlg = new TrackEffectsPopUp.with_settings("Track Effects", this, SettingsStructures.EchoSettings(), SettingsStructures.DynamicsSettings());
+    dlg.set_transient_for(this.window);
+    // connect up callbacks dlg.blah.connect
+    dlg.echo_toggled.connect((val) => {this.echo_toggled(val);});
+    dlg.echo_max_delay_updated.connect((val) => {this.echo_max_delay_updated(val);});
+    dlg.echo_delay_updated.connect((val) => {this.echo_delay_updated(val);});
+    dlg.echo_feedback_updated.connect((val) => {this.echo_feedback_updated(val);});
+    dlg.echo_intensity_updated.connect((val) => {this.echo_intensity_updated(val);});
+    dlg.dynamics_toggled.connect((val) => {this.dynamics_toggled(val);});
+    dlg.dynamics_mode_updated.connect((val) => {this.dynamics_mode_updated(val);});
+    dlg.dynamics_characteristics_updated.connect((val) => {this.dynamics_characteristics_updated(val);});
+    dlg.dynamics_ratio_updated.connect((val) => {this.dynamics_ratio_updated(val);});
+    dlg.dynamics_threshold_updated.connect((val) => {this.dynamics_threshold_updated(val);});
+    dlg.run();
+    dlg.destroy();
+    dlg = null;
+  }
+  
+  public void playback_starting_callback(Object sender) {
+    btn_active.set_sensitive(false);
+    btn_delete.set_sensitive(false);
+  }
+  
+  public void playback_ending_callback(Object sender) {
+    btn_active.set_sensitive(true);
+    btn_delete.set_sensitive(true);
+  }
+  
+  public void recording_starting_callback(Object sender) {
+    btn_active.set_sensitive(false);
+    btn_delete.set_sensitive(false);
+  }
+  
+  public void recording_ending_callback(Object sender) {
+    btn_active.set_sensitive(true);
+    btn_delete.set_sensitive(true);
+  }
+  
+  private void eq_updated_callback(EqualizerPopUp sender, int band, double val) {
+    eq_updated(band, val);
+  }
+  
+  private void mute_toggled(bool mute_on) {
+    volume_updated((mute_on) ? 0.0 : this.volume);
+  }
+  
+  private void volume_updated_callback(VolumeAndPanPopUp sender, double volume)
+  {
+    this.volume = volume;
+    volume_updated(this.volume);
+  }
+  
+  private void set_track_active(bool active) {
+    btn_mute.set_sensitive(active);
+    btn_volume.set_sensitive(active);
+    btn_eq.set_sensitive(active);
+    btn_effects.set_sensitive(active);
+    btn_active.set_image(new Gtk.Image.from_icon_name((active ? "general_presence_online" : "general_presence_invisible"), Gtk.IconSize.SMALL_TOOLBAR));
+    //track.active = active;
+    active_toggled(active);
+  }
+  
+  private void panorama_updated_callback(VolumeAndPanPopUp sender, double panorama)
+  {
+    this.panorama = panorama;
+    panorama_updated(this.panorama);
+  }
+  
+  /* Constructor */
+  construct {
+    this.volume = 1.0;
+    this.panorama = 0.0;
+    lbl_title = new Gtk.Label("<b>New Track</b>");
+    lbl_title.use_markup = true;
+    lbl_title.set_alignment(0.1f, 0.4f);
+    lbl_title.set_ellipsize(Pango.EllipsizeMode.START);
+    this.pack_start(lbl_title, true, true, 2);
+    Gtk.HButtonBox buttons = new Gtk.HButtonBox();
+    btn_active = new Gtk.ToggleButton(); //.with_label("Active");
+    btn_mute.set_image(new Gtk.Image.from_icon_name("general_presence_online", Gtk.IconSize.SMALL_TOOLBAR));
+    btn_active.toggled.connect((b) => { set_track_active(b.get_active()); });
+    buttons.add(btn_active);
+    btn_mute = new Gtk.ToggleButton(); //.with_label("Mute");
+    btn_mute.set_image(new Gtk.Image.from_icon_name("statusarea_volume_mute", Gtk.IconSize.SMALL_TOOLBAR));
+    btn_mute.toggled.connect((b) => { mute_toggled(b.get_active()); });
+    buttons.add(btn_mute);
+    btn_volume = new Gtk.Button(); //.with_label("Vol");
+    btn_volume.set_image(new Gtk.Image.from_icon_name("statusarea_volumelevel4", Gtk.IconSize.SMALL_TOOLBAR));
+    btn_volume.clicked.connect((b) => { show_volume_and_pan(); });
+    buttons.add(btn_volume);
+    btn_eq = new Gtk.Button.with_label("EQ");
+    btn_eq.clicked.connect((b) => { show_equalizer(); });
+    buttons.add(btn_eq);
+    btn_effects = new Gtk.Button.with_label("FX");
+    btn_effects.clicked.connect((b) => { show_effects(); });
+    buttons.add(btn_effects);
+    btn_delete = new Gtk.Button();    
+    btn_delete.set_image(new Gtk.Image.from_icon_name("camera_delete", Gtk.IconSize.SMALL_TOOLBAR));
+    btn_delete.clicked.connect((b) => { delete_clicked(); });
+    buttons.add(btn_delete);
+    this.pack_start(buttons, false, false, 0);
+  }  
+  
+  /* Overrides */
+  private override void add(Gtk.Widget w) {
+    base.add(w);
+  }
+  
+  /* Hidden inherited methods */
+  private new void pack_start(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
+    base.pack_start(w, expand, fill, padding);
+  }
+  
+  private new void pack_end(Gtk.Widget w, bool expand, bool fill, uint padding = 0) {
+    base.pack_start(w, expand, fill, padding);
+  }
+  
+  /* Public Methods */
+
+}
+
+}