banshee r3016 - in trunk/banshee: . libbanshee src/Backends/Banshee.GStreamer/Banshee.GStreamer src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Equalizer src/Core/Banshee.Services/Banshee.MediaEngine src/Core/Banshee.ThickClient src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui src/Core/Banshee.ThickClient/Banshee.Gui src/Core/Banshee.ThickClient/Resources



Author: gburt
Date: Thu Jan 24 21:53:37 2008
New Revision: 3016
URL: http://svn.gnome.org/viewvc/banshee?rev=3016&view=rev

Log:
2008-01-22  Gabriel Burt  <gabriel burt gmail com>

	Patch from Alexander Hxion <hixon alexander mediati org>.

	* src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs:
	* src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerView.cs:
	* src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs:
	* src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerBandScale.cs:
	* src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerLevelsBox.cs:
	* src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerWindow.cs:
	* src/Core/Banshee.ThickClient/Makefile.am:
	* src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml:
	* src/Core/Banshee.Services/Banshee.Equalizer/EqualizerManager.cs:
	* src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSetting.cs:
	* src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSettingEvent.cs:
	* src/Core/Banshee.Services/Banshee.Services.mdp:
	* src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs:
	* src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs:
	* src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs:
	* src/Core/Banshee.Services/Banshee.MediaEngine/IEqualizer.cs:
	* src/Core/Banshee.Services/Makefile.am:
	* src/Core/Banshee.Base/banshee-core.schemas.in:
	* src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs:
	* libbanshee/gst-playback-0.10.c: Added support for graphical equalizer.
	  Fixes BGO #426562.
	  
	* src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs:
	* src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs: Added
	  new PlayerEngineState.Initalized state type; fired when engine has
	  initialized itself. Required for the equalizer to enable the user's last
	  preset just after the engine starts.


Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSettingEvent.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/libbanshee/gst-playback-0.10.c
   trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSetting.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/IEqualizer.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerBandScale.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerLevelsBox.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerView.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerWindow.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
   trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
   trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml

Modified: trunk/banshee/libbanshee/gst-playback-0.10.c
==============================================================================
--- trunk/banshee/libbanshee/gst-playback-0.10.c	(original)
+++ trunk/banshee/libbanshee/gst-playback-0.10.c	Thu Jan 24 21:53:37 2008
@@ -1,8 +1,9 @@
 /***************************************************************************
  *  gst-playback-0.10.c
  *
- *  Copyright (C) 2005-2006 Novell, Inc.
+ *  Copyright (C) 2005-2007 Novell, Inc.
  *  Written by Aaron Bockover <aaron abock org>
+ *  Contributions by Alexander Hixon <hixon alexander mediati org>
  ****************************************************************************/
 
 /*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
@@ -67,6 +68,8 @@
     GstElement *playbin;
     GstElement *audiotee;
     GstElement *audiobin;
+    GstElement *equalizer;
+    GstElement *preamp;
     
     guint iterate_timeout_id;
     gchar *cdda_device;
@@ -387,6 +390,7 @@
     GstElement *fakesink;
     GstElement *audiosink;
     GstElement *audiosinkqueue;
+    GstElement *audioconvert;
     GstPad *teepad;
     
     g_return_val_if_fail(IS_GST_PLAYBACK(engine), FALSE);
@@ -412,11 +416,20 @@
     audiosinkqueue = gst_element_factory_make("queue", "audiosinkqueue");
     g_return_val_if_fail(audiosinkqueue != NULL, FALSE);
     
+    audioconvert = gst_element_factory_make("audioconvert", "audioconvert");
+    engine->equalizer = gst_element_factory_make("equalizer-10bands", "equalizer-10bands");
+    engine->preamp = gst_element_factory_make("volume", "preamp");
+    
     // add elements to custom audio sink
     gst_bin_add(GST_BIN(engine->audiobin), engine->audiotee);
+    if(engine->equalizer != NULL) {
+        gst_bin_add(GST_BIN(engine->audiobin), audioconvert);
+        gst_bin_add(GST_BIN(engine->audiobin), engine->equalizer);
+        gst_bin_add(GST_BIN(engine->audiobin), engine->preamp);
+    }
     gst_bin_add(GST_BIN(engine->audiobin), audiosinkqueue);
     gst_bin_add(GST_BIN(engine->audiobin), audiosink);
-    
+   
     // ghost pad the audio bin
     teepad = gst_element_get_pad(engine->audiotee, "sink");
     gst_element_add_pad(engine->audiobin, gst_ghost_pad_new("sink", teepad));
@@ -426,8 +439,19 @@
     gst_pad_link(gst_element_get_request_pad(engine->audiotee, "src0"), 
         gst_element_get_pad(audiosinkqueue, "sink"));
 
-    // link the queue with the real audio sink
-    gst_element_link(audiosinkqueue, audiosink);
+    if (engine->equalizer != NULL)
+    {
+        // link in equalizer, preamp and audioconvert.
+        gst_element_link(audiosinkqueue, engine->preamp);
+        gst_element_link(engine->preamp, engine->equalizer);
+        gst_element_link(engine->equalizer, audioconvert);
+        gst_element_link(audioconvert, audiosink);
+    }
+    else
+    {
+        // link the queue with the real audio sink
+        gst_element_link(audiosinkqueue, audiosink);
+    }
     
     g_object_set(G_OBJECT(engine->playbin), "audio-sink", engine->audiobin, NULL);
     
@@ -759,3 +783,88 @@
     *resource = GST_RESOURCE_ERROR;
     *stream = GST_STREAM_ERROR;
 }
+
+gboolean
+gst_equalizer_is_supported(GstPlayback *engine)
+{
+    return (engine != NULL && engine->equalizer != NULL && engine->preamp != NULL);
+}
+
+void
+gst_equalizer_set_preamp_level(GstPlayback *engine, gdouble level)
+{
+    if (engine->equalizer != NULL && engine->preamp != NULL)
+        g_object_set (engine->preamp, "volume", level, NULL);
+}
+
+void
+gst_equalizer_set_gain(GstPlayback *engine, guint bandnum, gdouble gain)
+{
+    if (engine->equalizer != NULL) {
+        GstObject *band;   
+        band = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (engine->equalizer), bandnum);
+        g_object_set (band, "gain", gain, NULL);
+        g_object_unref (band);
+    }
+}
+
+void
+gst_equalizer_get_bandrange(GstPlayback *engine, gint *min, gint *max)
+{    
+    /*
+     * NOTE: This only refers to the newer version of the equalizer element.
+     *
+     * Yes, I know GStreamer's equalizer goes from -24 to +12, but -12 to +12 is much better for two reasons:
+     * (x) Equal levels on both sides, which means we get a nice linear y=x
+     * (x) This also makes converting other eq presets easier.
+     * (x) We get a nice roud 0 dB in the middle of the band range, instead of -6, which is stupid
+     *     since 0 dB gives us no gain, yet its not in the middle - less sense to the end user.
+     *
+     * If that didn't make any sense, yay for late-night coding. :)
+     */
+    
+    if (engine->equalizer != NULL) {
+        GParamSpecDouble *pspec;
+        
+        // Fetch gain range of first band (since it should be the same for the rest)
+        pspec = (GParamSpecDouble*) g_object_class_find_property (G_OBJECT_GET_CLASS (engine->equalizer), "band0");
+        if (pspec) {
+            // Assume old equalizer.
+            *min = pspec->minimum;
+            *max = pspec->maximum;
+        }
+        else {
+            pspec = (GParamSpecDouble*) g_object_class_find_property (G_OBJECT_GET_CLASS (engine->equalizer), "band0::gain");
+            if (pspec && pspec->maximum == 12) {
+                // New equalizer - return even scale.
+                *min = -12;
+                *max = 12;
+            }
+            else if (pspec) {
+                // Return just the ranges the equalizer supports
+                *min = pspec->minimum;
+                *max = pspec->maximum;
+            }
+            else {
+                g_warning("Could not find valid gain range for equalizer.");
+            }
+        }
+    }
+}
+
+void
+gst_equalizer_get_frequencies(GstPlayback *engine, gdouble *freq[])
+{
+    gint i;
+    gdouble bandfreq[10];
+    
+    for(i = 0; i < 10; i++) {
+        GstObject *band;
+        
+        band = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (engine->equalizer), i);
+        g_object_get (G_OBJECT (band), "freq", &bandfreq[i], NULL);
+        g_object_unref (band);
+    }
+    
+    *freq = bandfreq;
+}

Modified: trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs	Thu Jan 24 21:53:37 2008
@@ -47,7 +47,7 @@
 
     internal delegate void GstTaggerTagFoundCallback(string tagName, ref GLib.Value value, IntPtr userData);        
     
-    public class PlayerEngine : Banshee.MediaEngine.PlayerEngine
+    public class PlayerEngine : Banshee.MediaEngine.PlayerEngine, Banshee.MediaEngine.IEqualizer
     {
         private uint GST_CORE_ERROR = 0;
         private uint GST_LIBRARY_ERROR = 0;
@@ -97,7 +97,7 @@
             
             eos_callback = new GstPlaybackEosCallback(OnEos);
             error_callback = new GstPlaybackErrorCallback(OnError);
-            state_changed_callback = new GstPlaybackStateChangedCallback(OnStateChanged);
+            //state_changed_callback = new GstPlaybackStateChangedCallback(OnStateChanged);
             iterate_callback = new GstPlaybackIterateCallback(OnIterate);
             buffering_callback = new GstPlaybackBufferingCallback(OnBuffering);
             tag_found_callback = new GstTaggerTagFoundCallback(OnTagFound);
@@ -108,6 +108,8 @@
             gst_playback_set_state_changed_callback(handle, state_changed_callback);
             gst_playback_set_buffering_callback(handle, buffering_callback);
             gst_playback_set_tag_found_callback(handle, tag_found_callback);
+            
+            OnStateChanged(PlayerEngineState.Initalized);
         }
         
         public override void Dispose()
@@ -228,9 +230,9 @@
             OnEventChanged(PlayerEngineEvent.Error, error_message);
         }
         
-        private void OnStateChanged(IntPtr engine, int new_state, int old_state, int pending_state)
+        /*private void OnStateChanged(IntPtr engine, int new_state, int old_state, int pending_state)
         {
-        }
+        }*/
         
         private void OnBuffering(IntPtr engine, int progress)
         {
@@ -304,6 +306,48 @@
             get { return "GStreamer 0.10"; }
         }
         
+        public override bool SupportsEqualizer {
+            get { return gst_equalizer_is_supported(handle); }
+        }
+    
+        public double AmplifierLevel {
+            set { gst_equalizer_set_preamp_level(handle, value); }
+        }
+        
+        public int [] BandRange {
+            get
+            {
+                int min = -1;
+                int max = -1;
+                
+                gst_equalizer_get_bandrange(handle, out min, out max);
+                
+                return new int[] { min, max };
+            }
+        }
+        
+        public uint [] EqualizerFrequencies {
+            get
+            {
+                double[] freq = new double[10];
+                gst_equalizer_get_frequencies(handle, out freq);
+                
+                uint[] ret = new uint[freq.Length];
+                
+                for(int i = 0; i < freq.Length; i++)
+                {
+                    ret[i] = (uint)freq[i];
+                }
+                
+                return ret;
+            }
+        }
+        
+        public void SetEqualizerGain(uint band, double gain)
+        {
+            gst_equalizer_set_gain(handle, band, gain);
+        }
+        
         private static string [] source_capabilities = { "file", "http", "cdda" };
         public override IEnumerable SourceCapabilities {
             get { return source_capabilities; }
@@ -379,5 +423,20 @@
         [DllImport("libbanshee")]
         private static extern void gst_playback_get_error_quarks(out uint core, out uint library, 
             out uint resource, out uint stream);
+        
+        [DllImport("libbanshee")]
+        private static extern bool gst_equalizer_is_supported(HandleRef engine);
+        
+        [DllImport("libbanshee")]
+        private static extern void gst_equalizer_set_preamp_level(HandleRef engine, double level);
+        
+        [DllImport("libbanshee")]
+        private static extern void gst_equalizer_set_gain(HandleRef engine, uint bandnum, double gain);
+        
+        [DllImport("libbanshee")]
+        private static extern void gst_equalizer_get_bandrange(HandleRef engine, out int min, out int max);
+        
+        [DllImport("libbanshee")]
+        private static extern void gst_equalizer_get_frequencies(HandleRef engine, [MarshalAs(UnmanagedType.LPArray)] out double[] freq);
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerManager.cs	Thu Jan 24 21:53:37 2008
@@ -1,30 +1,31 @@
-/***************************************************************************
- *  EqualizerManager.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerManager.cs
+//
+// Authors:
+//   Aaron Bockover <abockover novell com>
+//   Alexander Hixon <hixon alexander mediati org>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
 using System.IO;
@@ -33,6 +34,8 @@
 using System.Collections.Generic;
 
 using Banshee.Base;
+using Banshee.MediaEngine;
+using Banshee.ServiceStack;
 
 namespace Banshee.Equalizer
 {
@@ -40,7 +43,6 @@
     {
         private List<EqualizerSetting> equalizers = new List<EqualizerSetting>();
         private string path;
-        private uint [] supported_bands = new uint [] { 30, 60, 120, 250, 500, 1000, 2000, 4000, 8000, 16000 };
         
         public event EqualizerSettingEventHandler EqualizerAdded;
         public event EqualizerSettingEventHandler EqualizerRemoved;
@@ -109,6 +111,45 @@
             QueueSave();
         }
         
+        public void Enable(EqualizerSetting eq)
+        {
+            if (eq != null)
+            {
+                eq.Enabled = true;
+                
+                // Make a copy of the Dictionary first, otherwise it'll become out of sync
+                // when we begin to change the gain on the bands.
+                Dictionary<uint, double> bands = new Dictionary<uint, double>(eq.Bands);
+                
+                foreach(KeyValuePair<uint, double> band in bands)
+                {
+                    eq.SetGain(band.Key, band.Value);
+                }
+                
+                // Reset preamp.
+                eq.AmplifierLevel = eq.AmplifierLevel;
+            }
+        }
+        
+        public void Disable(EqualizerSetting eq)
+        {
+            if (eq != null)
+            {
+                eq.Enabled = false;
+            
+                // Set the actual equalizer gain on all bands to 0 dB,
+                // but don't change the gain in the dictionary (we can use/change those values
+                // later, but not affect the actual audio stream until we're enabled again).
+                
+                for(uint i = 0; i < eq.BandCount; i++)
+                {
+                    ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).SetEqualizerGain(i, 0);
+                }
+                
+                ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).AmplifierLevel = 1D;
+            }
+        }
+        
         public void Load()
         {
             Load(path);
@@ -130,10 +171,10 @@
                 
                 foreach(XmlNode child in node) {
                     if(child.Name == "preamp") {
-                        eq.Preamp = Convert.ToInt32(child.InnerText);
+                        eq.AmplifierLevel = Convert.ToDouble(child.InnerText);
                     } else if(child.Name == "band") {
-                        eq.AddBand(Convert.ToUInt32(child.Attributes["frequency"].Value),
-                            Convert.ToInt32(child.InnerText));
+                        eq.SetGain(Convert.ToUInt32(child.Attributes["num"].Value),
+                            Convert.ToDouble(child.InnerText));
                     } else {
                         throw new XmlException("Invalid node, expected one of preamp or band");
                     }
@@ -155,7 +196,32 @@
             doc.AppendChild(root);
             
             foreach(EqualizerSetting eq in this) {
-                root.AppendChild(eq.SaveXml(doc));
+                XmlNode root_node = doc.CreateNode(XmlNodeType.Element, "equalizer", null);
+            
+                XmlAttribute name_node = doc.CreateAttribute("name");
+                name_node.Value = eq.Name;
+                XmlNode preamp_node = doc.CreateNode(XmlNodeType.Element, "preamp", null);
+                XmlNode preamp_node_value = doc.CreateNode(XmlNodeType.Text, "value", null);
+                preamp_node_value.Value = Convert.ToString(eq.AmplifierLevel);
+                preamp_node.AppendChild(preamp_node_value);
+                
+                root_node.Attributes.Append(name_node);
+                root_node.AppendChild(preamp_node);
+
+                foreach(KeyValuePair<uint, double> band in eq.Bands) {
+                    XmlNode band_node = doc.CreateNode(XmlNodeType.Element, "band", null);
+                    XmlNode band_node_value = doc.CreateNode(XmlNodeType.Text, "value", null);
+                    band_node_value.Value = Convert.ToString(band.Value);
+                    band_node.AppendChild(band_node_value);
+                    
+                    XmlAttribute frequency_node = doc.CreateAttribute("num");
+                    frequency_node.Value = Convert.ToString(band.Key);
+                    band_node.Attributes.Append(frequency_node);
+                    
+                    root_node.AppendChild(band_node);
+                }
+                
+                root.AppendChild(root_node);
             }
             
             doc.Save(path);
@@ -218,10 +284,5 @@
         public string Path {
             get { return path; }
         }
-        
-        public uint [] SupportedBands {
-            get { return supported_bands; }
-            set { supported_bands = value; }
-        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSetting.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSetting.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSetting.cs	Thu Jan 24 21:53:37 2008
@@ -1,171 +1,164 @@
-/***************************************************************************
- *  EqualizerSetting.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerSetting.cs
+//
+// Author:
+//   Alexander Hixon <hixon alexander mediati org>
+//
+// Copyright (C) 2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
-using System.Xml;
 using System.Collections.Generic;
 
+using Banshee.MediaEngine;
+using Banshee.ServiceStack;
+using Banshee.Configuration;
+
 namespace Banshee.Equalizer
 {
     public class EqualizerSetting
     {
         private string name;
-        private int preamp = 0;
-        private Dictionary<uint, int> bands = new Dictionary<uint, int>();
+        private Dictionary<uint, double> bands = new Dictionary<uint, double>();
+        private double amp = 1;    // dB multiplier (0db is mute, 2dB is 2x normal volume?)
+        private bool enabled = true;
+        private const uint bandcount = 10;
         
         public event EventHandler Changed;
         
-        public EqualizerSetting()
-        {
-        }
-        
         public EqualizerSetting(string name)
         {
             this.name = name;
-        }
-        
-        public void AddBand(uint band, int value)
-        {
-            if(bands.ContainsKey(band)) {
-                bands[band] = value;
-            } else {
-                bands.Add(band, value);
-            }
             
-            OnChanged();
-        }
-        
-        public void SetBand(uint band, int value)
-        {
-            AddBand(band, value);
+            // Fill in 0 dB for all bands at init.
+            for (uint i = 0; i < bandcount; i++)
+            {
+                bands.Add(i, 0);
+            }
         }
         
-        public void RemoveBand(uint band)
-        {
-            if(bands.ContainsKey(band)) {
-                bands.Remove(band);
+        /// <summary>
+        /// Human-readable name of this equalizer instance.
+        /// </summary>
+        public string Name {
+            get { return name; }
+            set
+            {
+                name = value;
+                PresetSchema.Set(this.name);
+                OnChanged();
             }
-            
-            OnChanged();
         }
         
-        public XmlNode SaveXml(XmlDocument document)
-        {
-            XmlNode root_node = document.CreateNode(XmlNodeType.Element, "equalizer", null);
-            
-            XmlAttribute name_node = document.CreateAttribute("name");
-            name_node.Value = name;
-            
-            XmlNode preamp_node = document.CreateNode(XmlNodeType.Element, "preamp", null);
-            XmlNode preamp_node_value = document.CreateNode(XmlNodeType.Text, "value", null);
-            preamp_node_value.Value = Convert.ToString(preamp);
-            preamp_node.AppendChild(preamp_node_value);
-            
-            root_node.Attributes.Append(name_node);
-            root_node.AppendChild(preamp_node);
-            
-            foreach(KeyValuePair<uint, int> band in bands) {
-                XmlNode band_node = document.CreateNode(XmlNodeType.Element, "band", null);
-                XmlNode band_node_value = document.CreateNode(XmlNodeType.Text, "value", null);
-                band_node_value.Value = Convert.ToString(band.Value);
-                band_node.AppendChild(band_node_value);
+        public bool Enabled {
+            get { return enabled; }
+            set
+            {
+                enabled = value;
+                EnabledSchema.Set(value);
                 
-                XmlAttribute frequency_node = document.CreateAttribute("frequency");
-                frequency_node.Value = Convert.ToString(band.Key);
-                band_node.Attributes.Append(frequency_node);
-                
-                root_node.AppendChild(band_node);
+                // Make this the new default preset (last changed).
+                PresetSchema.Set(this.name);
             }
-            
-            return root_node;
         }
         
-        protected virtual void OnChanged()
-        {
-            EventHandler handler = Changed;
-            if(handler != null) {
-                handler(this, new EventArgs());
-            }
+        public Dictionary<uint, double> Bands {
+            get { return bands; }
         }
         
-        public int this[uint band] {
-            get { return bands[band]; }
-            set { SetBand(band, value); }
-        
+        public uint BandCount {
+            get { return bandcount; }
         }
         
-        public string Name {
-            get { return name; }
-            set { 
-                name = value; 
-                OnChanged();
+        /// <summary>
+        /// Sets/gets the preamp gain.
+        /// </summary>
+        public double AmplifierLevel {
+            get
+            {
+                return amp;
             }
-        }
-        
-        public int Preamp {
-            get { return preamp; }
-            set { 
-                preamp = value; 
+            set
+            {
+                amp = value;
+                if (enabled)
+                {
+                    ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).AmplifierLevel = value;
+                }
                 OnChanged();
             }
         }
 
-        public uint [] Bands {
-            get { 
-                uint [] bands_array = new uint[bands.Count];
-                bands.Keys.CopyTo(bands_array, 0);
-                return bands_array;
+        /// <summary>
+        /// Sets the gain on a selected band.
+        /// </summary>
+        /// <param name="band">The band to adjust gain.</param>
+        /// <param name="val">The value in dB to set the band gain to.</param>
+        public void SetGain(uint band, double val)
+        {
+            if (bands.ContainsKey(band))
+            {
+                bands[band] = val;
+            }
+            else
+            {
+                bands.Add(band, val);
+            }
+            
+            // Tell engine that we've changed.
+            if (enabled)
+            {
+                ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).SetEqualizerGain(band, val);
             }
+            
+            OnChanged();
         }
         
-        public int [] Values {
-            get { 
-                int [] values_array = new int[bands.Count];
-                bands.Values.CopyTo(values_array, 0);
-                return values_array;
-            }
+        public double this[uint band] {
+            get { return bands[band]; }
+            set { SetGain(band, value); }
         }
-    }
-    
-    
-    public delegate void EqualizerSettingEventHandler(object o, EqualizerSettingEventArgs args);
-    
-    public class EqualizerSettingEventArgs : EventArgs
-    {
-        private EqualizerSetting eq;
         
-        public EqualizerSettingEventArgs(EqualizerSetting eq)
+        protected virtual void OnChanged()
         {
-            this.eq = eq;
+            EventHandler handler = Changed;
+            if (handler != null)
+            {
+                handler(this, new EventArgs());
+            }
         }
         
-        public EqualizerSetting EqualizerSetting {
-            get { return eq; }
-        }
+        public static readonly SchemaEntry<bool> EnabledSchema = new SchemaEntry<bool>(
+            "player", "equalizer_enabled",
+            false,
+            "Equalizer status",
+            "Whether or not the equalizer is set to be enabled."
+        );
+        
+        public static readonly SchemaEntry<string> PresetSchema = new SchemaEntry<string>(
+            "player", "equalizer_preset",
+            "",
+            "Equalizer preset",
+            "Default preset to load into equalizer."
+        );
     }
 }

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSettingEvent.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Equalizer/EqualizerSettingEvent.cs	Thu Jan 24 21:53:37 2008
@@ -0,0 +1,48 @@
+//
+// EqualizerSettingEvent.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Banshee.Equalizer
+{
+    public delegate void EqualizerSettingEventHandler(object o, EqualizerSettingEventArgs args);
+    
+    public class EqualizerSettingEventArgs : EventArgs
+    {
+        private EqualizerSetting eq;
+        
+        public EqualizerSettingEventArgs(EqualizerSetting eq)
+        {
+            this.eq = eq;
+        }
+        
+        public EqualizerSetting EqualizerSetting {
+            get { return eq; }
+        }
+    }
+}
\ No newline at end of file

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/IEqualizer.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/IEqualizer.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/IEqualizer.cs	Thu Jan 24 21:53:37 2008
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Aaron Bockover <abockover novell com>
+//   Alexander Hixon <hixon alexander mediati org>
 //
 // Copyright (C) 2006-2007 Novell, Inc.
 //
@@ -26,19 +27,37 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
+
 namespace Banshee.MediaEngine
 {
     public interface IEqualizer
     {
-        void SetEqualizerGain(uint frequency, int value);
+        /// <summary>
+        /// Sets the gain of an equalizer band.
+        /// </summary>
+        void SetEqualizerGain(uint band, double value);
         
-        uint [] EqualizerFrequencies {
+        /// <summary>
+        /// Whether or not the engine supports the equalizer.
+        /// </summary>
+        bool SupportsEqualizer {
             get;
         }
         
-        int AmplifierLevel {
-            get;
+        double AmplifierLevel {
             set;
         }
+        
+        /// <summary>
+        /// Minimum and maximum dB values for equalizer bands.
+        /// </summary>
+        int [] BandRange {
+            get;
+        }
+        
+        uint [] EqualizerFrequencies {
+            get;
+        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs	Thu Jan 24 21:53:37 2008
@@ -249,5 +249,9 @@
         public abstract string Name {
             get;
         }
+        
+        public abstract bool SupportsEqualizer {
+            get;
+        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	Thu Jan 24 21:53:37 2008
@@ -40,6 +40,7 @@
 using Banshee.Metadata;
 using Banshee.Configuration;
 using Banshee.Collection;
+using Banshee.Equalizer;
 
 namespace Banshee.MediaEngine
 {
@@ -138,7 +139,35 @@
             if(args.State == PlayerEngineState.Loaded && CurrentTrack != null) {
                 active_engine.Volume = (ushort)VolumeSchema.Get ();
                 MetadataService.Instance.Lookup(CurrentTrack);
-            } 
+            } else if (args.State == PlayerEngineState.Initalized) {
+                // Enable our preferred equalizer if it exists and was enabled last time.
+                if (this.SupportsEqualizer && EqualizerSetting.EnabledSchema.Get())
+                {
+                    string name = EqualizerSetting.PresetSchema.Get();
+                    
+                    if (name != "")
+                    {
+                        // Don't use EqualizerManager.Instance - used by the eq dialog window.
+                        EqualizerManager manager = new EqualizerManager(EqualizerManager.Instance.Path);
+                        manager.Load();
+                        EqualizerSetting equalizer = null;
+                        foreach(EqualizerSetting eq in manager)
+                        {
+                            if (eq.Name == name)
+                            {
+                                equalizer = eq;
+                                break;
+                            }
+                        }
+                        
+                        if (equalizer != null)
+                        {
+                            Log.DebugFormat("Enabling equalizer preset: {0}", equalizer.Name);
+                            manager.Enable(equalizer);
+                        }
+                    }
+                }
+            }
             
             PlayerEngineStateHandler handler = StateChanged;
             if(handler != null) {
@@ -393,6 +422,10 @@
             get { return CurrentTrack != null && !CurrentTrack.IsLive; }
         }
         
+        public bool SupportsEqualizer {
+            get { return ((active_engine is IEqualizer) && active_engine.SupportsEqualizer); }
+        }
+        
         public uint Length {
             get { 
                 uint length = active_engine.Length;

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineState.cs	Thu Jan 24 21:53:37 2008
@@ -44,6 +44,7 @@
         Contacting,
         Loaded,
         Playing,
-        Paused
+        Paused,
+        Initalized
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	Thu Jan 24 21:53:37 2008
@@ -30,7 +30,6 @@
     <File name="Banshee.ServiceStack/IService.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources/ISource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.ServiceStack/ServiceStartedHandler.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.MediaEngine/IEqualizer.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/PlayerEngine.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/PlayerEngineState.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/PlayerEngineEvent.cs" subtype="Code" buildaction="Compile" />
@@ -75,6 +74,10 @@
     <File name="Banshee.Playlists.Formats.Xspf/XspfBaseObject.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Web/Browser.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Streaming/RadioTrackInfo.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Equalizer/EqualizerSetting.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Equalizer/EqualizerSettingEvent.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Equalizer/EqualizerManager.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.MediaEngine/IEqualizer.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Services.addins" subtype="Code" buildaction="EmbedAsResource" />
     <File name="Banshee.Sources/ErrorSource.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/IPlayerEngineService.cs" subtype="Code" buildaction="Compile" />

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Thu Jan 24 21:53:37 2008
@@ -30,6 +30,9 @@
 	Banshee.Database/BansheeDbFormatMigrator.cs \
 	Banshee.Database/BansheeModelCache.cs \
 	Banshee.Database/BansheeModelProvider.cs \
+	Banshee.Equalizer/EqualizerManager.cs \
+	Banshee.Equalizer/EqualizerSetting.cs \
+	Banshee.Equalizer/EqualizerSettingEvent.cs \
 	Banshee.Library/HomeDirectoryImportSource.cs \
 	Banshee.Library/IImportSource.cs \
 	Banshee.Library/ImportSourceManager.cs \

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerBandScale.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerBandScale.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerBandScale.cs	Thu Jan 24 21:53:37 2008
@@ -1,30 +1,30 @@
-/***************************************************************************
- *  EqualizerBandScale.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerBandScale.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
 using Gtk;
@@ -33,15 +33,15 @@
 {
     public class EqualizerBandScale : HBox
     {
-        private uint frequency;
+        private uint band;
         private Scale scale;
         private Label label;
         
         public event EventHandler ValueChanged;
     
-        public EqualizerBandScale(uint frequency, string labelText)
+        public EqualizerBandScale(uint band, int median, int min, int max, string labelText)
         {
-            this.frequency = frequency;
+            this.band = band;
             
             label = new Label();
             label.Markup = String.Format("<small>{0}</small>", GLib.Markup.EscapeText(labelText));
@@ -49,7 +49,8 @@
             label.Yalign = 1.0f;
             label.Angle = 90.0;
 
-            scale = new VScale(new Adjustment(0, -100, 100, 15, 15, 1));
+            // new Adjustment(value, lower, upper, step_incr, page_incr, page_size);
+            scale = new VScale(new Adjustment(median, min, max, max / 10, max / 10, 1));
             scale.DrawValue = false;
             scale.Inverted = true;
             scale.ValueChanged += OnValueChanged;
@@ -79,8 +80,8 @@
             set { label.Visible = value; }
         }
         
-        public uint Frequency {
-            get { return frequency; }
+        public uint Band {
+            get { return band; }
         }
     }   
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerLevelsBox.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerLevelsBox.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerLevelsBox.cs	Thu Jan 24 21:53:37 2008
@@ -1,30 +1,30 @@
-/***************************************************************************
- *  EqualizerLevelsBox.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerLevelsBox.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
 using Gtk;

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs	Thu Jan 24 21:53:37 2008
@@ -1,30 +1,30 @@
-/***************************************************************************
- *  EqualizerPresetComboBox.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerPresetComboBox.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
 using Gtk;
@@ -95,6 +95,25 @@
             }
         }
         
+        public bool ActivatePreferredEqualizer(string name)
+        {
+            if (name == null || name == "")
+            {
+                return ActivateFirstEqualizer();
+            }
+            else
+            {
+                foreach(EqualizerSetting eq in manager) {
+                    if (eq.Name == name) {
+                        ActiveEqualizer = eq;
+                        return true;
+                    }
+                }
+                
+                return false;
+            }
+        }
+        
         public bool ActivateFirstEqualizer()
         {
             TreeIter iter;

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerView.cs	Thu Jan 24 21:53:37 2008
@@ -1,31 +1,32 @@
-/***************************************************************************
- *  Equalizer.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- *             Ivan N. Zlatev <contact i-nZ.net>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerView.cs
+//
+// Authors:
+//   Aaron Bockover <abockover novell com>
+//   Ivan N. Zlatev <contact i-nZ.net>
+//   Alexander Hixon <hixon alexander mediati org>
+//
+// Copyright (C) 2006-2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
 using System.Collections;
@@ -33,15 +34,19 @@
 using Gtk;
 using Gdk;
 
+using Banshee.ServiceStack;
+using Banshee.MediaEngine;
+
 namespace Banshee.Equalizer.Gui
 {
     public class EqualizerView : HBox
     {
         private HBox band_box;
-        private uint [] bands;
+        private uint [] frequencies;
         private EqualizerBandScale [] band_scales;
         private EqualizerBandScale amplifier_scale;
         private EqualizerSetting active_eq;
+        private int [] range = new int[3];
         
         public event EqualizerChangedEventHandler EqualizerChanged;
         public event AmplifierChangedEventHandler AmplifierChanged;
@@ -55,12 +60,25 @@
         {
             Spacing = 10;
         
-            amplifier_scale = new EqualizerBandScale(0, "Preamp");
+            // amplifier_scale's values must be divisible by 100 to get *real* val. eg 100 == 1, 40 == 0.4, 1 == 0.01
+            amplifier_scale = new EqualizerBandScale(0, 100, 5, 150, "Preamp");
             amplifier_scale.ValueChanged += OnAmplifierValueChanged;
             amplifier_scale.Show();
             PackStart(amplifier_scale, false, false, 0);
             
-            EqualizerLevelsBox eq_levels = new EqualizerLevelsBox("+20 dB", "0 dB", "-20 dB");
+            int[] br = ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).BandRange;
+            int mid = (br[0] + br[1]) / 2;
+            
+            range[0] = br[0];
+            range[1] = mid;
+            range[2] = br[1];
+            
+            EqualizerLevelsBox eq_levels = new EqualizerLevelsBox(
+                FormatDecibelString(range[2]),
+                FormatDecibelString(range[1]),
+                FormatDecibelString(range[0])
+            );
+            
             eq_levels.Show();
             PackStart(eq_levels, false, false, 0);
             
@@ -72,26 +90,35 @@
             BuildBands();
         }
         
+        /// <summary>
+        /// Utility function to create a dB string for the levels box.
+        /// </summary>
+        private string FormatDecibelString(int db)
+        {
+            if (db > 0) { return String.Format("+{0} dB", db); } else { return String.Format("{0} dB", db); }
+        }
+        
         private void BuildBands()
         {
             foreach(Widget widget in band_box.Children) {
                 band_box.Remove(widget);
             }
             
-            if(bands == null || bands.Length <= 0) {
-                bands = new uint[0];
+            if(frequencies == null || frequencies.Length <= 0) {
+                frequencies = new uint[0];
                 band_scales = new EqualizerBandScale[0];
                 return;
             }
-
-            band_scales = new EqualizerBandScale[bands.Length];
             
-            for(uint i = 0; i < bands.Length; i++) {
-                string label = bands[i] < 1000 ? 
-                    String.Format("{0} Hz", bands[i]) :
-                    String.Format("{0} kHz", bands[i] / 1000);
+            band_scales = new EqualizerBandScale[10];
+            
+            for(uint i = 0; i < 10; i++) {
+                string label = frequencies[i] < 1000 ? 
+                    String.Format("{0} Hz", frequencies[i]) :
+                    String.Format("{0} kHz", frequencies[i] / 1000);
                     
-                band_scales[i] = new EqualizerBandScale(bands[i], label);
+                //band_scales[i] = new EqualizerBandScale(bands[i], label);
+                band_scales[i] = new EqualizerBandScale(i, range[1] * 10, range[0] * 10, range[2] * 10, label);
                 band_scales[i].ValueChanged += OnEqualizerValueChanged;
                 band_scales[i].Show();
                 
@@ -103,26 +130,21 @@
         {
             EqualizerBandScale scale = o as EqualizerBandScale;
             
-            if(scale.Value >= -13 && scale.Value <= 13) {
-                scale.Value = 0;
-                return;
-            } else if(active_eq != null) {
-                active_eq.SetBand(scale.Frequency, scale.Value);
+            if(active_eq != null) {
+                active_eq.SetGain(scale.Band, (double)scale.Value / 10D);
             }
             
             if(EqualizerChanged != null) {
-                EqualizerChanged(this, new EqualizerChangedEventArgs(scale.Frequency, scale.Value));
+                EqualizerChanged(this, new EqualizerChangedEventArgs(scale.Band, scale.Value));
             }
         }
 
         private void OnAmplifierValueChanged(object o, EventArgs args)
         {
             EqualizerBandScale scale = o as EqualizerBandScale;
-            if(scale.Value >= -13 && scale.Value <= 13) {
-                scale.Value = 0;
-                return;
-            } else if(active_eq != null) {
-                active_eq.Preamp = scale.Value;
+            if(active_eq != null) {
+                double val = (double)scale.Value / 100D;
+                active_eq.AmplifierLevel = val;
             }
             
             if(AmplifierChanged != null) {
@@ -130,10 +152,10 @@
             }
         }    
             
-        public uint [] Bands {
-            get { return (uint [])bands.Clone(); }
+        public uint [] Frequencies {
+            get { return (uint [])frequencies.Clone(); }
             set { 
-                bands = (uint [])value.Clone();
+                frequencies = (uint [])value.Clone();
                 BuildBands();
             }
         }
@@ -149,41 +171,20 @@
             }
             
             set {
-                if(value.Length == bands.Length) {                
-                    for(int i = 0; i < value.Length; i++) {
-                        if(value[i] < -100 || value[i] > 100) {
-                            value[i] = 0;
-                        }
-                        
-                        band_scales[i].Value = value[i];                   
-                    }
+                for(int i = 0; i < value.Length; i++) {
+                    band_scales[i].Value = value[i];                   
                 }
             }
         }
         
-        public void SetBand(uint band, int value)
+        public void SetBand(uint band, double value)
         {
-            if(value < -100 || value > 100) {
-                value = 0;
-            }
-        
-            for(int i = 0; i < bands.Length; i++) {
-                if(bands[i] == band) {
-                    band_scales[i].Value = value;
-                    return;
-                }
-            }
+            band_scales[band].Value = (int)(value * 10);
         }
 
-        public int AmplifierLevel {
-            get { return (int)amplifier_scale.Value; }
-            set {
-                if(value < -100 || value > 100) {
-                    value = 0;
-                }
-                
-                amplifier_scale.Value = value;
-            }
+        public double AmplifierLevel {
+            get { return (double)amplifier_scale.Value / 100D; }
+            set { amplifier_scale.Value = (int)(value * 100); }
         }
         
         public EqualizerSetting EqualizerSetting {
@@ -194,22 +195,14 @@
                 if(active_eq == null) {
                     AmplifierLevel = 0;
                     
-                    for(int i = 0; i < bands.Length; i++) {
-                        SetBand(bands[i], 0);
-                    }
-                    
                     return;
                 }
                 
-                AmplifierLevel = active_eq.Preamp;
+                AmplifierLevel = active_eq.AmplifierLevel;
                 
-                for(int i = 0; i < bands.Length; i++) {
-                    SetBand(bands[i], 0);
-                    
-                    try {
-                        SetBand(bands[i], active_eq[bands[i]]);
-                    } catch {
-                    }
+                for(int i = 0; i < active_eq.BandCount; i++) {
+                    uint x = (uint)i;
+                    SetBand(x, active_eq[x]);
                 }
             }
         }
@@ -220,17 +213,17 @@
     
     public sealed class EqualizerChangedEventArgs : EventArgs
     {
-        private uint freq;
+        private uint band;
         private int value;
 
-        public EqualizerChangedEventArgs(uint frequency, int value)
+        public EqualizerChangedEventArgs(uint band, int value)
         {
-            this.freq = frequency;
+            this.band = band;
             this.value = value;
         }
 
-        public uint Frequency {
-            get { return this.freq; }
+        public uint Band {
+            get { return this.band; }
         }
 
         public int Value {
@@ -251,4 +244,4 @@
             get { return this.value; }
         }
     }
-}
\ No newline at end of file
+}

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerWindow.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerWindow.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Equalizer.Gui/EqualizerWindow.cs	Thu Jan 24 21:53:37 2008
@@ -1,71 +1,100 @@
-/***************************************************************************
- *  EqualizerWindow.cs
- *
- *  Copyright (C) 2006 Novell, Inc.
- *  Written by Aaron Bockover <aaron abock org>
- *             Ivan N. Zlatev <contact i-nZ.net>
- ****************************************************************************/
-
-/*  THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a
- *  copy of this software and associated documentation files (the "Software"),  
- *  to deal in the Software without restriction, including without limitation  
- *  the rights to use, copy, modify, merge, publish, distribute, sublicense,  
- *  and/or sell copies of the Software, and to permit persons to whom the  
- *  Software is furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in 
- *  all copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
- *  DEALINGS IN THE SOFTWARE.
- */
+//
+// EqualizerWindow.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//   Alexander Hixon <hixon alexander mediati org>
+//
+// Copyright (C) 2006-2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 
 using System;
-
+using System.Collections;
+using Mono.Unix;
 using Gtk;
 using Glade;
-using Mono.Unix;
 
-using Banshee.Gui;
+using Banshee.Base;
+using Banshee.Gui.Dialogs;
+using Banshee.Gui.Widgets;
+using Banshee.ServiceStack;
+using Banshee.MediaEngine;
+using Banshee.Equalizer;
 
 namespace Banshee.Equalizer.Gui
 {
-    public class EqualizerEditor : GladeWindow
+    public class EqualizerWindow : GladeWindow
     {
         private EqualizerView eq_view;
         private EqualizerPresetComboBox eq_preset_combo;
+        [Widget] private CheckButton eq_enabled_checkbox;
         
-        //[Widget] private ComboBoxEntry preset_combobox;
-        
-        public EqualizerEditor() : base("EqualizerWindow")
+        public EqualizerWindow() : base("EqualizerWindow")
         {
             eq_view = new EqualizerView();
             eq_view.BorderWidth = 10;
             eq_view.SetSizeRequest(-1, 110);
-            eq_view.Bands = EqualizerManager.Instance.SupportedBands;
+            eq_view.Frequencies = ((IEqualizer)ServiceManager.PlayerEngine.ActiveEngine).EqualizerFrequencies;
             eq_view.Show();
             
+            eq_enabled_checkbox = (Glade["eq_enabled_checkbox"] as CheckButton);
+            
             eq_preset_combo = new EqualizerPresetComboBox();
             eq_preset_combo.Changed += OnPresetChanged;
-            eq_preset_combo.ActivateFirstEqualizer();
             eq_preset_combo.Show();
             
             Window.Realized += delegate {
                 Widget header = Glade["eq_header_evbox"];
                 header.ModifyBg(StateType.Normal, header.Style.Background(StateType.Active));
+                Window.Show();
             };
             
             (Glade["eq_view_box"] as Box).PackStart(eq_view, true, true, 0);
             (Glade["eq_preset_box"] as Box).PackStart(eq_preset_combo, true, false, 0);
             (Glade["new_preset_button"] as Button).Clicked += OnNewPreset;
             (Glade["delete_preset_button"] as Button).Clicked += OnDeletePreset;
+            
+            eq_enabled_checkbox.Active = EqualizerSetting.EnabledSchema.Get();
+            eq_preset_combo.ActivatePreferredEqualizer(EqualizerSetting.PresetSchema.Get());
+            
+            if(eq_enabled_checkbox.Active)
+            {
+                // enable equalizer if was enabled last session
+                EqualizerManager.Instance.Enable(eq_preset_combo.ActiveEqualizer);
+            }
+            
+            if (eq_preset_combo.ActiveEqualizer == null)
+            {
+                // user has no presets, so create one
+                OnNewPreset(null, null);
+                
+                // enable our new preset (it has no effect though, since all bands are 0db)
+                eq_enabled_checkbox.Active = true;
+                OnEnableDisable(null, null);    // notify engine and save it for next session
+            }
+            
+            eq_enabled_checkbox.Clicked += OnEnableDisable;
+            
+            Window.Show();
         }
          
         private void OnNewPreset(object o, EventArgs args)
@@ -85,7 +114,18 @@
         {
             if(eq_preset_combo.ActiveEqualizer != eq_view.EqualizerSetting) {
                 eq_view.EqualizerSetting = eq_preset_combo.ActiveEqualizer;
+                
+                OnEnableDisable(null, null);
+            }
+        }
+        
+        private void OnEnableDisable(object o, EventArgs args)
+        {
+            if (eq_enabled_checkbox.Active) {
+                EqualizerManager.Instance.Enable(eq_preset_combo.ActiveEqualizer);
+            } else {
+                EqualizerManager.Instance.Disable(eq_preset_combo.ActiveEqualizer);
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs	Thu Jan 24 21:53:37 2008
@@ -1,10 +1,11 @@
 //
 // ViewActions.cs
 //
-// Author:
+// Authors:
 //   Aaron Bockover <abockover novell com>
+//   Alexander Hixon <hixon alexander mediati org>
 //
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -30,15 +31,25 @@
 using Mono.Unix;
 using Gtk;
 
+using Banshee.MediaEngine;
+using Banshee.ServiceStack;
+using Banshee.Equalizer.Gui;
+
 namespace Banshee.Gui
 {
     public class ViewActions : ActionGroup
     {
+        private InterfaceActionService action_service;
+    
         public ViewActions (InterfaceActionService actionService) : base ("View")
         {
             Add (new ActionEntry [] {
                 new ActionEntry ("ViewMenuAction", null,
                     Catalog.GetString ("_View"), null, null, null),
+                    
+                new ActionEntry ("ShowEqualizerAction", null,
+                   Catalog.GetString ("_Equalizer"), null,
+                   Catalog.GetString ("View the graphical equalizer"), OnShowEqualizer)
             });
             
             Add (new ToggleActionEntry [] {               
@@ -48,8 +59,24 @@
                 
                 new ToggleActionEntry ("ShowCoverArtAction", null,
                     Catalog.GetString ("Show Cover _Art"), null,
-                    Catalog.GetString ("Toggle display of album cover art"), null, false),              
+                    Catalog.GetString ("Toggle display of album cover art"), null, false),
             });
+            
+            ServiceManager.PlayerEngine.StateChanged += OnPlayerEngineStateChanged;
+            action_service = actionService;
+        }
+        
+        private void OnPlayerEngineStateChanged (object o, PlayerEngineStateArgs args)
+        {            
+            if (args.State == PlayerEngineState.Initalized && !ServiceManager.PlayerEngine.SupportsEqualizer)
+            {
+                action_service["View.ShowEqualizerAction"].Sensitive = false;
+            }
+        }
+                
+        private void OnShowEqualizer (object o, EventArgs args)
+        {
+            EqualizerWindow eqwin = new EqualizerWindow();
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp	Thu Jan 24 21:53:37 2008
@@ -29,6 +29,7 @@
     <File name="Banshee.Gui/InterfaceActionService.cs" subtype="Code" buildaction="Compile" />
     <File name="Resources/core-ui-actions-layout.xml" subtype="Code" buildaction="EmbedAsResource" />
     <File name="Banshee.Gui/PlaybackActions.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Gui/ViewActions.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Gui/GlobalActions.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Gui.Widgets/ConnectedVolumeButton.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection.Gui/ColumnCellPlaybackIndicator.cs" subtype="Code" buildaction="Compile" />

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	Thu Jan 24 21:53:37 2008
@@ -19,6 +19,11 @@
 	Banshee.Collection.Gui/ColumnCellPlaybackIndicator.cs \
 	Banshee.Collection.Gui/CompositeTrackListView.cs \
 	Banshee.Collection.Gui/TrackListView.cs \
+	Banshee.Equalizer.Gui/EqualizerBandScale.cs \
+	Banshee.Equalizer.Gui/EqualizerLevelsBox.cs \
+	Banshee.Equalizer.Gui/EqualizerPresetComboBox.cs \
+	Banshee.Equalizer.Gui/EqualizerView.cs \
+	Banshee.Equalizer.Gui/EqualizerWindow.cs \
 	Banshee.Gui.Dialogs/AboutDialog.cs \
 	Banshee.Gui.Dialogs/ConfirmShutdownDialog.cs \
 	Banshee.Gui.Dialogs/ErrorListDialog.cs \

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml	Thu Jan 24 21:53:37 2008
@@ -44,6 +44,8 @@
             <placeholder name="BrowserViews" />
             <placeholder name="ViewMenuAdditions" />
             <menuitem name="FullScreen" action="FullScreenAction" />
+            <separator />
+            <menuitem name="ShowEqualizer" action="ShowEqualizerAction" />
         </menu>
 
         <menu name="PlaybackMenu" action="PlaybackMenuAction">



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]