pkgsrc/audio/cmp3/patches/patch-ac
hubertf 9a4e9b052c Add cmp3-2.0.p5: ncurses based frontend to mpg123
A simple yet featureful ncurses frontend to mpg123.  Includes
playlist support, volume control and tools to help with file
management.

Submitted by Rui-Xiang Guo <rxg@ms25.url.com.tw> in PR 12168
2001-02-10 14:18:35 +00:00

152 lines
3.6 KiB
Text

$NetBSD: patch-ac,v 1.1.1.1 2001/02/10 14:18:35 hubertf Exp $
--- cmp3volume.c.orig Fri Feb 9 15:54:18 2001
+++ cmp3volume.c Fri Feb 9 23:45:24 2001
@@ -3,7 +3,11 @@
*/
#include "cmp3funcs.h"
-#include<sys/soundcard.h>
+#if defined(__NetBSD__)
+#include <sys/audioio.h>
+#else
+#include <sys/soundcard.h>
+#endif
static int mixernum, /* ID number for the mixer */
vol; /* Current volume level */
@@ -12,6 +16,63 @@
* Initialize volume control
* Returns: nothing
****************************************************************************/
+#if defined(__NetBSD__)
+
+int device_id;
+mixer_ctrl_t *m, *values;
+
+extern void initvol()
+{
+ int i, ndev;
+ char *mixer_device;
+ mixer_devinfo_t dinfo, *infos;
+
+ mixer_device = getenv("MIXERDEVICE");
+ if (mixer_device == NULL)
+ mixer_device = "/dev/mixer0";
+
+ if ((mixernum=open(mixer_device, O_RDWR)) < 0) {
+ fprintf(stderr, "open mixer device: %s", strerror(errno));
+ enditall(SIGSEGV);
+ }
+
+ for (ndev = 0; ; ndev++) {
+ dinfo.index = ndev;
+ if (ioctl(mixernum, AUDIO_MIXER_DEVINFO, &dinfo) < 0)
+ break;
+ }
+ infos = calloc(ndev, sizeof *infos);
+ values = calloc(ndev, sizeof *values);
+
+ for (i = 0; i < ndev; i++) {
+ infos[i].index = i;
+ ioctl(mixernum, AUDIO_MIXER_DEVINFO, &infos[i]);
+ }
+
+ for (i = 0; i < ndev; i++) {
+ if (infos[i].type == AUDIO_MIXER_VALUE) {
+ values[i].dev = i;
+ values[i].type = infos[i].type;
+ }
+ if (strcmp(infos[i].label.name, AudioNdac) == 0) {
+ device_id = i;
+ break;
+ }
+ }
+
+ values[device_id].un.value.num_channels = 2;
+
+ m = &values[device_id];
+ ioctl(mixernum, AUDIO_MIXER_READ, m);
+ vol = m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
+ mvprintw(3,COLS/2-1,"-");
+ mvprintw(LINES-7,COLS/2-1,"-");
+ mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1,"*");
+ return;
+}
+
+#else
+
extern void initvol()
{
if ((mixernum=open("/dev/mixer", O_RDWR)) < 0) {
@@ -26,6 +87,8 @@
return;
}
+#endif
+
extern void endvol()
{
close(mixernum);
@@ -57,6 +120,23 @@
* Although I hate users in general, we should probably do it.
* Returns: nothing
****************************************************************************/
+#if defined(__NetBSD__)
+
+extern void volup()
+{
+ mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
+ vol += 3;
+ if (vol > 100)
+ vol = 100;
+ m = &values[device_id];
+ ioctl(mixernum, AUDIO_MIXER_WRITE, m);
+ m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+ mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
+ return;
+}
+
+#else
+
extern void volup()
{
int i;
@@ -71,10 +151,29 @@
return;
}
+#endif
+
/****************************************************************************
* It's too loud junior, turn it down!
* Returns: nothing
****************************************************************************/
+#if defined(__NetBSD__)
+
+extern void voldown()
+{
+ mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
+ vol -= 3;
+ if (vol < 0)
+ vol = 0;
+ m = &values[device_id];
+ ioctl(mixernum, AUDIO_MIXER_WRITE, m);
+ m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
+ mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
+ return;
+}
+
+#else
+
extern void voldown()
{
int i;
@@ -89,4 +188,6 @@
return;
}
+#endif
+
/* EOF */
\ No newline at end of file