Merge lp:~victored/beat-box/equalizer-fixes into lp:beat-box

Proposed by Victor Martinez
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
Reviewer Review Type Date Requested Status
Scott Ringwelski Approve
Review via email: mp+84419@code.launchpad.net

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.

To post a comment you must log in.
Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

Wow, this is impressive!

Revision history for this message
Victor Martinez (victored) wrote :

Thanks Sergey!

Revision history for this message
Scott Ringwelski (sgringwe) wrote :

I am merging the changes, however:

1. In lm.change_gains_thread, errors are thrown when no song is playing (i.e. song_info.song == null).
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!

review: Approve
Revision history for this message
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'schemas/org.gnome.beatbox.gschema.xml'
--- schemas/org.gnome.beatbox.gschema.xml 2011-11-22 03:08:33 +0000
+++ schemas/org.gnome.beatbox.gschema.xml 2011-12-05 01:21:23 +0000
@@ -107,18 +107,18 @@
107 </key>107 </key>
108 <key type="s" name="selected-preset">108 <key type="s" name="selected-preset">
109 <default>''</default>109 <default>''</default>
110 <summary>Contains information regarding the user-selected preset</summary>110 <summary>Contains the name of the user-selected preset</summary>
111 <description>Contains information regarding the user-selected preset</description>111 <description>Contains information regarding the user-selected preset</description>
112 </key>112 </key>
113 <key type="s" name="custom-presets">113 <key type="s" name="custom-presets">
114 <default>''</default>114 <default>''</default>
115 <summary>Custom Equalizer Presets</summary>115 <summary>Custom Equalizer Presets</summary>
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>
117 </key>117 </key>
118 <key type="s" name="default-presets">118 <key type="s" name="default-presets">
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>
120 <summary>Default Equalizer Presets</summary>120 <summary>Default Equalizer Presets</summary>
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>
122 </key>122 </key>
123 <key type="b" name="auto-switch-preset">123 <key type="b" name="auto-switch-preset">
124 <default>true</default>124 <default>true</default>
125125
=== modified file 'src/Dialogs/EqualizerWindow.vala'
--- src/Dialogs/EqualizerWindow.vala 2011-12-01 04:39:30 +0000
+++ src/Dialogs/EqualizerWindow.vala 2011-12-05 01:21:23 +0000
@@ -1,7 +1,7 @@
1/*-1/*-
2 * Copyright (c) 2011 Scott Ringwelski <sgringwe@mtu.edu>2 * Copyright (c) 2011 Scott Ringwelski <sgringwe@mtu.edu>
3 *3 *
4 * Originally Written by Scott Ringwelski and Victor Eduardo for BeatBox Music Player4 * Originally Written by Scott Ringwelski and Victor Eduardo for
5 * BeatBox Music Player: http://www.launchpad.net/beat-box5 * BeatBox Music Player: http://www.launchpad.net/beat-box
6 *6 *
7 * This library is free software; you can redistribute it and/or7 * This library is free software; you can redistribute it and/or
@@ -37,8 +37,7 @@
37 bool initialized;37 bool initialized;
38 bool automatic_chosen;38 bool automatic_chosen;
39 bool adding_preset;39 bool adding_preset;
4040 bool closing;
41 private string new_preset_name;
4241
43 List<VScale> scale_list;42 List<VScale> scale_list;
44 List<Label> label_list;43 List<Label> label_list;
@@ -46,6 +45,8 @@
46 bool in_transition;45 bool in_transition;
47 Gee.ArrayList<int> target_levels;46 Gee.ArrayList<int> target_levels;
48 47
48 private string new_preset_name;
49
49 public EqualizerWindow (LibraryManager lm, LibraryWindow lw) {50 public EqualizerWindow (LibraryManager lm, LibraryWindow lw) {
50 51
51 this.lm = lm;52 this.lm = lm;
@@ -53,9 +54,10 @@
53 54
54 scale_list = new List<VScale>();55 scale_list = new List<VScale>();
55 label_list = new List<Label>();56 label_list = new List<Label>();
57 target_levels = new Gee.ArrayList<int>();
58 closing = false;
56 adding_preset = false;59 adding_preset = false;
57 initialized = false;60 initialized = false;
58 target_levels = new Gee.ArrayList<int>();
59 automatic_chosen = false;61 automatic_chosen = false;
6062
61 build_ui();63 build_ui();
@@ -70,12 +72,10 @@
70 eq_switch.set_active(lm.settings.getEqualizerEnabled());72 eq_switch.set_active(lm.settings.getEqualizerEnabled());
71 on_eq_switch_toggled();73 on_eq_switch_toggled();
7274
73 if (lm.settings.getAutoSwitchPreset()) {
74 preset_combo.selectAutomaticPreset();
75 on_automatic_chosen();
76 }
77
78 initialized = true;75 initialized = true;
76
77 if (lm.settings.getAutoSwitchPreset())
78 preset_combo.selectAutomaticPreset();
79 }79 }
80 80
81 void build_ui () {81 void build_ui () {
@@ -85,17 +85,17 @@
85 window_position = WindowPosition.CENTER;85 window_position = WindowPosition.CENTER;
86 type_hint = Gdk.WindowTypeHint.DIALOG;86 type_hint = Gdk.WindowTypeHint.DIALOG;
87 set_transient_for(lw);87 set_transient_for(lw);
88
89 set_size_request(440, 224);88 set_size_request(440, 224);
90 resizable = false;89 resizable = false;
90 set_deletable(false);
9191
92 set_icon(render_icon(Gtk.Stock.PREFERENCES, IconSize.DIALOG, null));92 set_icon(render_icon(Gtk.Stock.PREFERENCES, IconSize.DIALOG, null));
93 93
94 var outer_box = new HBox(false, 10);94 var outer_box = new HBox(false, 10);
95 var inner_box = new VBox(false, 0);95 var inner_box = new VBox(false, 0);
96 var scales = new HBox(false, 0);96 var scales = new HBox(false, 0);
97 bottom_toolbar = new Toolbar();
98 97
98 bottom_toolbar = new Toolbar();
99 eq_switch = new Switch();99 eq_switch = new Switch();
100 preset_combo = new PresetList(lm, lw);100 preset_combo = new PresetList(lm, lw);
101 101
@@ -132,7 +132,7 @@
132132
133 }133 }
134134
135 preset_combo.set_size_request(150, -1);135 preset_combo.set_size_request(170, -1);
136136
137 var eq_switch_item = new ToolItem();137 var eq_switch_item = new ToolItem();
138 eq_switch_item.add(eq_switch);138 eq_switch_item.add(eq_switch);
@@ -141,7 +141,7 @@
141 side_list.add(preset_combo);141 side_list.add(preset_combo);
142142
143 new_preset_entry = new Entry();143 new_preset_entry = new Entry();
144 new_preset_entry.set_size_request(150, -1);144 new_preset_entry.set_size_request(170, -1);
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);
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");
147147
@@ -150,10 +150,11 @@
150150
151 var space_item = new ToolItem();151 var space_item = new ToolItem();
152 space_item.set_expand(true);152 space_item.set_expand(true);
153 153
154 var close_button = new Button.with_label("Close");154 var close_button = new Button.with_label("Close");
155 var close_button_item = new ToolItem();155 var close_button_item = new ToolItem();
156 close_button_item.set_expand(true);156 close_button.set_size_request(120, -1);
157 close_button_item.set_expand(false);
157 close_button_item.add(close_button);158 close_button_item.add(close_button);
158159
159 bottom_toolbar.insert(eq_switch_item, 0);160 bottom_toolbar.insert(eq_switch_item, 0);
@@ -172,18 +173,25 @@
172 173
173 eq_switch.notify["active"].connect(on_eq_switch_toggled);174 eq_switch.notify["active"].connect(on_eq_switch_toggled);
174 preset_combo.automatic_preset_chosen.connect(on_automatic_chosen);175 preset_combo.automatic_preset_chosen.connect(on_automatic_chosen);
175 preset_combo.add_preset_chosen.connect(addPresetClicked);176 preset_combo.add_preset_chosen.connect(add_preset_clicked);
176 preset_combo.delete_preset_chosen.connect(removePresetClicked);177 preset_combo.delete_preset_chosen.connect(remove_preset_clicked);
177 preset_combo.preset_selected.connect(presetSelected);178 preset_combo.preset_selected.connect (preset_selected);
178 new_preset_entry.activate.connect (add_new_preset);179 new_preset_entry.activate.connect (add_new_preset);
179 new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed);180 new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed);
181 new_preset_entry.focus_out_event.connect (on_entry_focus_out);
180182
181 close_button.clicked.connect(on_close);183 close_button.clicked.connect(on_close_button_clicked);
182 destroy.connect(on_close);184 destroy.connect(on_quit);
183 185
184 show_all();186 show_all();
185 }187 }
186 188
189 bool on_entry_focus_out () {
190 if(!closing)
191 new_preset_entry.grab_focus();
192 return true;
193 }
194
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) {
188 196
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);
@@ -246,11 +254,12 @@
246 foreach (EqualizerPreset preset in custom_presets) {254 foreach (EqualizerPreset preset in custom_presets) {
247 preset_combo.addPreset(preset);255 preset_combo.addPreset(preset);
248 }256 }
257
258 preset_combo.default_presets_changed = false;
249 }259 }
250260
251 void presetSelected(EqualizerPreset p) {261 void preset_selected (EqualizerPreset p) {
252 automatic_chosen = false;262 automatic_chosen = false;
253
254 set_sliders_sensitivity (true);263 set_sliders_sensitivity (true);
255 target_levels.clear();264 target_levels.clear();
256 265
@@ -258,17 +267,21 @@
258 target_levels.add(i);267 target_levels.add(i);
259 }268 }
260 269
261 if (!initialized) {270 set_target_levels ();
271
272 if (!in_transition && !closing) {
273 in_transition = true;
274 Timeout.add(20, transition_scales);
275 }
276 }
277
278 void set_target_levels () {
279 if (!initialized || closing) {
262 for (int index = 0; index < 10; ++index) {280 for (int index = 0; index < 10; ++index) {
263 scale_list.nth_data(index).set_value(target_levels.get(index));281 scale_list.nth_data(index).set_value(target_levels.get(index));
264 }282 }
265 return;283 return;
266 }284 }
267
268 if (!in_transition) {
269 in_transition = true;
270 Timeout.add(20, transition_scales);
271 }
272 }285 }
273 286
274 bool transition_scales () {287 bool transition_scales () {
@@ -280,7 +293,7 @@
280 double targetLvl = target_levels.get(index);293 double targetLvl = target_levels.get(index);
281 double difference = targetLvl - currLvl;294 double difference = targetLvl - currLvl;
282 295
283 if (Math.fabs(difference) <= 1)296 if (closing || Math.fabs(difference) <= 1)
284 scale_list.nth_data(index).set_value(targetLvl);297 scale_list.nth_data(index).set_value(targetLvl);
285 else {298 else {
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));
@@ -311,39 +324,19 @@
311324
312 adding_preset = true;325 adding_preset = true;
313326
314 bool preset_already_exists = false;
315 var current_presets = preset_combo.getPresets();
316
317 bottom_toolbar.remove(side_list);327 bottom_toolbar.remove(side_list);
318 bottom_toolbar.insert(new_preset_field, 1);328 bottom_toolbar.insert(new_preset_field, 1);
319329
320 string current_preset_name = preset_combo.getSelectedPreset().name;330 new_preset_name = create_new_preset_name(true);
321 string new_preset_name = " ";
322 int i = 1;
323
324 do
325 {
326 new_preset_name = current_preset_name + " (Custom" + ((preset_already_exists)? " " + i.to_string() : "") + ")";
327
328 preset_already_exists = false;
329
330 foreach(EqualizerPreset preset in current_presets) {
331 if(new_preset_name == preset.name) {
332 preset_already_exists = true;
333 break;
334 }
335 }
336
337 i++;
338
339 } while (preset_already_exists);
340331
341 new_preset_entry.set_text(new_preset_name);332 new_preset_entry.set_text(new_preset_name);
333 eq_switch.sensitive = false;
342 bottom_toolbar.show_all();334 bottom_toolbar.show_all();
343 new_preset_entry.grab_focus();335 new_preset_entry.grab_focus();
344 }336 }
345337
346 void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) {338 void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) {
339
347 if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset)340 if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset)
348 return;341 return;
349342
@@ -351,12 +344,13 @@
351 }344 }
352345
353 void add_new_preset() {346 void add_new_preset() {
347
354 if(!adding_preset)348 if(!adding_preset)
355 return;349 return;
356350
357 var new_name = new_preset_entry.get_text();351 var new_name = new_preset_entry.get_text();
358352
359 if(new_name != null)353 if(verify_preset_name(new_name))
360 new_preset_name = new_name;354 new_preset_name = new_name;
361355
362 int i = 0;356 int i = 0;
@@ -373,31 +367,118 @@
373 bottom_toolbar.remove(new_preset_field);367 bottom_toolbar.remove(new_preset_field);
374 bottom_toolbar.insert(side_list, 1);368 bottom_toolbar.insert(side_list, 1);
375 bottom_toolbar.show_all();369 bottom_toolbar.show_all();
376 370 eq_switch.sensitive = true;
377 adding_preset = false;371 adding_preset = false;
378 }372 }
379373
380 void addPresetClicked () {374 string create_new_preset_name (bool from_current) {
381 PresetNameWindow pnw = new PresetNameWindow(lw, new EqualizerPreset.basic("Custom Preset"));375
382 pnw.preset_saved.connect(presetNameWindowSaved);376 int i = 0;
383 }377 bool is_valid = false;
384 378
385 void presetNameWindowSaved (EqualizerPreset p) {379 string current_preset_name = (from_current)? preset_combo.getSelectedPreset().name : "";
380 string preset_name = "Custom Preset";
381
382 do
383 {
384 preset_name = (from_current)? current_preset_name + " (" : "";
385 preset_name += "Custom" + ((from_current)? "" : " Preset");
386 preset_name += ((!is_valid && i > 0)? " " + i.to_string() : "");
387 preset_name += (from_current)? ")" : "";
388
389 i++;
390
391 is_valid = verify_preset_name(preset_name);
392 } while (!is_valid);
393
394 return preset_name;
395 }
396
397 public bool verify_preset_name(string name) {
398
399 /* This function verifies the name of a new preset.
400 It will return 'true' whenever:
401 - The name is not null
402 - The name doesn't consist [enterely] of white space.
403 - The name is not already in the list.
404 */
405
406 int white_space = 0;
407 int str_length = name.length;
408 bool preset_already_exists = false;
409
410 if(str_length < 1)
411 return false;
412
413 for(int i = 0; i < str_length; ++i) {
414 if(name[i] == ' ' || name[i] == '\t')
415 white_space++;
416 }
417
418 if(white_space == str_length)
419 return false;
420
421 var current_presets = preset_combo.getPresets();
422
423 preset_already_exists = false;
424
425 foreach(EqualizerPreset preset in current_presets) {
426 if(name == preset.name) {
427 preset_already_exists = true;
428 break;
429 }
430 }
431
432 return !preset_already_exists;
433 }
434
435 void add_preset_clicked () {
436 string name = create_new_preset_name(false);
437 PresetNameWindow pnw = new PresetNameWindow(this, new EqualizerPreset.basic(name));
438 pnw.preset_saved.connect(preset_name_window_saved);
439 pnw.action_canceled.connect(select_last_used_preset);
440 }
441
442 void select_last_used_preset () {
443 var last_preset = preset_combo.last_selected_preset;
444
445 if(!automatic_chosen && last_preset != null)
446 preset_combo.selectPreset(last_preset.name);
447 else
448 preset_combo.selectAutomaticPreset();
449 }
450
451 void preset_name_window_saved (EqualizerPreset p) {
386 preset_combo.addPreset(p);452 preset_combo.addPreset(p);
387 }453 }
388454
389 void removePresetClicked () {455 void remove_preset_clicked () {
390456 if(!automatic_chosen)
391 preset_combo.removeCurrentPreset();457 preset_combo.removeCurrentPreset();
392 }458 }
393459
394 void on_close () {460 void on_close_button_clicked () {
461 closing = true;
462
463 if(adding_preset)
464 add_new_preset();
465
395 if(!in_transition)466 if(!in_transition)
396 close_equalizer();467 close_equalizer();
397 else468 else
398 Timeout.add(20, close_equalizer);469 Timeout.add(20, close_equalizer);
399 }470 }
400 471
472 void on_quit () {
473
474 if(!in_transition)
475 on_close_button_clicked();
476 else {
477 set_target_levels ();
478 close_equalizer ();
479 }
480 }
481
401 bool close_equalizer () {482 bool close_equalizer () {
402483
403 if(in_transition)484 if(in_transition)
@@ -405,27 +486,29 @@
405486
406 lm.settings.setEqualizerEnabled(eq_switch.get_active());487 lm.settings.setEqualizerEnabled(eq_switch.get_active());
407 488
408 if(preset_combo.getSelectedPreset() != null) {489 if(preset_combo.getSelectedPreset() != null)
409 lm.settings.setSelectedPreset(preset_combo.getSelectedPreset());490 lm.settings.setSelectedPreset(preset_combo.getSelectedPreset());
410 }
411491
412 var defaultPresets = new Gee.LinkedList<EqualizerPreset>();492 var defaultPresets = new Gee.LinkedList<EqualizerPreset>();
413 var customPresets = new Gee.LinkedList<EqualizerPreset>();493 var customPresets = new Gee.LinkedList<EqualizerPreset>();
414494
415 foreach(EqualizerPreset preset in preset_combo.getPresets()) {495 foreach (EqualizerPreset preset in preset_combo.getPresets()) {
416 if(preset.is_default == true)496 if (preset.is_default == true)
417 defaultPresets.add(preset);497 defaultPresets.add (preset);
418 else498 else
419 customPresets.add(preset);499 customPresets.add (preset);
420 }500 }
421501
422 lm.settings.setPresets(defaultPresets, null);502 if(preset_combo.default_presets_changed)
423 lm.settings.setPresets(customPresets, "custom-presets");503 lm.settings.setPresets (defaultPresets, null);
424504
425 lm.settings.setAutoSwitchPreset(automatic_chosen);505 lm.settings.setPresets (customPresets, lm.settings.CUSTOM_PRESETS);
506
507 lm.settings.setAutoSwitchPreset (automatic_chosen);
426508
427 destroy();509 destroy();
428 510
429 return false;511 return false;
430 }512 }
431}513}
514
432515
=== modified file 'src/Dialogs/PresetNameWindow.vala'
--- src/Dialogs/PresetNameWindow.vala 2011-11-30 22:17:03 +0000
+++ src/Dialogs/PresetNameWindow.vala 2011-12-05 01:21:23 +0000
@@ -20,14 +20,12 @@
20 * Boston, MA 02111-1307, USA.20 * Boston, MA 02111-1307, USA.
21 */21 */
2222
23/* Merely a place holder for multiple pieces of information regarding
24 * the current song playing. Mostly here because of dependence. */
25
26using Gtk;23using Gtk;
2724
28public class BeatBox.PresetNameWindow : Window {25public class BeatBox.PresetNameWindow : Window {
29 public EqualizerPreset _original;26 public EqualizerPreset _original;
30 27
28 EqualizerWindow ew;
31 VBox content;29 VBox content;
32 HBox padding;30 HBox padding;
33 31
@@ -35,14 +33,17 @@
35 public Button _save;33 public Button _save;
36 34
37 public signal void preset_saved(EqualizerPreset p);35 public signal void preset_saved(EqualizerPreset p);
36 public signal void action_canceled();
3837
39 public PresetNameWindow(LibraryWindow lw, EqualizerPreset original) {38 public PresetNameWindow(EqualizerWindow ew, EqualizerPreset original) {
40 title = "";39 title = "";
41 40
41 this.ew = ew;
42
42 this.window_position = WindowPosition.CENTER;43 this.window_position = WindowPosition.CENTER;
43 this.type_hint = Gdk.WindowTypeHint.DIALOG;44 this.type_hint = Gdk.WindowTypeHint.DIALOG;
44 this.set_modal(true);45 this.set_modal(true);
45 this.set_transient_for(lw);46 this.set_transient_for(ew);
46 this.destroy_with_parent = true;47 this.destroy_with_parent = true;
47 resizable = false;48 resizable = false;
48 set_size_request(200, -1); 49 set_size_request(200, -1);
@@ -80,6 +81,7 @@
80 81
81 _save.clicked.connect(saveClicked);82 _save.clicked.connect(saveClicked);
82 _name.activate.connect(nameActivate);83 _name.activate.connect(nameActivate);
84 this.destroy.connect(on_action_canceled);
83 }85 }
84 86
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) {
@@ -94,7 +96,9 @@
94 }96 }
95 97
96 public virtual void saveClicked() {98 public virtual void saveClicked() {
97 _original.name = _name.text;99 if(ew.verify_preset_name(_name.text))
100 _original.name = _name.text;
101
98 preset_saved(_original);102 preset_saved(_original);
99 103
100 this.destroy();104 this.destroy();
@@ -103,4 +107,9 @@
103 public virtual void nameActivate() {107 public virtual void nameActivate() {
104 saveClicked();108 saveClicked();
105 }109 }
110
111 public virtual void on_action_canceled() {
112 action_canceled();
113 this.destroy();
114 }
106}115}
107116
=== modified file 'src/LibraryManager.vala'
--- src/LibraryManager.vala 2011-12-03 21:19:37 +0000
+++ src/LibraryManager.vala 2011-12-05 01:21:23 +0000
@@ -222,11 +222,7 @@
222 222
223 // set the equalizer223 // set the equalizer
224 if(settings.getEqualizerEnabled() && !settings.getAutoSwitchPreset()) {224 if(settings.getEqualizerEnabled() && !settings.getAutoSwitchPreset()) {
225 EqualizerPreset p = settings.getSelectedPreset();225 set_selected_equalizer_preset ();
226 if(p != null) {
227 for(int i = 0; i < 10; ++i)
228 player.setEqualizerGain(i, p.getGain(i));
229 }
230 }226 }
231 227
232 dm = new DeviceManager(this);228 dm = new DeviceManager(this);
@@ -1291,13 +1287,7 @@
1291 }1287 }
1292 1288
1293 if(!matched_genre) {1289 if(!matched_genre) {
1294 var p = settings.getSelectedPreset();1290 set_selected_equalizer_preset ();
1295
1296 if(p == null)
1297 return null;
1298
1299 for(int i = 0; i < 10; ++i)
1300 player.setEqualizerGain(i, p.getGain(i));
1301 }1291 }
1302 }1292 }
1303 1293
@@ -1495,6 +1485,19 @@
1495 progress_cancel_clicked();1485 progress_cancel_clicked();
1496 }1486 }
1497 1487
1488 public void set_selected_equalizer_preset () {
1489 string selected_preset = settings.getSelectedPreset();
1490 if(selected_preset != null) {
1491 foreach (EqualizerPreset p in settings.getPresets(null)) {
1492 if(p.name == selected_preset) {
1493 for(int i = 0; i < 10; ++i)
1494 player.setEqualizerGain(i, p.getGain(i));
1495 break;
1496 }
1497 }
1498 }
1499 }
1500
1498 public Gdk.Pixbuf? get_album_art(int id) {1501 public Gdk.Pixbuf? get_album_art(int id) {
1499 Song s = _songs.get(id);1502 Song s = _songs.get(id);
1500 1503
15011504
=== modified file 'src/Settings.vala'
--- src/Settings.vala 2011-11-22 03:08:33 +0000
+++ src/Settings.vala 2011-12-05 01:21:23 +0000
@@ -306,18 +306,12 @@
306 return getBool(EQUALIZER_ENABLED, false);306 return getBool(EQUALIZER_ENABLED, false);
307 }307 }
308 308
309 public EqualizerPreset? getSelectedPreset() {309 public string? getSelectedPreset() {
310 string[] vals = getString(SELECTED_PRESET, "").split(",", 0);310 string rv = getString(SELECTED_PRESET, "");
311 311
312 if(vals.length == 0 || vals[0] == null)312 if(rv != null && rv.length == 0)
313 return null;313 return null;
314 314
315 var rv = new EqualizerPreset.basic(vals[0]);
316
317 for(int i = 1; i < vals.length; ++i) {
318 rv.setGain(i-1, int.parse(vals[i]));
319 }
320
321 return rv;315 return rv;
322 }316 }
323 317
@@ -458,13 +452,7 @@
458 }452 }
459 453
460 public void setSelectedPreset(EqualizerPreset preset) {454 public void setSelectedPreset(EqualizerPreset preset) {
461 string toSave = preset.name;455 setString(SELECTED_PRESET, (preset != null)? preset.name : "");
462
463 foreach(int gain in preset.gains) {
464 toSave += "," + gain.to_string();
465 }
466
467 setString(SELECTED_PRESET, toSave);
468 }456 }
469457
470 public void setPresets(Gee.Collection<EqualizerPreset> presets, string? type) {458 public void setPresets(Gee.Collection<EqualizerPreset> presets, string? type) {
471459
=== modified file 'src/Widgets/PresetList.vala'
--- src/Widgets/PresetList.vala 2011-11-30 22:17:03 +0000
+++ src/Widgets/PresetList.vala 2011-12-05 01:21:23 +0000
@@ -5,9 +5,11 @@
5 LibraryWindow lw;5 LibraryWindow lw;
6 ListStore store;6 ListStore store;
7 7
8 private int ndefaultpresets = 0;8 private int ndefaultpresets;
9 private int ncustompresets = 0;9 private int ncustompresets;
1010
11 private bool default_presets_modified;
12
11 private bool modifying_list;13 private bool modifying_list;
1214
13 public int preset_list_size {15 public int preset_list_size {
@@ -15,9 +17,17 @@
15 return ndefaultpresets + ncustompresets;17 return ndefaultpresets + ncustompresets;
16 }18 }
17 }19 }
18 20
19 EqualizerPreset currentPreset;21 public bool default_presets_changed {
20 22 get {
23 return default_presets_modified;
24 } set {
25 default_presets_modified = value;
26 }
27 }
28
29 public EqualizerPreset last_selected_preset;
30
21 public signal void preset_selected(EqualizerPreset p);31 public signal void preset_selected(EqualizerPreset p);
22 public signal void automatic_preset_chosen();32 public signal void automatic_preset_chosen();
23 public signal void add_preset_chosen();33 public signal void add_preset_chosen();
@@ -27,6 +37,8 @@
27 this.lm = lm;37 this.lm = lm;
28 this.lw = lw;38 this.lw = lw;
2939
40 ndefaultpresets = 0;
41 ncustompresets = 0;
30 modifying_list = false;42 modifying_list = false;
31 43
32 buildUI();44 buildUI();
@@ -74,7 +86,7 @@
74 store.set(iter, 0, null, 1, "Add New...");86 store.set(iter, 0, null, 1, "Add New...");
75 }87 }
7688
77 if((ndefaultpresets + ncustompresets) > 0) {89 if(this.preset_list_size > 0) {
78 store.append(out iter);90 store.append(out iter);
79 store.set(iter, 0, null, 1, "Delete Current");91 store.set(iter, 0, null, 1, "Delete Current");
80 }92 }
@@ -87,26 +99,23 @@
87 modifying_list = true;99 modifying_list = true;
88 TreeIter iter;100 TreeIter iter;
89101
90 if((ndefaultpresets + ncustompresets) < 1) {102 if(ep.is_default) {
91
92 clearList();
93
94 if(ep.is_default)
95 ndefaultpresets++;
96 else
97 ncustompresets++;
98
99 addTopOptions();
100 }
101 else if(ep.is_default)
102 ndefaultpresets++;103 ndefaultpresets++;
103 else104 default_presets_modified = true;
105 } else {
104 ncustompresets++;106 ncustompresets++;
107 }
108
109 if((this.preset_list_size - 1) < 1) {
110 clearList();
111 addTopOptions();
112 }
105113
106 store.append(out iter);114 store.append(out iter);
107 store.set(iter, 0, ep, 1, ep.name);115 store.set(iter, 0, ep, 1, ep.name);
108116
109 modifying_list = false;117 modifying_list = false;
118
110 // TODO: Sort item119 // TODO: Sort item
111120
112 set_active_iter(iter);121 set_active_iter(iter);
@@ -115,7 +124,7 @@
115 public void removeCurrentPreset() {124 public void removeCurrentPreset() {
116 modifying_list = true;125 modifying_list = true;
117 126
118 if(currentPreset == null || (ndefaultpresets + ncustompresets) < 1) {127 if(last_selected_preset == null || this.preset_list_size < 1) {
119 return;128 return;
120 }129 }
121 130
@@ -124,20 +133,23 @@
124 GLib.Object o;133 GLib.Object o;
125 store.get(iter, 0, out o);134 store.get(iter, 0, out o);
126 135
127 if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == currentPreset) {136 if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == last_selected_preset) {
128 if(((EqualizerPreset)o).is_default)137 if (((EqualizerPreset)o).is_default) {
129 ndefaultpresets--;138 ndefaultpresets--;
130 else139 default_presets_modified = true;
140 } else {
131 ncustompresets--;141 ncustompresets--;
142 }
132 143
133 store.remove(iter);144 store.remove(iter);
134 }145 }
135 }146 }
136147
137 if((ndefaultpresets + ncustompresets) < 1) {148 if(this.preset_list_size < 1) {
138 clearList();149 clearList();
139 addTopOptions();150 addTopOptions();
140 }151 }
152
141 modifying_list = false;153 modifying_list = false;
142 set_active(0);154 set_active(0);
143 }155 }
@@ -154,7 +166,7 @@
154166
155 if(o != null && o is EqualizerPreset) {167 if(o != null && o is EqualizerPreset) {
156 set_title(((EqualizerPreset)o).name);168 set_title(((EqualizerPreset)o).name);
157 currentPreset = (EqualizerPreset)o;169 last_selected_preset = (EqualizerPreset)o;
158 preset_selected((EqualizerPreset)o);170 preset_selected((EqualizerPreset)o);
159 }171 }
160 else { // is Automatic, Add Preset or Delete Current172 else { // is Automatic, Add Preset or Delete Current
@@ -166,7 +178,7 @@
166 }178 }
167 else {179 else {
168 delete_preset_chosen();180 delete_preset_chosen();
169 selectPreset(currentPreset);181 selectPreset(last_selected_preset.name);
170 }182 }
171 }183 }
172 }184 }
@@ -175,34 +187,36 @@
175 set_active(0);187 set_active(0);
176 }188 }
177 189
178 public void selectPreset(EqualizerPreset? p) {190 public void selectPreset(string? preset_name) {
179 if(p == null) {191 if(preset_name == null || preset_name.length < 1) {
180 set_active(0);192 set_active(0);
181 }193 }
182 194
183 TreeIter iter;195 TreeIter iter;
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) {
185 GLib.Object o;197 GLib.Object o;
186 store.get(iter, 0, out o);198 store.get(iter, 0, out o);
187 199
188 if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == p.name) {200 if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == preset_name) {
189 set_active_iter(iter);201 set_active_iter(iter);
190
191 return;202 return;
192 }203 }
193 }204 }
194 205
195 set_active(0);206 set_active(0);
196 }207 }
197 208
198 public EqualizerPreset getSelectedPreset() {209 public EqualizerPreset? getSelectedPreset() {
199 TreeIter it;210 TreeIter it;
200 get_active_iter(out it);211 get_active_iter(out it);
201 212
202 GLib.Object o;213 GLib.Object o;
203 store.get(it, 0, out o);214 store.get(it, 0, out o);
204 215
205 return (EqualizerPreset)o;216 if(o != null && o is EqualizerPreset)
217 return (EqualizerPreset)o;
218 else
219 return null;
206 }220 }
207 221
208 public Gee.Collection<EqualizerPreset> getPresets() {222 public Gee.Collection<EqualizerPreset> getPresets() {
@@ -220,3 +234,4 @@
220 return rv;234 return rv;
221 }235 }
222}236}
237

Subscribers

People subscribed via source and target branches