2012-08-25 12:59:54 +02:00
|
|
|
/*
|
2013-01-03 10:33:04 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2012-08-25 12:59:54 +02: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "PlayerCommands.hxx"
|
2012-09-25 12:10:12 +02:00
|
|
|
#include "CommandError.hxx"
|
2013-01-04 20:50:00 +01:00
|
|
|
#include "Playlist.hxx"
|
2012-08-29 20:17:13 +02:00
|
|
|
#include "PlaylistPrint.hxx"
|
2013-01-02 19:22:15 +01:00
|
|
|
#include "UpdateGlue.hxx"
|
2013-01-03 10:33:04 +01:00
|
|
|
#include "ClientInternal.hxx"
|
2013-01-07 08:59:11 +01:00
|
|
|
#include "Volume.hxx"
|
2013-01-03 10:33:04 +01:00
|
|
|
#include "protocol/Result.hxx"
|
|
|
|
#include "protocol/ArgParser.hxx"
|
2012-08-25 12:59:54 +02:00
|
|
|
|
|
|
|
extern "C" {
|
2013-01-04 22:31:53 +01:00
|
|
|
#include "audio_format.h"
|
2012-08-25 12:59:54 +02:00
|
|
|
#include "replay_gain_config.h"
|
2013-01-05 00:05:57 +01:00
|
|
|
#include "output_all.h"
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:31:53 +01:00
|
|
|
#include "PlayerControl.hxx"
|
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#define COMMAND_STATUS_STATE "state"
|
|
|
|
#define COMMAND_STATUS_REPEAT "repeat"
|
|
|
|
#define COMMAND_STATUS_SINGLE "single"
|
|
|
|
#define COMMAND_STATUS_CONSUME "consume"
|
|
|
|
#define COMMAND_STATUS_RANDOM "random"
|
|
|
|
#define COMMAND_STATUS_PLAYLIST "playlist"
|
|
|
|
#define COMMAND_STATUS_PLAYLIST_LENGTH "playlistlength"
|
|
|
|
#define COMMAND_STATUS_SONG "song"
|
|
|
|
#define COMMAND_STATUS_SONGID "songid"
|
|
|
|
#define COMMAND_STATUS_NEXTSONG "nextsong"
|
|
|
|
#define COMMAND_STATUS_NEXTSONGID "nextsongid"
|
|
|
|
#define COMMAND_STATUS_TIME "time"
|
|
|
|
#define COMMAND_STATUS_BITRATE "bitrate"
|
|
|
|
#define COMMAND_STATUS_ERROR "error"
|
|
|
|
#define COMMAND_STATUS_CROSSFADE "xfade"
|
|
|
|
#define COMMAND_STATUS_MIXRAMPDB "mixrampdb"
|
|
|
|
#define COMMAND_STATUS_MIXRAMPDELAY "mixrampdelay"
|
|
|
|
#define COMMAND_STATUS_AUDIO "audio"
|
|
|
|
#define COMMAND_STATUS_UPDATING_DB "updating_db"
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_play(Client *client, int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
int song = -1;
|
|
|
|
enum playlist_result result;
|
|
|
|
|
|
|
|
if (argc == 2 && !check_int(client, &song, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
2013-01-04 23:07:11 +01:00
|
|
|
result = playlist_play(&client->playlist, client->player_control,
|
|
|
|
song);
|
2012-08-25 12:59:54 +02:00
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_playid(Client *client, int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
int id = -1;
|
|
|
|
enum playlist_result result;
|
|
|
|
|
|
|
|
if (argc == 2 && !check_int(client, &id, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
result = playlist_play_id(&client->playlist, client->player_control,
|
|
|
|
id);
|
2012-08-25 12:59:54 +02:00
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-04 23:07:11 +01:00
|
|
|
handle_stop(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_stop(&client->playlist, client->player_control);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_currentsong(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_print_current(client, &client->playlist);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_pause(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc == 2) {
|
|
|
|
bool pause_flag;
|
|
|
|
if (!check_bool(client, &pause_flag, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
pc_set_pause(client->player_control, pause_flag);
|
|
|
|
} else
|
|
|
|
pc_pause(client->player_control);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_status(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
const char *state = NULL;
|
|
|
|
struct player_status player_status;
|
|
|
|
int updateJobId;
|
|
|
|
char *error;
|
|
|
|
int song;
|
|
|
|
|
|
|
|
pc_get_status(client->player_control, &player_status);
|
|
|
|
|
|
|
|
switch (player_status.state) {
|
|
|
|
case PLAYER_STATE_STOP:
|
|
|
|
state = "stop";
|
|
|
|
break;
|
|
|
|
case PLAYER_STATE_PAUSE:
|
|
|
|
state = "pause";
|
|
|
|
break;
|
|
|
|
case PLAYER_STATE_PLAY:
|
|
|
|
state = "play";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
const playlist &playlist = client->playlist;
|
2012-08-25 12:59:54 +02:00
|
|
|
client_printf(client,
|
|
|
|
"volume: %i\n"
|
|
|
|
COMMAND_STATUS_REPEAT ": %i\n"
|
|
|
|
COMMAND_STATUS_RANDOM ": %i\n"
|
|
|
|
COMMAND_STATUS_SINGLE ": %i\n"
|
|
|
|
COMMAND_STATUS_CONSUME ": %i\n"
|
|
|
|
COMMAND_STATUS_PLAYLIST ": %li\n"
|
|
|
|
COMMAND_STATUS_PLAYLIST_LENGTH ": %i\n"
|
|
|
|
COMMAND_STATUS_CROSSFADE ": %i\n"
|
|
|
|
COMMAND_STATUS_MIXRAMPDB ": %f\n"
|
|
|
|
COMMAND_STATUS_MIXRAMPDELAY ": %f\n"
|
|
|
|
COMMAND_STATUS_STATE ": %s\n",
|
|
|
|
volume_level_get(),
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_get_repeat(&playlist),
|
|
|
|
playlist_get_random(&playlist),
|
|
|
|
playlist_get_single(&playlist),
|
|
|
|
playlist_get_consume(&playlist),
|
|
|
|
playlist_get_version(&playlist),
|
|
|
|
playlist_get_length(&playlist),
|
2012-08-25 12:59:54 +02:00
|
|
|
(int)(pc_get_cross_fade(client->player_control) + 0.5),
|
|
|
|
pc_get_mixramp_db(client->player_control),
|
|
|
|
pc_get_mixramp_delay(client->player_control),
|
|
|
|
state);
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
song = playlist_get_current_song(&playlist);
|
2012-08-25 12:59:54 +02:00
|
|
|
if (song >= 0) {
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_SONG ": %i\n"
|
|
|
|
COMMAND_STATUS_SONGID ": %u\n",
|
2013-01-04 23:07:11 +01:00
|
|
|
song, playlist_get_song_id(&playlist, song));
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (player_status.state != PLAYER_STATE_STOP) {
|
|
|
|
struct audio_format_string af_string;
|
|
|
|
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_TIME ": %i:%i\n"
|
|
|
|
"elapsed: %1.3f\n"
|
|
|
|
COMMAND_STATUS_BITRATE ": %u\n"
|
|
|
|
COMMAND_STATUS_AUDIO ": %s\n",
|
|
|
|
(int)(player_status.elapsed_time + 0.5),
|
|
|
|
(int)(player_status.total_time + 0.5),
|
|
|
|
player_status.elapsed_time,
|
|
|
|
player_status.bit_rate,
|
|
|
|
audio_format_to_string(&player_status.audio_format,
|
|
|
|
&af_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((updateJobId = isUpdatingDB())) {
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_UPDATING_DB ": %i\n",
|
|
|
|
updateJobId);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = pc_get_error_message(client->player_control);
|
|
|
|
if (error != NULL) {
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_ERROR ": %s\n",
|
|
|
|
error);
|
|
|
|
g_free(error);
|
|
|
|
}
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
song = playlist_get_next_song(&playlist);
|
2012-08-25 12:59:54 +02:00
|
|
|
if (song >= 0) {
|
|
|
|
client_printf(client,
|
|
|
|
COMMAND_STATUS_NEXTSONG ": %i\n"
|
|
|
|
COMMAND_STATUS_NEXTSONGID ": %u\n",
|
2013-01-04 23:07:11 +01:00
|
|
|
song, playlist_get_song_id(&playlist, song));
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-04 23:07:11 +01:00
|
|
|
handle_next(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist &playlist = client->playlist;
|
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
/* single mode is not considered when this is user who
|
|
|
|
* wants to change song. */
|
2013-01-04 23:07:11 +01:00
|
|
|
const bool single = playlist.queue.single;
|
|
|
|
playlist.queue.single = false;
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_next(&playlist, client->player_control);
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist.queue.single = single;
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-04 23:07:11 +01:00
|
|
|
handle_previous(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_previous(&client->playlist, client->player_control);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_repeat(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_set_repeat(&client->playlist, client->player_control, status);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_single(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_set_single(&client->playlist, client->player_control, status);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_consume(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_set_consume(&client->playlist, status);
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_random(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
bool status;
|
|
|
|
if (!check_bool(client, &status, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_set_random(&client->playlist, client->player_control, status);
|
2013-01-05 00:05:57 +01:00
|
|
|
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->playlist.queue.random));
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_clearerror(G_GNUC_UNUSED Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
pc_clear_error(client->player_control);
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_seek(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
unsigned song, seek_time;
|
|
|
|
enum playlist_result result;
|
|
|
|
|
|
|
|
if (!check_unsigned(client, &song, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
if (!check_unsigned(client, &seek_time, argv[2]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
result = playlist_seek_song(&client->playlist, client->player_control,
|
2012-08-25 12:59:54 +02:00
|
|
|
song, seek_time);
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_seekid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
unsigned id, seek_time;
|
|
|
|
enum playlist_result result;
|
|
|
|
|
|
|
|
if (!check_unsigned(client, &id, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
if (!check_unsigned(client, &seek_time, argv[2]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
2013-01-04 23:07:11 +01:00
|
|
|
result = playlist_seek_song_id(&client->playlist,
|
|
|
|
client->player_control,
|
2012-08-25 12:59:54 +02:00
|
|
|
id, seek_time);
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_seekcur(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
const char *p = argv[1];
|
|
|
|
bool relative = *p == '+' || *p == '-';
|
|
|
|
int seek_time;
|
|
|
|
if (!check_int(client, &seek_time, p))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
|
|
|
|
enum playlist_result result =
|
2013-01-04 23:07:11 +01:00
|
|
|
playlist_seek_current(&client->playlist,
|
|
|
|
client->player_control,
|
2012-08-25 12:59:54 +02:00
|
|
|
seek_time, relative);
|
|
|
|
return print_playlist_result(client, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_crossfade(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
unsigned xfade_time;
|
|
|
|
|
|
|
|
if (!check_unsigned(client, &xfade_time, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
pc_set_cross_fade(client->player_control, xfade_time);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_mixrampdb(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
float db;
|
|
|
|
|
|
|
|
if (!check_float(client, &db, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
pc_set_mixramp_db(client->player_control, db);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_mixrampdelay(Client *client, G_GNUC_UNUSED int argc, char *argv[])
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
|
|
|
float delay_secs;
|
|
|
|
|
|
|
|
if (!check_float(client, &delay_secs, argv[1]))
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
pc_set_mixramp_delay(client->player_control, delay_secs);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_replay_gain_mode(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (!replay_gain_set_mode_string(argv[1])) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"Unrecognized replay gain mode");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-01-05 00:05:57 +01:00
|
|
|
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->playlist.queue.random));
|
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
handle_replay_gain_status(Client *client,
|
2012-08-25 12:59:54 +02:00
|
|
|
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
|
|
|
|
{
|
|
|
|
client_printf(client, "replay_gain_mode: %s\n",
|
|
|
|
replay_gain_get_mode_string());
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|