1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
* Copyright (C) 2003 Nils Faerber <nils@kernelconcepts.de>
*
* 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.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>
#include <libintl.h>
/* OSS sound specific */
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <gtk/gtk.h>
/* GPE specific */
#ifdef USE_GPE
#include <gpe/pixmaps.h>
#include <gpe/init.h>
#include <gpe/picturebutton.h>
#include <gpe/errorbox.h>
#endif
static struct gpe_icon my_icons[] = {
{ "icon", PREFIX "/share/pixmaps/gpe-mixer.png" },
{ "line" , "line"},
{ "line1" , "line"},
{ "cd" , "cd"},
{ "bass" , "bass"},
{ "vol" , "volume"},
{ "unkn" , "unkn"},
{ "treble" , "treble"},
{ "synth" , "synth"},
{ "speaker" , "speaker"},
{ "phout" , "speaker"},
{ "pcm" , "pcm"},
{ "pcm2" , "pcm"},
{ "mic" , "mic"},
{ NULL, NULL }
};
/* GTK UI */
GtkWidget *window; /* Main window */
GtkObject **MixerAdjuster;
gchar **channels = NULL;
/* helper for i8n */
#define _(x) gettext(x)
/* mixer handling */
char *mixer_labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
char *mixer_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
int devmask = 0;
int mixfd;
static gboolean
channel_active(const gchar *name)
{
int i = 0;
if (!channels)
return TRUE;
while (channels[i])
if (!strcmp(channels[i++], name))
return TRUE;
return FALSE;
}
static void
set_volume (GtkObject *o, void *t)
{
GtkAdjustment *a = GTK_ADJUSTMENT (o);
int volume = 100 - (int)a->value;
#ifdef DEBUG
g_print("vol=(%d)%d\n", *(int *)t, volume);
#endif
volume |= (volume << 8);
if (ioctl(mixfd, MIXER_WRITE(*(int *)t), &volume) == -1)
gpe_perror_box("WRITE_MIXER");
}
void create_mixers(GtkWidget *table)
{
int i,n=0;
int mval;
GtkWidget *slider;
GtkWidget *label;
GtkWidget *w;
int *devnum;
GtkTooltips *mixer_tips;
gchar *err = NULL;
GdkPixbuf *pbuf = NULL;
/* count mixers */
for (i=0; i<SOUND_MIXER_NRDEVICES; i++) {
if (((1 << i) & devmask) && channel_active(mixer_names[i]))
n++;
}
/* create table for all mixers */
table=gtk_table_new(2, n, FALSE);
gtk_container_add (GTK_CONTAINER (window), table);
MixerAdjuster = (GtkObject **)g_malloc0(n * sizeof (GtkObject *));
mixer_tips = gtk_tooltips_new ();
/* fill table with mixers */
n=0;
for (i=0; i<SOUND_MIXER_NRDEVICES; i++) {
if (((1 << i) & devmask) && channel_active(mixer_names[i])) {
devnum=(int *)malloc(sizeof(int));
*devnum=i;
MixerAdjuster[n] = gtk_adjustment_new (101.0, 0.0, 101.0, 1.0, 10.0, 1.0);
slider = gtk_vscale_new (GTK_ADJUSTMENT (MixerAdjuster[n]));
gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
gtk_table_attach(GTK_TABLE(table), slider, n, n+1, 1, 2, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_tooltips_set_tip(GTK_TOOLTIPS(mixer_tips),GTK_WIDGET(slider),mixer_names[i],mixer_names[i]);
if (ioctl(mixfd, MIXER_READ(i),&mval)== -1) /* get initial setting */
gpe_perror_box("MIXER_READ");
else
gtk_adjustment_set_value(GTK_ADJUSTMENT(MixerAdjuster[n]), 100 - (gdouble)(mval & 0x7f));
g_signal_connect (G_OBJECT (MixerAdjuster[n]), "value-changed",G_CALLBACK (set_volume), devnum);
gtk_widget_show(slider);
pbuf = gpe_try_find_icon (mixer_names[i], &err);
if (!pbuf)
pbuf = gpe_try_find_icon ("unkn", &err);
w = gtk_image_new_from_pixbuf (pbuf);
if (w) {
gtk_table_attach(GTK_TABLE(table), w, n, n+1, 0, 1, 0, 0, 1, 0);
gtk_widget_show(w);
gtk_tooltips_set_tip(GTK_TOOLTIPS(mixer_tips),GTK_WIDGET(w),mixer_names[i],mixer_names[i]);
} else {
label=gtk_label_new(_(mixer_labels[i]));
gtk_table_attach(GTK_TABLE(table), label, n, n+1, 0, 1, 0, 0, 1, 0);
gtk_widget_show(label);
gtk_tooltips_set_tip(GTK_TOOLTIPS(mixer_tips),GTK_WIDGET(label),mixer_names[i],mixer_names[i]);
}
n++;
}
}
gtk_widget_show (table);
}
gboolean mixer_idle (gpointer data)
{
unsigned int i, n;
int mval;
n=0;
for (i=0; i<SOUND_MIXER_NRDEVICES; i++) {
if (((1 << i) & devmask) && channel_active(mixer_names[n])){
if (ioctl(mixfd, MIXER_READ(i),&mval)== -1) /* get setting */
perror("MIXER_READ");
else
gtk_adjustment_set_value(GTK_ADJUSTMENT(MixerAdjuster[n]), 100 - (gdouble)(mval & 0x7f));
n++;
}
}
return TRUE;
}
int
main (int argc, char *argv[])
{
/* GTK Widgets */
GtkWidget *table;
int arg;
gchar *cstr = NULL;
#ifdef USE_GPE
if (gpe_application_init (&argc, &argv) == FALSE)
exit (1);
if (gpe_load_icons (my_icons) == FALSE)
exit (1);
#else
gtk_set_locale ();
gtk_init (&argc, &argv);
#endif
/* command line parameters */
while ((arg = getopt(argc, argv, "c:")) > 0) {
switch (arg) {
case 'c':
cstr = g_strdup(optarg);
break;
default:
fprintf(stderr, _("Unknown argument: %c\n"),arg);
}
}
/* get list of selected channels */
if (cstr) {
int i = 0;
gchar *j = cstr;
gchar *p = cstr;
while (j) {
channels = realloc(channels, sizeof (gchar*) * (i + 1));
if ((j = strstr(p, ","))) {
channels[i] = malloc(j - p + 1);
snprintf(channels[i], j - p + 1, "%s", p);
p = j + 1;
}
else {
channels = realloc(channels, sizeof (gchar*) * (i + 2));
channels[i] = g_strdup(p);
channels[i + 1] = NULL;
j = NULL;
}
i++;
}
g_free(cstr);
i = 0;
while (channels[i])
printf("DC: %s\n",channels[i++]);
}
/* mixer init */
if ((mixfd = open("/dev/mixer", O_RDWR)) < 0) {
gpe_perror_box("opening mixer");
exit(1);
}
if (ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) {
gpe_perror_box("SOUND_MIXER_READ_DEVMASK");
exit(1);
}
/* GTK Window stuff */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Mixer");
gtk_window_set_default_size(GTK_WINDOW(window), 240, 100);
#ifdef USE_FB
gtk_widget_realize (window);
gdk_window_set_type_hint (window->window, GDK_WINDOW_TYPE_HINT_TOOLBAR);
#endif // USE_FB
/* Destroy handler */
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
/* Create the table of mixer widgets */
table = NULL;
create_mixers(table);
#ifdef USE_GPE
gpe_set_window_icon (window, "icon");
#endif
/* Auto update mixer settings */
gtk_timeout_add(500 /*ms*/, mixer_idle, NULL);
gtk_widget_show (window);
gtk_main ();
return (0);
}
|