Skip to content

Commit ace5c07

Browse files
committed
Conditionally support mixer script
1 parent 68c4853 commit ace5c07

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

client/player/player.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,15 @@
2626
#include "common/utils/string_utils.hpp"
2727

2828
// 3rd party headers
29+
#ifdef SUPPORTS_VOLUME_SCRIPT
2930
#pragma GCC diagnostic push
3031
#pragma GCC diagnostic ignored "-Wunused-parameter"
31-
#if BOOST_VERSION >= 108000
3232
#if defined(__clang__) && (__clang_major__ >= 13) && !((__clang_major__ == 13) && (__clang_minor__ == 0) && (__clang_patchlevel__ == 0))
3333
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
3434
#endif
3535
#pragma GCC diagnostic ignored "-Wpedantic"
36-
#include <boost/process/v2.hpp>
37-
#else
38-
#pragma GCC diagnostic ignored "-Wpragmas"
39-
#pragma GCC diagnostic ignored "-Wunused-result"
40-
#pragma GCC diagnostic ignored "-Wmissing-braces"
41-
#pragma GCC diagnostic ignored "-Wnarrowing"
42-
#pragma GCC diagnostic ignored "-Wc++11-narrowing"
43-
#include <boost/process/args.hpp>
44-
#include <boost/process/child.hpp>
45-
#include <boost/process/exe.hpp>
36+
#include <boost/process/v2/execute.hpp>
37+
#include <boost/process/v2/process.hpp>
4638
#endif
4739
#pragma GCC diagnostic pop
4840

@@ -244,8 +236,7 @@ void Player::setVolume(const Volume& volume)
244236
}
245237
else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::script)
246238
{
247-
#if BOOST_VERSION >= 108000
248-
// Use Boost process v2 if Boost >= 1.80.0 is available
239+
#ifdef SUPPORTS_VOLUME_SCRIPT
249240
static std::optional<Volume> pending_volume_setting;
250241
static bool script_running = false;
251242
if (script_running)
@@ -282,17 +273,7 @@ void Player::setVolume(const Volume& volume)
282273
}
283274
}
284275
#else
285-
// Use Boost process v1
286-
try
287-
{
288-
using namespace boost::process;
289-
child c(exe = settings_.mixer.parameter, args = {"--volume", cpt::to_string(volume), "--mute", mute ? "true" : "false"});
290-
c.detach();
291-
}
292-
catch (const std::exception& e)
293-
{
294-
LOG(ERROR, LOG_TAG) << "Failed to run script '" + settings_.mixer.parameter + "', error: " << e.what() << "\n";
295-
}
276+
LOG(ERROR, LOG_TAG) << "Mixer mode 'script' not supported\n";
296277
#endif
297278
}
298279
}

client/player/player.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include <thread>
3737
#include <vector>
3838

39+
#if (BOOST_VERSION >= 108000 && !defined(WINDOWS))
40+
#define SUPPORTS_VOLUME_SCRIPT
41+
#endif
42+
3943
namespace player
4044
{
4145

client/snapclient.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***
22
This file is part of snapcast
3-
Copyright (C) 2014-2022 Johannes Pohl
3+
Copyright (C) 2014-2024 Johannes Pohl
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -172,10 +172,14 @@ int main(int argc, char** argv)
172172
hw_mixer_supported = true;
173173
#endif
174174
std::shared_ptr<popl::Value<std::string>> mixer_mode;
175+
176+
std::string mixers = "software";
175177
if (hw_mixer_supported)
176-
mixer_mode = op.add<Value<string>>("", "mixer", "software|hardware|script|none|?[:<options>]", "software");
177-
else
178-
mixer_mode = op.add<Value<string>>("", "mixer", "software|script|none|?[:<options>]", "software");
178+
mixers += "|hardware";
179+
#ifdef SUPPORTS_VOLUME_SCRIPT
180+
mixers += "|script";
181+
#endif
182+
mixer_mode = op.add<Value<string>>("", "mixer", mixers + "|none|?[:<options>]", "software");
179183

180184
// daemon settings
181185
#ifdef HAS_DAEMON
@@ -400,16 +404,26 @@ int main(int argc, char** argv)
400404
settings.player.mixer.mode = ClientSettings::Mixer::Mode::software;
401405
else if ((mode == "hardware") && hw_mixer_supported)
402406
settings.player.mixer.mode = ClientSettings::Mixer::Mode::hardware;
407+
#ifdef SUPPORTS_VOLUME_SCRIPT
403408
else if (mode == "script")
404409
settings.player.mixer.mode = ClientSettings::Mixer::Mode::script;
410+
#endif
405411
else if (mode == "none")
406412
settings.player.mixer.mode = ClientSettings::Mixer::Mode::none;
407413
else if ((mode == "?") || (mode == "help"))
408414
{
409-
cout << "mixer can be one of 'software', " << (hw_mixer_supported ? "'hardware', " : "") << "'script', 'none'\n"
415+
cout << "mixer can be one of 'software', " << (hw_mixer_supported ? "'hardware', " : "")
416+
#ifdef SUPPORTS_VOLUME_SCRIPT
417+
<< "'script', "
418+
#endif
419+
<< "'none'\n"
410420
<< "followed by optional parameters:\n"
411421
<< " * software[:poly[:<exponent>]|exp[:<base>]]\n"
412-
<< (hw_mixer_supported ? " * hardware[:<mixer name>]\n" : "") << " * script[:<script filename>]\n";
422+
<< (hw_mixer_supported ? " * hardware[:<mixer name>]\n" : "")
423+
#ifdef SUPPORTS_VOLUME_SCRIPT
424+
<< " * script[:<script filename>]"
425+
#endif
426+
<< "\n";
413427
exit(EXIT_SUCCESS);
414428
}
415429
else

0 commit comments

Comments
 (0)