From f87121138452f41fd9f9e40f2f5a2d3f8d706f11 Mon Sep 17 00:00:00 2001 From: badaix Date: Tue, 22 Jun 2021 12:20:40 +0200 Subject: [PATCH] Make capability properties mandatory --- common/properties.hpp | 39 ++++++++++++++++--------------- doc/json_rpc_api/stream_plugin.md | 4 ++-- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/common/properties.hpp b/common/properties.hpp index 97b11683..2f3ce6ec 100644 --- a/common/properties.hpp +++ b/common/properties.hpp @@ -154,11 +154,11 @@ public: /// https://www.musicpd.org/doc/html/protocol.html#tags /// The current playback status - PlaybackStatus playback_status; + boost::optional playback_status; /// The current loop / repeat status boost::optional loop_status; /// The current playback rate - float rate; + boost::optional rate; /// A value of false indicates that playback is progressing linearly through a playlist, while true means playback is progressing through a playlist in some /// other order. boost::optional shuffle; @@ -171,22 +171,23 @@ public: /// The maximum value which the Rate property can take. Clients should not attempt to set the Rate property above this value boost::optional maximum_rate; /// Whether the client can call the Next method on this interface and expect the current track to change - boost::optional can_go_next; + bool can_go_next = false; /// Whether the client can call the Previous method on this interface and expect the current track to change - boost::optional can_go_previous; + bool can_go_previous = false; /// Whether playback can be started using "play" or "playPause" - boost::optional can_play; + bool can_play = false; /// Whether playback can be paused using "pause" or "playPause" - boost::optional can_pause; + bool can_pause = false; /// Whether the client can control the playback position using "seek" and "setPosition". This may be different for different tracks - boost::optional can_seek; + bool can_seek = false; /// Whether the media player may be controlled over this interface - boost::optional can_control; + bool can_control = false; json toJson() const { json j; - addTag(j, "playbackStatus", to_string(playback_status)); + if (playback_status.has_value()) + addTag(j, "playbackStatus", boost::optional(to_string(playback_status.value()))); if (loop_status.has_value()) addTag(j, "loopStatus", boost::optional(to_string(loop_status.value()))); addTag(j, "rate", rate); @@ -220,28 +221,28 @@ public: boost::optional opt; readTag(j, "playbackStatus", opt); - if (!opt.has_value()) - playback_status = PlaybackStatus::kStopped; - else + if (opt.has_value()) playback_status = playback_status_from_string(opt.value()); + else + playback_status = boost::none; readTag(j, "loopStatus", opt); if (opt.has_value()) loop_status = loop_status_from_string(opt.value()); else loop_status = boost::none; - readTag(j, "rate", rate, 1.0f); + readTag(j, "rate", rate); readTag(j, "shuffle", shuffle); readTag(j, "volume", volume); readTag(j, "position", position); readTag(j, "minimumRate", minimum_rate); readTag(j, "maximumRate", maximum_rate); - readTag(j, "canGoNext", can_go_next); - readTag(j, "canGoPrevious", can_go_previous); - readTag(j, "canPlay", can_play); - readTag(j, "canPause", can_pause); - readTag(j, "canSeek", can_seek); - readTag(j, "canControl", can_control); + readTag(j, "canGoNext", can_go_next, false); + readTag(j, "canGoPrevious", can_go_previous, false); + readTag(j, "canPlay", can_play, false); + readTag(j, "canPause", can_pause, false); + readTag(j, "canSeek", can_seek, false); + readTag(j, "canControl", can_control, false); } bool operator==(const Properties& other) const diff --git a/doc/json_rpc_api/stream_plugin.md b/doc/json_rpc_api/stream_plugin.md index d172da6f..085ef9e2 100644 --- a/doc/json_rpc_api/stream_plugin.md +++ b/doc/json_rpc_api/stream_plugin.md @@ -65,7 +65,7 @@ todo Success: ```json -{"id": 1, "jsonrpc": "2.0", "result": {"artist":["Travis Scott & HVME"],"file":"http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3","name":"1Live, Westdeutscher Rundfunk Koeln","title":"Goosebumps (Remix)","trackId":"3"}} +{"id": 1, "jsonrpc": "2.0", "result": {"canControl":true,"canGoNext":true,"canGoPrevious":true,"canPause":true,"canPlay":true,"canSeek":false,"loopStatus":"none","playbackStatus":"playing","position":593.394,"shuffle":false,"volume":86}} ``` Error: @@ -85,7 +85,7 @@ todo Success: ```json -{"id": 1, "jsonrpc": "2.0", "result": {"canControl":true,"canGoNext":true,"canGoPrevious":true,"canPause":true,"canPlay":true,"canSeek":false,"loopStatus":"none","playbackStatus":"playing","position":593.394,"shuffle":false,"volume":86}} +{"id": 1, "jsonrpc": "2.0", "result": {"artist":["Travis Scott & HVME"],"file":"http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3","name":"1Live, Westdeutscher Rundfunk Koeln","title":"Goosebumps (Remix)","trackId":"3"}} ``` ## Notifications: