read_mixer.cxx 2.08 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 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/FilterRegistry.hxx"
24
#include "pcm/Volume.hxx"
25 26
#include "Main.hxx"
#include "event/Loop.hxx"
27
#include "config/Block.hxx"
28
#include "util/PrintException.hxx"
29 30 31 32

#include <assert.h>
#include <string.h>
#include <unistd.h>
33
#include <stdlib.h>
34

35
const FilterPlugin *
36
filter_plugin_by_name(gcc_unused const char *name) noexcept
37 38 39 40 41
{
	assert(false);
	return NULL;
}

42
int main(int argc, gcc_unused char **argv)
43
try {
44 45 46
	int volume;

	if (argc != 2) {
47 48
		fprintf(stderr, "Usage: read_mixer PLUGIN\n");
		return EXIT_FAILURE;
49 50
	}

51
	EventLoop event_loop;
52

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

63
	mixer_open(mixer);
64

65
	volume = mixer_get_volume(mixer);
66 67 68 69 70 71
	mixer_close(mixer);
	mixer_free(mixer);

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

	if (volume < 0) {
72
		fprintf(stderr, "failed to read volume\n");
73
		return EXIT_FAILURE;
74 75
	}

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