/* * Copyright (C) 2003 Nils Faerber * * 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 #include #include #include #include #include #include #include /* OSS sound specific */ #include #include #include #include /* GPE specific */ #ifdef USE_GPE #include #include #include #include #include #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 */ GtkStyle *style; 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; istyle); 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 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++]); } gdk_color_parse (color, &col); /* 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); gtk_widget_realize (window); gdk_window_set_type_hint (window->window, GDK_WINDOW_TYPE_HINT_TOOLBAR); /* 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); }