Adding first code drop
[demorecorder] / src / MixerBin.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 MixerBin : Gst.Bin {
21
22   Gst.Element adder;
23   Gst.Element equalizer;
24   Gst.Element panorama;
25   Gst.Element volume;
26   List<TrackBin> tracks;
27   Gst.GhostPad sink_pad;
28   Gst.GhostPad src_pad;
29   
30   public MixerBin(string name) {
31     this.name = name;
32     tracks = new List<TrackBin>();
33     
34     adder      = Gst.ElementFactory.make("adder", "adder_source");
35     this.add(adder);
36     equalizer  = Gst.ElementFactory.make("equalizer-10bands", "eq");
37     this.add(equalizer);
38     panorama = Gst.ElementFactory.make("audiopanorama", "panorama");
39     this.add(panorama);
40     volume    = Gst.ElementFactory.make("volume", "vol");
41     this.add(volume);
42     
43     adder.link(equalizer);
44     equalizer.link(panorama);
45     panorama.link(volume);
46     //volume.link(sink);
47     
48     sink_pad = new Gst.GhostPad("sink", adder.get_static_pad("sink"));
49     this.add_pad(sink_pad);
50     src_pad = new Gst.GhostPad("src", volume.get_static_pad("src"));
51     this.add_pad(src_pad);
52   }
53   
54   public bool add_track(TrackBin bin) {
55     this.add(bin);
56     bin.link(adder);
57     if (null == tracks) {
58       tracks = new List<TrackBin>();
59     }
60     tracks.append(bin);
61     return true;
62   }
63   
64   public void remove_all_tracks() {
65     while (null != tracks.first()) {
66       TrackBin track = tracks.first().data as TrackBin;
67       if (null != track) {
68         track.unlink(adder);
69         this.remove(track);
70       }
71       tracks.remove_link(tracks.first());
72     }
73   }
74   
75   public bool remove_track(TrackBin track) {
76     track.unlink(adder);
77     this.remove(track);
78     tracks.remove(track);
79     return true;
80   }
81   
82   public new Gst.PadTemplate get_pad_template(string name) {
83     switch (name) {
84       case "src":
85         return this.volume.get_pad_template("src");
86       case "sink":
87         return this.adder.get_pad_template("sink");
88       default:
89         return this.get_pad_template(name);
90     }
91   }
92   
93   public void set_volume(double val)
94   requires (val >= 0.0 && val <= 10.0) {
95     volume.set_property("volume", val);
96   }
97   public double get_volume() {
98     GLib.Value ret = 0.0;
99     volume.get_property("volume", ref ret);
100     return ret.get_double();
101   }
102   
103   public void set_panorama(double val) 
104   requires (val >= -1 && val <= 1) {
105     panorama.set_property("panorama", val);
106   }
107   public double get_panorama() {
108     GLib.Value ret = 0.0;
109     panorama.get_property("panorama", ref ret);
110     return ret.get_double();
111   }
112   
113   public void set_eq(int band, double val)
114   requires (band > -1 && band < 10)
115   requires (val >= -24 && val <= 12) {
116     equalizer.set_property("band" + band.to_string(), val);
117   }
118   public double get_eq(int band) {
119     GLib.Value ret = 0.0;
120     equalizer.get_property("band" + band.to_string(), ref ret);
121     return ret.get_double();
122   }
123   
124 }
125
126 }