read_mixer.cxx 2 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "NullMixerListener.hxx"
Max Kellermann's avatar
Max Kellermann committed
21 22
#include "mixer/MixerControl.hxx"
#include "mixer/MixerList.hxx"
23
#include "filter/Registry.hxx"
24
#include "event/Loop.hxx"
25
#include "config/Block.hxx"
26
#include "util/PrintException.hxx"
27

28 29
#include <cassert>

30
#include <stdlib.h>
31

32
const FilterPlugin *
Rosen Penev's avatar
Rosen Penev committed
33
filter_plugin_by_name([[maybe_unused]] const char *name) noexcept
34 35
{
	assert(false);
36
	return nullptr;
37 38
}

Rosen Penev's avatar
Rosen Penev committed
39
int main(int argc, [[maybe_unused]] char **argv)
40
try {
41 42 43
	int volume;

	if (argc != 2) {
44 45
		fprintf(stderr, "Usage: read_mixer PLUGIN\n");
		return EXIT_FAILURE;
46 47
	}

48
	EventLoop event_loop;
49

50
	NullMixerListener mixer_listener;
51
	Mixer *mixer = mixer_new(event_loop, alsa_mixer_plugin,
52 53 54 55 56
				 /* ugly dangerous dummy pointer to
				    make the compiler happy; this
				    works with most mixers, because
				    they don't need the AudioOutput */
				 *(AudioOutput *)0x1,
57
				 mixer_listener,
58
				 ConfigBlock());
59

60
	mixer_open(mixer);
61

62
	volume = mixer_get_volume(mixer);
63 64 65 66 67 68
	mixer_close(mixer);
	mixer_free(mixer);

	assert(volume >= -1 && volume <= 100);

	if (volume < 0) {
69
		fprintf(stderr, "failed to read volume\n");
70
		return EXIT_FAILURE;
71 72
	}

73
	printf("%d\n", volume);
74
	return 0;
75 76
} catch (...) {
	PrintException(std::current_exception());
77
	return EXIT_FAILURE;
78
}