2009-02-04 20:31:53 +01:00
|
|
|
/*
|
2013-01-03 00:35:05 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-02-04 20:31:53 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* 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 2 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-02-04 20:31:53 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions for editing the playlist (adding, removing, reordering
|
|
|
|
* songs in the queue).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-04 20:50:00 +01:00
|
|
|
#include "PlaylistInternal.hxx"
|
|
|
|
|
2013-01-03 00:35:05 +01:00
|
|
|
extern "C" {
|
2009-02-04 20:31:53 +01:00
|
|
|
#include "player_control.h"
|
2009-02-25 16:44:06 +01:00
|
|
|
#include "uri.h"
|
2009-02-04 20:31:53 +01:00
|
|
|
#include "song.h"
|
|
|
|
#include "idle.h"
|
2013-01-03 00:35:05 +01:00
|
|
|
}
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2013-01-03 00:30:15 +01:00
|
|
|
#include "DatabaseGlue.hxx"
|
|
|
|
#include "DatabasePlugin.hxx"
|
|
|
|
|
2009-02-04 20:31:53 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
static void playlist_increment_version(struct playlist *playlist)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
queue_increment_version(&playlist->queue);
|
|
|
|
|
|
|
|
idle_add(IDLE_PLAYLIST);
|
|
|
|
}
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
void
|
|
|
|
playlist_clear(struct playlist *playlist, struct player_control *pc)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_stop(playlist, pc);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
queue_clear(&playlist->queue);
|
|
|
|
|
|
|
|
playlist->current = -1;
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_increment_version(playlist);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_append_file(struct playlist *playlist, struct player_control *pc,
|
2012-03-06 22:01:24 +01:00
|
|
|
const char *path_fs, unsigned *added_id)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
2012-03-06 22:01:24 +01:00
|
|
|
struct song *song = song_file_load(path_fs, NULL);
|
2009-02-04 20:31:53 +01:00
|
|
|
if (song == NULL)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
return playlist_append_song(playlist, pc, song, added_id);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_append_song(struct playlist *playlist, struct player_control *pc,
|
2009-02-04 20:31:53 +01:00
|
|
|
struct song *song, unsigned *added_id)
|
|
|
|
{
|
|
|
|
const struct song *queued;
|
|
|
|
unsigned id;
|
|
|
|
|
|
|
|
if (queue_is_full(&playlist->queue))
|
|
|
|
return PLAYLIST_RESULT_TOO_LARGE;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
|
|
|
|
2012-08-21 19:17:14 +02:00
|
|
|
id = queue_append(&playlist->queue, song, 0);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
if (playlist->queue.random) {
|
|
|
|
/* shuffle the new song into the list of remaining
|
|
|
|
songs to play */
|
|
|
|
|
|
|
|
unsigned start;
|
|
|
|
if (playlist->queued >= 0)
|
|
|
|
start = playlist->queued + 1;
|
|
|
|
else
|
|
|
|
start = playlist->current + 1;
|
|
|
|
if (start < queue_length(&playlist->queue))
|
|
|
|
queue_shuffle_order_last(&playlist->queue, start,
|
|
|
|
queue_length(&playlist->queue));
|
|
|
|
}
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_increment_version(playlist);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
if (added_id)
|
|
|
|
*added_id = id;
|
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_append_uri(struct playlist *playlist, struct player_control *pc,
|
|
|
|
const char *uri, unsigned *added_id)
|
2009-07-14 21:28:36 +02:00
|
|
|
{
|
|
|
|
g_debug("add to playlist: %s", uri);
|
|
|
|
|
2013-01-03 00:30:15 +01:00
|
|
|
const Database *db = nullptr;
|
|
|
|
struct song *song;
|
|
|
|
if (uri_has_scheme(uri)) {
|
|
|
|
song = song_remote_new(uri);
|
|
|
|
} else {
|
|
|
|
db = GetDatabase(nullptr);
|
|
|
|
if (db == nullptr)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
|
|
|
song = db->GetSong(uri, nullptr);
|
|
|
|
if (song == nullptr)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
}
|
2009-07-14 21:28:36 +02:00
|
|
|
|
2012-08-15 23:28:19 +02:00
|
|
|
enum playlist_result result =
|
|
|
|
playlist_append_song(playlist, pc, song, added_id);
|
2013-01-03 00:30:15 +01:00
|
|
|
if (db != nullptr)
|
|
|
|
db->ReturnSong(song);
|
2012-08-15 23:28:19 +02:00
|
|
|
|
|
|
|
return result;
|
2009-07-14 21:28:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_swap_songs(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned song1, unsigned song2)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
const struct song *queued;
|
|
|
|
|
|
|
|
if (!queue_valid_position(&playlist->queue, song1) ||
|
|
|
|
!queue_valid_position(&playlist->queue, song2))
|
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
|
|
|
|
|
|
|
queue_swap(&playlist->queue, song1, song2);
|
|
|
|
|
|
|
|
if (playlist->queue.random) {
|
|
|
|
/* update the queue order, so that playlist->current
|
|
|
|
still points to the current song order */
|
|
|
|
|
|
|
|
queue_swap_order(&playlist->queue,
|
|
|
|
queue_position_to_order(&playlist->queue,
|
|
|
|
song1),
|
|
|
|
queue_position_to_order(&playlist->queue,
|
|
|
|
song2));
|
|
|
|
} else {
|
|
|
|
/* correct the "current" song order */
|
|
|
|
|
|
|
|
if (playlist->current == (int)song1)
|
|
|
|
playlist->current = song2;
|
|
|
|
else if (playlist->current == (int)song2)
|
|
|
|
playlist->current = song1;
|
|
|
|
}
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_increment_version(playlist);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_swap_songs_id(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned id1, unsigned id2)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
int song1 = queue_id_to_position(&playlist->queue, id1);
|
|
|
|
int song2 = queue_id_to_position(&playlist->queue, id2);
|
|
|
|
|
|
|
|
if (song1 < 0 || song2 < 0)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
return playlist_swap_songs(playlist, pc, song1, song2);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
2011-07-19 00:34:33 +02:00
|
|
|
enum playlist_result
|
|
|
|
playlist_set_priority(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned start, unsigned end,
|
|
|
|
uint8_t priority)
|
|
|
|
{
|
|
|
|
if (start >= queue_length(&playlist->queue))
|
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
|
|
|
if (end > queue_length(&playlist->queue))
|
|
|
|
end = queue_length(&playlist->queue);
|
|
|
|
|
|
|
|
if (start >= end)
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
|
|
|
|
/* remember "current" and "queued" */
|
|
|
|
|
|
|
|
int current_position = playlist->current >= 0
|
|
|
|
? (int)queue_order_to_position(&playlist->queue,
|
|
|
|
playlist->current)
|
|
|
|
: -1;
|
|
|
|
|
|
|
|
const struct song *queued = playlist_get_queued_song(playlist);
|
|
|
|
|
|
|
|
/* apply the priority changes */
|
|
|
|
|
|
|
|
queue_set_priority_range(&playlist->queue, start, end, priority,
|
|
|
|
playlist->current);
|
|
|
|
|
|
|
|
playlist_increment_version(playlist);
|
|
|
|
|
|
|
|
/* restore "current" and choose a new "queued" */
|
|
|
|
|
|
|
|
if (current_position >= 0)
|
|
|
|
playlist->current = queue_position_to_order(&playlist->queue,
|
|
|
|
current_position);
|
|
|
|
|
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
|
|
|
playlist_set_priority_id(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned song_id, uint8_t priority)
|
|
|
|
{
|
|
|
|
int song_position = queue_id_to_position(&playlist->queue, song_id);
|
|
|
|
if (song_position < 0)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
|
|
|
return playlist_set_priority(playlist, pc,
|
|
|
|
song_position, song_position + 1,
|
|
|
|
priority);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-09-30 23:10:15 +02:00
|
|
|
static void
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_internal(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned song, const struct song **queued_p)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
unsigned songOrder;
|
|
|
|
|
2009-09-30 23:10:15 +02:00
|
|
|
assert(song < queue_length(&playlist->queue));
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
songOrder = queue_position_to_order(&playlist->queue, song);
|
|
|
|
|
|
|
|
if (playlist->playing && playlist->current == (int)songOrder) {
|
2009-11-03 21:08:48 +01:00
|
|
|
bool paused = pc_get_state(pc) == PLAYER_STATE_PAUSE;
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
/* the current song is going to be deleted: stop the player */
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
pc_stop(pc);
|
2009-02-04 20:31:53 +01:00
|
|
|
playlist->playing = false;
|
|
|
|
|
|
|
|
/* see which song is going to be played instead */
|
|
|
|
|
|
|
|
playlist->current = queue_next_order(&playlist->queue,
|
|
|
|
playlist->current);
|
|
|
|
if (playlist->current == (int)songOrder)
|
|
|
|
playlist->current = -1;
|
|
|
|
|
|
|
|
if (playlist->current >= 0 && !paused)
|
|
|
|
/* play the song after the deleted one */
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_play_order(playlist, pc, playlist->current);
|
2009-02-04 20:31:53 +01:00
|
|
|
else
|
|
|
|
/* no songs left to play, stop playback
|
|
|
|
completely */
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_stop(playlist, pc);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-09-30 23:10:15 +02:00
|
|
|
*queued_p = NULL;
|
2009-02-10 17:55:08 +01:00
|
|
|
} else if (playlist->current == (int)songOrder)
|
|
|
|
/* there's a "current song" but we're not playing
|
|
|
|
currently - clear "current" */
|
|
|
|
playlist->current = -1;
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
/* now do it: remove the song */
|
|
|
|
|
|
|
|
queue_delete(&playlist->queue, song);
|
|
|
|
|
|
|
|
/* update the "current" and "queued" variables */
|
|
|
|
|
|
|
|
if (playlist->current > (int)songOrder) {
|
|
|
|
playlist->current--;
|
|
|
|
}
|
2009-09-30 23:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned song)
|
2009-09-30 23:10:15 +02:00
|
|
|
{
|
|
|
|
const struct song *queued;
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-09-30 23:10:15 +02:00
|
|
|
if (song >= queue_length(&playlist->queue))
|
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_internal(playlist, pc, song, &queued);
|
2009-09-30 23:10:15 +02:00
|
|
|
|
|
|
|
playlist_increment_version(playlist);
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-09-30 23:13:13 +02:00
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_range(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned start, unsigned end)
|
2009-09-30 23:13:13 +02:00
|
|
|
{
|
|
|
|
const struct song *queued;
|
|
|
|
|
|
|
|
if (start >= queue_length(&playlist->queue))
|
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
|
|
|
if (end > queue_length(&playlist->queue))
|
|
|
|
end = queue_length(&playlist->queue);
|
|
|
|
|
|
|
|
if (start >= end)
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
|
|
|
|
|
|
|
do {
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_internal(playlist, pc, --end, &queued);
|
2009-09-30 23:13:13 +02:00
|
|
|
} while (end != start);
|
|
|
|
|
|
|
|
playlist_increment_version(playlist);
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-09-30 23:13:13 +02:00
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-02-04 20:31:53 +01:00
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_id(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned id)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
int song = queue_id_to_position(&playlist->queue, id);
|
|
|
|
if (song < 0)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
return playlist_delete(playlist, pc, song);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete_song(struct playlist *playlist, struct player_control *pc,
|
|
|
|
const struct song *song)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
for (int i = queue_length(&playlist->queue) - 1; i >= 0; --i)
|
|
|
|
if (song == queue_get(&playlist->queue, i))
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_delete(playlist, pc, i);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_move_range(struct playlist *playlist, struct player_control *pc,
|
2009-07-14 21:28:36 +02:00
|
|
|
unsigned start, unsigned end, int to)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
const struct song *queued;
|
|
|
|
int currentSong;
|
|
|
|
|
2009-03-26 22:02:56 +01:00
|
|
|
if (!queue_valid_position(&playlist->queue, start) ||
|
|
|
|
!queue_valid_position(&playlist->queue, end - 1))
|
2009-02-04 20:31:53 +01:00
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
2009-03-26 22:02:56 +01:00
|
|
|
if ((to >= 0 && to + end - start - 1 >= queue_length(&playlist->queue)) ||
|
2009-02-04 20:31:53 +01:00
|
|
|
(to < 0 && abs(to) > (int)queue_length(&playlist->queue)))
|
|
|
|
return PLAYLIST_RESULT_BAD_RANGE;
|
|
|
|
|
2009-03-26 22:02:56 +01:00
|
|
|
if ((int)start == to)
|
|
|
|
/* nothing happens */
|
2009-02-04 20:31:53 +01:00
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (to < 0) => move to offset from current song
|
|
|
|
* (-playlist.length == to) => move to position BEFORE current song
|
|
|
|
*/
|
|
|
|
currentSong = playlist->current >= 0
|
|
|
|
? (int)queue_order_to_position(&playlist->queue,
|
|
|
|
playlist->current)
|
|
|
|
: -1;
|
|
|
|
if (to < 0 && playlist->current >= 0) {
|
2011-12-19 21:15:00 +01:00
|
|
|
if (start <= (unsigned)currentSong && (unsigned)currentSong < end)
|
2009-02-04 20:31:53 +01:00
|
|
|
/* no-op, can't be moved to offset of itself */
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
to = (currentSong + abs(to)) % queue_length(&playlist->queue);
|
2009-03-26 22:02:56 +01:00
|
|
|
if (start < (unsigned)to)
|
|
|
|
to--;
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
2009-03-26 22:02:56 +01:00
|
|
|
queue_move_range(&playlist->queue, start, end, to);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
if (!playlist->queue.random) {
|
|
|
|
/* update current/queued */
|
2009-03-26 22:02:56 +01:00
|
|
|
if ((int)start <= playlist->current &&
|
|
|
|
(unsigned)playlist->current < end)
|
|
|
|
playlist->current += to - start;
|
|
|
|
else if (playlist->current >= (int)end &&
|
2009-02-04 20:31:53 +01:00
|
|
|
playlist->current <= to) {
|
2009-03-26 22:02:56 +01:00
|
|
|
playlist->current -= end - start;
|
2009-02-04 20:31:53 +01:00
|
|
|
} else if (playlist->current >= to &&
|
2009-03-26 22:02:56 +01:00
|
|
|
playlist->current < (int)start) {
|
|
|
|
playlist->current += end - start;
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_increment_version(playlist);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
return PLAYLIST_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_result
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_move_id(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned id1, int to)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
int song = queue_id_to_position(&playlist->queue, id1);
|
|
|
|
if (song < 0)
|
|
|
|
return PLAYLIST_RESULT_NO_SUCH_SONG;
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
return playlist_move_range(playlist, pc, song, song+1, to);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
void
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_shuffle(struct playlist *playlist, struct player_control *pc,
|
|
|
|
unsigned start, unsigned end)
|
2009-02-04 20:31:53 +01:00
|
|
|
{
|
|
|
|
const struct song *queued;
|
|
|
|
|
2009-02-13 11:12:31 +01:00
|
|
|
if (end > queue_length(&playlist->queue))
|
|
|
|
/* correct the "end" offset */
|
|
|
|
end = queue_length(&playlist->queue);
|
|
|
|
|
|
|
|
if ((start+1) >= end)
|
|
|
|
/* needs at least two entries. */
|
2009-02-04 20:31:53 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
queued = playlist_get_queued_song(playlist);
|
2009-02-13 10:38:32 +01:00
|
|
|
if (playlist->playing && playlist->current >= 0) {
|
|
|
|
unsigned current_position;
|
|
|
|
current_position = queue_order_to_position(&playlist->queue,
|
|
|
|
playlist->current);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-02-13 10:38:32 +01:00
|
|
|
if (current_position >= start && current_position < end)
|
|
|
|
{
|
2009-02-04 20:31:53 +01:00
|
|
|
/* put current playing song first */
|
2009-02-13 10:38:32 +01:00
|
|
|
queue_swap(&playlist->queue, start, current_position);
|
|
|
|
|
|
|
|
if (playlist->queue.random) {
|
|
|
|
playlist->current =
|
|
|
|
queue_position_to_order(&playlist->queue, start);
|
|
|
|
} else
|
|
|
|
playlist->current = start;
|
|
|
|
|
|
|
|
/* start shuffle after the current song */
|
|
|
|
start++;
|
|
|
|
}
|
2009-02-04 20:31:53 +01:00
|
|
|
} else {
|
2009-02-13 10:38:32 +01:00
|
|
|
/* no playback currently: reset playlist->current */
|
2009-02-04 20:31:53 +01:00
|
|
|
|
|
|
|
playlist->current = -1;
|
|
|
|
}
|
|
|
|
|
2009-02-13 10:38:32 +01:00
|
|
|
queue_shuffle_range(&playlist->queue, start, end);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_increment_version(playlist);
|
2009-02-04 20:31:53 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
playlist_update_queued_song(playlist, pc, queued);
|
2009-02-04 20:31:53 +01:00
|
|
|
}
|