summaryrefslogtreecommitdiff
path: root/libmpd/playbackoptions.rb
blob: 84afd47263eb1a747fdb5460911d757c2b4c55d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env ruby
#
#--
# Copyright 2009-2014 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
# Distributed under the terms of the GNU General Public License v3.
# See http://www.gnu.org/licenses/gpl.txt for the full license text.
#++
#
# *Author*:: David Vazgenovich Shakaryan
# *License*:: GNU General Public License v3

# Collection of methods related to playback options.
module MPDPlaybackOptions
  # Sets consume state.
  # When consume is activated, each song played is removed from the playlist.
  #
  # Accepts an argument of +true+ to enable or +false+ to disable.
  # If no argument is given, defaults to +true+.
  def consume(state = true)
    send_request('consume %s' % state.to_i)
  end

  # Returns +true+ if consume is activated.
  # Otherwise, returns +false+.
  def consume?
    status[:consume] == '1'
  end

  # Sets crossfading between songs.
  def crossfade(seconds)
    send_request('crossfade %s' % seconds)
  end

  # Returns the current crossfade setting as an integer.
  def crossfade?
    status[:xfade].to_i
  end

  # Sets random state.
  #
  # Accepts an argument of +true+ to enable or +false+ to disable.
  # If no argument is given, defaults to +true+.
  def random(state = true)
    send_request('random %s' % state.to_i)
  end

  # Returns +true+ if random is activated.
  # Otherwise, returns +false+.
  def random?
    status[:random] == '1'
  end

  # Sets repeat state.
  #
  # Accepts an argument of +true+ to enable or +false+ to disable.
  # If no argument is given, defaults to +true+.
  def repeat(state = true)
    send_request('repeat %s' % state.to_i)
  end

  # Returns +true+ if repeat is activated.
  # Otherwise, returns +false+.
  def repeat?
    status[:repeat] == '1'
  end

  # Sets volume from a range of 0 to 100.
  def volume(volume)
    send_request('setvol %s' % volume)
  end

  # Returns the current volume as an integer.
  def volume?
    status[:volume].to_i
  end

  # Sets single state.
  # When single is activated, playback is stopped after the current song. If
  # repeat is also activated, the current song is repeated.
  #
  # Accepts an argument of +true+ to enable or +false+ to disable.
  # If no argument is given, defaults to +true+.
  def single(state = true)
    send_request('single %s' % state.to_i)
  end

  # Returns +true+ if single is activated.
  # Otherwise, returns +false+.
  def single?
    status[:single] == '1'
  end
end