Class: Mpc
- Inherits:
-
Object
- Object
- Mpc
- Defined in:
- lib/mpc.rb,
lib/mpc/song.rb,
lib/mpc/version.rb
Defined Under Namespace
Classes: Song
Constant Summary collapse
- VERSION =
"0.9.4"
- @@regexps =
{ "ACK" => /\AACK \[(\d+)\@(\d+)\] \{(.*)\} (.+)\Z/, "OK" => /\AOK\n\Z/, "FILE" => /\Afile\:(.*)\Z/, "CONNECT" => /\AOK MPD (\d+)\.(\d+).(\d+)\n\Z/ }
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #add(song, pos = nil) ⇒ Object
- #connect ⇒ Object
- #current_song ⇒ Object
- #disconnect ⇒ Object
- #info ⇒ Object
-
#initialize(host = "127.0.0.1", port = 6600) ⇒ Mpc
constructor
A new instance of Mpc.
- #next ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #play(pos = "") ⇒ Object
- #playing? ⇒ Boolean
- #previous ⇒ Object
- #random(state = nil) ⇒ Object
- #random? ⇒ Boolean
- #repeat(state = nil) ⇒ Object
- #repeat? ⇒ Boolean
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #volume(level = nil) ⇒ Object
- #volume_down ⇒ Object
- #volume_up ⇒ Object
Constructor Details
#initialize(host = "127.0.0.1", port = 6600) ⇒ Mpc
Returns a new instance of Mpc.
14 15 16 17 |
# File 'lib/mpc.rb', line 14 def initialize(host = "127.0.0.1", port = 6600) @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
13 14 15 |
# File 'lib/mpc.rb', line 13 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
13 14 15 |
# File 'lib/mpc.rb', line 13 def port @port end |
Instance Method Details
#add(song, pos = nil) ⇒ Object
101 102 103 |
# File 'lib/mpc.rb', line 101 def add(song, pos = nil) send_command "addid #{song} #{pos}" end |
#connect ⇒ Object
19 20 21 22 |
# File 'lib/mpc.rb', line 19 def connect @socket = socket @socket.gets end |
#current_song ⇒ Object
92 93 94 95 |
# File 'lib/mpc.rb', line 92 def current_song song = to_hash(send_command("currentsong")) Song.new(song) end |
#disconnect ⇒ Object
24 25 26 27 |
# File 'lib/mpc.rb', line 24 def disconnect @socket.close @socket = nil end |
#info ⇒ Object
97 98 99 |
# File 'lib/mpc.rb', line 97 def info "State: #{status[:state]} Volume: #{volume}% Artists: #{stats[:artists]} Albums: #{stats[:albums]} Songs: #{stats[:songs]}" end |
#next ⇒ Object
53 54 55 |
# File 'lib/mpc.rb', line 53 def next send_command "next" end |
#pause ⇒ Object
45 46 47 |
# File 'lib/mpc.rb', line 45 def pause send_command "pause 1" end |
#paused? ⇒ Boolean
49 50 51 |
# File 'lib/mpc.rb', line 49 def paused? status[:state] == "pause" end |
#play(pos = "") ⇒ Object
29 30 31 |
# File 'lib/mpc.rb', line 29 def play(pos = "") send_command "play #{pos}" end |
#playing? ⇒ Boolean
33 34 35 |
# File 'lib/mpc.rb', line 33 def status[:state] == "play" end |
#previous ⇒ Object
57 58 59 |
# File 'lib/mpc.rb', line 57 def previous send_command "previous" end |
#random(state = nil) ⇒ Object
61 62 63 64 |
# File 'lib/mpc.rb', line 61 def random(state = nil) state ||= bool_to_int(!random?) send_command "random #{state}" end |
#random? ⇒ Boolean
66 67 68 |
# File 'lib/mpc.rb', line 66 def random? status[:random] == "1" end |
#repeat(state = nil) ⇒ Object
70 71 72 73 |
# File 'lib/mpc.rb', line 70 def repeat(state = nil) state ||= bool_to_int(!repeat?) send_command "repeat #{state}" end |
#repeat? ⇒ Boolean
75 76 77 |
# File 'lib/mpc.rb', line 75 def repeat? status[:repeat] == "1" end |
#stop ⇒ Object
37 38 39 |
# File 'lib/mpc.rb', line 37 def stop send_command "stop" end |
#stopped? ⇒ Boolean
41 42 43 |
# File 'lib/mpc.rb', line 41 def stopped? status[:state] == "stop" end |
#volume(level = nil) ⇒ Object
79 80 81 82 |
# File 'lib/mpc.rb', line 79 def volume(level = nil) set_volume(level) if level get_volume end |
#volume_down ⇒ Object
88 89 90 |
# File 'lib/mpc.rb', line 88 def volume_down set_volume(volume.to_i - 20) end |
#volume_up ⇒ Object
84 85 86 |
# File 'lib/mpc.rb', line 84 def volume_up set_volume(volume.to_i + 20) end |