import sonata-1.4.2, a GTK2 client for the Music Player Daemon, from
[pkgsrc.git] / audio / cmp3 / patches / patch-ac
1 $NetBSD$
2
3 --- cmp3volume.c.orig   Fri Feb  9 15:54:18 2001
4 +++ cmp3volume.c        Fri Feb  9 23:45:24 2001
5 @@ -3,7 +3,11 @@
6  */    
7  
8  #include "cmp3funcs.h"
9 -#include<sys/soundcard.h>
10 +#if defined(__NetBSD__)
11 +#include <sys/audioio.h>
12 +#else
13 +#include <sys/soundcard.h>
14 +#endif
15  
16  static int mixernum,                    /* ID number for the mixer */
17             vol;                         /* Current volume level */
18 @@ -12,6 +16,63 @@
19   *  Initialize volume control
20   *  Returns: nothing
21   ****************************************************************************/
22 +#if defined(__NetBSD__)
23 +
24 +int device_id;
25 +mixer_ctrl_t *m, *values;
26 +
27 +extern void initvol()
28 +{
29 +    int i, ndev;
30 +    char *mixer_device;
31 +    mixer_devinfo_t dinfo, *infos;
32 +
33 +    mixer_device = getenv("MIXERDEVICE");
34 +    if (mixer_device == NULL)
35 +        mixer_device = "/dev/mixer0";
36 +
37 +    if ((mixernum=open(mixer_device, O_RDWR)) < 0) {
38 +        fprintf(stderr, "open mixer device: %s", strerror(errno));
39 +        enditall(SIGSEGV);
40 +    }
41 +
42 +    for (ndev = 0; ; ndev++) {
43 +        dinfo.index = ndev;
44 +        if (ioctl(mixernum, AUDIO_MIXER_DEVINFO, &dinfo) < 0)
45 +            break;
46 +    }
47 +    infos = calloc(ndev, sizeof *infos);
48 +    values = calloc(ndev, sizeof *values);
49 +
50 +    for (i = 0; i < ndev; i++) {
51 +        infos[i].index = i;
52 +        ioctl(mixernum, AUDIO_MIXER_DEVINFO, &infos[i]);
53 +    }
54 +
55 +    for (i = 0; i < ndev; i++) {
56 +        if (infos[i].type == AUDIO_MIXER_VALUE) {
57 +            values[i].dev = i;
58 +            values[i].type = infos[i].type;
59 +        }
60 +        if (strcmp(infos[i].label.name, AudioNdac) == 0) {
61 +            device_id = i;
62 +            break;
63 +        }
64 +    }
65 +
66 +    values[device_id].un.value.num_channels = 2;
67 +
68 +    m = &values[device_id];
69 +    ioctl(mixernum, AUDIO_MIXER_READ, m);
70 +    vol = m->un.value.level[0] * 100 / AUDIO_MAX_GAIN;
71 +    mvprintw(3,COLS/2-1,"-");
72 +    mvprintw(LINES-7,COLS/2-1,"-");
73 +    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1,"*");
74 +    return;
75 +}
76 +
77 +#else
78 +
79  extern void initvol()
80  {
81      if ((mixernum=open("/dev/mixer", O_RDWR)) < 0) {
82 @@ -26,6 +87,8 @@
83      return;
84  }
85  
86 +#endif
87 +
88  extern void endvol()
89  {
90      close(mixernum);
91 @@ -57,6 +120,23 @@
92   *  Although I hate users in general, we should probably do it.
93   *  Returns: nothing
94   ****************************************************************************/
95 +#if defined(__NetBSD__)
96 +
97 +extern void volup()
98 +{
99 +    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
100 +    vol += 3;
101 +    if (vol > 100)
102 +        vol = 100;
103 +    m = &values[device_id];
104 +    ioctl(mixernum, AUDIO_MIXER_WRITE, m);
105 +    m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
106 +    mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
107 +    return;
108 +}
109 +
110 +#else
111 +
112  extern void volup()
113  {
114      int i;
115 @@ -71,10 +151,29 @@
116      return;
117  }
118  
119 +#endif
120 +
121  /****************************************************************************
122   *  It's too loud junior, turn it down!
123   *  Returns: nothing
124   ****************************************************************************/
125 +#if defined(__NetBSD__)
126 +
127 +extern void voldown()
128 +{
129 +    mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," ");
130 +    vol -= 3;
131 +    if (vol < 0)
132 +        vol = 0;
133 +    m = &values[device_id];
134 +    ioctl(mixernum, AUDIO_MIXER_WRITE, m);
135 +    m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100;
136 +    mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*");
137 +    return;
138 +}
139 +
140 +#else
141 +
142  extern void voldown()
143  {
144      int i;
145 @@ -89,4 +188,6 @@
146      return;
147  }
148  
149 +#endif
150 +
151  /* EOF */
152 \ No newline at end of file