# Copyright (c) 2006 Andy Gimblett # http://gimbo.org.uk/ # Licensed under the same terms as Ruby (see LICENSE). # # =========================================================================== # #{{{ wmii xmms control/monitor plugin. # # This file must be placed in $HOME/.wmii-3/plugins. # # Thus plugin contains a monitor of xmms status, and defines a few key # bindings for simple control of xmms. It requires the ruby xmms # bindings to be installed. It's tuned to behave exactly how I want, # which might not suit everyone but hey, hack away... # # Changelog: # 2006.07.14.1101 AMG v1.0 # First published version. require 'xmms' Plugin.define "wmii-xmms@gimbo.org.uk" do author '"Andy Gimblett" ' x = Xmms::Remote::new # I define bindings for: # - Toggling playing/paused status (if stopped, causes play). # - Toggling shuffle status. # - Skipping to next/previous track. # - Moving back and forward 5 seconds within current track. # That's all I use, most of the time. binding("xmms-play_pause", "MODKEY-Control-space") do |wmii,| begin x.play_pause rescue Xmms::Error end end binding("xmms-toggle_shuffle", "MODKEY-Control-Return") do |wmii,| begin x.toggle_shuffle rescue Xmms::Error end end # Next/prev bindings clash with default key bindings for move-next # and move-prev from standard plugins --- I have disabled those, # personally. binding("xmms-next", "MODKEY-Control-Down") do |wmii,| begin x.next rescue Xmms::Error end end binding("xmms-prev", "MODKEY-Control-Up") do |wmii,| begin x.prev rescue Xmms::Error end end binding("xmms-forward", "MODKEY-Control-Right") do |wmii,| # Jump forward five seconds (unless would go past end of song). begin if x.time + 5000 < x.get_playlist_time x.time = x.time + 5000 end rescue Xmms::Error end end binding("xmms-back", "MODKEY-Control-Left") do |wmii,| # Jump back five seconds (but not to before time 0!) begin x.time = [x.time - 5000, 0].max rescue Xmms::Error end end # {{{ XMMS monitor - report on track playing, time remaining, # paused/playing status, and normal/shuffle status. If not playing, # just report track name in parentheses. If XMMS not running, be # blank. bar_applet("xmms", 300) do |wmii, bar| Thread.new do loop do begin title = x.title m, ss = ((x.get_playlist_time - x.time) / 1000).divmod(60) remaining = "%d:%02d" % [m, ss] if x.shuffling? shuf = "@" else shuf = ">" end if x.paused? bar.data = "#{title} p#{remaining}#{shuf}" elsif x.playing? bar.data = "#{title} -#{remaining}#{shuf}" else bar.data = "(#{title}#{shuf})" end rescue Xmms::Error bar.data = "" end sleep 1 end end end end