2
// KaraokeConfigDialog.cs
5
// Frank Ziegler <funtastix@googlemail.com>
7
// Copyright (c) 2011 Frank Ziegler
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
using Banshee.Gui.Dialogs;
34
namespace Banshee.Karaoke
37
public class KaraokeConfigDialog : BansheeDialog
39
KaraokeService karaoke_service;
41
private double default_filter_width = 100;
42
private double default_filter_band = 220;
44
Gtk.Image preferences_image = new Gtk.Image ();
45
Gtk.Label header_label = new Gtk.Label ();
46
Gtk.Label description_label = new Gtk.Label ();
48
Gtk.Label choose_level_label = new Gtk.Label ();
49
Gtk.Label choose_band_label = new Gtk.Label ();
50
Gtk.Label choose_width_label = new Gtk.Label ();
52
Gtk.HScale level_scale = new Gtk.HScale (0, 100, 1);
53
Gtk.HScale band_scale = new Gtk.HScale (0, 441, 1);
54
Gtk.HScale width_scale = new Gtk.HScale (0, 100, 1);
56
Gtk.Button default_button = new Gtk.Button (Gtk.Stock.Home);
58
Gtk.Button cancel_button = new Gtk.Button (Gtk.Stock.Cancel);
59
Gtk.Button save_button = new Gtk.Button (Gtk.Stock.Save);
65
public KaraokeConfigDialog (KaraokeService service, float current_level, float current_band, float current_width)
67
karaoke_service = service;
69
initial_level = current_level;
70
initial_band = current_band;
71
initial_width = current_width;
73
preferences_image.Yalign = 0f;
74
preferences_image.IconName = "gtk-preferences";
75
preferences_image.IconSize = (int)IconSize.Dialog;
77
header_label.Text = String.Format ("<span weight=\"bold\" size=\"larger\">{0}</span>", AddinManager.CurrentLocalizer.GetString ("Karaoke configuration"));
78
header_label.UseMarkup = true;
79
header_label.Yalign = 0f;
80
header_label.Xalign = 0f;
81
description_label.Text = AddinManager.CurrentLocalizer.GetString ("You can alter the parameters of the karaoke effect here and "
82
+ "define custom filter-band, filter-width and effect level.");
83
description_label.Yalign = 0f;
84
description_label.Xalign = 0f;
85
description_label.Wrap = true;
87
choose_level_label.Text = AddinManager.CurrentLocalizer.GetString ("Effect Level:");
88
choose_band_label.Text = AddinManager.CurrentLocalizer.GetString ("Filter Band:");
89
choose_width_label.Text = AddinManager.CurrentLocalizer.GetString ("Filter Width:");
90
choose_level_label.Xalign = choose_band_label.Xalign = choose_width_label.Xalign = 0f;
92
level_scale.Digits = 0;
93
level_scale.DrawValue = true;
94
level_scale.TooltipText = AddinManager.CurrentLocalizer.GetString ("The effect level defines to what degree the voice "
95
+ "frequencies are reduced.");
96
level_scale.ValuePos = PositionType.Right;
97
level_scale.Value = current_level * 100;
98
level_scale.ValueChanged += OnLevelValueChanged;
99
band_scale.Digits = 0;
100
band_scale.DrawValue = true;
101
band_scale.TooltipText = AddinManager.CurrentLocalizer.GetString ("The filter band defines position of filter within "
102
+ "the frequency spectrum.");
103
band_scale.ValuePos = PositionType.Right;
104
band_scale.Value = current_band;
105
band_scale.ValueChanged += OnBandValueChanged;
106
width_scale.Digits = 0;
107
width_scale.DrawValue = true;
108
width_scale.TooltipText = AddinManager.CurrentLocalizer.GetString ("The filter width defines how wide the spectrum "
109
+ "of the filtered frequencies is.");
110
width_scale.ValuePos = PositionType.Right;
111
width_scale.Value = current_width;
112
width_scale.ValueChanged += OnWidthValueChanged;
114
default_button.Label = AddinManager.CurrentLocalizer.GetString ("Restore _defaults");
115
default_button.Image = new Image ("gtk-home", IconSize.Button);
117
cancel_button.Label = AddinManager.CurrentLocalizer.GetString ("_Cancel");
118
cancel_button.Image = new Image ("gtk-cancel", IconSize.Button);
119
save_button.Label = AddinManager.CurrentLocalizer.GetString ("_Save");
120
save_button.Image = new Image ("gtk-save", IconSize.Button);
122
HBox main_container = new HBox ();
123
VBox action_container = new VBox ();
125
action_container.PackStart (header_label, true, true, 0);
126
action_container.PackStart (description_label, true, true, 0);
128
Table table = new Table (3, 2, false);
129
table.RowSpacing = 6;
130
table.ColumnSpacing = 12;
131
table.Attach (choose_level_label, 0, 1, 0, 1,
132
AttachOptions.Fill, AttachOptions.Fill, 0, 0);
133
table.Attach (level_scale, 1, 2, 0, 1,
134
AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
135
table.Attach (choose_band_label, 0, 1, 1, 2,
136
AttachOptions.Fill, AttachOptions.Fill, 0, 0);
137
table.Attach (band_scale, 1, 2, 1, 2,
138
AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
139
table.Attach (choose_width_label, 0, 1, 2, 3,
140
AttachOptions.Fill, AttachOptions.Fill, 0, 0);
141
table.Attach (width_scale, 1, 2, 2, 3,
142
AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0, 0);
144
action_container.PackStart (table, true, true, 5);
146
main_container.PackStart (preferences_image, false, true, 5);
147
main_container.PackEnd (action_container, true, true, 5);
148
this.VBox.PackStart (main_container, true, true, 5);
150
AddActionWidget (default_button, ResponseType.None);
152
AddActionWidget (cancel_button, 0);
153
AddActionWidget (save_button, 0);
155
default_button.Clicked += new EventHandler (OnDefaultButtonClicked);
156
cancel_button.Clicked += new EventHandler (OnCancelButtonClicked);
157
save_button.Clicked += new EventHandler (OnSaveButtonClicked);
159
Title = "Karaoke configuration";
160
IconName = "gtk-preferences";
167
void OnLevelValueChanged (object sender, EventArgs e)
169
karaoke_service.ApplyKaraokeEffectLevel ((float)(level_scale.Value / 100));
172
void OnBandValueChanged (object sender, EventArgs e)
174
karaoke_service.ApplyKaraokeFilterBand ((float)band_scale.Value);
177
void OnWidthValueChanged (object sender, EventArgs e)
179
karaoke_service.ApplyKaraokeFilterWidth ((float)width_scale.Value);
183
/// Handles click on the Default button
186
/// A <see cref="System.Object"/> -- not used
189
/// A <see cref="EventArgs"/> -- not used
191
private void OnDefaultButtonClicked (object o, EventArgs a)
193
level_scale.Value = 100;
194
band_scale.Value = default_filter_band;
195
width_scale.Value = default_filter_width;
199
/// Handles click on the Cancel button
202
/// A <see cref="System.Object"/> -- not used
205
/// A <see cref="EventArgs"/> -- not used
207
private void OnCancelButtonClicked (object o, EventArgs a)
209
karaoke_service.ApplyKaraokeEffectLevel (initial_level);
210
karaoke_service.ApplyKaraokeFilterBand (initial_band);
211
karaoke_service.ApplyKaraokeFilterWidth (initial_width);
217
/// Sets the configuration and saves it to SchemaEntries
220
/// A <see cref="System.Object"/> -- not used
223
/// A <see cref="EventArgs"/> -- not used
225
private void OnSaveButtonClicked (object o, EventArgs a)
227
KaraokeService.EffectLevelEntry.Set ((int)level_scale.Value);
228
karaoke_service.EffectLevel = (float)(level_scale.Value / 100);
230
KaraokeService.FilterBandEntry.Set ((int)band_scale.Value);
231
karaoke_service.FilterBand = (float)band_scale.Value;
233
KaraokeService.FilterWidthEntry.Set ((int)width_scale.Value);
234
karaoke_service.FilterWidth = (float)width_scale.Value;