added more funcionality to salsa (save/load sound settings), moved volume

settings to /etc/alsa/
This commit is contained in:
Martin Stransky 2007-04-18 12:28:22 +00:00
parent db08b0e5b6
commit 5e20f4bdf5
2 changed files with 88 additions and 24 deletions

View File

@ -4,7 +4,7 @@
Summary: Advanced Linux Sound Architecture (ALSA) utilities
Name: alsa-utils
Version: 1.0.14
Release: 0.4%{?prever_dot}%{?dist}
Release: 0.5%{?prever_dot}%{?dist}
License: GPL
Group: Applications/Multimedia
URL: http://www.alsa-project.org/
@ -39,15 +39,19 @@ Architecture (ALSA).
%{__rm} -rf ${RPM_BUILD_ROOT}
make install DESTDIR=$RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_sbindir}
ln -s ../../sbin/alsactl $RPM_BUILD_ROOT/%{_sbindir}/alsactl
install -m 755 salsa $RPM_BUILD_ROOT/sbin
# Install ALSA udev rules
mkdir -p -m755 $RPM_BUILD_ROOT/etc/udev/rules.d/
install -m 644 %{SOURCE10} $RPM_BUILD_ROOT/etc/udev/rules.d/90-alsa.rules
# Install support utilities
mkdir -p -m755 $RPM_BUILD_ROOT/bin
install -m 755 alsaunmute %{buildroot}/bin
install -m 755 alsacard %{buildroot}/bin
install -m 755 salsa %{buildroot}/sbin
# Link alsactl to /usr/sbin
mkdir -p $RPM_BUILD_ROOT/%{_sbindir}
ln -s ../../sbin/alsactl $RPM_BUILD_ROOT/%{_sbindir}/alsactl
%clean
%{__rm} -rf $RPM_BUILD_ROOT
@ -57,9 +61,9 @@ install -m 755 alsacard %{buildroot}/bin
%doc COPYING ChangeLog README TODO
/etc/udev/rules.d/*
/bin/*
/sbin/*
%{_bindir}/*
%{_sbindir}/*
/sbin/*
%{_mandir}/man?/*
%dir %{_datadir}/sounds
%dir %{_datadir}/sounds/alsa
@ -70,6 +74,10 @@ install -m 755 alsacard %{buildroot}/bin
/usr/share/locale/*
%changelog
* Wed Apr 18 2007 Martin Stransky <stransky@redhat.com> 1.0.14-0.5.rc2
- added more funcionality to salsa (save/load sound settings),
moved volume settings to /etc/alsa/
* Thu Apr 10 2007 Martin Stransky <stransky@redhat.com> 1.0.14-0.4.rc2
- added support for large files
- minor fix in alsaunmute

92
salsa.c
View File

@ -1,4 +1,4 @@
/* Copyright 2005 Red Hat, Inc.
/* Copyright 2007 Red Hat, Inc.
*
* Portions extraced from various ALSA code:
* Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
@ -16,10 +16,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <alsa/asoundlib.h>
#define ALSA_CONFIG_PATH "/etc/asound.state"
#define ALSA_CONFIG_PATH "/etc/alsa/asound.state"
#define ALL_CARDS (-1)
int get_card_number()
{
@ -46,8 +49,8 @@ int has_config(int index)
snd_ctl_t *handle;
snd_ctl_card_info_t *info;
const char *id;
char path[32];
char path[32];
rc = snd_config_top(&config);
if (rc < 0)
goto out;
@ -75,15 +78,30 @@ out:
}
int run_alsactl(int index)
void load_volume_settings(int index)
{
char *args[] = { "/sbin/alsactl", "restore", NULL, NULL };
char num[10];
char *args[] = { "/sbin/alsactl", "-f", ALSA_CONFIG_PATH, "restore", NULL, NULL };
char num[10];
sprintf(num, "%d", index);
args[2] = num;
if(index != ALL_CARDS) {
snprintf(num, 10, "%d", index);
args[4] = num;
}
execv(args[0], args);
}
void save_volume_settings(int index)
{
char *args[] = { "/sbin/alsactl", "-f", ALSA_CONFIG_PATH, "store", NULL, NULL };
char num[10];
if(index != ALL_CARDS) {
snprintf(num, 10, "%d", index);
args[4] = num;
}
execv(args[0], args);
return 1;
}
void frob_mixer(int index)
@ -94,17 +112,55 @@ void frob_mixer(int index)
execl("/bin/alsaunmute","/bin/alsaunmute", tmp, "-v", NULL);
}
void banner(void)
{
printf("ALSA volume settings handler, Copyright 2007 Red Hat, Inc.\n");
printf("This software may be freely redistributed under\nthe terms of the GNU public license.\n\n");
printf("Usage: salsa [options] [card number]\n\n");
printf(" Options:\n");
printf(" -l - Load volume settings\n");
printf(" -s - Save volume settings\n\n");
printf(" Card number:\n");
printf(" ## - An affected card. If it isn't specified,\n");
printf(" configure all installed sound cards.\n\n");
exit(0);
}
int main(int argc, char **argv)
{
int i;
i = get_card_number();
if (i < 0)
return 0;
if (has_config(i))
return run_alsactl(i);
else
frob_mixer(i);
if(argc == 1) {
i = get_card_number();
if (i < 0) {
return 0;
}
if (has_config(i)) {
load_volume_settings(i);
}
else {
frob_mixer(i);
}
}
else if(argc >= 2) {
int card_number = ALL_CARDS;
if(argc == 3) {
card_number = atoi(argv[2]);
}
if(argv[1][1] == 'l') {
load_volume_settings(card_number);
}
else if(argv[1][1] == 's') {
save_volume_settings(card_number);
}
else {
banner();
}
}
return(0);
}