1999-05-02 16:21:30 +00:00
|
|
|
/*
|
|
|
|
|
* Control Interface - defaults
|
1999-05-11 22:15:16 +00:00
|
|
|
* Copyright (c) 1998 by Jaroslav Kysela <perex@suse.cz>
|
1999-05-02 16:21:30 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library 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 Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-08-04 10:24:12 +00:00
|
|
|
#include <string.h>
|
2001-01-31 17:26:56 +00:00
|
|
|
#include "local.h"
|
1999-05-02 16:21:30 +00:00
|
|
|
|
|
|
|
|
static int defaults_card(const char *env)
|
|
|
|
|
{
|
|
|
|
|
char *e;
|
|
|
|
|
|
|
|
|
|
e = getenv(env);
|
|
|
|
|
if (!e)
|
|
|
|
|
return -ENOENT;
|
2000-08-25 14:33:53 +00:00
|
|
|
return snd_card_get_index(e);
|
1999-05-02 16:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int defaults_device(const char *env)
|
|
|
|
|
{
|
|
|
|
|
char *e;
|
|
|
|
|
int dev;
|
|
|
|
|
|
|
|
|
|
e = getenv(env);
|
|
|
|
|
if (e) {
|
|
|
|
|
dev = atoi(env);
|
|
|
|
|
if (dev >= 0 && dev < 1024 * 1024)
|
|
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_card(void)
|
|
|
|
|
{
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
result = defaults_card("ALSA_CARD");
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
2000-11-30 19:17:55 +00:00
|
|
|
result = -1;
|
|
|
|
|
if (snd_card_next(&result))
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
return result;
|
1999-05-02 16:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_mixer_card(void)
|
|
|
|
|
{
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
result = defaults_card("ALSA_MIXER_CARD");
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
|
|
|
|
return snd_defaults_card();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_pcm_card(void)
|
|
|
|
|
{
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
result = defaults_card("ALSA_PCM_CARD");
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
|
|
|
|
return snd_defaults_card();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_pcm_device(void)
|
|
|
|
|
{
|
2000-11-30 19:17:55 +00:00
|
|
|
snd_ctl_t *handle;
|
|
|
|
|
char id[16];
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
result = defaults_device("ALSA_PCM_DEVICE");
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
|
|
|
|
sprintf(id, "hw:%i", snd_defaults_pcm_card());
|
|
|
|
|
if (snd_ctl_open(&handle, id) < 0)
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
result = -1;
|
|
|
|
|
if (snd_ctl_pcm_next_device(handle, &result) < 0) {
|
|
|
|
|
snd_ctl_close(handle);
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
1999-05-02 16:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_rawmidi_card(void)
|
|
|
|
|
{
|
|
|
|
|
int result;
|
|
|
|
|
|
2000-02-08 08:41:28 +00:00
|
|
|
result = defaults_card("ALSA_RAWMIDI_CARD");
|
1999-05-02 16:21:30 +00:00
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
|
|
|
|
return snd_defaults_card();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int snd_defaults_rawmidi_device(void)
|
|
|
|
|
{
|
2000-11-30 19:17:55 +00:00
|
|
|
snd_ctl_t *handle;
|
|
|
|
|
char id[16];
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
result = defaults_device("ALSA_RAWMIDI_DEVICE");
|
|
|
|
|
if (result >= 0)
|
|
|
|
|
return result;
|
|
|
|
|
sprintf(id, "hw:%i", snd_defaults_rawmidi_card());
|
|
|
|
|
if (snd_ctl_open(&handle, id) < 0)
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
result = -1;
|
|
|
|
|
if (snd_ctl_rawmidi_next_device(handle, &result) < 0) {
|
|
|
|
|
snd_ctl_close(handle);
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
1999-05-02 16:21:30 +00:00
|
|
|
}
|