Module: MPD::Plugins::Queue

Included in:
MPD
Defined in:
lib/ruby-mpd/plugins/queue.rb

Overview

These commands manipulate the current playlist, what’s playing now. For a distinction between this and other playlists, this is called queue.

Instance Method Summary collapse

Instance Method Details

#add(path) ⇒ Boolean

Add the file path to the queue. If path is a directory, it will be added recursively.

Returns:

  • (Boolean)

    returns true if successful.



21
22
23
# File 'lib/ruby-mpd/plugins/queue.rb', line 21

def add(path)
  send_command :add, path
end

#addid(path, pos = nil) ⇒ Integer

Adds a song to the queue (non-recursive) and returns the song id. Optionally, one can specify the position on which to add the song (since MPD 0.14).

Returns:

  • (Integer)

    id of the song that was added.



28
29
30
# File 'lib/ruby-mpd/plugins/queue.rb', line 28

def addid(path, pos=nil)
  send_command :addid, path, pos
end

#clearBoolean

Clears the current queue.

Returns:

  • (Boolean)

    returns true if successful.



34
35
36
# File 'lib/ruby-mpd/plugins/queue.rb', line 34

def clear
  send_command :clear
end

#delete(pos) ⇒ Boolean

Deletes the song from the queue.

Since MPD 0.15 a range can also be passed. Songs with positions within range will be deleted. if range is passed, songs with positions within range will be deleted.

Parameters:

  • pos (Integer, Range)

    Song with position in the queue will be deleted,

  • pos (Hash)

    :id to specify the song ID to delete instead of position.

Returns:

  • (Boolean)

    returns true if successful.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby-mpd/plugins/queue.rb', line 45

def delete(pos)
  if pos.is_a?(Hash)
    if pos[:id]
      send_command :deleteid, pos[:id]
    else
      raise ArgumentError, 'Only :id key is allowed!'
    end
  else
    send_command :delete, pos
  end
end

#move(from, to) ⇒ Boolean

Move the song at from to to in the queue.

  • Since 0.14, to can be a negative number, which is the offset of the song from the currently playing (or to-be-played) song. So -1 would mean the song would be moved to be the next song in the queue. Moving a song to -queue.length will move it to the song before the current song on the queue; so this will work for repeating playlists, too.

  • Since 0.15, from can be a range of songs to move.

Parameters:

  • from (Hash)

    :id to specify the song ID to move instead of position.

Returns:

  • (Boolean)

    returns true if successful.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ruby-mpd/plugins/queue.rb', line 66

def move(from, to)
  if from.is_a?(Hash)
    if from[:id]
      send_command :moveid, from[:id], to
    else
      raise ArgumentError, 'Only :id key is allowed!'
    end
  else
    send_command :move, from, to
  end
end

#queue(limit = nil) ⇒ Array<MPD::Song>

List the current playlist/queue. An Integer or Range can be used to limit the information returned to a specific subset.

or a single song.

Returns:

  • (Array<MPD::Song>)

    Array of songs in the queue



14
15
16
# File 'lib/ruby-mpd/plugins/queue.rb', line 14

def queue(limit=nil)
  build_songs_list send_command(:playlistinfo, limit)
end

#queue_changes(version) ⇒ Array<MPD::Song>

List the changes since the specified version in the queue.

Returns:



100
101
102
# File 'lib/ruby-mpd/plugins/queue.rb', line 100

def queue_changes(version)
  build_songs_list send_command(:plchanges, version)
end

#queue_search(type, what, options = {}) ⇒ Array<MPD::Song>

Searches for songs in the queue matched by the what argument. Case insensitive by default.

Parameters:

  • type (Symbol)

    Can be any tag supported by MPD, or one of the two special parameters: :file to search by full path (relative to database root), and :any to match against all available tags.

  • options (Hash) (defaults to: {})

    Use :case_sensitive to make the query case sensitive.

Returns:



93
94
95
96
# File 'lib/ruby-mpd/plugins/queue.rb', line 93

def queue_search(type, what, options = {})
  command = options[:case_sensitive] ? :playlistfind : :playlistsearch
  build_songs_list send_command(command, type, what)
end

#save(playlist) ⇒ Boolean

Saves the current playlist/queue to playlist.m3u in the playlist directory.

Returns:

  • (Boolean)

    returns true if successful.



148
149
150
# File 'lib/ruby-mpd/plugins/queue.rb', line 148

def save(playlist)
  send_command :save, playlist
end

#shuffle(range = nil) ⇒ Boolean

Shuffles the queue. Optionally, a Range can be used to shuffle a specific subset.

Returns:

  • (Boolean)

    returns true if successful.



127
128
129
# File 'lib/ruby-mpd/plugins/queue.rb', line 127

def shuffle(range=nil)
  send_command :shuffle, range
end

#song_priority(priority, pos) ⇒ Object

Set the priority of the specified songs. A higher priority means that it will be played first when “random” mode is enabled.

Parameters:

  • priority (Integer)

    An integer between 0 and 255. The default priority of new songs is 0.

  • pos (Integer)

    A specific position.

  • pos (Range)

    A range of positions.

  • pos (Hash)

    :id to specify the song ID to move instead of position.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ruby-mpd/plugins/queue.rb', line 112

def song_priority(priority, pos)
  if pos.is_a?(Hash)
    if pos[:id]
      send_command :prioid, priority, pos[:id]
    else
      raise ArgumentError, 'Only :id key is allowed!'
    end
  else
    send_command :prio, priority, pos
  end
end

#song_with_id(songid) ⇒ MPD::Song

Returns the song with the songid in the playlist,

Returns:



80
81
82
# File 'lib/ruby-mpd/plugins/queue.rb', line 80

def song_with_id(songid)
  Song.new send_command(:playlistid, songid)
end

#swap(posA, posB) ⇒ Boolean

Swaps the song at position posA with the song as position posB in the queue.

Returns:

  • (Boolean)

    returns true if successful.



134
135
136
# File 'lib/ruby-mpd/plugins/queue.rb', line 134

def swap(posA, posB)
  send_command :swap, posA, posB
end

#swapid(songidA, songidB) ⇒ Boolean

Swaps the positions of the song with the id songidA with the song with the id songidB in the queue.

Returns:

  • (Boolean)

    returns true if successful.



141
142
143
# File 'lib/ruby-mpd/plugins/queue.rb', line 141

def swapid(songidA, songidB)
  send_command :swapid, songidA, songidB
end