mpd/test/read_mixer.cxx

61 lines
1.3 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "NullMixerListener.hxx"
#include "mixer/Control.hxx"
#include "mixer/Mixer.hxx"
2022-08-18 17:03:37 +02:00
#include "mixer/plugins/AlsaMixerPlugin.hxx"
#include "filter/Registry.hxx"
2013-01-15 07:53:44 +01:00
#include "event/Loop.hxx"
#include "config/Block.hxx"
2018-07-17 21:56:43 +02:00
#include "util/PrintException.hxx"
#include <cassert>
#include <stdlib.h>
2016-11-23 17:43:50 +01:00
const FilterPlugin *
filter_plugin_by_name([[maybe_unused]] const char *name) noexcept
{
assert(false);
2020-02-01 13:49:19 +01:00
return nullptr;
}
int main(int argc, [[maybe_unused]] char **argv)
2016-09-09 12:52:51 +02:00
try {
int volume;
if (argc != 2) {
fprintf(stderr, "Usage: read_mixer PLUGIN\n");
return EXIT_FAILURE;
}
EventLoop event_loop;
2013-01-15 07:53:44 +01:00
NullMixerListener mixer_listener;
Mixer *mixer = mixer_new(event_loop, alsa_mixer_plugin,
/* ugly dangerous dummy pointer to
make the compiler happy; this
works with most mixers, because
they don't need the AudioOutput */
*(AudioOutput *)0x1,
mixer_listener,
2016-09-09 12:52:51 +02:00
ConfigBlock());
volume = mixer->LockGetVolume();
mixer_free(mixer);
assert(volume >= -1 && volume <= 100);
if (volume < 0) {
2016-09-09 12:52:51 +02:00
fprintf(stderr, "failed to read volume\n");
return EXIT_FAILURE;
}
printf("%d\n", volume);
return 0;
2018-07-17 21:56:43 +02:00
} catch (...) {
PrintException(std::current_exception());
2016-09-09 12:52:51 +02:00
return EXIT_FAILURE;
}