Merge lp:~victored/beat-box/equalizer-fixes into lp:beat-box
- equalizer-fixes
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 375 | ||||
Proposed branch: | lp:~victored/beat-box/equalizer-fixes | ||||
Merge into: | lp:beat-box | ||||
Diff against target: |
814 lines (+248/-150) 6 files modified
schemas/org.gnome.beatbox.gschema.xml (+4/-4) src/Dialogs/EqualizerWindow.vala (+158/-75) src/Dialogs/PresetNameWindow.vala (+15/-6) src/LibraryManager.vala (+15/-12) src/Settings.vala (+5/-17) src/Widgets/PresetList.vala (+51/-36) |
||||
To merge this branch: | bzr merge lp:~victored/beat-box/equalizer-fixes | ||||
Related bugs: |
|
||||
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Ringwelski | Approve | ||
Review via email: mp+84419@code.launchpad.net |
Commit message
Description of the change
Some extra improvements to the equalizer:
* Make the switch insensitive while adding a new preset
* Validate the text in new-preset-entry and NewPresetWindow
* Don't let new-preset-entry lose keyboard focus
* NewPresetWindow is now transient for EqualizerWindow instead of LibraryWindow.
* Set the last preset in the ComboBox if NewPresetWindow is closed not using 'DONE'.
* Settings: make getSelectedPreset() and setSelectedPreset() handle only the name of the current preset.
* Corrected values for "Full Treble". This was causing an improper behavior.
* Make the new-preset-entry match the size of the ComboBox
* Code cleanup
* Error validation (avoid some potential segfaults)
* Apply the automatic preset correctly
* Ensure the proper saving of custom presets
- They're saved and applied even if the window is closed during the process.
* Minor code fixes
* Remove the close button from the equalizer-window (as long as the window manager supports it). Currently, this works only under GNOME-Shell and Unity-2D.
The code is mature enough for merging into trunk.
Sergey "Shnatsel" Davidoff (shnatsel) wrote : | # |
Victor Martinez (victored) wrote : | # |
Thanks Sergey!
Scott Ringwelski (sgringwe) wrote : | # |
I am merging the changes, however:
1. In lm.change_
2. ... that's it!
So, what i'm going to do is merge and then I will add a simple check for that myself, since it's easier that way.
Great work again!
Victor Martinez (victored) wrote : | # |
My bad! Thanks a lot for fixing that error!
BTW, the on_close() function on EqualizerWindows is potentially dangerous. Maybe some sleep time should be added whenever the scales are in transition in order to avoid the failed-assertion messages. There are no other errors [I'm aware of] aside from that.
Preview Diff
1 | === modified file 'schemas/org.gnome.beatbox.gschema.xml' | |||
2 | --- schemas/org.gnome.beatbox.gschema.xml 2011-11-22 03:08:33 +0000 | |||
3 | +++ schemas/org.gnome.beatbox.gschema.xml 2011-12-05 01:21:23 +0000 | |||
4 | @@ -107,18 +107,18 @@ | |||
5 | 107 | </key> | 107 | </key> |
6 | 108 | <key type="s" name="selected-preset"> | 108 | <key type="s" name="selected-preset"> |
7 | 109 | <default>''</default> | 109 | <default>''</default> |
9 | 110 | <summary>Contains information regarding the user-selected preset</summary> | 110 | <summary>Contains the name of the user-selected preset</summary> |
10 | 111 | <description>Contains information regarding the user-selected preset</description> | 111 | <description>Contains information regarding the user-selected preset</description> |
11 | 112 | </key> | 112 | </key> |
12 | 113 | <key type="s" name="custom-presets"> | 113 | <key type="s" name="custom-presets"> |
13 | 114 | <default>''</default> | 114 | <default>''</default> |
14 | 115 | <summary>Custom Equalizer Presets</summary> | 115 | <summary>Custom Equalizer Presets</summary> |
16 | 116 | <description>Contains the list of presets added by the user</description> | 116 | <description>Contains the list of presets added by the user. Gain values are between -80 and 80</description> |
17 | 117 | </key> | 117 | </key> |
18 | 118 | <key type="s" name="default-presets"> | 118 | <key type="s" name="default-presets"> |
20 | 119 | <default>'Flat,0,0,0,0,0,0,0,0,0,0/Classical,0,0,0,0,0,0,-40,-40,-40,-50/Club,0,0,20,30,30,30,20,0,0,0/Dance,50,35,10,0,0,-30,-40,-40,0,0/Full Bass,70,70,70,40,20,-45,-50,-55,-55,-55/Full Treble,-50,-50,-50,-25,15,55,80,80,80,85/Full Bass + Treble,35,30,0,-40,-25,10,45,55,60,60/Laptop/Headphones,25,50,25,-20,0,-30,-40,-40,0,0/Large Hall,50,50,30,30,0,-25,-25,-25,0,0/Live,-25,0,20,25,30,30,20,15,15,10/Party,35,35,0,0,0,0,0,0,35,35/Pop,-10,25,35,40,25,-5,-15,-15,-10,-10/Reggae,0,0,-5,-30,0,-35,-35,0,0,0/Rock,40,25,-30,-40,-20,20,45,55,55,55/Soft,25,10,-5,-15,-5,20,45,50,55,60/Ska,-15,-25,-25,-5,20,30,45,50,55,50/Soft Rock,20,20,10,-5,-25,-30,-20,-5,15,45/Techno,40,30,0,-30,-25,0,40,50,50,45/'</default> | 119 | <default>'Flat,0,0,0,0,0,0,0,0,0,0/Classical,0,0,0,0,0,0,-40,-40,-40,-50/Club,0,0,20,30,30,30,20,0,0,0/Dance,50,35,10,0,0,-30,-40,-40,0,0/Full Bass,70,70,70,40,20,-45,-50,-55,-55,-55/Full Treble,-50,-50,-50,-25,15,55,80,80,80,80/Full Bass + Treble,35,30,0,-40,-25,10,45,55,60,60/Laptop/Headphones,25,50,25,-20,0,-30,-40,-40,0,0/Large Hall,50,50,30,30,0,-25,-25,-25,0,0/Live,-25,0,20,25,30,30,20,15,15,10/Party,35,35,0,0,0,0,0,0,35,35/Pop,-10,25,35,40,25,-5,-15,-15,-10,-10/Reggae,0,0,-5,-30,0,-35,-35,0,0,0/Rock,40,25,-30,-40,-20,20,45,55,55,55/Soft,25,10,-5,-15,-5,20,45,50,55,60/Ska,-15,-25,-25,-5,20,30,45,50,55,50/Soft Rock,20,20,10,-5,-25,-30,-20,-5,15,45/Techno,40,30,0,-30,-25,0,40,50,50,45/'</default> |
21 | 120 | <summary>Default Equalizer Presets</summary> | 120 | <summary>Default Equalizer Presets</summary> |
23 | 121 | <description>Contains the list of default presets</description> | 121 | <description>Contains the list of default presets. Gain values are between -80 and 80</description> |
24 | 122 | </key> | 122 | </key> |
25 | 123 | <key type="b" name="auto-switch-preset"> | 123 | <key type="b" name="auto-switch-preset"> |
26 | 124 | <default>true</default> | 124 | <default>true</default> |
27 | 125 | 125 | ||
28 | === modified file 'src/Dialogs/EqualizerWindow.vala' | |||
29 | --- src/Dialogs/EqualizerWindow.vala 2011-12-01 04:39:30 +0000 | |||
30 | +++ src/Dialogs/EqualizerWindow.vala 2011-12-05 01:21:23 +0000 | |||
31 | @@ -1,7 +1,7 @@ | |||
32 | 1 | /*- | 1 | /*- |
33 | 2 | * Copyright (c) 2011 Scott Ringwelski <sgringwe@mtu.edu> | 2 | * Copyright (c) 2011 Scott Ringwelski <sgringwe@mtu.edu> |
34 | 3 | * | 3 | * |
36 | 4 | * Originally Written by Scott Ringwelski and Victor Eduardo for BeatBox Music Player | 4 | * Originally Written by Scott Ringwelski and Victor Eduardo for |
37 | 5 | * BeatBox Music Player: http://www.launchpad.net/beat-box | 5 | * BeatBox Music Player: http://www.launchpad.net/beat-box |
38 | 6 | * | 6 | * |
39 | 7 | * This library is free software; you can redistribute it and/or | 7 | * This library is free software; you can redistribute it and/or |
40 | @@ -37,8 +37,7 @@ | |||
41 | 37 | bool initialized; | 37 | bool initialized; |
42 | 38 | bool automatic_chosen; | 38 | bool automatic_chosen; |
43 | 39 | bool adding_preset; | 39 | bool adding_preset; |
46 | 40 | 40 | bool closing; | |
45 | 41 | private string new_preset_name; | ||
47 | 42 | 41 | ||
48 | 43 | List<VScale> scale_list; | 42 | List<VScale> scale_list; |
49 | 44 | List<Label> label_list; | 43 | List<Label> label_list; |
50 | @@ -46,6 +45,8 @@ | |||
51 | 46 | bool in_transition; | 45 | bool in_transition; |
52 | 47 | Gee.ArrayList<int> target_levels; | 46 | Gee.ArrayList<int> target_levels; |
53 | 48 | 47 | ||
54 | 48 | private string new_preset_name; | ||
55 | 49 | |||
56 | 49 | public EqualizerWindow (LibraryManager lm, LibraryWindow lw) { | 50 | public EqualizerWindow (LibraryManager lm, LibraryWindow lw) { |
57 | 50 | 51 | ||
58 | 51 | this.lm = lm; | 52 | this.lm = lm; |
59 | @@ -53,9 +54,10 @@ | |||
60 | 53 | 54 | ||
61 | 54 | scale_list = new List<VScale>(); | 55 | scale_list = new List<VScale>(); |
62 | 55 | label_list = new List<Label>(); | 56 | label_list = new List<Label>(); |
63 | 57 | target_levels = new Gee.ArrayList<int>(); | ||
64 | 58 | closing = false; | ||
65 | 56 | adding_preset = false; | 59 | adding_preset = false; |
66 | 57 | initialized = false; | 60 | initialized = false; |
67 | 58 | target_levels = new Gee.ArrayList<int>(); | ||
68 | 59 | automatic_chosen = false; | 61 | automatic_chosen = false; |
69 | 60 | 62 | ||
70 | 61 | build_ui(); | 63 | build_ui(); |
71 | @@ -70,12 +72,10 @@ | |||
72 | 70 | eq_switch.set_active(lm.settings.getEqualizerEnabled()); | 72 | eq_switch.set_active(lm.settings.getEqualizerEnabled()); |
73 | 71 | on_eq_switch_toggled(); | 73 | on_eq_switch_toggled(); |
74 | 72 | 74 | ||
75 | 73 | if (lm.settings.getAutoSwitchPreset()) { | ||
76 | 74 | preset_combo.selectAutomaticPreset(); | ||
77 | 75 | on_automatic_chosen(); | ||
78 | 76 | } | ||
79 | 77 | |||
80 | 78 | initialized = true; | 75 | initialized = true; |
81 | 76 | |||
82 | 77 | if (lm.settings.getAutoSwitchPreset()) | ||
83 | 78 | preset_combo.selectAutomaticPreset(); | ||
84 | 79 | } | 79 | } |
85 | 80 | 80 | ||
86 | 81 | void build_ui () { | 81 | void build_ui () { |
87 | @@ -85,17 +85,17 @@ | |||
88 | 85 | window_position = WindowPosition.CENTER; | 85 | window_position = WindowPosition.CENTER; |
89 | 86 | type_hint = Gdk.WindowTypeHint.DIALOG; | 86 | type_hint = Gdk.WindowTypeHint.DIALOG; |
90 | 87 | set_transient_for(lw); | 87 | set_transient_for(lw); |
91 | 88 | |||
92 | 89 | set_size_request(440, 224); | 88 | set_size_request(440, 224); |
93 | 90 | resizable = false; | 89 | resizable = false; |
94 | 90 | set_deletable(false); | ||
95 | 91 | 91 | ||
96 | 92 | set_icon(render_icon(Gtk.Stock.PREFERENCES, IconSize.DIALOG, null)); | 92 | set_icon(render_icon(Gtk.Stock.PREFERENCES, IconSize.DIALOG, null)); |
97 | 93 | 93 | ||
98 | 94 | var outer_box = new HBox(false, 10); | 94 | var outer_box = new HBox(false, 10); |
99 | 95 | var inner_box = new VBox(false, 0); | 95 | var inner_box = new VBox(false, 0); |
100 | 96 | var scales = new HBox(false, 0); | 96 | var scales = new HBox(false, 0); |
101 | 97 | bottom_toolbar = new Toolbar(); | ||
102 | 98 | 97 | ||
103 | 98 | bottom_toolbar = new Toolbar(); | ||
104 | 99 | eq_switch = new Switch(); | 99 | eq_switch = new Switch(); |
105 | 100 | preset_combo = new PresetList(lm, lw); | 100 | preset_combo = new PresetList(lm, lw); |
106 | 101 | 101 | ||
107 | @@ -132,7 +132,7 @@ | |||
108 | 132 | 132 | ||
109 | 133 | } | 133 | } |
110 | 134 | 134 | ||
112 | 135 | preset_combo.set_size_request(150, -1); | 135 | preset_combo.set_size_request(170, -1); |
113 | 136 | 136 | ||
114 | 137 | var eq_switch_item = new ToolItem(); | 137 | var eq_switch_item = new ToolItem(); |
115 | 138 | eq_switch_item.add(eq_switch); | 138 | eq_switch_item.add(eq_switch); |
116 | @@ -141,7 +141,7 @@ | |||
117 | 141 | side_list.add(preset_combo); | 141 | side_list.add(preset_combo); |
118 | 142 | 142 | ||
119 | 143 | new_preset_entry = new Entry(); | 143 | new_preset_entry = new Entry(); |
121 | 144 | new_preset_entry.set_size_request(150, -1); | 144 | new_preset_entry.set_size_request(170, -1); |
122 | 145 | new_preset_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.Stock.OK); | 145 | new_preset_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.Stock.OK); |
123 | 146 | new_preset_entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, "Save this preset"); | 146 | new_preset_entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, "Save this preset"); |
124 | 147 | 147 | ||
125 | @@ -150,10 +150,11 @@ | |||
126 | 150 | 150 | ||
127 | 151 | var space_item = new ToolItem(); | 151 | var space_item = new ToolItem(); |
128 | 152 | space_item.set_expand(true); | 152 | space_item.set_expand(true); |
130 | 153 | 153 | ||
131 | 154 | var close_button = new Button.with_label("Close"); | 154 | var close_button = new Button.with_label("Close"); |
132 | 155 | var close_button_item = new ToolItem(); | 155 | var close_button_item = new ToolItem(); |
134 | 156 | close_button_item.set_expand(true); | 156 | close_button.set_size_request(120, -1); |
135 | 157 | close_button_item.set_expand(false); | ||
136 | 157 | close_button_item.add(close_button); | 158 | close_button_item.add(close_button); |
137 | 158 | 159 | ||
138 | 159 | bottom_toolbar.insert(eq_switch_item, 0); | 160 | bottom_toolbar.insert(eq_switch_item, 0); |
139 | @@ -172,18 +173,25 @@ | |||
140 | 172 | 173 | ||
141 | 173 | eq_switch.notify["active"].connect(on_eq_switch_toggled); | 174 | eq_switch.notify["active"].connect(on_eq_switch_toggled); |
142 | 174 | preset_combo.automatic_preset_chosen.connect(on_automatic_chosen); | 175 | preset_combo.automatic_preset_chosen.connect(on_automatic_chosen); |
146 | 175 | preset_combo.add_preset_chosen.connect(addPresetClicked); | 176 | preset_combo.add_preset_chosen.connect(add_preset_clicked); |
147 | 176 | preset_combo.delete_preset_chosen.connect(removePresetClicked); | 177 | preset_combo.delete_preset_chosen.connect(remove_preset_clicked); |
148 | 177 | preset_combo.preset_selected.connect(presetSelected); | 178 | preset_combo.preset_selected.connect (preset_selected); |
149 | 178 | new_preset_entry.activate.connect (add_new_preset); | 179 | new_preset_entry.activate.connect (add_new_preset); |
150 | 179 | new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed); | 180 | new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed); |
151 | 181 | new_preset_entry.focus_out_event.connect (on_entry_focus_out); | ||
152 | 180 | 182 | ||
155 | 181 | close_button.clicked.connect(on_close); | 183 | close_button.clicked.connect(on_close_button_clicked); |
156 | 182 | destroy.connect(on_close); | 184 | destroy.connect(on_quit); |
157 | 183 | 185 | ||
158 | 184 | show_all(); | 186 | show_all(); |
159 | 185 | } | 187 | } |
160 | 186 | 188 | ||
161 | 189 | bool on_entry_focus_out () { | ||
162 | 190 | if(!closing) | ||
163 | 191 | new_preset_entry.grab_focus(); | ||
164 | 192 | return true; | ||
165 | 193 | } | ||
166 | 194 | |||
167 | 187 | static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { | 195 | static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { |
168 | 188 | 196 | ||
169 | 189 | var alignment = new Gtk.Alignment(0.0f, 0.0f, 1.0f, 1.0f); | 197 | var alignment = new Gtk.Alignment(0.0f, 0.0f, 1.0f, 1.0f); |
170 | @@ -246,11 +254,12 @@ | |||
171 | 246 | foreach (EqualizerPreset preset in custom_presets) { | 254 | foreach (EqualizerPreset preset in custom_presets) { |
172 | 247 | preset_combo.addPreset(preset); | 255 | preset_combo.addPreset(preset); |
173 | 248 | } | 256 | } |
174 | 257 | |||
175 | 258 | preset_combo.default_presets_changed = false; | ||
176 | 249 | } | 259 | } |
177 | 250 | 260 | ||
179 | 251 | void presetSelected(EqualizerPreset p) { | 261 | void preset_selected (EqualizerPreset p) { |
180 | 252 | automatic_chosen = false; | 262 | automatic_chosen = false; |
181 | 253 | |||
182 | 254 | set_sliders_sensitivity (true); | 263 | set_sliders_sensitivity (true); |
183 | 255 | target_levels.clear(); | 264 | target_levels.clear(); |
184 | 256 | 265 | ||
185 | @@ -258,17 +267,21 @@ | |||
186 | 258 | target_levels.add(i); | 267 | target_levels.add(i); |
187 | 259 | } | 268 | } |
188 | 260 | 269 | ||
190 | 261 | if (!initialized) { | 270 | set_target_levels (); |
191 | 271 | |||
192 | 272 | if (!in_transition && !closing) { | ||
193 | 273 | in_transition = true; | ||
194 | 274 | Timeout.add(20, transition_scales); | ||
195 | 275 | } | ||
196 | 276 | } | ||
197 | 277 | |||
198 | 278 | void set_target_levels () { | ||
199 | 279 | if (!initialized || closing) { | ||
200 | 262 | for (int index = 0; index < 10; ++index) { | 280 | for (int index = 0; index < 10; ++index) { |
201 | 263 | scale_list.nth_data(index).set_value(target_levels.get(index)); | 281 | scale_list.nth_data(index).set_value(target_levels.get(index)); |
202 | 264 | } | 282 | } |
203 | 265 | return; | 283 | return; |
204 | 266 | } | 284 | } |
205 | 267 | |||
206 | 268 | if (!in_transition) { | ||
207 | 269 | in_transition = true; | ||
208 | 270 | Timeout.add(20, transition_scales); | ||
209 | 271 | } | ||
210 | 272 | } | 285 | } |
211 | 273 | 286 | ||
212 | 274 | bool transition_scales () { | 287 | bool transition_scales () { |
213 | @@ -280,7 +293,7 @@ | |||
214 | 280 | double targetLvl = target_levels.get(index); | 293 | double targetLvl = target_levels.get(index); |
215 | 281 | double difference = targetLvl - currLvl; | 294 | double difference = targetLvl - currLvl; |
216 | 282 | 295 | ||
218 | 283 | if (Math.fabs(difference) <= 1) | 296 | if (closing || Math.fabs(difference) <= 1) |
219 | 284 | scale_list.nth_data(index).set_value(targetLvl); | 297 | scale_list.nth_data(index).set_value(targetLvl); |
220 | 285 | else { | 298 | else { |
221 | 286 | scale_list.nth_data(index).set_value(scale_list.nth_data(index).get_value() + (difference / 8.0)); | 299 | scale_list.nth_data(index).set_value(scale_list.nth_data(index).get_value() + (difference / 8.0)); |
222 | @@ -311,39 +324,19 @@ | |||
223 | 311 | 324 | ||
224 | 312 | adding_preset = true; | 325 | adding_preset = true; |
225 | 313 | 326 | ||
226 | 314 | bool preset_already_exists = false; | ||
227 | 315 | var current_presets = preset_combo.getPresets(); | ||
228 | 316 | |||
229 | 317 | bottom_toolbar.remove(side_list); | 327 | bottom_toolbar.remove(side_list); |
230 | 318 | bottom_toolbar.insert(new_preset_field, 1); | 328 | bottom_toolbar.insert(new_preset_field, 1); |
231 | 319 | 329 | ||
252 | 320 | string current_preset_name = preset_combo.getSelectedPreset().name; | 330 | new_preset_name = create_new_preset_name(true); |
233 | 321 | string new_preset_name = " "; | ||
234 | 322 | int i = 1; | ||
235 | 323 | |||
236 | 324 | do | ||
237 | 325 | { | ||
238 | 326 | new_preset_name = current_preset_name + " (Custom" + ((preset_already_exists)? " " + i.to_string() : "") + ")"; | ||
239 | 327 | |||
240 | 328 | preset_already_exists = false; | ||
241 | 329 | |||
242 | 330 | foreach(EqualizerPreset preset in current_presets) { | ||
243 | 331 | if(new_preset_name == preset.name) { | ||
244 | 332 | preset_already_exists = true; | ||
245 | 333 | break; | ||
246 | 334 | } | ||
247 | 335 | } | ||
248 | 336 | |||
249 | 337 | i++; | ||
250 | 338 | |||
251 | 339 | } while (preset_already_exists); | ||
253 | 340 | 331 | ||
254 | 341 | new_preset_entry.set_text(new_preset_name); | 332 | new_preset_entry.set_text(new_preset_name); |
255 | 333 | eq_switch.sensitive = false; | ||
256 | 342 | bottom_toolbar.show_all(); | 334 | bottom_toolbar.show_all(); |
257 | 343 | new_preset_entry.grab_focus(); | 335 | new_preset_entry.grab_focus(); |
258 | 344 | } | 336 | } |
259 | 345 | 337 | ||
260 | 346 | void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) { | 338 | void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) { |
261 | 339 | |||
262 | 347 | if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset) | 340 | if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset) |
263 | 348 | return; | 341 | return; |
264 | 349 | 342 | ||
265 | @@ -351,12 +344,13 @@ | |||
266 | 351 | } | 344 | } |
267 | 352 | 345 | ||
268 | 353 | void add_new_preset() { | 346 | void add_new_preset() { |
269 | 347 | |||
270 | 354 | if(!adding_preset) | 348 | if(!adding_preset) |
271 | 355 | return; | 349 | return; |
272 | 356 | 350 | ||
273 | 357 | var new_name = new_preset_entry.get_text(); | 351 | var new_name = new_preset_entry.get_text(); |
274 | 358 | 352 | ||
276 | 359 | if(new_name != null) | 353 | if(verify_preset_name(new_name)) |
277 | 360 | new_preset_name = new_name; | 354 | new_preset_name = new_name; |
278 | 361 | 355 | ||
279 | 362 | int i = 0; | 356 | int i = 0; |
280 | @@ -373,31 +367,118 @@ | |||
281 | 373 | bottom_toolbar.remove(new_preset_field); | 367 | bottom_toolbar.remove(new_preset_field); |
282 | 374 | bottom_toolbar.insert(side_list, 1); | 368 | bottom_toolbar.insert(side_list, 1); |
283 | 375 | bottom_toolbar.show_all(); | 369 | bottom_toolbar.show_all(); |
285 | 376 | 370 | eq_switch.sensitive = true; | |
286 | 377 | adding_preset = false; | 371 | adding_preset = false; |
287 | 378 | } | 372 | } |
288 | 379 | 373 | ||
295 | 380 | void addPresetClicked () { | 374 | string create_new_preset_name (bool from_current) { |
296 | 381 | PresetNameWindow pnw = new PresetNameWindow(lw, new EqualizerPreset.basic("Custom Preset")); | 375 | |
297 | 382 | pnw.preset_saved.connect(presetNameWindowSaved); | 376 | int i = 0; |
298 | 383 | } | 377 | bool is_valid = false; |
299 | 384 | 378 | ||
300 | 385 | void presetNameWindowSaved (EqualizerPreset p) { | 379 | string current_preset_name = (from_current)? preset_combo.getSelectedPreset().name : ""; |
301 | 380 | string preset_name = "Custom Preset"; | ||
302 | 381 | |||
303 | 382 | do | ||
304 | 383 | { | ||
305 | 384 | preset_name = (from_current)? current_preset_name + " (" : ""; | ||
306 | 385 | preset_name += "Custom" + ((from_current)? "" : " Preset"); | ||
307 | 386 | preset_name += ((!is_valid && i > 0)? " " + i.to_string() : ""); | ||
308 | 387 | preset_name += (from_current)? ")" : ""; | ||
309 | 388 | |||
310 | 389 | i++; | ||
311 | 390 | |||
312 | 391 | is_valid = verify_preset_name(preset_name); | ||
313 | 392 | } while (!is_valid); | ||
314 | 393 | |||
315 | 394 | return preset_name; | ||
316 | 395 | } | ||
317 | 396 | |||
318 | 397 | public bool verify_preset_name(string name) { | ||
319 | 398 | |||
320 | 399 | /* This function verifies the name of a new preset. | ||
321 | 400 | It will return 'true' whenever: | ||
322 | 401 | - The name is not null | ||
323 | 402 | - The name doesn't consist [enterely] of white space. | ||
324 | 403 | - The name is not already in the list. | ||
325 | 404 | */ | ||
326 | 405 | |||
327 | 406 | int white_space = 0; | ||
328 | 407 | int str_length = name.length; | ||
329 | 408 | bool preset_already_exists = false; | ||
330 | 409 | |||
331 | 410 | if(str_length < 1) | ||
332 | 411 | return false; | ||
333 | 412 | |||
334 | 413 | for(int i = 0; i < str_length; ++i) { | ||
335 | 414 | if(name[i] == ' ' || name[i] == '\t') | ||
336 | 415 | white_space++; | ||
337 | 416 | } | ||
338 | 417 | |||
339 | 418 | if(white_space == str_length) | ||
340 | 419 | return false; | ||
341 | 420 | |||
342 | 421 | var current_presets = preset_combo.getPresets(); | ||
343 | 422 | |||
344 | 423 | preset_already_exists = false; | ||
345 | 424 | |||
346 | 425 | foreach(EqualizerPreset preset in current_presets) { | ||
347 | 426 | if(name == preset.name) { | ||
348 | 427 | preset_already_exists = true; | ||
349 | 428 | break; | ||
350 | 429 | } | ||
351 | 430 | } | ||
352 | 431 | |||
353 | 432 | return !preset_already_exists; | ||
354 | 433 | } | ||
355 | 434 | |||
356 | 435 | void add_preset_clicked () { | ||
357 | 436 | string name = create_new_preset_name(false); | ||
358 | 437 | PresetNameWindow pnw = new PresetNameWindow(this, new EqualizerPreset.basic(name)); | ||
359 | 438 | pnw.preset_saved.connect(preset_name_window_saved); | ||
360 | 439 | pnw.action_canceled.connect(select_last_used_preset); | ||
361 | 440 | } | ||
362 | 441 | |||
363 | 442 | void select_last_used_preset () { | ||
364 | 443 | var last_preset = preset_combo.last_selected_preset; | ||
365 | 444 | |||
366 | 445 | if(!automatic_chosen && last_preset != null) | ||
367 | 446 | preset_combo.selectPreset(last_preset.name); | ||
368 | 447 | else | ||
369 | 448 | preset_combo.selectAutomaticPreset(); | ||
370 | 449 | } | ||
371 | 450 | |||
372 | 451 | void preset_name_window_saved (EqualizerPreset p) { | ||
373 | 386 | preset_combo.addPreset(p); | 452 | preset_combo.addPreset(p); |
374 | 387 | } | 453 | } |
375 | 388 | 454 | ||
379 | 389 | void removePresetClicked () { | 455 | void remove_preset_clicked () { |
380 | 390 | 456 | if(!automatic_chosen) | |
381 | 391 | preset_combo.removeCurrentPreset(); | 457 | preset_combo.removeCurrentPreset(); |
382 | 392 | } | 458 | } |
383 | 393 | 459 | ||
385 | 394 | void on_close () { | 460 | void on_close_button_clicked () { |
386 | 461 | closing = true; | ||
387 | 462 | |||
388 | 463 | if(adding_preset) | ||
389 | 464 | add_new_preset(); | ||
390 | 465 | |||
391 | 395 | if(!in_transition) | 466 | if(!in_transition) |
392 | 396 | close_equalizer(); | 467 | close_equalizer(); |
393 | 397 | else | 468 | else |
394 | 398 | Timeout.add(20, close_equalizer); | 469 | Timeout.add(20, close_equalizer); |
395 | 399 | } | 470 | } |
397 | 400 | 471 | ||
398 | 472 | void on_quit () { | ||
399 | 473 | |||
400 | 474 | if(!in_transition) | ||
401 | 475 | on_close_button_clicked(); | ||
402 | 476 | else { | ||
403 | 477 | set_target_levels (); | ||
404 | 478 | close_equalizer (); | ||
405 | 479 | } | ||
406 | 480 | } | ||
407 | 481 | |||
408 | 401 | bool close_equalizer () { | 482 | bool close_equalizer () { |
409 | 402 | 483 | ||
410 | 403 | if(in_transition) | 484 | if(in_transition) |
411 | @@ -405,27 +486,29 @@ | |||
412 | 405 | 486 | ||
413 | 406 | lm.settings.setEqualizerEnabled(eq_switch.get_active()); | 487 | lm.settings.setEqualizerEnabled(eq_switch.get_active()); |
414 | 407 | 488 | ||
416 | 408 | if(preset_combo.getSelectedPreset() != null) { | 489 | if(preset_combo.getSelectedPreset() != null) |
417 | 409 | lm.settings.setSelectedPreset(preset_combo.getSelectedPreset()); | 490 | lm.settings.setSelectedPreset(preset_combo.getSelectedPreset()); |
418 | 410 | } | ||
419 | 411 | 491 | ||
420 | 412 | var defaultPresets = new Gee.LinkedList<EqualizerPreset>(); | 492 | var defaultPresets = new Gee.LinkedList<EqualizerPreset>(); |
421 | 413 | var customPresets = new Gee.LinkedList<EqualizerPreset>(); | 493 | var customPresets = new Gee.LinkedList<EqualizerPreset>(); |
422 | 414 | 494 | ||
426 | 415 | foreach(EqualizerPreset preset in preset_combo.getPresets()) { | 495 | foreach (EqualizerPreset preset in preset_combo.getPresets()) { |
427 | 416 | if(preset.is_default == true) | 496 | if (preset.is_default == true) |
428 | 417 | defaultPresets.add(preset); | 497 | defaultPresets.add (preset); |
429 | 418 | else | 498 | else |
431 | 419 | customPresets.add(preset); | 499 | customPresets.add (preset); |
432 | 420 | } | 500 | } |
433 | 421 | 501 | ||
438 | 422 | lm.settings.setPresets(defaultPresets, null); | 502 | if(preset_combo.default_presets_changed) |
439 | 423 | lm.settings.setPresets(customPresets, "custom-presets"); | 503 | lm.settings.setPresets (defaultPresets, null); |
440 | 424 | 504 | ||
441 | 425 | lm.settings.setAutoSwitchPreset(automatic_chosen); | 505 | lm.settings.setPresets (customPresets, lm.settings.CUSTOM_PRESETS); |
442 | 506 | |||
443 | 507 | lm.settings.setAutoSwitchPreset (automatic_chosen); | ||
444 | 426 | 508 | ||
445 | 427 | destroy(); | 509 | destroy(); |
446 | 428 | 510 | ||
447 | 429 | return false; | 511 | return false; |
448 | 430 | } | 512 | } |
449 | 431 | } | 513 | } |
450 | 514 | |||
451 | 432 | 515 | ||
452 | === modified file 'src/Dialogs/PresetNameWindow.vala' | |||
453 | --- src/Dialogs/PresetNameWindow.vala 2011-11-30 22:17:03 +0000 | |||
454 | +++ src/Dialogs/PresetNameWindow.vala 2011-12-05 01:21:23 +0000 | |||
455 | @@ -20,14 +20,12 @@ | |||
456 | 20 | * Boston, MA 02111-1307, USA. | 20 | * Boston, MA 02111-1307, USA. |
457 | 21 | */ | 21 | */ |
458 | 22 | 22 | ||
459 | 23 | /* Merely a place holder for multiple pieces of information regarding | ||
460 | 24 | * the current song playing. Mostly here because of dependence. */ | ||
461 | 25 | |||
462 | 26 | using Gtk; | 23 | using Gtk; |
463 | 27 | 24 | ||
464 | 28 | public class BeatBox.PresetNameWindow : Window { | 25 | public class BeatBox.PresetNameWindow : Window { |
465 | 29 | public EqualizerPreset _original; | 26 | public EqualizerPreset _original; |
466 | 30 | 27 | ||
467 | 28 | EqualizerWindow ew; | ||
468 | 31 | VBox content; | 29 | VBox content; |
469 | 32 | HBox padding; | 30 | HBox padding; |
470 | 33 | 31 | ||
471 | @@ -35,14 +33,17 @@ | |||
472 | 35 | public Button _save; | 33 | public Button _save; |
473 | 36 | 34 | ||
474 | 37 | public signal void preset_saved(EqualizerPreset p); | 35 | public signal void preset_saved(EqualizerPreset p); |
475 | 36 | public signal void action_canceled(); | ||
476 | 38 | 37 | ||
478 | 39 | public PresetNameWindow(LibraryWindow lw, EqualizerPreset original) { | 38 | public PresetNameWindow(EqualizerWindow ew, EqualizerPreset original) { |
479 | 40 | title = ""; | 39 | title = ""; |
480 | 41 | 40 | ||
481 | 41 | this.ew = ew; | ||
482 | 42 | |||
483 | 42 | this.window_position = WindowPosition.CENTER; | 43 | this.window_position = WindowPosition.CENTER; |
484 | 43 | this.type_hint = Gdk.WindowTypeHint.DIALOG; | 44 | this.type_hint = Gdk.WindowTypeHint.DIALOG; |
485 | 44 | this.set_modal(true); | 45 | this.set_modal(true); |
487 | 45 | this.set_transient_for(lw); | 46 | this.set_transient_for(ew); |
488 | 46 | this.destroy_with_parent = true; | 47 | this.destroy_with_parent = true; |
489 | 47 | resizable = false; | 48 | resizable = false; |
490 | 48 | set_size_request(200, -1); | 49 | set_size_request(200, -1); |
491 | @@ -80,6 +81,7 @@ | |||
492 | 80 | 81 | ||
493 | 81 | _save.clicked.connect(saveClicked); | 82 | _save.clicked.connect(saveClicked); |
494 | 82 | _name.activate.connect(nameActivate); | 83 | _name.activate.connect(nameActivate); |
495 | 84 | this.destroy.connect(on_action_canceled); | ||
496 | 83 | } | 85 | } |
497 | 84 | 86 | ||
498 | 85 | public static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { | 87 | public static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { |
499 | @@ -94,7 +96,9 @@ | |||
500 | 94 | } | 96 | } |
501 | 95 | 97 | ||
502 | 96 | public virtual void saveClicked() { | 98 | public virtual void saveClicked() { |
504 | 97 | _original.name = _name.text; | 99 | if(ew.verify_preset_name(_name.text)) |
505 | 100 | _original.name = _name.text; | ||
506 | 101 | |||
507 | 98 | preset_saved(_original); | 102 | preset_saved(_original); |
508 | 99 | 103 | ||
509 | 100 | this.destroy(); | 104 | this.destroy(); |
510 | @@ -103,4 +107,9 @@ | |||
511 | 103 | public virtual void nameActivate() { | 107 | public virtual void nameActivate() { |
512 | 104 | saveClicked(); | 108 | saveClicked(); |
513 | 105 | } | 109 | } |
514 | 110 | |||
515 | 111 | public virtual void on_action_canceled() { | ||
516 | 112 | action_canceled(); | ||
517 | 113 | this.destroy(); | ||
518 | 114 | } | ||
519 | 106 | } | 115 | } |
520 | 107 | 116 | ||
521 | === modified file 'src/LibraryManager.vala' | |||
522 | --- src/LibraryManager.vala 2011-12-03 21:19:37 +0000 | |||
523 | +++ src/LibraryManager.vala 2011-12-05 01:21:23 +0000 | |||
524 | @@ -222,11 +222,7 @@ | |||
525 | 222 | 222 | ||
526 | 223 | // set the equalizer | 223 | // set the equalizer |
527 | 224 | if(settings.getEqualizerEnabled() && !settings.getAutoSwitchPreset()) { | 224 | if(settings.getEqualizerEnabled() && !settings.getAutoSwitchPreset()) { |
533 | 225 | EqualizerPreset p = settings.getSelectedPreset(); | 225 | set_selected_equalizer_preset (); |
529 | 226 | if(p != null) { | ||
530 | 227 | for(int i = 0; i < 10; ++i) | ||
531 | 228 | player.setEqualizerGain(i, p.getGain(i)); | ||
532 | 229 | } | ||
534 | 230 | } | 226 | } |
535 | 231 | 227 | ||
536 | 232 | dm = new DeviceManager(this); | 228 | dm = new DeviceManager(this); |
537 | @@ -1291,13 +1287,7 @@ | |||
538 | 1291 | } | 1287 | } |
539 | 1292 | 1288 | ||
540 | 1293 | if(!matched_genre) { | 1289 | if(!matched_genre) { |
548 | 1294 | var p = settings.getSelectedPreset(); | 1290 | set_selected_equalizer_preset (); |
542 | 1295 | |||
543 | 1296 | if(p == null) | ||
544 | 1297 | return null; | ||
545 | 1298 | |||
546 | 1299 | for(int i = 0; i < 10; ++i) | ||
547 | 1300 | player.setEqualizerGain(i, p.getGain(i)); | ||
549 | 1301 | } | 1291 | } |
550 | 1302 | } | 1292 | } |
551 | 1303 | 1293 | ||
552 | @@ -1495,6 +1485,19 @@ | |||
553 | 1495 | progress_cancel_clicked(); | 1485 | progress_cancel_clicked(); |
554 | 1496 | } | 1486 | } |
555 | 1497 | 1487 | ||
556 | 1488 | public void set_selected_equalizer_preset () { | ||
557 | 1489 | string selected_preset = settings.getSelectedPreset(); | ||
558 | 1490 | if(selected_preset != null) { | ||
559 | 1491 | foreach (EqualizerPreset p in settings.getPresets(null)) { | ||
560 | 1492 | if(p.name == selected_preset) { | ||
561 | 1493 | for(int i = 0; i < 10; ++i) | ||
562 | 1494 | player.setEqualizerGain(i, p.getGain(i)); | ||
563 | 1495 | break; | ||
564 | 1496 | } | ||
565 | 1497 | } | ||
566 | 1498 | } | ||
567 | 1499 | } | ||
568 | 1500 | |||
569 | 1498 | public Gdk.Pixbuf? get_album_art(int id) { | 1501 | public Gdk.Pixbuf? get_album_art(int id) { |
570 | 1499 | Song s = _songs.get(id); | 1502 | Song s = _songs.get(id); |
571 | 1500 | 1503 | ||
572 | 1501 | 1504 | ||
573 | === modified file 'src/Settings.vala' | |||
574 | --- src/Settings.vala 2011-11-22 03:08:33 +0000 | |||
575 | +++ src/Settings.vala 2011-12-05 01:21:23 +0000 | |||
576 | @@ -306,18 +306,12 @@ | |||
577 | 306 | return getBool(EQUALIZER_ENABLED, false); | 306 | return getBool(EQUALIZER_ENABLED, false); |
578 | 307 | } | 307 | } |
579 | 308 | 308 | ||
582 | 309 | public EqualizerPreset? getSelectedPreset() { | 309 | public string? getSelectedPreset() { |
583 | 310 | string[] vals = getString(SELECTED_PRESET, "").split(",", 0); | 310 | string rv = getString(SELECTED_PRESET, ""); |
584 | 311 | 311 | ||
586 | 312 | if(vals.length == 0 || vals[0] == null) | 312 | if(rv != null && rv.length == 0) |
587 | 313 | return null; | 313 | return null; |
595 | 314 | 314 | ||
589 | 315 | var rv = new EqualizerPreset.basic(vals[0]); | ||
590 | 316 | |||
591 | 317 | for(int i = 1; i < vals.length; ++i) { | ||
592 | 318 | rv.setGain(i-1, int.parse(vals[i])); | ||
593 | 319 | } | ||
594 | 320 | |||
596 | 321 | return rv; | 315 | return rv; |
597 | 322 | } | 316 | } |
598 | 323 | 317 | ||
599 | @@ -458,13 +452,7 @@ | |||
600 | 458 | } | 452 | } |
601 | 459 | 453 | ||
602 | 460 | public void setSelectedPreset(EqualizerPreset preset) { | 454 | public void setSelectedPreset(EqualizerPreset preset) { |
610 | 461 | string toSave = preset.name; | 455 | setString(SELECTED_PRESET, (preset != null)? preset.name : ""); |
604 | 462 | |||
605 | 463 | foreach(int gain in preset.gains) { | ||
606 | 464 | toSave += "," + gain.to_string(); | ||
607 | 465 | } | ||
608 | 466 | |||
609 | 467 | setString(SELECTED_PRESET, toSave); | ||
611 | 468 | } | 456 | } |
612 | 469 | 457 | ||
613 | 470 | public void setPresets(Gee.Collection<EqualizerPreset> presets, string? type) { | 458 | public void setPresets(Gee.Collection<EqualizerPreset> presets, string? type) { |
614 | 471 | 459 | ||
615 | === modified file 'src/Widgets/PresetList.vala' | |||
616 | --- src/Widgets/PresetList.vala 2011-11-30 22:17:03 +0000 | |||
617 | +++ src/Widgets/PresetList.vala 2011-12-05 01:21:23 +0000 | |||
618 | @@ -5,9 +5,11 @@ | |||
619 | 5 | LibraryWindow lw; | 5 | LibraryWindow lw; |
620 | 6 | ListStore store; | 6 | ListStore store; |
621 | 7 | 7 | ||
624 | 8 | private int ndefaultpresets = 0; | 8 | private int ndefaultpresets; |
625 | 9 | private int ncustompresets = 0; | 9 | private int ncustompresets; |
626 | 10 | 10 | ||
627 | 11 | private bool default_presets_modified; | ||
628 | 12 | |||
629 | 11 | private bool modifying_list; | 13 | private bool modifying_list; |
630 | 12 | 14 | ||
631 | 13 | public int preset_list_size { | 15 | public int preset_list_size { |
632 | @@ -15,9 +17,17 @@ | |||
633 | 15 | return ndefaultpresets + ncustompresets; | 17 | return ndefaultpresets + ncustompresets; |
634 | 16 | } | 18 | } |
635 | 17 | } | 19 | } |
639 | 18 | 20 | ||
640 | 19 | EqualizerPreset currentPreset; | 21 | public bool default_presets_changed { |
641 | 20 | 22 | get { | |
642 | 23 | return default_presets_modified; | ||
643 | 24 | } set { | ||
644 | 25 | default_presets_modified = value; | ||
645 | 26 | } | ||
646 | 27 | } | ||
647 | 28 | |||
648 | 29 | public EqualizerPreset last_selected_preset; | ||
649 | 30 | |||
650 | 21 | public signal void preset_selected(EqualizerPreset p); | 31 | public signal void preset_selected(EqualizerPreset p); |
651 | 22 | public signal void automatic_preset_chosen(); | 32 | public signal void automatic_preset_chosen(); |
652 | 23 | public signal void add_preset_chosen(); | 33 | public signal void add_preset_chosen(); |
653 | @@ -27,6 +37,8 @@ | |||
654 | 27 | this.lm = lm; | 37 | this.lm = lm; |
655 | 28 | this.lw = lw; | 38 | this.lw = lw; |
656 | 29 | 39 | ||
657 | 40 | ndefaultpresets = 0; | ||
658 | 41 | ncustompresets = 0; | ||
659 | 30 | modifying_list = false; | 42 | modifying_list = false; |
660 | 31 | 43 | ||
661 | 32 | buildUI(); | 44 | buildUI(); |
662 | @@ -74,7 +86,7 @@ | |||
663 | 74 | store.set(iter, 0, null, 1, "Add New..."); | 86 | store.set(iter, 0, null, 1, "Add New..."); |
664 | 75 | } | 87 | } |
665 | 76 | 88 | ||
667 | 77 | if((ndefaultpresets + ncustompresets) > 0) { | 89 | if(this.preset_list_size > 0) { |
668 | 78 | store.append(out iter); | 90 | store.append(out iter); |
669 | 79 | store.set(iter, 0, null, 1, "Delete Current"); | 91 | store.set(iter, 0, null, 1, "Delete Current"); |
670 | 80 | } | 92 | } |
671 | @@ -87,26 +99,23 @@ | |||
672 | 87 | modifying_list = true; | 99 | modifying_list = true; |
673 | 88 | TreeIter iter; | 100 | TreeIter iter; |
674 | 89 | 101 | ||
687 | 90 | if((ndefaultpresets + ncustompresets) < 1) { | 102 | if(ep.is_default) { |
676 | 91 | |||
677 | 92 | clearList(); | ||
678 | 93 | |||
679 | 94 | if(ep.is_default) | ||
680 | 95 | ndefaultpresets++; | ||
681 | 96 | else | ||
682 | 97 | ncustompresets++; | ||
683 | 98 | |||
684 | 99 | addTopOptions(); | ||
685 | 100 | } | ||
686 | 101 | else if(ep.is_default) | ||
688 | 102 | ndefaultpresets++; | 103 | ndefaultpresets++; |
690 | 103 | else | 104 | default_presets_modified = true; |
691 | 105 | } else { | ||
692 | 104 | ncustompresets++; | 106 | ncustompresets++; |
693 | 107 | } | ||
694 | 108 | |||
695 | 109 | if((this.preset_list_size - 1) < 1) { | ||
696 | 110 | clearList(); | ||
697 | 111 | addTopOptions(); | ||
698 | 112 | } | ||
699 | 105 | 113 | ||
700 | 106 | store.append(out iter); | 114 | store.append(out iter); |
701 | 107 | store.set(iter, 0, ep, 1, ep.name); | 115 | store.set(iter, 0, ep, 1, ep.name); |
702 | 108 | 116 | ||
703 | 109 | modifying_list = false; | 117 | modifying_list = false; |
704 | 118 | |||
705 | 110 | // TODO: Sort item | 119 | // TODO: Sort item |
706 | 111 | 120 | ||
707 | 112 | set_active_iter(iter); | 121 | set_active_iter(iter); |
708 | @@ -115,7 +124,7 @@ | |||
709 | 115 | public void removeCurrentPreset() { | 124 | public void removeCurrentPreset() { |
710 | 116 | modifying_list = true; | 125 | modifying_list = true; |
711 | 117 | 126 | ||
713 | 118 | if(currentPreset == null || (ndefaultpresets + ncustompresets) < 1) { | 127 | if(last_selected_preset == null || this.preset_list_size < 1) { |
714 | 119 | return; | 128 | return; |
715 | 120 | } | 129 | } |
716 | 121 | 130 | ||
717 | @@ -124,20 +133,23 @@ | |||
718 | 124 | GLib.Object o; | 133 | GLib.Object o; |
719 | 125 | store.get(iter, 0, out o); | 134 | store.get(iter, 0, out o); |
720 | 126 | 135 | ||
723 | 127 | if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == currentPreset) { | 136 | if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == last_selected_preset) { |
724 | 128 | if(((EqualizerPreset)o).is_default) | 137 | if (((EqualizerPreset)o).is_default) { |
725 | 129 | ndefaultpresets--; | 138 | ndefaultpresets--; |
727 | 130 | else | 139 | default_presets_modified = true; |
728 | 140 | } else { | ||
729 | 131 | ncustompresets--; | 141 | ncustompresets--; |
730 | 142 | } | ||
731 | 132 | 143 | ||
732 | 133 | store.remove(iter); | 144 | store.remove(iter); |
733 | 134 | } | 145 | } |
734 | 135 | } | 146 | } |
735 | 136 | 147 | ||
737 | 137 | if((ndefaultpresets + ncustompresets) < 1) { | 148 | if(this.preset_list_size < 1) { |
738 | 138 | clearList(); | 149 | clearList(); |
739 | 139 | addTopOptions(); | 150 | addTopOptions(); |
740 | 140 | } | 151 | } |
741 | 152 | |||
742 | 141 | modifying_list = false; | 153 | modifying_list = false; |
743 | 142 | set_active(0); | 154 | set_active(0); |
744 | 143 | } | 155 | } |
745 | @@ -154,7 +166,7 @@ | |||
746 | 154 | 166 | ||
747 | 155 | if(o != null && o is EqualizerPreset) { | 167 | if(o != null && o is EqualizerPreset) { |
748 | 156 | set_title(((EqualizerPreset)o).name); | 168 | set_title(((EqualizerPreset)o).name); |
750 | 157 | currentPreset = (EqualizerPreset)o; | 169 | last_selected_preset = (EqualizerPreset)o; |
751 | 158 | preset_selected((EqualizerPreset)o); | 170 | preset_selected((EqualizerPreset)o); |
752 | 159 | } | 171 | } |
753 | 160 | else { // is Automatic, Add Preset or Delete Current | 172 | else { // is Automatic, Add Preset or Delete Current |
754 | @@ -166,7 +178,7 @@ | |||
755 | 166 | } | 178 | } |
756 | 167 | else { | 179 | else { |
757 | 168 | delete_preset_chosen(); | 180 | delete_preset_chosen(); |
759 | 169 | selectPreset(currentPreset); | 181 | selectPreset(last_selected_preset.name); |
760 | 170 | } | 182 | } |
761 | 171 | } | 183 | } |
762 | 172 | } | 184 | } |
763 | @@ -175,34 +187,36 @@ | |||
764 | 175 | set_active(0); | 187 | set_active(0); |
765 | 176 | } | 188 | } |
766 | 177 | 189 | ||
769 | 178 | public void selectPreset(EqualizerPreset? p) { | 190 | public void selectPreset(string? preset_name) { |
770 | 179 | if(p == null) { | 191 | if(preset_name == null || preset_name.length < 1) { |
771 | 180 | set_active(0); | 192 | set_active(0); |
772 | 181 | } | 193 | } |
774 | 182 | 194 | ||
775 | 183 | TreeIter iter; | 195 | TreeIter iter; |
776 | 184 | for(int i = 0; store.get_iter_from_string(out iter, i.to_string()); ++i) { | 196 | for(int i = 0; store.get_iter_from_string(out iter, i.to_string()); ++i) { |
777 | 185 | GLib.Object o; | 197 | GLib.Object o; |
778 | 186 | store.get(iter, 0, out o); | 198 | store.get(iter, 0, out o); |
781 | 187 | 199 | ||
782 | 188 | if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == p.name) { | 200 | if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == preset_name) { |
783 | 189 | set_active_iter(iter); | 201 | set_active_iter(iter); |
784 | 190 | |||
785 | 191 | return; | 202 | return; |
786 | 192 | } | 203 | } |
787 | 193 | } | 204 | } |
789 | 194 | 205 | ||
790 | 195 | set_active(0); | 206 | set_active(0); |
791 | 196 | } | 207 | } |
792 | 197 | 208 | ||
794 | 198 | public EqualizerPreset getSelectedPreset() { | 209 | public EqualizerPreset? getSelectedPreset() { |
795 | 199 | TreeIter it; | 210 | TreeIter it; |
796 | 200 | get_active_iter(out it); | 211 | get_active_iter(out it); |
797 | 201 | 212 | ||
798 | 202 | GLib.Object o; | 213 | GLib.Object o; |
799 | 203 | store.get(it, 0, out o); | 214 | store.get(it, 0, out o); |
802 | 204 | 215 | ||
803 | 205 | return (EqualizerPreset)o; | 216 | if(o != null && o is EqualizerPreset) |
804 | 217 | return (EqualizerPreset)o; | ||
805 | 218 | else | ||
806 | 219 | return null; | ||
807 | 206 | } | 220 | } |
808 | 207 | 221 | ||
809 | 208 | public Gee.Collection<EqualizerPreset> getPresets() { | 222 | public Gee.Collection<EqualizerPreset> getPresets() { |
810 | @@ -220,3 +234,4 @@ | |||
811 | 220 | return rv; | 234 | return rv; |
812 | 221 | } | 235 | } |
813 | 222 | } | 236 | } |
814 | 237 |
Wow, this is impressive!