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
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
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.
20 public class TrackBin: Gst.Bin {
23 Gst.Element converter;
25 Gst.Element equalizer;
29 Gst.GhostPad sink_pad;
32 public TrackBin(string name) {
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);
40 converter = Gst.ElementFactory.make("audioconvert", "converter-" + name);
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
50 equalizer = Gst.ElementFactory.make("equalizer-10bands", "equalizer-" + name);
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);
60 volume = Gst.ElementFactory.make("volume", "volume-" + name);
61 volume.set_property("volume", 1);
64 panorama = Gst.ElementFactory.make("audiopanorama", "panorama-" + name);
65 panorama.set_property("panorama", 0);
68 converter.link(dynamics);
69 dynamics.link(equalizer);
72 panorama.link(volume);
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);
81 public void volume_updated_callback(TrackTransport sender, double volume) {
82 this.set_volume(volume);
85 public void panorama_updated_callback(TrackTransport sender, double panorama) {
86 this.set_panorama(panorama);
89 public void eq_updated_callback(TrackTransport sender, int band, double val) {
90 this.set_eq(band, val);
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());
102 private void drained(Gst.Pad decodebin, void* data) {
105 public new Gst.PadTemplate get_pad_template(string name) {
108 return this.volume.get_pad_template("src");
110 return this.decoder.get_pad_template("sink");
112 return this.get_pad_template(name);
117 this.set_state(Gst.State.PLAYING);
120 public void pause() {
121 this.set_state(Gst.State.PAUSED);
125 this.set_state(Gst.State.READY);
128 public void set_uri(string uri) {
129 this.set_state(Gst.State.NULL);
130 decoder.set_property("uri", uri);
132 public string get_uri() {
133 GLib.Value ret = 0.0;
134 decoder.get_property("uri", ref ret);
135 return ret.get_string();
138 public void set_volume(double val)
139 requires (val >= 0.0 && val <= 10.0) {
140 volume.set_property("volume", val);
142 public double get_volume() {
143 GLib.Value ret = 0.0;
144 volume.get_property("volume", ref ret);
145 return ret.get_double();
148 public void set_panorama(double val)
149 requires (val >= -1 && val <= 1) {
150 panorama.set_property("panorama", val);
152 public double get_panorama() {
153 GLib.Value ret = 0.0;
154 panorama.get_property("panorama", ref ret);
155 return ret.get_double();
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);
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();
169 public void set_echo_delay(uint64 val) {
170 echo.set_property("delay", val);
172 public uint64 get_echo_delay() {
173 GLib.Value ret = 0.0;
174 echo.get_property("delay", ref ret);
175 return ret.get_uint64();
178 public void set_echo_max_delay(uint64 val) {
179 echo.set_property("max-delay", val);
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();
187 public void set_echo_feedback(double val) {
188 echo.set_property("feedback", val);
190 public double get_echo_feedback() {
191 GLib.Value ret = 0.0;
192 echo.get_property("feedback", ref ret);
193 return ret.get_double();
196 public void set_echo_intensity(double val) {
197 echo.set_property("intensity", val);
199 public double get_echo_intensity() {
200 GLib.Value ret = 0.0;
201 echo.get_property("intensity", ref ret);
202 return ret.get_double();
205 public void set_echo_active(bool val) {
209 set_echo_feedback(0);
210 set_echo_intensity(0);
213 public bool get_echo_active() {
217 public void set_dynamics_mode(string val) {
218 dynamics.set_property("mode", val);
220 public string get_dynamics_mode() {
221 GLib.Value ret = 0.0;
222 dynamics.get_property("mode", ref ret);
223 return ret.get_string();
226 public void set_dynamics_characteristics(string val) {
227 dynamics.set_property("characteristics", val);
229 public string get_dynamics_characteristics() {
230 GLib.Value ret = 0.0;
231 dynamics.get_property("characteristics", ref ret);
232 return ret.get_string();
235 public void set_dynamics_threshold(double val) {
236 dynamics.set_property("threshold", val);
238 public double get_dynamics_threshold() {
239 GLib.Value ret = 0.0;
240 dynamics.get_property("threshold", ref ret);
241 return ret.get_double();
244 public void set_dynamics_ratio(double val) {
245 dynamics.set_property("ratio", val);
247 public double get_dynamics_ratio() {
248 GLib.Value ret = 0.0;
249 dynamics.get_property("ratio", ref ret);
250 return ret.get_double();
253 public void set_dynamics_active(bool val) {
256 set_dynamics_mode("compressor");
257 set_dynamics_characteristics("soft-knee");
258 set_dynamics_ratio(1);
259 set_dynamics_threshold(0);
262 public bool get_dynamics_active() {