diff options
Diffstat (limited to 'src/command/PlayerCommands.cxx')
-rw-r--r-- | src/command/PlayerCommands.cxx | 187 |
1 files changed, 102 insertions, 85 deletions
diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index e0c0f61a8..3e58cecb1 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -24,10 +24,10 @@ #include "queue/Playlist.hxx" #include "PlaylistPrint.hxx" #include "client/Client.hxx" +#include "client/Response.hxx" #include "mixer/Volume.hxx" #include "Partition.hxx" #include "Instance.hxx" -#include "protocol/Result.hxx" #include "AudioFormat.hxx" #include "ReplayGainConfig.hxx" #include "util/ConstBuffer.hxx" @@ -59,23 +59,27 @@ CommandResult handle_play(Client &client, Request args) { + Response r(client); + int song = -1; - if (!args.ParseOptional(0, song, client)) + if (!args.ParseOptional(0, song, r)) return CommandResult::ERROR; PlaylistResult result = client.partition.PlayPosition(song); - return print_playlist_result(client, result); + return print_playlist_result(r, result); } CommandResult handle_playid(Client &client, Request args) { + Response r(client); + int id = -1; - if (!args.ParseOptional(0, id, client)) + if (!args.ParseOptional(0, id, r)) return CommandResult::ERROR; PlaylistResult result = client.partition.PlayId(id); - return print_playlist_result(client, result); + return print_playlist_result(r, result); } CommandResult @@ -88,16 +92,19 @@ handle_stop(Client &client, gcc_unused Request args) CommandResult handle_currentsong(Client &client, gcc_unused Request args) { - playlist_print_current(client, client.playlist); + Response r(client); + playlist_print_current(r, client.partition, client.playlist); return CommandResult::OK; } CommandResult handle_pause(Client &client, Request args) { + Response r(client); + if (!args.IsEmpty()) { bool pause_flag; - if (!args.Parse(0, pause_flag, client)) + if (!args.Parse(0, pause_flag, r)) return CommandResult::ERROR; client.player_control.SetPause(pause_flag); @@ -127,68 +134,64 @@ handle_status(Client &client, gcc_unused Request args) break; } + Response r(client); + const playlist &playlist = client.playlist; - 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_MIXRAMPDB ": %f\n" - COMMAND_STATUS_STATE ": %s\n", - volume_level_get(client.partition.outputs), - playlist.GetRepeat(), - playlist.GetRandom(), - playlist.GetSingle(), - playlist.GetConsume(), - (unsigned long)playlist.GetVersion(), - playlist.GetLength(), - client.player_control.GetMixRampDb(), - state); + r.Format("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_MIXRAMPDB ": %f\n" + COMMAND_STATUS_STATE ": %s\n", + volume_level_get(client.partition.outputs), + playlist.GetRepeat(), + playlist.GetRandom(), + playlist.GetSingle(), + playlist.GetConsume(), + (unsigned long)playlist.GetVersion(), + playlist.GetLength(), + client.player_control.GetMixRampDb(), + state); if (client.player_control.GetCrossFade() > 0) - client_printf(client, - COMMAND_STATUS_CROSSFADE ": %i\n", - int(client.player_control.GetCrossFade() + 0.5)); + r.Format(COMMAND_STATUS_CROSSFADE ": %i\n", + int(client.player_control.GetCrossFade() + 0.5)); if (client.player_control.GetMixRampDelay() > 0) - client_printf(client, - COMMAND_STATUS_MIXRAMPDELAY ": %f\n", - client.player_control.GetMixRampDelay()); + r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n", + client.player_control.GetMixRampDelay()); song = playlist.GetCurrentPosition(); if (song >= 0) { - client_printf(client, - COMMAND_STATUS_SONG ": %i\n" - COMMAND_STATUS_SONGID ": %u\n", - song, playlist.PositionToId(song)); + r.Format(COMMAND_STATUS_SONG ": %i\n" + COMMAND_STATUS_SONGID ": %u\n", + song, playlist.PositionToId(song)); } if (player_status.state != PlayerState::STOP) { - client_printf(client, - COMMAND_STATUS_TIME ": %i:%i\n" - "elapsed: %1.3f\n" - COMMAND_STATUS_BITRATE ": %u\n", - player_status.elapsed_time.RoundS(), - player_status.total_time.IsNegative() - ? 0u - : unsigned(player_status.total_time.RoundS()), - player_status.elapsed_time.ToDoubleS(), - player_status.bit_rate); + r.Format(COMMAND_STATUS_TIME ": %i:%i\n" + "elapsed: %1.3f\n" + COMMAND_STATUS_BITRATE ": %u\n", + player_status.elapsed_time.RoundS(), + player_status.total_time.IsNegative() + ? 0u + : unsigned(player_status.total_time.RoundS()), + player_status.elapsed_time.ToDoubleS(), + player_status.bit_rate); if (!player_status.total_time.IsNegative()) - client_printf(client, "duration: %1.3f\n", - player_status.total_time.ToDoubleS()); + r.Format("duration: %1.3f\n", + player_status.total_time.ToDoubleS()); if (player_status.audio_format.IsDefined()) { struct audio_format_string af_string; - client_printf(client, - COMMAND_STATUS_AUDIO ": %s\n", - audio_format_to_string(player_status.audio_format, - &af_string)); + r.Format(COMMAND_STATUS_AUDIO ": %s\n", + audio_format_to_string(player_status.audio_format, + &af_string)); } } @@ -198,25 +201,21 @@ handle_status(Client &client, gcc_unused Request args) ? update_service->GetId() : 0; if (updateJobId != 0) { - client_printf(client, - COMMAND_STATUS_UPDATING_DB ": %i\n", - updateJobId); + r.Format(COMMAND_STATUS_UPDATING_DB ": %i\n", + updateJobId); } #endif Error error = client.player_control.LockGetError(); if (error.IsDefined()) - client_printf(client, - COMMAND_STATUS_ERROR ": %s\n", - error.GetMessage()); + r.Format(COMMAND_STATUS_ERROR ": %s\n", + error.GetMessage()); song = playlist.GetNextPosition(); - if (song >= 0) { - client_printf(client, - COMMAND_STATUS_NEXTSONG ": %i\n" - COMMAND_STATUS_NEXTSONGID ": %u\n", - song, playlist.PositionToId(song)); - } + if (song >= 0) + r.Format(COMMAND_STATUS_NEXTSONG ": %i\n" + COMMAND_STATUS_NEXTSONGID ": %u\n", + song, playlist.PositionToId(song)); return CommandResult::OK; } @@ -247,8 +246,10 @@ handle_previous(Client &client, gcc_unused Request args) CommandResult handle_repeat(Client &client, Request args) { + Response r(client); + bool status; - if (!args.Parse(0, status, client)) + if (!args.Parse(0, status, r)) return CommandResult::ERROR; client.partition.SetRepeat(status); @@ -258,8 +259,10 @@ handle_repeat(Client &client, Request args) CommandResult handle_single(Client &client, Request args) { + Response r(client); + bool status; - if (!args.Parse(0, status, client)) + if (!args.Parse(0, status, r)) return CommandResult::ERROR; client.partition.SetSingle(status); @@ -269,8 +272,10 @@ handle_single(Client &client, Request args) CommandResult handle_consume(Client &client, Request args) { + Response r(client); + bool status; - if (!args.Parse(0, status, client)) + if (!args.Parse(0, status, r)) return CommandResult::ERROR; client.partition.SetConsume(status); @@ -280,8 +285,10 @@ handle_consume(Client &client, Request args) CommandResult handle_random(Client &client, Request args) { + Response r(client); + bool status; - if (!args.Parse(0, status, client)) + if (!args.Parse(0, status, r)) return CommandResult::ERROR; client.partition.SetRandom(status); @@ -299,53 +306,58 @@ handle_clearerror(gcc_unused Client &client, gcc_unused Request args) CommandResult handle_seek(Client &client, Request args) { + Response r(client); + unsigned song; SongTime seek_time; - - if (!args.Parse(0, song, client)) - return CommandResult::ERROR; - if (!args.Parse(1, seek_time, client)) + if (!args.Parse(0, song, r) || !args.Parse(1, seek_time, r)) return CommandResult::ERROR; PlaylistResult result = client.partition.SeekSongPosition(song, seek_time); - return print_playlist_result(client, result); + return print_playlist_result(r, result); } CommandResult handle_seekid(Client &client, Request args) { + Response r(client); + unsigned id; SongTime seek_time; - if (!args.Parse(0, id, client)) + if (!args.Parse(0, id, r)) return CommandResult::ERROR; - if (!args.Parse(1, seek_time, client)) + if (!args.Parse(1, seek_time, r)) return CommandResult::ERROR; PlaylistResult result = client.partition.SeekSongId(id, seek_time); - return print_playlist_result(client, result); + return print_playlist_result(r, result); } CommandResult handle_seekcur(Client &client, Request args) { + Response r(client); + const char *p = args.front(); bool relative = *p == '+' || *p == '-'; SignedSongTime seek_time; - if (!ParseCommandArg(client, seek_time, p)) + if (!ParseCommandArg(r, seek_time, p)) return CommandResult::ERROR; PlaylistResult result = client.partition.SeekCurrent(seek_time, relative); - return print_playlist_result(client, result); + return print_playlist_result(r, result); } CommandResult handle_crossfade(Client &client, Request args) { + Response r(client); + unsigned xfade_time; - if (!args.Parse(0, xfade_time, client)) + if (!args.Parse(0, xfade_time, r)) return CommandResult::ERROR; client.player_control.SetCrossFade(xfade_time); @@ -355,8 +367,10 @@ handle_crossfade(Client &client, Request args) CommandResult handle_mixrampdb(Client &client, Request args) { + Response r(client); + float db; - if (!args.Parse(0, db, client)) + if (!args.Parse(0, db, r)) return CommandResult::ERROR; client.player_control.SetMixRampDb(db); @@ -366,8 +380,10 @@ handle_mixrampdb(Client &client, Request args) CommandResult handle_mixrampdelay(Client &client, Request args) { + Response r(client); + float delay_secs; - if (!args.Parse(0, delay_secs, client)) + if (!args.Parse(0, delay_secs, r)) return CommandResult::ERROR; client.player_control.SetMixRampDelay(delay_secs); @@ -378,9 +394,10 @@ handle_mixrampdelay(Client &client, Request args) CommandResult handle_replay_gain_mode(Client &client, Request args) { + Response r(client); + if (!replay_gain_set_mode_string(args.front())) { - command_error(client, ACK_ERROR_ARG, - "Unrecognized replay gain mode"); + r.Error(ACK_ERROR_ARG, "Unrecognized replay gain mode"); return CommandResult::ERROR; } @@ -391,7 +408,7 @@ handle_replay_gain_mode(Client &client, Request args) CommandResult handle_replay_gain_status(Client &client, gcc_unused Request args) { - client_printf(client, "replay_gain_mode: %s\n", - replay_gain_get_mode_string()); + Response r(client); + r.Format("replay_gain_mode: %s\n", replay_gain_get_mode_string()); return CommandResult::OK; } |