Implemented volume control for jukebox

This commit is contained in:
emeric
2026-02-18 00:12:32 +01:00
parent 5f6d3e796a
commit 7a30bb98f6
9 changed files with 137 additions and 51 deletions
+15 -2
View File
@@ -44,7 +44,7 @@ namespace lms::api::subsonic
statusNode.setAttribute("currentIndex", jukeboxService.getCurrentTrackIndex() ? *jukeboxService.getCurrentTrackIndex() : -1); // required
statusNode.setAttribute("playing", !jukeboxService.isPaused()); // required
statusNode.setAttribute("position", std::chrono::duration_cast<std::chrono::seconds>(jukeboxService.getPlaybackTrackTime()).count());
statusNode.setAttribute("gain", 1.f);
statusNode.setAttribute("gain", jukeboxService.getVolume());
return statusNode;
}
@@ -158,6 +158,19 @@ namespace lms::api::subsonic
return response;
}
Response handleJukeboxSetGain(RequestContext& context, jukebox::IJukeboxService& jukeboxService)
{
const auto gain{ getMandatoryParameterAs<float>(context.getParameters(), "gain") };
if (gain < 0 || gain > 1)
throw BadParameterGenericError{ "gain", "gain must be between 0.0 and 1.0" };
jukeboxService.setVolume(gain); // consider gain is linear
Response response{ Response::createOkResponse(context.getServerProtocolVersion()) };
response.addNode("jukeboxStatus", createJukeboxStatusNode(jukeboxService));
return response;
}
using Actionhandler = std::function<Response(RequestContext& context, jukebox::IJukeboxService& jukeboxService)>;
static const std::unordered_map<std::string, Actionhandler> actionHandlers{
{ "get", detail::handleJukeboxGet },
@@ -170,7 +183,7 @@ namespace lms::api::subsonic
{ "clear", detail::handleJukeboxClear },
{ "remove", detail::handleJukeboxRemove },
{ "shuffle", detail::handleJukeboxShuffle },
{ "setGain", detail::handleJukeboxStatus }, // not implemented
{ "setGain", detail::handleJukeboxSetGain },
};
} // namespace detail