read_mixer.cxx 2.1 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 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 "config.h"
21
#include "NullMixerListener.hxx"
Max Kellermann's avatar
Max Kellermann committed
22 23
#include "mixer/MixerControl.hxx"
#include "mixer/MixerList.hxx"
24
#include "filter/FilterRegistry.hxx"
25
#include "pcm/Volume.hxx"
26 27
#include "Main.hxx"
#include "event/Loop.hxx"
28
#include "config/Block.hxx"
29
#include "util/PrintException.hxx"
30 31 32 33

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

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

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

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

52
	EventLoop event_loop;
53

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

64
	mixer_open(mixer);
65

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

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

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

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