[nas] [PATCH] mute button for aupanel
Erik Auerswald
auerswal at unix-ag.uni-kl.de
Fri Oct 21 16:17:10 MDT 2005
Hi,
I'd like to have a mute button in aupanel, so I I've written a patch
(against nas version 1.7b) that implements one.
Muting is realized by saving the current value (to restore on unmute)
and seeting gain to 0. Every device is muted independently.
I have tested the patch on linux only, but it should work on other
operating systems as well.
Erik
-------------- next part --------------
diff -Naur nas-1.7b/clients/audio/aupanel/aupanel.c nas-1.7b.mute/clients/audio/aupanel/aupanel.c
--- nas-1.7b/clients/audio/aupanel/aupanel.c 2005-04-07 21:08:14.000000000 +0200
+++ nas-1.7b.mute/clients/audio/aupanel/aupanel.c 2005-10-21 23:48:14.000000000 +0200
@@ -83,6 +83,7 @@
form,
quit,
query,
+ mute,
menu,
menuButton,
device,
@@ -96,7 +97,8 @@
outputModeLine;
AuServer *aud;
int numDevices,
- deviceNum;
+ deviceNum,
+ *restoreValues;
AuDeviceAttributes *da;
} GlobalDataRec, *GlobalDataPtr;
@@ -105,10 +107,12 @@
"*input: true",
"*font: *courier-medium-r-normal*140*",
"*query.label: Query",
+ "*mute.label: Mute",
+ "*mute.fromHoriz: devices",
"*devices.label: Devices",
"*devices.fromHoriz: query",
"*quit.label: Quit",
- "*quit.fromHoriz: devices",
+ "*quit.fromHoriz: mute",
"*deviceLabel.label: Stereo Channel Output",
"*deviceLabel.fromVert: query",
"*deviceLabel.font: *courier-bold-r-normal*140*",
@@ -231,6 +235,12 @@
XtCallActionProc(g->outputModeLine, "reset", NULL, NULL, 0);
}
+ if ((AuFixedPointRoundUp(AuDeviceGain(da)) == 0) &&
+ (g->restoreValues[g->deviceNum] > 0))
+ XtCallActionProc(g->mute, "set", NULL, NULL, 0);
+ else
+ XtCallActionProc(g->mute, "reset", NULL, NULL, 0);
+
}
static void
@@ -333,6 +343,30 @@
}
static void
+muteCB(w, gp, call_data)
+Widget w;
+XtPointer gp;
+XtPointer call_data;
+{
+ GlobalDataPtr g = (GlobalDataPtr) gp;
+ AuDeviceAttributes *da;
+ int current;
+
+ queryCB(w, gp, call_data);
+ da = &g->da[g->deviceNum];
+ current = AuFixedPointRoundUp(AuDeviceGain(da));
+
+ if(current > 0) {
+ g->restoreValues[g->deviceNum] = current;
+ setGain(w, gp, (XtPointer)0);
+ } else if(g->restoreValues[g->deviceNum] > 0){
+ setGain(w, gp, (XtPointer)g->restoreValues[g->deviceNum]);
+ g->restoreValues[g->deviceNum] = 0;
+ }
+ showDevice((GlobalDataPtr)gp);
+}
+
+static void
createWidgets(g)
GlobalDataPtr g;
{
@@ -360,6 +394,10 @@
MakeWidget(g->menuButton, g->form, menuButtonWidgetClass, "devices");
+ MakeWidget(g->mute, g->form, toggleWidgetClass, "mute");
+ XtAddCallback(g->mute, XtNcallback, muteCB, g);
+ XtVaSetValues(g->mute, XtNsensitive, True, NULL);
+
MakeCommandButton(g->quit, g->form, "quit", quitCB);
MakeLabel(g->device, g->form, "deviceLabel");
@@ -432,6 +470,9 @@
if (!(g->aud = AuOpenServer(audioServer, 0, NULL, 0, NULL, NULL)))
fatalError("Can't connect to audio server");
+ if(!(g->restoreValues = calloc(AuServerNumDevices(g->aud), sizeof(int))))
+ fatalError("Out of memory");
+
createWidgets(g);
XtRealizeWidget(g->top);
alignWidgets(g);
@@ -442,5 +483,7 @@
showDevice(g);
XtAppMainLoop(appContext);
+
+ free(g->restoreValues);
return 0;
}
diff -Naur nas-1.7b/clients/audio/aupanel/aupanel.man nas-1.7b.mute/clients/audio/aupanel/aupanel.man
--- nas-1.7b/clients/audio/aupanel/aupanel.man 1999-05-08 20:47:17.000000000 +0200
+++ nas-1.7b.mute/clients/audio/aupanel/aupanel.man 2005-10-21 23:48:14.000000000 +0200
@@ -22,6 +22,8 @@
these selections.
.PP
To query the current device attributes, click on the \fBQuery\fP button.
+.PP
+To mute (resp. unmute) the current device, click on the \fBMute\fP button.
.SH ENVIRONMENT
In addition to the standard toolkit environment variables, the
following environment variables are used by \fIaupanel\fP:
More information about the Nas
mailing list