Blame alsamixer/cli.c

Packit 229ac0
/*
Packit 229ac0
 * alsamixer - curses mixer for the ALSA project
Packit 229ac0
 * Copyright (c) 1998,1999 Tim Janik
Packit 229ac0
 *                         Jaroslav Kysela <perex@perex.cz>
Packit 229ac0
 * Copyright (c) 2009      Clemens Ladisch <clemens@ladisch.de>
Packit 229ac0
 *
Packit 229ac0
 * This program is free software: you can redistribute it and/or modify
Packit 229ac0
 * it under the terms of the GNU General Public License as published by
Packit 229ac0
 * the Free Software Foundation, either version 2 of the License, or
Packit 229ac0
 * (at your option) any later version.
Packit 229ac0
 *
Packit 229ac0
 * This program is distributed in the hope that it will be useful,
Packit 229ac0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 229ac0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 229ac0
 * GNU General Public License for more details.
Packit 229ac0
 *
Packit 229ac0
 * You should have received a copy of the GNU General Public License
Packit 229ac0
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 229ac0
 */
Packit 229ac0
Packit 229ac0
#include "aconfig.h"
Packit 229ac0
#include <stdio.h>
Packit 229ac0
#include <stdlib.h>
Packit 229ac0
#include <locale.h>
Packit 229ac0
#include <getopt.h>
Packit 229ac0
#include <alsa/asoundlib.h>
Packit 229ac0
#include "gettext_curses.h"
Packit 229ac0
#include "mixer_widget.h"
Packit 229ac0
#include "mainloop.h"
Packit 229ac0
Packit 229ac0
static int use_color = 1;
Packit 229ac0
static struct snd_mixer_selem_regopt selem_regopt = {
Packit 229ac0
	.ver = 1,
Packit 229ac0
	.abstract = SND_MIXER_SABSTRACT_NONE,
Packit 229ac0
	.device = "default",
Packit 229ac0
};
Packit 229ac0
Packit 229ac0
static void show_help(void)
Packit 229ac0
{
Packit 229ac0
	puts(_("Usage: alsamixer [options]"));
Packit 229ac0
	puts(_("Useful options:\n"
Packit 229ac0
	       "  -h, --help              this help\n"
Packit 229ac0
	       "  -c, --card=NUMBER       sound card number or id\n"
Packit 229ac0
	       "  -D, --device=NAME       mixer device name\n"
Packit 229ac0
	       "  -V, --view=MODE         starting view mode: playback/capture/all"));
Packit 229ac0
	puts(_("Debugging options:\n"
Packit 229ac0
	       "  -g, --no-color          toggle using of colors\n"
Packit 229ac0
	       "  -a, --abstraction=NAME  mixer abstraction level: none/basic"));
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
static void parse_options(int argc, char *argv[])
Packit 229ac0
{
Packit 229ac0
	static const char short_options[] = "hc:D:V:gsa:";
Packit 229ac0
	static const struct option long_options[] = {
Packit 229ac0
		{ .name = "help", .val = 'h' },
Packit 229ac0
		{ .name = "card", .has_arg = 1, .val = 'c' },
Packit 229ac0
		{ .name = "device", .has_arg = 1, .val = 'D' },
Packit 229ac0
		{ .name = "view", .has_arg = 1, .val = 'V' },
Packit 229ac0
		{ .name = "no-color", .val = 'g' },
Packit 229ac0
		{ .name = "abstraction", .has_arg = 1, .val = 'a' },
Packit Service 62625b
		{ 0 }
Packit 229ac0
	};
Packit 229ac0
	int option;
Packit 229ac0
	int card_index;
Packit 229ac0
	static char name_buf[16];
Packit 229ac0
Packit 229ac0
	while ((option = getopt_long(argc, argv, short_options,
Packit 229ac0
				     long_options, NULL)) != -1) {
Packit 229ac0
		switch (option) {
Packit 229ac0
		case '?':
Packit 229ac0
		case 'h':
Packit 229ac0
			show_help();
Packit 229ac0
			exit(EXIT_SUCCESS);
Packit 229ac0
		case 'c':
Packit 229ac0
			card_index = snd_card_get_index(optarg);
Packit 229ac0
			if (card_index < 0) {
Packit 229ac0
				fprintf(stderr, _("invalid card index: %s\n"), optarg);
Packit 229ac0
				goto fail;
Packit 229ac0
			}
Packit 229ac0
			sprintf(name_buf, "hw:%d", card_index);
Packit 229ac0
			selem_regopt.device = name_buf;
Packit 229ac0
			break;
Packit 229ac0
		case 'D':
Packit 229ac0
			selem_regopt.device = optarg;
Packit 229ac0
			break;
Packit 229ac0
		case 'V':
Packit 229ac0
			if (*optarg == 'p' || *optarg == 'P')
Packit 229ac0
				view_mode = VIEW_MODE_PLAYBACK;
Packit 229ac0
			else if (*optarg == 'c' || *optarg == 'C')
Packit 229ac0
				view_mode = VIEW_MODE_CAPTURE;
Packit 229ac0
			else
Packit 229ac0
				view_mode = VIEW_MODE_ALL;
Packit 229ac0
			break;
Packit 229ac0
		case 'g':
Packit 229ac0
			use_color = !use_color;
Packit 229ac0
			break;
Packit 229ac0
		case 'a':
Packit 229ac0
			if (!strcmp(optarg, "none"))
Packit 229ac0
				selem_regopt.abstract = SND_MIXER_SABSTRACT_NONE;
Packit 229ac0
			else if (!strcmp(optarg, "basic"))
Packit 229ac0
				selem_regopt.abstract = SND_MIXER_SABSTRACT_BASIC;
Packit 229ac0
			else {
Packit 229ac0
				fprintf(stderr, _("unknown abstraction level: %s\n"), optarg);
Packit 229ac0
				goto fail;
Packit 229ac0
			}
Packit 229ac0
			break;
Packit 229ac0
		default:
Packit 229ac0
			fprintf(stderr, _("unknown option: %c\n"), option);
Packit 229ac0
fail:
Packit 229ac0
			fputs(_("try `alsamixer --help' for more information\n"), stderr);
Packit 229ac0
			exit(EXIT_FAILURE);
Packit 229ac0
		}
Packit 229ac0
	}
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
int main(int argc, char *argv[])
Packit 229ac0
{
Packit 229ac0
	if (!isatty(fileno(stdin)))
Packit 229ac0
		return 0;
Packit 229ac0
Packit 229ac0
	setlocale(LC_ALL, "");
Packit 229ac0
#ifdef ENABLE_NLS_IN_CURSES
Packit 229ac0
	textdomain(PACKAGE);
Packit 229ac0
#endif
Packit 229ac0
Packit 229ac0
	parse_options(argc, argv);
Packit 229ac0
Packit 229ac0
	create_mixer_object(&selem_regopt);
Packit 229ac0
Packit 229ac0
	initialize_curses(use_color);
Packit 229ac0
Packit 229ac0
	create_mixer_widget();
Packit 229ac0
Packit 229ac0
	mainloop();
Packit 229ac0
Packit 229ac0
	app_shutdown();
Packit 229ac0
	return 0;
Packit 229ac0
}