Adding first code drop
[demorecorder] / src / DynamicsPopUp.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 DynamicsPopUp : Hildon.Dialog {
21
22   Hildon.TouchSelector characteristics_selector;
23   Hildon.TouchSelector mode_selector;
24   Gtk.HScale ratio_slider;
25   Gtk.HScale threshold_slider;
26   
27   public signal void characteristics_updated(string val);
28   public signal void mode_updated(string val);
29   public signal void ratio_updated(double val);
30   public signal void threshold_updated(double val);
31   
32   public SettingsStructures.DynamicsSettings get_settings_structure() {
33     SettingsStructures.DynamicsSettings settings = SettingsStructures.DynamicsSettings();
34     settings.active = true;
35     settings.mode = this.get_mode();
36     settings.characteristics = this.get_characteristics();
37     settings.ratio = this.get_ratio();
38     settings.threshold = this.get_threshold();
39     return settings;
40   }
41   public void set_settings_structure(SettingsStructures.DynamicsSettings settings) {
42     // ignore active for now
43     this.set_mode(settings.mode);
44     this.set_characteristics(settings.characteristics);
45     this.set_ratio(settings.ratio);
46     this.set_threshold(settings.threshold);
47   }
48   
49   public DynamicsPopUp(string title, Gtk.Widget parent) {
50     this.set_title(title);
51     this.set_parent(parent);
52     this.construct_interface(SettingsStructures.DynamicsSettings());
53   }
54   public DynamicsPopUp.with_settings(string title, Gtk.Widget parent, SettingsStructures.DynamicsSettings settings) {
55     this.set_title(title);
56     this.set_parent(parent);
57     stdout.printf("dynamics popup constructing interface\n");
58     stdout.flush();
59     this.construct_interface(settings);
60     stdout.printf("dynamics popup interface constructed\n");
61     stdout.flush();
62   }
63    
64   private void construct_interface(SettingsStructures.DynamicsSettings settings) {
65     this.set_default_response(Gtk.ResponseType.ACCEPT);
66     this.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.ACCEPT);
67     
68     Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
69     
70     Gtk.HButtonBox button_bar = new Gtk.HButtonBox();
71     button_bar.set_layout(Gtk.ButtonBoxStyle.START);
72     button_bar.set_homogeneous(true);
73     button_bar.set_spacing(4);
74     
75     mode_selector = new Hildon.TouchSelector.text();
76     mode_selector.append_text("compressor");
77     mode_selector.append_text("expander");
78     //mode_selector.set_active(0, 0);
79     stdout.printf("dynamics setting mode %s\n", settings.mode);
80     stdout.flush();
81     this.set_mode(settings.mode);
82     stdout.printf("dynamics mode set %s\n", settings.mode);
83     stdout.flush();
84     Hildon.PickerButton mode_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
85     mode_picker.set_title("Mode:");
86     mode_picker.set_selector(mode_selector);
87     mode_picker.set_alignment(0, 0, 1, 1);
88     stdout.printf("dynamics mode connect\n");
89     stdout.flush();
90     mode_picker.value_changed.connect( (s) => { mode_updated(s.get_selector().get_current_text()); } );
91     stdout.printf("dynamics mode connected\n");
92     stdout.flush();
93     button_bar.pack_start(mode_picker, true, true, 2);
94     
95     stdout.printf("dynamics mode starting 0\n");
96     stdout.flush();
97     characteristics_selector = new Hildon.TouchSelector.text();
98     stdout.printf("dynamics mode starting 1\n");
99     stdout.flush();
100     characteristics_selector.append_text("soft-knee");
101     stdout.printf("dynamics mode starting 2\n");
102     stdout.flush();
103     characteristics_selector.append_text("hard-knee");
104     //characteristics_selector.set_active(0, 0);
105     stdout.printf("dynamics setting characteristics %s\n", settings.characteristics);
106     stdout.flush();
107     this.set_characteristics(settings.characteristics);
108     Hildon.PickerButton characteristics_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
109     characteristics_picker.set_title("Characteristics:");
110     characteristics_picker.set_selector(characteristics_selector);
111     characteristics_picker.set_alignment(0, 0, 1, 1);
112     characteristics_picker.value_changed.connect( (s) => { characteristics_updated(s.get_selector().get_current_text()); } );
113     button_bar.pack_start(characteristics_picker, true, true, 2);
114     
115     control_area.pack_start(button_bar, true, true, 2);
116     
117     Gtk.HBox ratio_bar = new Gtk.HBox(false, 4);
118     
119     Gtk.Label ratio_label = new Gtk.Label("Ratio: ");
120     ratio_slider = new Gtk.HScale.with_range(0.0, 25.0, 0.5);
121     ratio_slider.set_value_pos(Gtk.PositionType.LEFT);
122     stdout.printf("dynamics setting ratio\n");
123     stdout.flush();
124     this.set_ratio(settings.ratio);
125     ratio_slider.value_changed.connect((s) => {ratio_updated(s.get_value());});
126     ratio_bar.pack_start(ratio_label, false, false, 2);
127     ratio_bar.pack_start(ratio_slider, true, true, 2);
128     
129     control_area.pack_start(ratio_bar, true, true, 2);
130     
131     Gtk.HBox threshold_bar = new Gtk.HBox(false, 4);
132     
133     Gtk.Label threshold_label = new Gtk.Label("Threshold: ");
134     threshold_slider = new Gtk.HScale.with_range(0.0, 1.0, 0.05);
135     threshold_slider.set_value_pos(Gtk.PositionType.LEFT);
136     stdout.printf("dynamics setting threshold\n");
137     stdout.flush();
138     this.set_threshold(settings.threshold);
139     threshold_slider.value_changed.connect((s) => {threshold_updated(s.get_value());});
140     threshold_bar.pack_start(threshold_label, false, false, 2);
141     threshold_bar.pack_start(threshold_slider, true, true, 2);
142     
143     control_area.pack_start(threshold_bar, true, true, 2);
144     
145     this.show_all();
146   }
147   
148   public string get_mode() {
149     return mode_selector.get_current_text();
150   }
151   public void set_mode(string val) {
152     switch (val) {
153       case "compressor":
154         mode_selector.set_active(0, 0);
155         break;
156       case "expander":
157         mode_selector.set_active(0, 1);
158         break;
159       default:
160         mode_selector.set_active(0, 0);
161         break;
162     }
163   }
164   
165   public string get_characteristics() {
166     return characteristics_selector.get_current_text();
167   }
168   public void set_characteristics(string val) {
169     switch (val) {
170       case "soft-knee":
171         characteristics_selector.set_active(0, 0);
172         break;
173       case "hard-knee":
174         characteristics_selector.set_active(0, 1);
175         break;
176       default:
177         characteristics_selector.set_active(0, 0);
178         break;
179     }
180   }
181   
182   public double get_ratio() {
183     return ratio_slider.get_value();
184   }
185   public void set_ratio(double val) {
186     ratio_slider.set_value(val);
187   }
188   
189   public double get_threshold() {
190     return threshold_slider.get_value();
191   }
192   public void set_threshold(double val) {
193     threshold_slider.set_value(val);
194   }
195
196 }
197
198 }