Added About Dialog
[demorecorder] / src / TrackBin.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 TrackBin: Gst.Bin {
21
22   Gst.Element decoder;
23   Gst.Element converter;
24   Gst.Element dynamics;
25   Gst.Element equalizer;
26   Gst.Element echo;
27   Gst.Element volume;
28   Gst.Element panorama;
29   Gst.GhostPad sink_pad;
30   Gst.GhostPad src_pad;
31   
32   public TrackBin(string name) {
33     this.set_name(name);
34     
35     decoder = Gst.ElementFactory.make("uridecodebin", "decoder-" + name);
36     decoder.connect("swapped-object-signal::autoplug-continue", autoplug_continue, this);
37     decoder.connect("swapped-object-signal::drained", drained, this);
38     this.add(decoder);
39     
40     converter = Gst.ElementFactory.make("audioconvert", "converter-" + name);
41     this.add(converter);
42     
43     dynamics = Gst.ElementFactory.make("audiodynamic", "dynamics");
44     dynamics.set_property("mode", "compressor"); // compression
45     dynamics.set_property("characteristics", "soft-knee"); // compression
46     dynamics.set_property("threshold", 1); // shouldn't kick in
47     dynamics.set_property("ratio", 100); // shouldn't be applied
48     this.add(dynamics);
49     
50     equalizer = Gst.ElementFactory.make("equalizer-10bands", "equalizer-" + name);
51     this.add(equalizer);
52     
53     echo = Gst.ElementFactory.make("audioecho", "echo");
54     echo.set_property("delay", 0);
55     echo.set_property("feedback", 0);
56     echo.set_property("intensity", 0);
57     echo.set_property("max-delay", 1 * Time.Nanoseconds.SECOND);
58     this.add(echo);
59     
60     volume = Gst.ElementFactory.make("volume", "volume-" + name);
61     volume.set_property("volume", 1);
62     this.add(volume);
63     
64     panorama = Gst.ElementFactory.make("audiopanorama", "panorama-" + name);
65     panorama.set_property("panorama", 0);
66     this.add(panorama);
67     
68     converter.link(dynamics);
69     dynamics.link(equalizer);
70     equalizer.link(echo);
71     echo.link(panorama);
72     panorama.link(volume);
73     
74     sink_pad = new Gst.GhostPad("sink", decoder.get_static_pad("sink"));
75     this.add_pad(sink_pad);
76     src_pad = new Gst.GhostPad("src", volume.get_static_pad("src"));
77     this.add_pad(src_pad);
78     
79   }
80   /*
81   public void volume_updated_callback(TrackTransport sender, double volume) {
82     this.set_volume(volume);
83   }
84   
85   public void panorama_updated_callback(TrackTransport sender, double panorama) {
86     this.set_panorama(panorama);
87   }
88   
89   public void eq_updated_callback(TrackTransport sender, int band, double val) {
90     this.set_eq(band, val);
91   }
92   */
93   private bool autoplug_continue(Gst.Pad decodebin, Gst.Caps arg1, void* data) {
94     Gst.PadLinkReturn ret = decodebin.link(converter.get_static_pad("sink"));
95     if (Gst.PadLinkReturn.OK != ret) {
96       //stdout.printf("link failed: %s %s\n", this.get_name(), ret.to_string());
97       //stdout.flush();
98     }
99     return true;
100   }
101   
102   private void drained(Gst.Pad decodebin, void* data) {
103   }
104   
105   public new Gst.PadTemplate get_pad_template(string name) {
106     switch (name) {
107       case "src":
108         return this.volume.get_pad_template("src");
109       case "sink":
110         return this.decoder.get_pad_template("sink");
111       default:
112         return this.get_pad_template(name);
113     }
114   }
115   
116   public void play() {
117     this.set_state(Gst.State.PLAYING);
118   }
119   
120   public void pause() {
121     this.set_state(Gst.State.PAUSED);
122   }
123   
124   public void stop() {
125     this.set_state(Gst.State.READY);
126   }
127   
128   public void set_uri(string uri) {
129     this.set_state(Gst.State.NULL);
130     decoder.set_property("uri", uri);
131   }
132   public string get_uri() {
133     GLib.Value ret = 0.0;
134     decoder.get_property("uri", ref ret);
135     return ret.get_string();
136   }
137   
138   public void set_volume(double val)
139   requires (val >= 0.0 && val <= 10.0) {
140     volume.set_property("volume", val);
141   }
142   public double get_volume() {
143     GLib.Value ret = 0.0;
144     volume.get_property("volume", ref ret);
145     return ret.get_double();
146   }
147   
148   public void set_panorama(double val) 
149   requires (val >= -1 && val <= 1) {
150     panorama.set_property("panorama", val);
151   }
152   public double get_panorama() {
153     GLib.Value ret = 0.0;
154     panorama.get_property("panorama", ref ret);
155     return ret.get_double();
156   }
157   
158   public void set_eq(int band, double val)
159   requires (band > -1 && band < 10)
160   requires (val >= -24 && val <= 12) {
161     equalizer.set_property("band" + band.to_string(), val);
162   }
163   public double get_eq(int band) {
164     GLib.Value ret = 0.0;
165     equalizer.get_property("band" + band.to_string(), ref ret);
166     return ret.get_double();
167   }
168   
169   public void set_echo_delay(uint64 val) {
170     echo.set_property("delay", val);
171   }
172   public uint64 get_echo_delay() {
173     GLib.Value ret = 0.0;
174     echo.get_property("delay", ref ret);
175     return ret.get_uint64();
176   }
177   
178   public void set_echo_max_delay(uint64 val) {
179     echo.set_property("max-delay", val);
180   }
181   public uint64 get_echo_max_delay() {
182     GLib.Value ret = 0.0;
183     echo.get_property("max-delay", ref ret);
184     return ret.get_uint64();
185   }
186   
187   public void set_echo_feedback(double val) {
188     echo.set_property("feedback", val);
189   }
190   public double get_echo_feedback() {
191     GLib.Value ret = 0.0;
192     echo.get_property("feedback", ref ret);
193     return ret.get_double();
194   }
195   
196   public void set_echo_intensity(double val) {
197     echo.set_property("intensity", val);
198   }
199   public double get_echo_intensity() {
200     GLib.Value ret = 0.0;
201     echo.get_property("intensity", ref ret);
202     return ret.get_double();
203   }
204   
205   public void set_echo_active(bool val) {
206     if (val) {}
207     else {
208       set_echo_delay(0);
209       set_echo_feedback(0);
210       set_echo_intensity(0);
211     }
212   }
213   public bool get_echo_active() {
214     return true;
215   }
216   
217   public void set_dynamics_mode(string val) {
218     dynamics.set_property("mode", val);
219   }
220   public string get_dynamics_mode() {
221     GLib.Value ret = 0.0;
222     dynamics.get_property("mode", ref ret);
223     return ret.get_string();
224   }
225   
226   public void set_dynamics_characteristics(string val) {
227     dynamics.set_property("characteristics", val);
228   }
229   public string get_dynamics_characteristics() {
230     GLib.Value ret = 0.0;
231     dynamics.get_property("characteristics", ref ret);
232     return ret.get_string();
233   }
234   
235   public void set_dynamics_threshold(double val) {
236     dynamics.set_property("threshold", val);
237   }
238   public double get_dynamics_threshold() {
239     GLib.Value ret = 0.0;
240     dynamics.get_property("threshold", ref ret);
241     return ret.get_double();
242   }
243   
244   public void set_dynamics_ratio(double val) {
245     dynamics.set_property("ratio", val);
246   }
247   public double get_dynamics_ratio() {
248     GLib.Value ret = 0.0;
249     dynamics.get_property("ratio", ref ret);
250     return ret.get_double();
251   }
252   
253   public void set_dynamics_active(bool val) {
254     if (val) {}
255     else {
256       set_dynamics_mode("compressor");
257       set_dynamics_characteristics("soft-knee");
258       set_dynamics_ratio(1);
259       set_dynamics_threshold(0);
260     }
261   }
262   public bool get_dynamics_active() {
263     return true;
264   }
265   
266 }
267
268 }