1999-11-10 01:12:40 -08:00
|
|
|
/* E-Mixer.c
|
|
|
|
*
|
1999-11-12 16:11:47 -08:00
|
|
|
* Copyright (C) 1999 Tom Gilbert, Steve Brunton
|
1999-11-10 01:12:40 -08:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
1999-11-12 16:11:47 -08:00
|
|
|
/* SGI Stuff skillfully implemented (and supported by) Steve Brunton
|
|
|
|
* <brunton@dweeb.turner.com> */
|
|
|
|
|
1999-11-10 01:12:40 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <config.h>
|
1999-11-19 15:01:40 -08:00
|
|
|
#include "epplet.h"
|
1999-11-10 01:12:40 -08:00
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_SOUNDCARD_H
|
|
|
|
#include <linux/soundcard.h>
|
|
|
|
#elif HAVE_MACHINE_SOUNDCARD_H
|
|
|
|
#include <machine/soundcard.h>
|
|
|
|
#elif HAVE_SYS_SOUNDCARD_H
|
|
|
|
#include <sys/soundcard.h>
|
1999-11-12 16:09:31 -08:00
|
|
|
#elif SGI_AUDIO
|
|
|
|
#include <dmedia/audio.h>
|
|
|
|
#define MAX_CHANNELS 8
|
1999-11-10 01:12:40 -08:00
|
|
|
#else
|
|
|
|
#error No soundcard defenition!
|
|
|
|
#endif /* SOUNDCARD_H */
|
|
|
|
|
|
|
|
Epplet_gadget slider, mutebtn, closebtn, helpbtn;
|
|
|
|
|
1999-11-12 16:09:31 -08:00
|
|
|
#ifdef SGI_AUDIO
|
|
|
|
ALport audport;
|
|
|
|
int minVol; /* to deal with SGI audio HW volume ranges */
|
|
|
|
float adjPct;
|
|
|
|
#else
|
1999-11-10 01:12:40 -08:00
|
|
|
int mixerfd = -1;
|
1999-11-12 16:09:31 -08:00
|
|
|
#endif
|
1999-11-10 01:12:40 -08:00
|
|
|
int mute;
|
|
|
|
int vol;
|
1999-11-29 13:50:40 -08:00
|
|
|
int layout;
|
|
|
|
|
|
|
|
#define LAYOUT_CONVENTIONAL 0
|
|
|
|
#define LAYOUT_WIDE 1
|
|
|
|
#define LAYOUT_TALL 2
|
1999-11-10 01:12:40 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
openMixer (char *device_name)
|
|
|
|
{
|
1999-11-29 15:52:59 -08:00
|
|
|
#ifdef OSS_GETVERSION
|
|
|
|
int res, ver;
|
|
|
|
#endif
|
1999-11-12 16:09:31 -08:00
|
|
|
#ifdef SGI_AUDIO
|
|
|
|
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;
|
|
|
|
#else
|
1999-11-10 01:12:40 -08:00
|
|
|
mixerfd = open (device_name, O_RDWR, 0);
|
|
|
|
if (mixerfd < 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Couldn't open mixer device %s\n", device_name);
|
|
|
|
exit (1);
|
|
|
|
}
|
1999-11-12 16:09:31 -08:00
|
|
|
#endif
|
1999-11-10 01:12:40 -08:00
|
|
|
|
|
|
|
/* 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");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
readMixer (void)
|
|
|
|
{
|
1999-11-12 16:09:31 -08:00
|
|
|
#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 */
|
|
|
|
|
|
|
|
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 (audpv[0].sizeOut < 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "AL_GAIN was an invalid paramater\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (x = 0; x < audpv[0].sizeOut; x++)
|
|
|
|
{
|
|
|
|
tvol += alFixedToDouble (gain[x]);
|
|
|
|
++numchan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-29 13:50:40 -08:00
|
|
|
if (layout == LAYOUT_TALL)
|
|
|
|
return 100 - ((tvol / numchan) - minVol) / adjPct;
|
1999-11-12 16:09:31 -08:00
|
|
|
return ((tvol / numchan) - minVol) / adjPct;
|
|
|
|
#else
|
1999-11-10 01:12:40 -08:00
|
|
|
int tvol, r, l;
|
|
|
|
|
|
|
|
ioctl (mixerfd, MIXER_READ (SOUND_MIXER_VOLUME), &tvol);
|
|
|
|
|
|
|
|
l = tvol & 0xff;
|
|
|
|
r = (tvol & 0xff00) >> 8;
|
|
|
|
|
1999-11-29 13:50:40 -08:00
|
|
|
if (layout == LAYOUT_TALL)
|
|
|
|
return 100 - (r + l) / 2;
|
|
|
|
return (r + l) / 2;
|
1999-11-12 16:09:31 -08:00
|
|
|
#endif
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setMixer (int vol)
|
|
|
|
{
|
|
|
|
int tvol;
|
|
|
|
|
1999-11-12 16:09:31 -08:00
|
|
|
#ifdef SGI_AUDIO
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
1999-11-10 01:12:40 -08:00
|
|
|
tvol = (vol << 8) + vol;
|
|
|
|
ioctl (mixerfd, MIXER_WRITE (SOUND_MIXER_VOLUME), &tvol);
|
1999-11-12 16:09:31 -08:00
|
|
|
|
|
|
|
#endif
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_close (void *data)
|
|
|
|
{
|
|
|
|
Epplet_unremember ();
|
1999-11-12 16:09:31 -08:00
|
|
|
#ifdef SGI_AUDIO
|
|
|
|
alClosePort (audport);
|
|
|
|
#else
|
1999-11-10 01:12:40 -08:00
|
|
|
close (mixerfd);
|
1999-11-12 16:09:31 -08:00
|
|
|
#endif
|
1999-12-11 09:22:13 -08:00
|
|
|
Esync();
|
1999-11-10 01:12:40 -08:00
|
|
|
exit (0);
|
1999-11-15 11:37:56 -08:00
|
|
|
data = NULL;
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mute_cb (void *data)
|
|
|
|
{
|
|
|
|
if (mute == 1)
|
|
|
|
setMixer (0);
|
|
|
|
else
|
1999-11-29 13:50:40 -08:00
|
|
|
{
|
|
|
|
if (layout == LAYOUT_TALL)
|
|
|
|
setMixer (100 - vol);
|
|
|
|
else
|
|
|
|
setMixer (vol);
|
|
|
|
}
|
1999-11-15 11:37:56 -08:00
|
|
|
return;
|
|
|
|
data = NULL;
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adj_cb (void *data)
|
|
|
|
{
|
|
|
|
if (!mute)
|
1999-11-29 13:50:40 -08:00
|
|
|
{
|
|
|
|
if (layout == LAYOUT_TALL)
|
|
|
|
setMixer (100 - vol);
|
|
|
|
else
|
|
|
|
setMixer (vol);
|
|
|
|
}
|
1999-11-15 11:37:56 -08:00
|
|
|
return;
|
|
|
|
data = NULL;
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_help (void *data)
|
|
|
|
{
|
|
|
|
Epplet_show_about ("E-Mixer");
|
1999-11-15 11:37:56 -08:00
|
|
|
return;
|
|
|
|
data = NULL;
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mixer_timeout_callback (void *data)
|
|
|
|
{
|
|
|
|
vol = readMixer ();
|
|
|
|
Epplet_gadget_data_changed (slider);
|
1999-11-15 11:37:56 -08:00
|
|
|
return;
|
|
|
|
data = NULL;
|
1999-11-10 01:12:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_mixer_gadget (void)
|
|
|
|
{
|
|
|
|
vol = readMixer ();
|
|
|
|
|
1999-11-29 13:50:40 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1999-11-10 01:12:40 -08:00
|
|
|
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_timer (mixer_timeout_callback, NULL, 0.5, "TIMER");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
1999-11-29 13:50:40 -08:00
|
|
|
int i;
|
1999-11-12 16:09:31 -08:00
|
|
|
#ifdef SGI_AUDIO
|
|
|
|
openMixer ("audout");
|
|
|
|
#else
|
1999-11-10 01:12:40 -08:00
|
|
|
openMixer ("/dev/mixer");
|
1999-11-12 16:09:31 -08:00
|
|
|
#endif
|
1999-11-29 13:50:40 -08:00
|
|
|
|
|
|
|
layout = LAYOUT_CONVENTIONAL;
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(argv[i], "--wide"))
|
|
|
|
{
|
|
|
|
layout = LAYOUT_WIDE;
|
|
|
|
}
|
|
|
|
else if (!strcmp(argv[i], "--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);
|
|
|
|
}
|
1999-11-10 01:12:40 -08:00
|
|
|
|
|
|
|
create_mixer_gadget ();
|
|
|
|
|
|
|
|
Epplet_show ();
|
|
|
|
Epplet_Loop ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|