~ubuntu-branches/debian/jessie/banshee-community-extensions/jessie

« back to all changes in this revision

Viewing changes to src/Karaoke/Banshee.Karaoke/KaraokeConfigDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2011-03-11 21:50:31 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110311215031-d1rjgw6vbrux2b1e
Tags: 1.9.5-1
* [aea54e9] New upstream release:
  + Enhancements:
    - Karaoke: added a new extension to filter out the singers voice
  + Bugs Fixed:
    - LastfmFingerprint: Fix some exceptions
    - Fix missing unique IDs in several extension sources
    - Lirc: Fix potential memory issues
    - Lyrics: Fix NullPointerException when artist is unknown
* [27bfc37] Update debian/copyright
* [2ee2a15] Fix spelling errors in description of lastfm
* [3a7a674] Add banshee-extension-karaoke
* [edcfa51] Drop upstreamed lirc memleak and ampache unicode patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// KaraokeConfigDialog.cs
 
3
// 
 
4
// Author:
 
5
//   Frank Ziegler <funtastix@googlemail.com>
 
6
// 
 
7
// Copyright (c) 2011 Frank Ziegler
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
 
 
29
using Gtk;
 
30
using Mono.Addins;
 
31
 
 
32
using Banshee.Gui.Dialogs;
 
33
 
 
34
namespace Banshee.Karaoke
 
35
{
 
36
 
 
37
    public class KaraokeConfigDialog : BansheeDialog
 
38
    {
 
39
        KaraokeService karaoke_service;
 
40
 
 
41
        private double default_filter_width = 100;
 
42
        private double default_filter_band = 220;
 
43
 
 
44
        Gtk.Image preferences_image = new Gtk.Image ();
 
45
        Gtk.Label header_label = new Gtk.Label ();
 
46
        Gtk.Label description_label = new Gtk.Label ();
 
47
 
 
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 ();
 
51
 
 
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);
 
55
 
 
56
        Gtk.Button default_button = new Gtk.Button (Gtk.Stock.Home);
 
57
 
 
58
        Gtk.Button cancel_button = new Gtk.Button (Gtk.Stock.Cancel);
 
59
        Gtk.Button save_button = new Gtk.Button (Gtk.Stock.Save);
 
60
 
 
61
        float initial_level;
 
62
        float initial_band;
 
63
        float initial_width;
 
64
 
 
65
        public KaraokeConfigDialog (KaraokeService service, float current_level, float current_band, float current_width)
 
66
        {
 
67
            karaoke_service = service;
 
68
 
 
69
            initial_level = current_level;
 
70
            initial_band = current_band;
 
71
            initial_width = current_width;
 
72
 
 
73
            preferences_image.Yalign = 0f;
 
74
            preferences_image.IconName = "gtk-preferences";
 
75
            preferences_image.IconSize = (int)IconSize.Dialog;
 
76
 
 
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;
 
86
 
 
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;
 
91
 
 
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;
 
113
 
 
114
            default_button.Label = AddinManager.CurrentLocalizer.GetString ("Restore _defaults");
 
115
            default_button.Image = new Image ("gtk-home", IconSize.Button);
 
116
 
 
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);
 
121
 
 
122
            HBox main_container = new HBox ();
 
123
            VBox action_container = new VBox ();
 
124
 
 
125
            action_container.PackStart (header_label, true, true, 0);
 
126
            action_container.PackStart (description_label, true, true, 0);
 
127
 
 
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);
 
143
 
 
144
            action_container.PackStart (table, true, true, 5);
 
145
 
 
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);
 
149
 
 
150
            AddActionWidget (default_button, ResponseType.None);
 
151
 
 
152
            AddActionWidget (cancel_button, 0);
 
153
            AddActionWidget (save_button, 0);
 
154
 
 
155
            default_button.Clicked += new EventHandler (OnDefaultButtonClicked);
 
156
            cancel_button.Clicked += new EventHandler (OnCancelButtonClicked);
 
157
            save_button.Clicked += new EventHandler (OnSaveButtonClicked);
 
158
 
 
159
            Title = "Karaoke configuration";
 
160
            IconName = "gtk-preferences";
 
161
            HeightRequest = 260;
 
162
            WidthRequest = 500;
 
163
 
 
164
            ShowAll ();
 
165
        }
 
166
 
 
167
        void OnLevelValueChanged (object sender, EventArgs e)
 
168
        {
 
169
            karaoke_service.ApplyKaraokeEffectLevel ((float)(level_scale.Value / 100));
 
170
        }
 
171
 
 
172
        void OnBandValueChanged (object sender, EventArgs e)
 
173
        {
 
174
            karaoke_service.ApplyKaraokeFilterBand ((float)band_scale.Value);
 
175
        }
 
176
 
 
177
        void OnWidthValueChanged (object sender, EventArgs e)
 
178
        {
 
179
            karaoke_service.ApplyKaraokeFilterWidth ((float)width_scale.Value);
 
180
        }
 
181
 
 
182
        /// <summary>
 
183
        /// Handles click on the Default button
 
184
        /// </summary>
 
185
        /// <param name="o">
 
186
        /// A <see cref="System.Object"/> -- not used
 
187
        /// </param>
 
188
        /// <param name="a">
 
189
        /// A <see cref="EventArgs"/> -- not used
 
190
        /// </param>
 
191
        private void OnDefaultButtonClicked (object o, EventArgs a)
 
192
        {
 
193
            level_scale.Value = 100;
 
194
            band_scale.Value = default_filter_band;
 
195
            width_scale.Value = default_filter_width;
 
196
        }
 
197
 
 
198
        /// <summary>
 
199
        /// Handles click on the Cancel button
 
200
        /// </summary>
 
201
        /// <param name="o">
 
202
        /// A <see cref="System.Object"/> -- not used
 
203
        /// </param>
 
204
        /// <param name="a">
 
205
        /// A <see cref="EventArgs"/> -- not used
 
206
        /// </param>
 
207
        private void OnCancelButtonClicked (object o, EventArgs a)
 
208
        {
 
209
            karaoke_service.ApplyKaraokeEffectLevel (initial_level);
 
210
            karaoke_service.ApplyKaraokeFilterBand (initial_band);
 
211
            karaoke_service.ApplyKaraokeFilterWidth (initial_width);
 
212
 
 
213
            Destroy ();
 
214
        }
 
215
 
 
216
        /// <summary>
 
217
        /// Sets the configuration and saves it to SchemaEntries
 
218
        /// </summary>
 
219
        /// <param name="o">
 
220
        /// A <see cref="System.Object"/> -- not used
 
221
        /// </param>
 
222
        /// <param name="a">
 
223
        /// A <see cref="EventArgs"/> -- not used
 
224
        /// </param>
 
225
        private void OnSaveButtonClicked (object o, EventArgs a)
 
226
        {
 
227
            KaraokeService.EffectLevelEntry.Set ((int)level_scale.Value);
 
228
            karaoke_service.EffectLevel = (float)(level_scale.Value / 100);
 
229
 
 
230
            KaraokeService.FilterBandEntry.Set ((int)band_scale.Value);
 
231
            karaoke_service.FilterBand = (float)band_scale.Value;
 
232
 
 
233
            KaraokeService.FilterWidthEntry.Set ((int)width_scale.Value);
 
234
            karaoke_service.FilterWidth = (float)width_scale.Value;
 
235
 
 
236
            Destroy ();
 
237
        }
 
238
 
 
239
    }
 
240
}
 
241