[nas] [PATCH] add initial device option to aupanel
Erik Auerswald
auerswal at unix-ag.uni-kl.de
Wed Jul 19 12:31:06 MDT 2006
Hi,
the attached patch adds a command line option to select the initial
device to aupanel. See the manpage changes for info about how to specify
the device.
The code to use the hexadecimal device id is more or less taken from
auctl.
Erik
-------------- next part --------------
Index: clients/audio/aupanel/aupanel.man
===================================================================
--- clients/audio/aupanel/aupanel.man (revision 156)
+++ clients/audio/aupanel/aupanel.man (working copy)
@@ -4,10 +4,25 @@
aupanel \- allows user adjustment of Network Audio System device attributes
.IX aupanel#(1) "" "\fLaupanel\fP(1)"
.SH SYNOPSIS
-\fBaupanel\fP [\fB\-audio\fP \fIservername\fP]
+\fBaupanel\fP [\fB\-audio\fP \fIservername\fP] [\fB\-device\fP \fIid\fP]
.SH DESCRIPTION
\fIaupanel\fP provides an X-based window-oriented interface allowing the user
to adjust the attributes of the devices provided by the Network Audio System service.
+.SH OPTIONS
+The following options may be used with \fIaupanel\fP:
+.TP 8
+.BI "\-audio " servername
+This option specifies the Network Audio System server to contact.
+.TP 8
+.BI "\-device " id
+This option specifies the initially activated audio device on the server.
+If the \fIid\fP is a decimal number \fBn\fP, the \fBn\fP\fIth\fP device returned
+by the server is used. If it is a hexadecimal number (starting with \fI0x\fP)
+it is used as the resource identifier of the desired device. Otherwise,
+\fIid\fP should be the exact device name (e.g. Stereo Channel Output).
+You can use \fIauinfo\fP to query an audioserver for this information.
+.PP
+Additionally, options from the Athena Widget Set can be used.
.SH AUPANEL AND THE ATHENA WIDGET SET
\fIaupanel\fP uses the X Toolkit Intrinsics and the Athena Widget Set.
For more information, see the Athena Widget Set documentation.
@@ -34,7 +49,7 @@
will attempt to connect to the audio server running on the
X Window System display.
.SH "SEE ALSO"
-nas(1), auctl(1), X(1)
+nas(1), auctl(1), auinfo(1), X(1)
.SH COPYRIGHT
Copyright 1993, 1994 Network Computing Devices, Inc.
.SH AUTHOR
Index: clients/audio/aupanel/aupanel.c
===================================================================
--- clients/audio/aupanel/aupanel.c (revision 156)
+++ clients/audio/aupanel/aupanel.c (working copy)
@@ -56,7 +56,7 @@
#define APP_CLASS "Aupanel"
#define USAGE "\
-usage: aupanel [-a audioserver]\
+usage: aupanel [-a audioserver] [-dev id]\
"
#define MakeCommandButton(w, parent, label, callback) \
@@ -290,6 +290,8 @@
queryCB(w, g, call_data);
}
+static void set_device_by_name(GlobalDataPtr g, const char *name);
+
static void
menuCB(Widget w, XtPointer gp, XtPointer call_data)
{
@@ -299,12 +301,7 @@
XtVaGetValues(w, XtNlabel, &string, NULL);
XtVaSetValues(g->device, XtNlabel, string, NULL);
-
- for (i = 0; i < g->numDevices; i++)
- if (!strcmp(string, AuDeviceDescription(&g->da[i])->data))
- break;
-
- g->deviceNum = i;
+ set_device_by_name(g, string);
queryCB(w, g, call_data);
showDevice(g);
}
@@ -426,6 +423,61 @@
XtVaSetValues(g->device, XtNresizable, False, NULL);
}
+static AuInt32 parse_hex(const char *s)
+{
+ AuInt32 val = 0;
+
+ sscanf (s, "%lx", &val);
+ return val;
+}
+
+static AuBool is_decimal_number(const char *s)
+{
+ int i;
+
+ if (!s)
+ return AuFalse;
+
+ for (i=0; s[i]; i++)
+ if ((s[i] < '0') || (s[i] > '9'))
+ return AuFalse;
+
+ return AuTrue;
+}
+
+static AuDeviceID parse_device_id(const char *s)
+{
+ if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X')))
+ return parse_hex(s);
+ return AuNone;
+}
+
+static void set_device_by_id(GlobalDataPtr g, AuDeviceID id)
+{
+ int i;
+ AuDeviceAttributes *d;
+
+ for (i=0; i<g->numDevices; i++) {
+ d = AuServerDevice(g->aud, i);
+ if ((AuDeviceValueMask(d) & AuCompCommonIDMask) &&
+ id == d->common.id) {
+ g->deviceNum = i;
+ break;
+ }
+ }
+}
+
+static void set_device_by_name(GlobalDataPtr g, const char *name)
+{
+ int i;
+
+ for (i = 0; i < g->numDevices; i++)
+ if (!strcmp(name, AuDeviceDescription(&g->da[i])->data)) {
+ g->deviceNum = i;
+ break;
+ }
+}
+
int
main(int argc, char **argv)
{
@@ -433,17 +485,23 @@
GlobalDataPtr g = &globals;
XtAppContext appContext;
char *audioServer = NULL;
+ int i;
+ AuDeviceID initialDevice = AuNone;
+ char *initialDeviceName = NULL;
g->top = XtVaAppInitialize(&appContext, APP_CLASS, NULL, ZERO,
&argc, argv, defaultResources, NULL, 0);
- if (argc == 3)
- if (!strncmp(argv[1], "-a", 2))
- audioServer = argv[2];
- else
- fatalError(USAGE, NULL);
- else if (argc != 1)
- fatalError(USAGE, NULL);
+ for (i = 1; i < argc; i++) {
+ if (!strncmp(argv[i], "-a", 2)) {
+ audioServer = argv[++i];
+ } else if (!strncmp(argv[i], "-dev", 4)) {
+ initialDeviceName = argv[++i];
+ initialDevice = parse_device_id(initialDeviceName);
+ } else {
+ fatalError(USAGE, NULL);
+ }
+ }
if (!(g->aud = AuOpenServer(audioServer, 0, NULL, 0, NULL, NULL)))
fatalError("Can't connect to audio server", NULL);
@@ -458,6 +516,23 @@
AuXtAppAddAudioHandler(appContext, g->aud);
g->deviceNum = 0;
+
+ if (initialDevice != AuNone) {
+ set_device_by_id(g, initialDevice);
+ } else if (initialDeviceName) {
+ if (is_decimal_number(initialDeviceName)) {
+ g->deviceNum = atoi(initialDeviceName);
+ if (g->deviceNum >= g->numDevices) {
+ fprintf(stderr, "cannot activate device %d, there are only %d"
+ " devices (0 to %d)\n",
+ g->deviceNum, g->numDevices, g->numDevices - 1);
+ g->deviceNum = 0;
+ }
+ } else {
+ set_device_by_name(g, initialDeviceName);
+ }
+ }
+
showDevice(g);
XtAppMainLoop(appContext);
More information about the Nas
mailing list