Patch from Jerome De Greef <jdegreef@brutele.be> to save and restore volume

on mute/unmute.


SVN revision: 4385
This commit is contained in:
Tom Gilbert 2001-03-17 16:36:26 +00:00
parent 7b375bdd99
commit 8b160403b7
1 changed files with 213 additions and 198 deletions

View File

@ -45,7 +45,7 @@ Epplet_gadget slider, mutebtn, closebtn, helpbtn;
#ifdef SGI_AUDIO
ALport audport;
int minVol; /* to deal with SGI audio HW volume ranges */
int minVol; /* to deal with SGI audio HW volume ranges */
float adjPct;
#else
int mixerfd = -1;
@ -59,286 +59,301 @@ int layout;
#define LAYOUT_TALL 2
static void
openMixer (char *device_name)
openMixer(char *device_name)
{
#ifdef OSS_GETVERSION
int res, ver;
int res, ver;
#endif
#ifdef SGI_AUDIO
ALparamInfo pi;
int maxVol;
ALparamInfo pi;
int maxVol;
audport = alOpenPort (device_name, "w", NULL);
if (!audport)
{
fprintf (stderr, "Couldn't open audio port %s\n", device_name);
exit (1);
}
alGetParamInfo (alGetResource (audport), AL_GAIN, &pi);
minVol = alFixedToDouble (pi.min.ll);
maxVol = alFixedToDouble (pi.max.ll);
adjPct = (maxVol - minVol) * 0.01;
audport = alOpenPort(device_name, "w", NULL);
if (!audport)
{
fprintf(stderr, "Couldn't open audio port %s\n", device_name);
exit(1);
}
alGetParamInfo(alGetResource(audport), AL_GAIN, &pi);
minVol = alFixedToDouble(pi.min.ll);
maxVol = alFixedToDouble(pi.max.ll);
adjPct = (maxVol - minVol) * 0.01;
#else
mixerfd = open (device_name, O_RDWR, 0);
if (mixerfd < 0)
{
fprintf (stderr, "Couldn't open mixer device %s\n", device_name);
exit (1);
}
mixerfd = open(device_name, O_RDWR, 0);
if (mixerfd < 0)
{
fprintf(stderr, "Couldn't open mixer device %s\n", device_name);
exit(1);
}
#endif
/* check driver-version */
/* check driver-version */
#ifdef OSS_GETVERSION
res = ioctl (mixerfd, OSS_GETVERSION, &ver);
if ((res == 0) && (ver != SOUND_VERSION))
{
fprintf (stderr, "warning: compiled "
"with a different version of\nsoundcard.h.\n");
}
res = ioctl(mixerfd, OSS_GETVERSION, &ver);
if ((res == 0) && (ver != SOUND_VERSION))
{
fprintf(stderr,
"warning: compiled "
"with a different version of\nsoundcard.h.\n");
}
#endif
}
static int
readMixer (void)
readMixer(void)
{
#ifdef SGI_AUDIO
int x;
int numchan = 0;
double tvol = 0;
ALpv audpv[2]; /* audio resource paramater info */
ALfixed gain[MAX_CHANNELS]; /* where to store the gain information. up to 8 channels */
int x;
int numchan = 0;
double tvol = 0;
ALpv audpv[2]; /* audio resource paramater info */
ALfixed gain[MAX_CHANNELS]; /* where to store the gain information. up to 8 channels */
audpv[0].param = AL_GAIN;
audpv[0].value.ptr = gain;
audpv[0].sizeIn = MAX_CHANNELS; /* can get up to 8-channel vector back */
audpv[0].param = AL_GAIN;
audpv[0].value.ptr = gain;
audpv[0].sizeIn = MAX_CHANNELS; /* can get up to 8-channel vector back */
if (alGetParams (alGetResource (audport), audpv, 1) < 0)
{
fprintf (stderr, "alGetParams failed: %d\n", oserror ());
}
else
{
if (alGetParams(alGetResource(audport), audpv, 1) < 0)
{
fprintf(stderr, "alGetParams failed: %d\n", oserror());
}
else
{
if (audpv[0].sizeOut < 0)
{
fprintf (stderr, "AL_GAIN was an invalid paramater\n");
}
{
fprintf(stderr, "AL_GAIN was an invalid paramater\n");
}
else
{
for (x = 0; x < audpv[0].sizeOut; x++)
{
tvol += alFixedToDouble (gain[x]);
++numchan;
}
}
}
if (layout == LAYOUT_TALL)
return 100 - ((tvol / numchan) - minVol) / adjPct;
return ((tvol / numchan) - minVol) / adjPct;
{
for (x = 0; x < audpv[0].sizeOut; x++)
{
tvol += alFixedToDouble(gain[x]);
++numchan;
}
}
}
if (layout == LAYOUT_TALL)
return 100 - ((tvol / numchan) - minVol) / adjPct;
return ((tvol / numchan) - minVol) / adjPct;
#else
int tvol, r, l;
int tvol, r, l;
ioctl (mixerfd, MIXER_READ (SOUND_MIXER_VOLUME), &tvol);
ioctl(mixerfd, MIXER_READ(SOUND_MIXER_VOLUME), &tvol);
l = tvol & 0xff;
r = (tvol & 0xff00) >> 8;
l = tvol & 0xff;
r = (tvol & 0xff00) >> 8;
if (layout == LAYOUT_TALL)
return 100 - (r + l) / 2;
return (r + l) / 2;
if (layout == LAYOUT_TALL)
return 100 - (r + l) / 2;
return (r + l) / 2;
#endif
}
static void
setMixer (int vol)
setMixer(int vol)
{
int tvol;
int tvol;
#ifdef SGI_AUDIO
int x;
ALpv audpv[2];
ALfixed gain[MAX_CHANNELS];
int x;
ALpv audpv[2];
ALfixed gain[MAX_CHANNELS];
tvol = (vol * adjPct) + minVol;
for (x = 0; x < MAX_CHANNELS; ++x)
{
gain[x] = alDoubleToFixed (tvol);
}
audpv[0].param = AL_GAIN;
audpv[0].value.ptr = gain;
audpv[0].sizeIn = MAX_CHANNELS;
if (alSetParams (alGetResource (audport), audpv, 1) < 0)
{
fprintf (stderr, "alSetParams failed : %d\n", oserror ());
}
if (audpv[0].sizeOut < 0)
{
fprintf (stderr, "volume - %d wasn't valid\n", tvol);
}
tvol = (vol * adjPct) + minVol;
for (x = 0; x < MAX_CHANNELS; ++x)
{
gain[x] = alDoubleToFixed(tvol);
}
audpv[0].param = AL_GAIN;
audpv[0].value.ptr = gain;
audpv[0].sizeIn = MAX_CHANNELS;
if (alSetParams(alGetResource(audport), audpv, 1) < 0)
{
fprintf(stderr, "alSetParams failed : %d\n", oserror());
}
if (audpv[0].sizeOut < 0)
{
fprintf(stderr, "volume - %d wasn't valid\n", tvol);
}
#else
tvol = (vol << 8) + vol;
ioctl (mixerfd, MIXER_WRITE (SOUND_MIXER_VOLUME), &tvol);
tvol = (vol << 8) + vol;
ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tvol);
#endif
}
static void
cb_close (void *data)
cb_close(void *data)
{
Epplet_unremember ();
Epplet_unremember();
#ifdef SGI_AUDIO
alClosePort (audport);
alClosePort(audport);
#else
close (mixerfd);
close(mixerfd);
#endif
Esync();
exit (0);
data = NULL;
Esync();
exit(0);
data = NULL;
}
static void
mute_cb (void *data)
mute_cb(void *data)
{
if (mute == 1)
setMixer (0);
else
{
static int old_vol = 0;
if (mute == 1)
{
old_vol = vol;
setMixer(0);
}
else
{
vol = old_vol;
if (layout == LAYOUT_TALL)
setMixer (100 - vol);
setMixer(100 - vol);
else
setMixer (vol);
}
return;
data = NULL;
setMixer(vol);
}
return;
data = NULL;
}
static void
adj_cb (void *data)
adj_cb(void *data)
{
if (!mute)
{
if (!mute)
{
if (layout == LAYOUT_TALL)
setMixer (100 - vol);
setMixer(100 - vol);
else
setMixer (vol);
}
return;
data = NULL;
setMixer(vol);
}
return;
data = NULL;
}
static void
cb_help (void *data)
cb_help(void *data)
{
Epplet_show_about ("E-Mixer");
return;
data = NULL;
Epplet_show_about("E-Mixer");
return;
data = NULL;
}
static void
mixer_timeout_callback (void *data)
mixer_timeout_callback(void *data)
{
vol = readMixer ();
Epplet_gadget_data_changed (slider);
Epplet_timer (mixer_timeout_callback, NULL, 0.5, "TIMER");
return;
data = NULL;
vol = readMixer();
Epplet_gadget_data_changed(slider);
Epplet_timer(mixer_timeout_callback, NULL, 0.5, "TIMER");
return;
data = NULL;
}
static void
create_mixer_gadget (void)
create_mixer_gadget(void)
{
vol = readMixer ();
vol = readMixer();
switch (layout)
{
case LAYOUT_WIDE:
slider =
Epplet_create_hslider (30, 3, 48, 0, 100, 1, 25, &vol, adj_cb, NULL);
mutebtn =
Epplet_create_togglebutton ("M", NULL, 80, 2, 12, 12, &mute, mute_cb,
NULL);
closebtn = Epplet_create_button (NULL, NULL, 2, 2, 0, 0, "CLOSE", 0,
NULL, cb_close, NULL);
helpbtn = Epplet_create_button (NULL, NULL, 16, 2, 0, 0, "HELP", 0,
NULL, cb_help, NULL);
break;
case LAYOUT_TALL:
slider =
Epplet_create_vslider (3, 30, 48, 0, 100, 1, 25, &vol, adj_cb, NULL);
mutebtn =
Epplet_create_togglebutton ("M", NULL, 2, 80, 12, 12, &mute, mute_cb,
NULL);
closebtn = Epplet_create_button (NULL, NULL, 2, 2, 0, 0, "CLOSE", 0,
NULL, cb_close, NULL);
helpbtn = Epplet_create_button (NULL, NULL, 2, 16, 0, 0, "HELP", 0,
NULL, cb_help, NULL);
break;
default:
slider =
Epplet_create_hslider (4, 4, 40, 0, 100, 1, 25, &vol, adj_cb, NULL);
mutebtn =
Epplet_create_togglebutton ("Mute", NULL, 5, 18, 36, 12, &mute, mute_cb,
NULL);
closebtn = Epplet_create_button (NULL, NULL, 2, 34, 0, 0, "CLOSE", 0,
NULL, cb_close, NULL);
helpbtn = Epplet_create_button (NULL, NULL, 34, 34, 0, 0, "HELP", 0,
NULL, cb_help, NULL);
}
switch (layout)
{
case LAYOUT_WIDE:
slider =
Epplet_create_hslider(30, 3, 48, 0, 100, 1, 25, &vol, adj_cb,
NULL);
mutebtn =
Epplet_create_togglebutton("M", NULL, 80, 2, 12, 12, &mute,
mute_cb, NULL);
closebtn =
Epplet_create_button(NULL, NULL, 2, 2, 0, 0, "CLOSE", 0, NULL,
cb_close, NULL);
helpbtn =
Epplet_create_button(NULL, NULL, 16, 2, 0, 0, "HELP", 0, NULL,
cb_help, NULL);
break;
case LAYOUT_TALL:
slider =
Epplet_create_vslider(3, 30, 48, 0, 100, 1, 25, &vol, adj_cb,
NULL);
mutebtn =
Epplet_create_togglebutton("M", NULL, 2, 80, 12, 12, &mute,
mute_cb, NULL);
closebtn =
Epplet_create_button(NULL, NULL, 2, 2, 0, 0, "CLOSE", 0, NULL,
cb_close, NULL);
helpbtn =
Epplet_create_button(NULL, NULL, 2, 16, 0, 0, "HELP", 0, NULL,
cb_help, NULL);
break;
default:
slider =
Epplet_create_hslider(4, 4, 40, 0, 100, 1, 25, &vol, adj_cb, NULL);
mutebtn =
Epplet_create_togglebutton("Mute", NULL, 5, 18, 36, 12, &mute,
mute_cb, NULL);
closebtn =
Epplet_create_button(NULL, NULL, 2, 34, 0, 0, "CLOSE", 0, NULL,
cb_close, NULL);
helpbtn =
Epplet_create_button(NULL, NULL, 34, 34, 0, 0, "HELP", 0, NULL,
cb_help, NULL);
}
mute = 0;
mute = 0;
Epplet_gadget_show (slider);
Epplet_gadget_show (mutebtn);
Epplet_gadget_show (closebtn);
Epplet_gadget_show (helpbtn);
Epplet_timer (mixer_timeout_callback, NULL, 0.5, "TIMER");
Epplet_gadget_show(slider);
Epplet_gadget_show(mutebtn);
Epplet_gadget_show(closebtn);
Epplet_gadget_show(helpbtn);
Epplet_timer(mixer_timeout_callback, NULL, 0.5, "TIMER");
}
int
main (int argc, char **argv)
main(int argc, char **argv)
{
int i;
int i;
atexit(Epplet_cleanup);
atexit(Epplet_cleanup);
#ifdef SGI_AUDIO
openMixer ("audout");
openMixer("audout");
#else
openMixer ("/dev/mixer");
openMixer("/dev/mixer");
#endif
layout = LAYOUT_CONVENTIONAL;
for (i = 1; i < argc; i++)
{
layout = LAYOUT_CONVENTIONAL;
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--wide"))
{
layout = LAYOUT_WIDE;
}
{
layout = LAYOUT_WIDE;
}
else if (!strcmp(argv[i], "--tall"))
{
layout = LAYOUT_TALL;
}
}
{
layout = LAYOUT_TALL;
}
}
switch (layout)
{
case LAYOUT_WIDE:
Epplet_Init ("E-Mixer", "0.2", "Enlightenment Volume Control Epplet", 6, 1,
argc, argv, 0);
break;
case LAYOUT_TALL:
Epplet_Init ("E-Mixer", "0.2", "Enlightenment Volume Control Epplet", 1, 6,
argc, argv, 0);
break;
default:
Epplet_Init ("E-Mixer", "0.2", "Enlightenment Volume Control Epplet", 3, 3,
argc, argv, 0);
}
switch (layout)
{
case LAYOUT_WIDE:
Epplet_Init("E-Mixer", "0.2", "Enlightenment Volume Control Epplet",
6, 1, argc, argv, 0);
break;
case LAYOUT_TALL:
Epplet_Init("E-Mixer", "0.2", "Enlightenment Volume Control Epplet",
1, 6, argc, argv, 0);
break;
default:
Epplet_Init("E-Mixer", "0.2", "Enlightenment Volume Control Epplet",
3, 3, argc, argv, 0);
}
create_mixer_gadget ();
create_mixer_gadget();
Epplet_show ();
Epplet_Loop ();
Epplet_show();
Epplet_Loop();
return 0;
return 0;
}