Permalink
Browse files

First commit and starting with the equalizer plugin.

  • Loading branch information...
0 parents commit 036b30c967d37c03148b5ecc43f9030ac5164de4 @luqmana committed Oct 22, 2011
Showing with 1,268 additions and 0 deletions.
  1. +2 −0 README
  2. +90 −0 equalizer/Conf.py
  3. +111 −0 equalizer/ConfDialog.py
  4. +70 −0 equalizer/__init__.py
  5. +593 −0 equalizer/equalizer-prefs.glade
  6. +14 −0 equalizer/equalizer-ui.xml
  7. +9 −0 equalizer/equalizer.rb-plugin
  8. +379 −0 equalizer/equalizer.svg
2 README
@@ -0,0 +1,2 @@
+This is just a single repo to consolidate my efforts in porting various
+Rhythmbox plugins to work with the new plugin api.
@@ -0,0 +1,90 @@
+# Conf.py
+#
+# Copyright (C) 2008 - Teemu Kallio <teemu.kallio@cs.helsinki.fi>
+# 2009-2010 - Floreal Morandat <morandat AT lirmm DOT fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+import gconf
+
+EQUALIZER_GCONF_PREFIX = '/apps/rhythmbox/plugins/equalizer'
+EQUALIZER_PRESET = 'preset'
+
+class Config:
+ def __init__(self):
+
+ self.gconf_keys = [ 'band0',
+ 'band1',
+ 'band2',
+ 'band3',
+ 'band4',
+ 'band5',
+ 'band6',
+ 'band7',
+ 'band8',
+ 'band9']
+
+ self.gconf = gconf.client_get_default()
+ self.config = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0,0]
+ if self.gconf.get_string(EQUALIZER_GCONF_PREFIX+'/'+EQUALIZER_PRESET):
+ self.preset = self.gconf.get_string(EQUALIZER_GCONF_PREFIX+'/'+EQUALIZER_PRESET)
+ else:
+ self.preset = "default"
+
+ self.read_settings(self.preset)
+
+ def read_settings(self, preset):
+ for i in range(0,10):
+ self.config[i] = self.read_value(preset, self.gconf_keys[i], self.config[i])
+
+ def apply_settings(self, eq):
+ for i in range(0, 10):
+ eq.set_property('band' + `i`, self.config[i])
+
+ def write_settings(self):
+ preset = self.preset
+ self.gconf.set_string(EQUALIZER_GCONF_PREFIX+'/'+EQUALIZER_PRESET, preset)
+ for i in range(0, 10):
+ self.gconf.set_float(self.make_path(self.gconf_keys[i], preset), self.config[i])
+
+ def make_path(self, path, preset):
+ return EQUALIZER_GCONF_PREFIX+'/' + preset + '/' + path
+
+ def list_preset(self):
+ return self.gconf.all_dirs(EQUALIZER_GCONF_PREFIX)
+
+ def read_value(self, preset, value, default):
+ gc = self.gconf
+ path = self.make_path(value, preset)
+ rv = gc.get_float(path)
+ if(not rv):
+ rv = default
+ #gc.set_float(path, default)
+ return rv
+
+ def change_preset(self, new_preset, eq):
+ self.preset = self.mangle(new_preset)
+ self.read_settings(self.preset)
+ self.apply_settings(eq)
+
+ def preset_exists(self, preset):
+ return self.gconf.dir_exists(EQUALIZER_GCONF_PREFIX+'/' + preset)
+
+ def mangle(self, preset):
+ #return preset
+ return preset.replace(' ', '_')
+
+ def demangle(self, preset):
+ #return preset
+ return preset.replace('_', ' ')
@@ -0,0 +1,111 @@
+# ConfDialog.py
+#
+# Copyright (C) 2008 - Teemu Kallio <teemu.kallio@cs.helsinki.fi>
+# 2009-2010 - Floreal Morandat <morandat AT lirmm DOT fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+import gtk, gtk.glade
+import gnomevfs, gnome
+import Conf
+
+STOCK_IMAGE = "stock-equalizer-button"
+
+class ConfDialog(object):
+ def __init__(self, glade_file, conf, eq):
+ self.eq = eq
+ self.conf = conf
+ gladexml = gtk.glade.XML(glade_file)
+
+ self.dialog = gladexml.get_widget('preferences_dialog')
+ self.dialog.connect("response", self.dialog_response)
+
+ box = gladexml.get_widget("presetchooser")
+ self.box = box
+ self.read_presets()
+ #box.connect("changed", self.preset_change)
+ box.child.connect("changed", self.preset_change)
+
+ self.bands = []
+ for i in range(0,10):
+ self.bands.append(gladexml.get_widget("b" + `i`))
+ self.bands[i].connect("value_changed", self.slider_changed)
+ self.update_bands()
+ #gc.set_float(path, default)
+ conf.apply_settings(eq)
+
+ def read_presets(self):
+ box = self.box
+ conf = self.conf
+ box.get_model().clear()
+ i = 0
+ current = conf.demangle(conf.preset)
+ for str in conf.list_preset():
+ preset_entry = conf.demangle(str.rsplit('/',1)[1])
+ box.append_text(preset_entry)
+ if preset_entry == current:
+ box.set_active(i)
+ i += 1
+
+ def update_bands(self):
+ for i in range(0, 10):
+ self.bands[i].set_value(self.conf.config[i])
+
+ def get_dialog(self):
+ return self.dialog
+
+ def dialog_response(self, dialog, response):
+ if(response == -6):
+ for i in range(0, 10):
+ self.conf.config[i] = 0.0
+ self.update_bands()
+
+ if(response == -4 or response == -7):
+ self.conf.write_settings()
+ dialog.hide()
+
+ def preset_change(self, entry):
+ new_preset = entry.get_text()
+ if new_preset != '':
+ self.conf.change_preset(entry.get_text(), self.eq)
+ self.update_bands()
+
+ def slider_changed(self, hscale):
+ eq = self.eq
+ if eq == None:
+ return
+ i = self.bands.index(hscale)
+ val = self.bands[i].get_value()
+ self.conf.config[i] = val
+ eq.set_property('band' + `i`, val)
+
+ def add_ui(self, plugin, shell):
+ icon_factory = gtk.IconFactory()
+ icon_factory.add(STOCK_IMAGE, gtk.IconSet(gtk.gdk.pixbuf_new_from_file(plugin.find_file("equalizer.svg"))))
+ icon_factory.add_default()
+
+ action = gtk.Action ('Equalize',
+ _('_Equalizer'),
+ _('10 Band Equalizer'),
+ STOCK_IMAGE)
+ action.connect ('activate', self.show_ui, shell)
+ action_group = gtk.ActionGroup ('EqualizerActionGroup')
+ action_group.add_action (action)
+ shell.get_ui_manager().insert_action_group (action_group, -1)
+ ui_manager = shell.get_ui_manager()
+ ui_manager.add_ui_from_file(plugin.find_file("equalizer-ui.xml"))
+
+ def show_ui(self, shell, state):
+ self.read_presets()
+ self.get_dialog().present()
@@ -0,0 +1,70 @@
+# __init__.py
+# Copyright (C) 2008 - Teemu Kallio <teemu.kallio@cs.helsinki.fi>
+# 2009-2010 - Floreal Morandat <morandat AT lirmm DOT fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+import rb, rhythmdb
+import gst
+from ConfDialog import ConfDialog
+import Conf
+
+class EqualizerPlugin(rb.Plugin):
+
+ def __init__(self):
+ rb.Plugin.__init__(self)
+
+ def activate(self, shell):
+ self.shell = shell
+ self.conf = Conf.Config()
+ eq = gst.element_factory_make("equalizer-10bands")
+ self.eq = eq
+ self.conf.apply_settings(eq)
+ glade_f = self.find_file("equalizer-prefs.glade")
+ dialog = ConfDialog(glade_f, self.conf, eq)
+ dialog.add_ui(self, shell)
+ self.dialog = dialog
+ sp = shell.get_player()
+ sp.connect ('playing-song-changed', self.playing_entry_changed)
+
+ if(shell.props.shell_player.get_playing()):
+ sp.stop()
+ sp.props.player.add_filter(eq)
+ sp.play()
+ else:
+ sp.props.player.add_filter(eq)
+
+ def deactivate(self, shell):
+ if(shell.props.shell_player.get_playing()):
+ shell.props.shell_player.stop()
+ shell.get_player().props.player.remove_filter(self.eq)
+ shell.props.shell_player.play()
+ else:
+ shell.get_player().props.player.remove_filter(self.eq)
+ del self.shell
+ del self.conf
+ del self.dialog
+ del self.eq
+
+ def playing_entry_changed (self, sp, entry):
+ if entry == None:
+ return
+ genre = self.shell.props.db.entry_get(entry, rhythmdb.PROP_GENRE)
+ if self.conf.preset_exists(genre):
+ self.conf.change_preset(genre, self.eq)
+
+ def create_configure_dialog(self, dialog=None):
+ dialog = self.dialog.get_dialog()
+ dialog.present()
+ return dialog
Oops, something went wrong.

0 comments on commit 036b30c

Please sign in to comment.