1
Description: Added support to use the ALSA mixer APIs.
2
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gnomeradio/+bug/613809
3
Author: POJAR GEORGE <geoubuntu@gmail.com>
4
Index: gnomeradio-1.8/src/mixer.c
5
===================================================================
6
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7
+++ gnomeradio-1.8/src/mixer.c 2013-03-27 14:42:17.835281300 +0000
10
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
12
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
13
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation; either version 2, or (at your option)
18
+ * any later version.
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program; if not, write to the Free Software Foundation,
27
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33
+ * Sets the mixer device and channel.
35
+static int null_set_device( const char *devname )
41
+ * Sets the initial state of the mixer device.
43
+static void null_set_state( int ismuted, int unmute_volume )
48
+ * Returns the current volume setting.
50
+static int null_get_volume( void )
56
+ * Returns the volume that would be used to restore the unmute state.
58
+static int null_get_unmute_volume( void )
64
+ * Tunes the relative volume.
66
+static int null_set_volume( int percentdiff )
72
+ * Sets the mute state.
74
+static void null_mute( int mute )
79
+ * Returns true if the mixer is muted.
81
+static int null_ismute( void )
87
+ * Closes the mixer device if it is open.
89
+static void null_close_device( void )
93
+/* The null device, which always works. */
94
+static struct mixer null_mixer = {
95
+ .set_device = null_set_device,
96
+ .set_state = null_set_state,
97
+ .get_volume = null_get_volume,
98
+ .get_unmute_volume = null_get_unmute_volume,
99
+ .set_volume = null_set_volume,
101
+ .ismute = null_ismute,
102
+ .close_device = null_close_device,
105
+/* List of all available access methods.
106
+ * Uses weak symbols: NULL is not linked in. */
107
+static struct mixer *mixers[] = {
110
+ &null_mixer /* LAST */
112
+/* The actual access method. */
113
+struct mixer *mixer = &null_mixer;
116
+ * Sets the mixer device and channel.
117
+ * Try each access method until one succeeds.
119
+int mixer_set_device( const char *devname )
122
+ mixer->close_device();
123
+ for (i = 0; i < sizeof(mixers)/sizeof(mixers[0]); i++) {
127
+ if (mixer->set_device(devname) == 0)
134
Index: gnomeradio-1.8/src/mixer.h
135
===================================================================
136
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
137
+++ gnomeradio-1.8/src/mixer.h 2013-03-27 14:42:17.835281300 +0000
140
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
142
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
143
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
145
+ * This program is free software; you can redistribute it and/or modify
146
+ * it under the terms of the GNU General Public License as published by
147
+ * the Free Software Foundation; either version 2, or (at your option)
148
+ * any later version.
150
+ * This program is distributed in the hope that it will be useful,
151
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
152
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153
+ * GNU General Public License for more details.
155
+ * You should have received a copy of the GNU General Public License
156
+ * along with this program; if not, write to the Free Software Foundation,
157
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
160
+#ifndef MIXER_H_INCLUDED
161
+#define MIXER_H_INCLUDED
168
+ * Sets the mixer device and channel.
169
+ * All interfaces are scanned until one succeeds.
171
+int mixer_set_device( const char *devname );
175
+ * Sets the mixer device and channel.
177
+int (* set_device)( const char *devname );
180
+ * Sets the initial state of the mixer device.
182
+void (* set_state)( int ismuted, int unmute_volume );
185
+ * Returns the current volume setting.
187
+int (* get_volume)( void );
190
+ * Returns the volume that would be used to restore the unmute state.
192
+int (* get_unmute_volume)( void );
195
+ * Tunes the relative volume.
197
+int (* set_volume)( int percentdiff );
200
+ * Sets the mute state.
202
+void (* mute)( int mute );
205
+ * Returns true if the mixer is muted.
207
+int (* ismute)( void );
210
+ * Closes the mixer device if it is open.
212
+void (* close_device)( void );
215
+#pragma weak alsa_mixer
216
+extern struct mixer alsa_mixer;
217
+#pragma weak oss_mixer
218
+extern struct mixer oss_mixer;
219
+extern struct mixer *mixer;
224
+#endif /* MIXER_H_INCLUDED */
225
Index: gnomeradio-1.8/src/tech.c
226
===================================================================
227
--- gnomeradio-1.8.orig/src/tech.c 2013-03-27 14:42:17.843281300 +0000
228
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
231
- * This program is free software; you can redistribute it and/or modify
232
- * it under the terms of the GNU General Public License as published by
233
- * the Free Software Foundation; either version 2 of the License, or
234
- * (at your option) any later version.
236
- * This program is distributed in the hope that it will be useful,
237
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
238
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
239
- * GNU Library General Public License for more details.
241
- * You should have received a copy of the GNU General Public License
242
- * along with this program; if not, write to the Free Software
243
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
252
-#include <sys/ioctl.h>
255
-#include <sys/soundcard.h>
259
-static int mixer_fd = -1, mixer_src = -1;
260
-static char *devices[] = SOUND_DEVICE_NAMES;
263
- * These functions handle the mixer device
266
-int mixer_init(char *mixer_device, char *mixer_source)
272
- for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
273
- if (strcmp(mixer_source, devices[i]) == 0)
276
- mixer_fd = open(mixer_device, O_RDWR);
286
-char* mixer_get_sndcard_name(void)
289
- char *result = NULL;
291
- if (ioctl(mixer_fd, SOUND_MIXER_INFO, &info) == -1)
294
- result = strdup(info.name);
299
-char** mixer_get_rec_devices(void)
301
- int i, o, devmask, res;
304
- if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
308
- result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
310
- for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
312
- res = (devmask >> i)%2;
315
- result[o] = malloc(strlen(devices[i])+1);
316
- sprintf(result[o], "%s", devices[i]);
325
-int mixer_set_rec_device(void)
327
- int devmask, recmask;
335
- if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
338
- recmask = 1 << mixer_src;
339
- if (!(recmask & devmask))
342
- if ((ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &recmask)) == -1)
348
-int mixer_close(void)
356
-int mixer_set_volume(int volume)
362
- assert(volume <= 100);
363
- assert(volume >= 0);
370
- i_vol += volume << 8;
372
- /*printf("Setting %s to vol %i\n", devices[mixer_src], volume);*/
373
- if ((ioctl(mixer_fd, MIXER_WRITE(mixer_src), &i_vol)) < 0)
379
-int mixer_get_volume(void)
381
- int i_vol = 0, r, l, volume;
389
- if ((ioctl(mixer_fd, MIXER_READ(mixer_src), &i_vol)) < 0)
393
- l = i_vol % (1 << 8);
394
- volume = (r + l)/2;
395
- /*printf("%d %d %d %d\n", r, l, volume, i_vol);*/
397
- assert((volume >= 0) && (volume <= 100));
401
Index: gnomeradio-1.8/src/tech.h
402
===================================================================
403
--- gnomeradio-1.8.orig/src/tech.h 2013-03-27 14:42:17.843281300 +0000
404
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
407
- * This program is free software; you can redistribute it and/or modify
408
- * it under the terms of the GNU General Public License as published by
409
- * the Free Software Foundation; either version 2 of the License, or
410
- * (at your option) any later version.
412
- * This program is distributed in the hope that it will be useful,
413
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
414
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
415
- * GNU Library General Public License for more details.
417
- * You should have received a copy of the GNU General Public License
418
- * along with this program; if not, write to the Free Software
419
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
425
-int mixer_init(char *mixer_device, char *mixer_source);
427
-char* mixer_get_sndcard_name(void);
429
-char** mixer_get_rec_devices(void);
431
-int mixer_close(void);
433
-int mixer_set_volume(int volume);
435
-int mixer_get_volume(void);
437
-int mixer_set_rec_device(void);
440
Index: gnomeradio-1.8/src/gui.c
441
===================================================================
442
--- gnomeradio-1.8.orig/src/gui.c 2013-03-27 14:42:17.843281300 +0000
443
+++ gnomeradio-1.8/src/gui.c 2013-03-27 14:42:17.839281300 +0000
447
#include "trayicon.h"
451
#include "rec_tech.h"
454
int alsa_latency = DEFAULT_LATENCY;
457
-GtkWidget* mute_button, *preset_combo;
458
+GtkWidget* volume_button, *preset_combo;
462
@@ -256,22 +256,22 @@
464
void start_radio(gboolean restart, GtkWidget *app)
466
- DriverType driver = DRIVER_ANY;
467
+ DriverType driver = DRIVER_ANY;
471
- if (settings.driver) {
472
- if (0 == strcmp(settings.driver, "v4l1"))
473
- driver = DRIVER_V4L1;
474
- if (0 == strcmp(settings.driver, "v4l2"))
475
- driver = DRIVER_V4L2;
477
+ if (settings.driver) {
478
+ if (0 == strcmp(settings.driver, "v4l1"))
479
+ driver = DRIVER_V4L1;
480
+ if (0 == strcmp(settings.driver, "v4l2"))
481
+ driver = DRIVER_V4L2;
484
- if (!radio_init(settings.device, driver))
486
- char *caption = g_strdup_printf(_("Could not open device \"%s\"!"), settings.device);
487
+ if (!radio_init(settings.device, driver)) {
488
+ char *caption = g_strdup_printf(_("Could not open radio device \"%s\"!"), settings.device);
489
char *detail = g_strdup_printf(_("Check your settings and make sure that no other\n"
490
- "program is using %s.\nAlso make sure that you have read-access to it."), settings.device);
491
+ "program is using %s.\n"
492
+ "Also make sure that you have read-access to it."), settings.device);
493
show_error_message(caption, detail);
496
@@ -286,51 +286,30 @@
501
+ mixer->close_device();
503
- res = mixer_init(settings.mixer_dev, settings.mixer);
509
- buffer = g_strdup_printf(_("Mixer source \"%s\" is not a valid source!"), settings.mixer);
511
- buffer = g_strdup_printf(_("Could not open \"%s\"!"), settings.mixer_dev);
513
- show_error_message(buffer, NULL);
514
+ res = mixer_set_device(settings.mixer);
516
+ char *caption = g_strdup_printf(_("Could not open mixer device and channel \"%s\"!"), settings.mixer);
517
+ char *detail = g_strdup_printf(_("Use alsamixer to get information about device and channel names\n"
518
+ "for the sound cards that is ready to use.\n"
519
+ "The format to set mixer device and channel:\n"
520
+ "\"hw:card name/channel name\" (e.g. \"hw:0/Line\" or \"hw:ICH5/Line\")"));
521
+ show_error_message(caption, detail);
525
+ gtk_widget_set_sensitive(volume_button, FALSE);
529
- vol = mixer_get_volume();
531
- gtk_volume_button_set_value(mute_button, vol);
532
- /*gtk_adjustment_set_value(volume, (double)vol);*/
536
+ prefs_button_clicked_cb(NULL, app);
538
-GList* get_mixer_recdev_list(void)
541
- char **array, *dev;
542
- GList *result = NULL;
544
- array = mixer_get_rec_devices();
552
- char *text = g_strdup(dev);
553
- result = g_list_append(result, text);
561
+ vol = mixer->get_volume();
563
+ gtk_volume_button_set_value(volume_button, vol);
564
+ gtk_widget_set_sensitive(volume_button, TRUE);
568
static gboolean redraw_status_window(void)
570
radio_mute(alsa_loopback);
574
+ mixer->close_device();
578
@@ -484,27 +463,22 @@
580
static void volume_value_changed_cb(GtkVolumeButton *button, gpointer user_data)
583
- int vol = (int)(gtk_volume_button_get_value(mute_button) + 0.5f);
585
- mixer_set_volume(vol);
587
-/* text = g_strdup_printf(_("Volume: %d%%"), vol);
588
- gtk_widget_set_tooltip_text(vol_scale, text);
592
- g_signal_handler_block(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
593
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mute_menuitem), vol == 0);
594
- g_signal_handler_unblock(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
596
+ int vol = (int)(gtk_volume_button_get_value(volume_button) + 0.5f);
598
+ mixer->set_volume(vol - mixer->get_volume());
601
+ g_signal_handler_block(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
602
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mute_menuitem), vol == 0);
603
+ g_signal_handler_unblock(G_OBJECT(mute_menuitem), mute_menuitem_toggled_cb_id);
608
static gboolean poll_volume_change(gpointer data)
611
- if ((vol = mixer_get_volume()) < 0)
612
+ if ((vol = mixer->get_volume()) < 0)
615
if (vol != (int)volume->value)
617
Recording* recording;
620
- if (!mixer_set_rec_device())
623
- dialog = gtk_message_dialog_new(NULL, DIALOG_FLAGS, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
624
- "Could not set \"%s\" as recording Source", settings.mixer);
625
- gtk_dialog_run (GTK_DIALOG (dialog));
626
- gtk_widget_destroy (dialog);
630
/* You can translate the filename for a recording:
631
* args for this format are: path, station title, time
634
void toggle_volume(void)
637
- int vol = mixer_get_volume();
638
+ int vol = mixer->get_volume();
642
@@ -815,21 +779,21 @@
643
alsa_thread_startup(alsa_playback, alsa_capture,
644
alsa_latency, stderr, debug);
646
- mixer_set_volume(vol);
647
- gtk_volume_button_set_value(mute_button, vol);
648
+ mixer->set_volume(vol);
649
+ gtk_volume_button_set_value(volume_button, vol);
650
/*gtk_adjustment_set_value(volume, vol);*/
654
-static void mute_button_toggled_cb(GtkButton *button, gpointer data)
655
+static void volume_button_toggled_cb(GtkButton *button, gpointer data)
657
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mute_button)))
658
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(volume_button)))
660
- gtk_widget_set_tooltip_text(mute_button, _("Unmute"));
661
+ gtk_widget_set_tooltip_text(volume_button, _("Unmute"));
665
- gtk_widget_set_tooltip_text(mute_button, _("Mute"));
666
+ gtk_widget_set_tooltip_text(volume_button, _("Mute"));
671
stfw_button = gtk_button_new();
672
stbw_button = gtk_button_new();
673
about_button = gtk_button_new();
674
- /*mute_button = gtk_toggle_button_new();*/
675
- mute_button = gtk_volume_button_new();
676
- gtk_button_set_relief(GTK_BUTTON(mute_button), GTK_RELIEF_NORMAL);
677
+ /*volume_button = gtk_toggle_button_new();*/
678
+ volume_button = gtk_volume_button_new();
679
+ gtk_button_set_relief(GTK_BUTTON(volume_button), GTK_RELIEF_NORMAL);
680
+ gtk_widget_set_sensitive(volume_button, FALSE);
681
rec_button = gtk_button_new();
682
/*help_button = gtk_button_new();*/
685
gtk_container_add(GTK_CONTAINER(stfw_button), stfw_pixmap);
686
gtk_container_add(GTK_CONTAINER(stbw_button), stbw_pixmap);
687
gtk_container_add(GTK_CONTAINER(about_button), about_pixmap);
688
- /*gtk_container_add(GTK_CONTAINER(mute_button), mute_pixmap);*/
689
+ /*gtk_container_add(GTK_CONTAINER(volume_button), mute_pixmap);*/
690
gtk_container_add(GTK_CONTAINER(rec_button), rec_pixmap);
691
/*gtk_container_add(GTK_CONTAINER(help_button), help_pixmap);*/
693
@@ -1058,7 +1023,7 @@
694
/* gtk_scale_set_digits(GTK_SCALE(vol_scale), 0);
695
gtk_scale_set_draw_value(GTK_SCALE(vol_scale), FALSE);
697
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_button), mixer_get_volume() == 0);*/
698
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(volume_button), mixer->get_volume() == 0);*/
700
gtk_widget_set_size_request(drawing_area, DIGIT_WIDTH*6+10+SIGNAL_WIDTH+STEREO_WIDTH, DIGIT_HEIGTH+10);
702
@@ -1069,7 +1034,7 @@
703
gtk_box_pack_start(GTK_BOX(hbox2), stfw_button, FALSE, FALSE, 2);
704
gtk_box_pack_start(GTK_BOX(hbox2), scfw_button, FALSE, FALSE, 2);
705
gtk_box_pack_start(GTK_BOX(hbox2), vseparator1, FALSE, FALSE, 2);
706
- gtk_box_pack_start(GTK_BOX(hbox2), mute_button, FALSE, FALSE, 2);
707
+ gtk_box_pack_start(GTK_BOX(hbox2), volume_button, FALSE, FALSE, 2);
708
/*gtk_box_pack_start(GTK_BOX(hbox2), vseparator2, TRUE, TRUE, 3);*/
709
gtk_box_pack_start(GTK_BOX(hbox2), rec_button, FALSE, FALSE, 2);
710
gtk_box_pack_start(GTK_BOX(hbox2), vseparator4, FALSE, FALSE, 2);
711
@@ -1110,7 +1075,7 @@
712
g_signal_connect(G_OBJECT(app), "delete_event", G_CALLBACK(delete_event_cb), NULL);
713
g_signal_connect(G_OBJECT(quit_button), "clicked", G_CALLBACK(quit_button_clicked_cb), NULL);
714
g_signal_connect(G_OBJECT(adj), "value-changed", G_CALLBACK(adj_value_changed_cb), (gpointer) app);
715
- g_signal_connect(G_OBJECT(mute_button), "value-changed", G_CALLBACK(volume_value_changed_cb), NULL);
716
+ g_signal_connect(G_OBJECT(volume_button), "value-changed", G_CALLBACK(volume_value_changed_cb), NULL);
717
g_signal_connect(G_OBJECT(stfw_button), "pressed", G_CALLBACK(step_button_pressed_cb), (gpointer)TRUE);
718
g_signal_connect(G_OBJECT(stbw_button), "pressed", G_CALLBACK(step_button_pressed_cb), (gpointer)FALSE);
719
g_signal_connect(G_OBJECT(stfw_button), "clicked", G_CALLBACK(step_button_clicked_cb), (gpointer)TRUE);
720
@@ -1131,7 +1096,7 @@
721
gtk_widget_set_tooltip_text(about_button, _("About Gnomeradio"));
722
gtk_widget_set_tooltip_text(rec_button, _("Record radio as OGG, Flac, Wave or MP3"));
723
gtk_widget_set_tooltip_text(prefs_button, _("Edit your Preferences"));
724
- gtk_widget_set_tooltip_text(mute_button, _("Adjust the Volume"));
725
+ gtk_widget_set_tooltip_text(volume_button, _("Adjust the Volume"));
726
gtk_widget_set_tooltip_text(quit_button, _("Quit"));
727
text = g_strdup_printf(_("Frequency: %.2f MHz"), gtk_adjustment_get_value(adj)/STEPS);
728
gtk_widget_set_tooltip_text(freq_scale, text);
729
@@ -1154,7 +1119,7 @@
730
radio_mute(alsa_loopback);
734
+ mixer->close_device();
738
@@ -1178,7 +1143,7 @@
740
key_press_event_cb(GtkWidget *app, GdkEventKey *event, gpointer data)
742
- int vol = (int)(gtk_volume_button_get_value(mute_button) + 0.5f);
743
+ int vol = (int)(gtk_volume_button_get_value(volume_button) + 0.5f);
745
switch (event->keyval)
747
@@ -1210,12 +1175,12 @@
751
- gtk_volume_button_set_value(mute_button, vol > 95 ? 100 : vol + 5);
752
+ gtk_volume_button_set_value(volume_button, vol > 95 ? 100 : vol + 5);
753
/*gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);*/
756
case GDK_KEY_KP_Subtract:
757
- gtk_volume_button_set_value(mute_button, vol < 5 ? 0 : vol - 5);
758
+ gtk_volume_button_set_value(volume_button, vol < 5 ? 0 : vol - 5);
759
/*gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);*/
762
Index: gnomeradio-1.8/src/gui.h
763
===================================================================
764
--- gnomeradio-1.8.orig/src/gui.h 2013-03-27 14:42:17.843281300 +0000
765
+++ gnomeradio-1.8/src/gui.h 2013-03-27 14:42:17.839281300 +0000
767
struct Gnomeradio_Settings
772
gboolean mute_on_exit;
780
void start_mixer(gboolean restart, GtkWidget *app);
782
-GList* get_mixer_recdev_list(void);
784
void exit_gnome_radio(void);
786
void scfw_button_clicked_cb(GtkButton *button, gpointer data);
787
Index: gnomeradio-1.8/src/prefs.c
788
===================================================================
789
--- gnomeradio-1.8.orig/src/prefs.c 2013-03-27 14:42:17.843281300 +0000
790
+++ gnomeradio-1.8/src/prefs.c 2013-03-27 14:42:17.839281300 +0000
793
#include "rec_tech.h"
795
-extern GtkWidget* mute_button, *preset_combo;
796
+extern GtkWidget *preset_combo;
797
extern GtkAdjustment *adj;
802
extern gboolean main_visible;
804
-static GtkWidget *device_entry;
805
-static GtkWidget *mixer_combo;
806
+static GtkWidget *device_entry, *mixer_entry;
807
static GtkWidget *mute_on_exit_cb;
808
static GtkWidget *save_button, *up_button, *down_button, *remove_button;
809
static GtkWidget *list_view;
811
gconf_client_set_string(client, "/apps/gnomeradio/device", settings.device, NULL);
812
gconf_client_set_string(client, "/apps/gnomeradio/driver", settings.driver, NULL);
813
gconf_client_set_string(client, "/apps/gnomeradio/mixer", settings.mixer, NULL);
814
- gconf_client_set_string(client, "/apps/gnomeradio/mixer-device", settings.mixer_dev, NULL);
815
gconf_client_set_bool(client, "/apps/gnomeradio/mute-on-exit", settings.mute_on_exit, NULL);
816
/*gconf_client_set_float(client, "/apps/gnomeradio/volume", volume->value, NULL);*/
817
gconf_client_set_float(client, "/apps/gnomeradio/last-freq", gtk_adjustment_get_value(adj)/STEPS, NULL);
819
settings.driver = g_strdup("any");
820
settings.mixer = gconf_client_get_string(client, "/apps/gnomeradio/mixer", NULL);
822
- settings.mixer = g_strdup("line");
823
- settings.mixer_dev = gconf_client_get_string(client, "/apps/gnomeradio/mixer-device", NULL);
824
- if (!settings.mixer_dev)
825
- settings.mixer_dev = g_strdup("/dev/mixer");
826
+ settings.mixer = g_strdup("hw:0/Line");
827
settings.mute_on_exit = gconf_client_get_bool(client, "/apps/gnomeradio/mute-on-exit", NULL);
828
/*volume->value = gconf_client_get_float(client, "/apps/gnomeradio/volume", NULL);*/
829
freq = gconf_client_get_float(client, "/apps/gnomeradio/last-freq", NULL);
830
@@ -206,28 +201,14 @@
834
-static gboolean mixer_combo_change_cb(GtkComboBox *combo, gpointer data)
835
+static gboolean mixer_entry_activate_cb(GtkWidget *widget, gpointer data)
839
- gchar *mixer_dev, *tmp;
842
- mixer_devs = g_object_get_data(G_OBJECT(combo), "mixer_devs");
843
- active = gtk_combo_box_get_active(combo);
844
- g_assert(active > -1);
846
- mixer_dev = (gchar*)g_list_nth_data(mixer_devs, active);
847
- g_assert(mixer_dev);
849
- if (g_str_equal(mixer_dev, settings.mixer))
851
+ const gchar *text = gtk_entry_get_text(GTK_ENTRY(mixer_entry));
853
- if (settings.mixer) g_free(settings.mixer);
854
- settings.mixer = g_strdup(mixer_dev);
855
+ if (!strcmp(settings.mixer, text)) return FALSE;
857
- if ((tmp = strstr(settings.mixer, " (")))
859
+ if (settings.mixer) g_free(settings.mixer);
860
+ settings.mixer = g_strdup(text);
862
start_mixer(TRUE, data);
865
gtk_widget_set_sensitive(save_button, sel);
868
-static void free_string_list(GList *list)
871
- g_list_foreach(list, (GFunc)g_free, NULL);
875
static void free_preset_list(gpointer data, gpointer user_data)
878
@@ -1002,15 +976,14 @@
879
GtkWidget *destination_label;
880
GtkWidget *destination_button;
881
GtkWidget *profile_combo;
882
- GtkWidget *mixer_eb, *profile_eb;
883
+ GtkWidget *profile_eb;
884
GtkWidget *device_label, *mixer_label;
885
GtkWidget *button_box;
886
GtkWidget *open_button, *add_button;
887
GtkWidget *scrolled_window;
888
GtkCellRenderer *cellrenderer;
889
GtkTreeViewColumn *list_column;
890
- GList *mixer_devs, *ptr;
893
char *settings_hdr, *presets_hdr, *record_hdr;
896
@@ -1052,20 +1025,11 @@
898
mixer_label = gtk_label_new(_("Mixer Source:"));
899
gtk_misc_set_alignment(GTK_MISC(mixer_label), 0.0, 0.5);
900
- mixer_eb = gtk_event_box_new();
901
- mixer_combo = gtk_combo_box_text_new();
902
- gtk_container_add(GTK_CONTAINER(mixer_eb), mixer_combo);
903
- ptr = mixer_devs = get_mixer_recdev_list();
904
- for (i = 0, active = 0; ptr; ptr = g_list_next(ptr)) {
905
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mixer_combo), ptr->data);
906
- if (g_str_equal(ptr->data, settings.mixer)) active = i;
909
- gtk_combo_box_set_active(GTK_COMBO_BOX(mixer_combo), active);
910
- g_object_set_data_full(G_OBJECT(mixer_combo), "mixer_devs", mixer_devs, (GDestroyNotify)free_string_list);
911
+ mixer_entry = gtk_entry_new();
912
+ gtk_entry_set_text(GTK_ENTRY(mixer_entry), settings.mixer);
914
gtk_grid_attach(GTK_GRID(grid), mixer_label, 1, 2, 1, 1);
915
- gtk_grid_attach(GTK_GRID(grid), mixer_eb, 2, 2, 1, 1);
916
+ gtk_grid_attach(GTK_GRID(grid), mixer_entry, 2, 2, 1, 1);
918
mute_on_exit_cb = gtk_check_button_new_with_label(_("Mute on exit"));
919
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mute_on_exit_cb), settings.mute_on_exit);
920
@@ -1074,13 +1038,13 @@
922
g_signal_connect(G_OBJECT(device_entry), "hide", G_CALLBACK(device_entry_activate_cb), app);
923
g_signal_connect(G_OBJECT(device_entry), "activate", G_CALLBACK(device_entry_activate_cb), NULL);
924
- g_signal_connect(G_OBJECT(mixer_combo), "changed", G_CALLBACK(mixer_combo_change_cb), app);
925
+ g_signal_connect(G_OBJECT(mixer_entry), "hide", G_CALLBACK(mixer_entry_activate_cb), app);
926
+ g_signal_connect(G_OBJECT(mixer_entry), "activate", G_CALLBACK(mixer_entry_activate_cb), NULL);
927
g_signal_connect(G_OBJECT(mute_on_exit_cb), "toggled", G_CALLBACK(mute_on_exit_toggled_cb), NULL);
929
- gtk_widget_set_tooltip_text(device_entry, _("Specify the radio-device (in most cases /dev/radio0)"));
930
- gtk_widget_set_tooltip_text(mixer_eb,
931
- _("Choose the mixer source (line, line1, etc.) that is able to control the volume of your radio"));
932
- gtk_widget_set_tooltip_text(mute_on_exit_cb, _("If unchecked, gnomeradio won't mute after exiting"));
933
+ gtk_widget_set_tooltip_text(device_entry, _("The radio device to use (e.g. /dev/radio0)"));
934
+ gtk_widget_set_tooltip_text(mixer_entry, _("The mixer device and channel to use (e.g. hw:0/Line)"));
935
+ gtk_widget_set_tooltip_text(mute_on_exit_cb, _("Mute mixer device on exit"));
937
/* The presets part */
938
presets_hdr = g_strconcat("<span weight=\"bold\">", _("Presets"), "</span>", NULL);
939
@@ -1185,7 +1149,7 @@
940
save_button = gtk_button_new();
941
gtk_button_set_image(GTK_BUTTON(save_button), gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
942
gtk_button_set_relief (GTK_BUTTON (save_button), GTK_RELIEF_NONE);
943
- gtk_widget_set_tooltip_text(save_button, _("Save to file"));
944
+ gtk_widget_set_tooltip_text(save_button, _("Save presets to file"));
946
if (settings.presets == NULL) {
947
gtk_widget_set_sensitive(save_button, FALSE);
948
@@ -1198,7 +1162,7 @@
949
open_button = gtk_button_new();
950
gtk_button_set_image(GTK_BUTTON(open_button), gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
951
gtk_button_set_relief (GTK_BUTTON (open_button), GTK_RELIEF_NONE);
952
- gtk_widget_set_tooltip_text(open_button, _("Load from file"));
953
+ gtk_widget_set_tooltip_text(open_button, _("Load presets from file"));
954
gtk_widget_set_sensitive(open_button, TRUE);
956
g_signal_connect(G_OBJECT(open_button), "clicked", G_CALLBACK(load_from_file_cb), NULL);
957
@@ -1210,7 +1174,7 @@
958
gtk_box_pack_end(GTK_BOX(button_box), save_button, FALSE, FALSE, 0);
959
gtk_box_pack_end(GTK_BOX(button_box), open_button, FALSE, FALSE, 0);
961
- gtk_grid_attach(GTK_GRID(grid), button_box, 1, 7, 2, 1);
962
+ gtk_grid_attach(GTK_GRID(grid), button_box, 2, 7, 1, 1);
964
/* The record settings part */
965
record_hdr = g_strconcat("<span weight=\"bold\">", _("Record Settings"), "</span>", NULL);
966
@@ -1245,8 +1209,8 @@
968
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(destination_button), rec_settings.destination);
970
- gtk_widget_set_tooltip_text(destination_button, _("Choose a destination directory for recording file."));
971
- gtk_widget_set_tooltip_text(profile_eb, _("Choose the Media Profile that should be used to record."));
972
+ gtk_widget_set_tooltip_text(destination_button, _("Select a location to save the recording file"));
973
+ gtk_widget_set_tooltip_text(profile_eb, _("Choose the profile to be used for recording"));
975
gtk_widget_show_all(dialog);
977
Index: gnomeradio-1.8/src/record.c
978
===================================================================
979
--- gnomeradio-1.8.orig/src/record.c 2013-03-27 14:42:17.843281300 +0000
980
+++ gnomeradio-1.8/src/record.c 2013-03-27 14:42:17.839281300 +0000
983
#include <glib/gi18n.h>
986
#include "rec_tech.h"
989
Index: gnomeradio-1.8/src/trayicon.c
990
===================================================================
991
--- gnomeradio-1.8.orig/src/trayicon.c 2013-03-27 14:42:17.843281300 +0000
992
+++ gnomeradio-1.8/src/trayicon.c 2013-03-27 14:42:17.839281300 +0000
996
#include "trayicon.h"
1000
extern GtkAdjustment *adj;
1003
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), gtk_separator_menu_item_new());
1005
mute_menuitem = gtk_check_menu_item_new_with_label(_("Muted"));
1006
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mute_menuitem), mixer_get_volume() == 0);
1007
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mute_menuitem), mixer->get_volume() == 0);
1008
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), mute_menuitem);
1009
mute_menuitem_toggled_cb_id =
1010
g_signal_connect(G_OBJECT(mute_menuitem), "toggled", (GCallback)mute_menuitem_toggled_cb, (gpointer)app);
1011
Index: gnomeradio-1.8/src/lirc.c
1012
===================================================================
1013
--- gnomeradio-1.8.orig/src/lirc.c 2013-03-27 14:42:17.843281300 +0000
1014
+++ gnomeradio-1.8/src/lirc.c 2013-03-27 14:42:17.839281300 +0000
1018
#include <gtk/gtk.h>
1020
#include <lirc/lirc_client.h>
1025
-extern GtkWidget* mute_button;
1026
+extern GtkWidget* volume_button;
1027
extern GtkWidget *app;
1031
static void execute_lirc_command (char *cmd)
1033
printf("lirc command: %s\n", cmd);
1034
- int vol = (int)(gtk_volume_button_get_value(mute_button) + 0.5f);
1035
+ int vol = (int)(gtk_volume_button_get_value(volume_button) + 0.5f);
1037
if (strcasecmp (cmd, "tune up") == 0)
1041
else if (strcasecmp (cmd, "volume up") == 0)
1043
- gtk_volume_button_set_value(mute_button, vol > 95 ? 100 : vol + 5);
1044
+ gtk_volume_button_set_value(volume_button, vol > 95 ? 100 : vol + 5);
1045
/*gtk_adjustment_set_value(volume, (volume->value > 95) ? 100 : volume->value+5);*/
1047
else if (strcasecmp (cmd, "volume down") == 0)
1049
- gtk_volume_button_set_value(mute_button, vol < 5 ? 0 : vol - 5);
1050
+ gtk_volume_button_set_value(volume_button, vol < 5 ? 0 : vol - 5);
1051
/*gtk_adjustment_set_value(volume,(volume->value < 5) ? 0 : volume->value-5);*/
1053
else if (strcasecmp (cmd, "mute") == 0)
1054
Index: gnomeradio-1.8/data/gnomeradio.schemas.in
1055
===================================================================
1056
--- gnomeradio-1.8.orig/data/gnomeradio.schemas.in 2013-03-27 14:42:17.843281300 +0000
1057
+++ gnomeradio-1.8/data/gnomeradio.schemas.in 2013-03-27 14:42:17.839281300 +0000
1059
<default>TRUE</default>
1061
<short>Mute on exit</short>
1062
- <long>If unchecked, gnomeradio won't mute after exiting</long>
1063
+ <long>Mute mixer device on exit</long>
1068
<default>/dev/radio0</default>
1070
<short>Radio device</short>
1071
- <long>Specify the radio-device (in most cases /dev/radio)</long>
1072
+ <long>The radio device to use (e.g. /dev/radio0)</long>
1077
<default>any</default>
1079
<short>Device driver</short>
1080
- <long>Specify the device driver to use (any, v4l1 or v4l2)</long>
1081
+ <long>The device driver to use (any, v4l1 or v4l2)</long>
1086
<applyto>/apps/gnomeradio/mixer</applyto>
1087
<owner>gnomeradio</owner>
1089
- <default>line</default>
1090
+ <default>hw:0/Line</default>
1092
<short>Mixer source</short>
1093
- <long>Choose the mixer source (line, line1, etc.) that is able to control the volume of your radio</long>
1098
- <key>/schemas/apps/gnomeradio/mixer-device</key>
1099
- <applyto>/apps/gnomeradio/mixer-device</applyto>
1100
- <owner>gnomeradio</owner>
1101
- <type>string</type>
1102
- <default>/dev/mixer</default>
1104
- <short>Mixer Device</short>
1105
- <long>The mixer device that gnomeradio should use. Only changeable via this key (no GUI option)</long>
1106
+ <long>The mixer device and channel to use (e.g. hw:0/Line)</long>
1111
<default>-1</default>
1113
<short>Last presets</short>
1114
- <long>The preset that was enabled when gnomeradio was terminated. Range is 0 ... (# presets - 1). None is -1</long>
1115
+ <long>The preset that was enabled when gnomeradio was terminated. Range is 0 ... (presets - 1). None is -1</long>
1119
Index: gnomeradio-1.8/src/Makefile.am
1120
===================================================================
1121
--- gnomeradio-1.8.orig/src/Makefile.am 2013-03-27 14:42:17.843281300 +0000
1122
+++ gnomeradio-1.8/src/Makefile.am 2013-03-27 14:42:17.839281300 +0000
1124
get_media_devices.h \
1137
get_media_devices.c \
1151
Index: gnomeradio-1.8/src/mixer-alsa.c
1152
===================================================================
1153
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1154
+++ gnomeradio-1.8/src/mixer-alsa.c 2013-03-27 14:42:17.839281300 +0000
1157
+ * Copyright (C) 2006 Philipp Hahn <pmhahn@users.sourceforge.net>
1159
+ * This program is free software; you can redistribute it and/or modify
1160
+ * it under the terms of the GNU General Public License as published by
1161
+ * the Free Software Foundation; either version 2, or (at your option)
1162
+ * any later version.
1164
+ * This program is distributed in the hope that it will be useful,
1165
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1166
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1167
+ * GNU General Public License for more details.
1169
+ * You should have received a copy of the GNU General Public License
1170
+ * along with this program; if not, write to the Free Software Foundation,
1171
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1175
+#include <sys/types.h>
1176
+#include <string.h>
1178
+#include <alsa/asoundlib.h>
1181
+static const char alsa_core_devnames[] = "default";
1182
+static char *card, *channel;
1183
+static int muted = 0;
1184
+static int mutecount = 0;
1185
+static snd_mixer_t *handle = NULL;
1186
+static snd_mixer_elem_t *elem = NULL;
1188
+static long alsa_min, alsa_max, alsa_vol;
1190
+static void alsa_open_mixer( void )
1193
+ static snd_mixer_selem_id_t *sid = NULL;
1194
+ if ((err = snd_mixer_open (&handle, 0)) < 0) {
1195
+ fprintf(stderr, "mixer: open error: %s\n", snd_strerror(err));
1198
+ if ((err = snd_mixer_attach (handle, card)) < 0) {
1199
+ fprintf(stderr, "mixer: attach error: %s\n", snd_strerror(err));
1202
+ if ((err = snd_mixer_selem_register (handle, NULL, NULL)) < 0) {
1203
+ fprintf(stderr, "mixer: register error: %s\n", snd_strerror(err));
1206
+ if ((err = snd_mixer_load (handle)) < 0) {
1207
+ fprintf(stderr, "mixer: load error: %s\n", snd_strerror(err));
1210
+ snd_mixer_selem_id_malloc(&sid);
1213
+ snd_mixer_selem_id_set_name(sid, channel);
1214
+ if (!(elem = snd_mixer_find_selem(handle, sid))) {
1215
+ fprintf(stderr, "mixer: find error: %s\n", snd_strerror(err));
1218
+ if (!snd_mixer_selem_has_playback_volume(elem)) {
1219
+ fprintf(stderr, "mixer: no playback\n");
1222
+ snd_mixer_selem_get_playback_volume_range(elem, &alsa_min, &alsa_max);
1223
+ if ((alsa_max - alsa_min) <= 0) {
1224
+ fprintf(stderr, "mixer: no valid playback range\n");
1227
+ snd_mixer_selem_id_free(sid);
1232
+ snd_mixer_close(handle);
1238
+/* Volume saved to file */
1239
+static int alsa_get_unmute_volume( void )
1245
+ if (snd_mixer_selem_is_playback_mono(elem)) {
1246
+ snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &val);
1251
+ for (c = 0; c <= SND_MIXER_SCHN_LAST; c++) {
1252
+ if (snd_mixer_selem_has_playback_channel(elem, c)) {
1253
+ snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &val);
1263
+ sum = (long)((double)(alsa_vol * (alsa_max - alsa_min)) / 100. + 0.5);
1266
+ alsa_vol = (long)(((val * 100.) / (alsa_max - alsa_min)) + 0.5);
1272
+static int alsa_get_volume( void )
1277
+ return alsa_get_unmute_volume();
1280
+static int alsa_set_volume( int percentdiff )
1284
+ alsa_get_volume();
1286
+ alsa_vol += percentdiff;
1287
+ if( alsa_vol > 100 ) alsa_vol = 100;
1288
+ if( alsa_vol < 0 ) alsa_vol = 0;
1290
+ volume = (long)((alsa_vol * (alsa_max - alsa_min) / 100.) + 0.5);
1292
+ snd_mixer_selem_set_playback_volume_all(elem, volume + alsa_min);
1293
+ snd_mixer_selem_set_playback_switch_all(elem, 1);
1300
+static void alsa_mute( int mute )
1303
+ * Make sure that if multiple users mute the card,
1304
+ * we only honour the last one.
1306
+ if( !mute && mutecount ) mutecount--;
1307
+ if( mutecount ) return;
1312
+ if (snd_mixer_selem_has_playback_switch(elem))
1313
+ snd_mixer_selem_set_playback_switch_all(elem, 0);
1315
+ fprintf(stderr, "mixer: mute not implemented\n");
1318
+ if (snd_mixer_selem_has_playback_switch(elem))
1319
+ snd_mixer_selem_set_playback_switch_all(elem, 1);
1321
+ fprintf(stderr, "mixer: mute not implemented\n");
1325
+static int alsa_ismute( void )
1330
+static int alsa_set_device( const char *devname )
1334
+ if (card) free(card);
1335
+ card = strdup( devname );
1336
+ if( !card ) return -1;
1338
+ i = strcspn( card, "/" );
1339
+ if( i == strlen( card ) ) {
1343
+ channel = card + i + 1;
1345
+ alsa_open_mixer();
1347
+ fprintf( stderr, "mixer: Can't open mixer %s, "
1348
+ "mixer volume and mute unavailable.\n", card );
1354
+static void alsa_set_state( int ismuted, int unmute_volume )
1357
+ * 1. we come back unmuted: Don't touch anything
1358
+ * 2. we don't have a saved volume: Don't touch anything
1359
+ * 3. we come back muted and we have a saved volume:
1360
+ * - if gnomeradio muted it, unmute to old volume
1361
+ * - if user did it, remember that we're muted and old volume
1363
+ if( alsa_get_volume() == 0 && unmute_volume > 0 ) {
1364
+ snd_mixer_selem_set_playback_volume_all(elem, unmute_volume);
1373
+static void alsa_close_device( void )
1377
+ snd_mixer_close(handle);
1383
+struct mixer alsa_mixer = {
1384
+ .set_device = alsa_set_device,
1385
+ .set_state = alsa_set_state,
1386
+ .get_volume = alsa_get_volume,
1387
+ .get_unmute_volume = alsa_get_unmute_volume,
1388
+ .set_volume = alsa_set_volume,
1389
+ .mute = alsa_mute,
1390
+ .ismute = alsa_ismute,
1391
+ .close_device = alsa_close_device,
1393
Index: gnomeradio-1.8/src/mixer-oss.c
1394
===================================================================
1395
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1396
+++ gnomeradio-1.8/src/mixer-oss.c 2013-03-27 14:42:17.839281300 +0000
1399
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
1401
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
1402
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
1404
+ * This program is free software; you can redistribute it and/or modify
1405
+ * it under the terms of the GNU General Public License as published by
1406
+ * the Free Software Foundation; either version 2, or (at your option)
1407
+ * any later version.
1409
+ * This program is distributed in the hope that it will be useful,
1410
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1411
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1412
+ * GNU General Public License for more details.
1414
+ * You should have received a copy of the GNU General Public License
1415
+ * along with this program; if not, write to the Free Software Foundation,
1416
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1421
+#include <unistd.h>
1422
+#include <sys/types.h>
1423
+#include <sys/stat.h>
1424
+#include <sys/ioctl.h>
1425
+#include <sys/soundcard.h>
1426
+#include <sys/mman.h>
1427
+#include <string.h>
1430
+static char *mixer_device = "/dev/mixer";
1431
+static int saved_volume = (50 << 8 & 0xFF00) | (50 & 0x00FF);
1432
+static int mixer_channel = SOUND_MIXER_LINE;
1433
+static int mixer_dev_mask = 1 << SOUND_MIXER_LINE;
1434
+static int muted = 0;
1435
+static int mutecount = 0;
1436
+static int fd = -1;
1438
+static int oss_get_volume( void )
1443
+ if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
1446
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1447
+ if( devs & mixer_dev_mask ) {
1448
+ cmd = MIXER_READ( mixer_channel );
1453
+ ioctl( fd, cmd, &v );
1454
+ curvol = ( v & 0xFF00 ) >> 8;
1460
+static int oss_get_unmute_volume( void )
1463
+ return saved_volume;
1467
+ if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
1470
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1471
+ if( devs & mixer_dev_mask ) {
1472
+ cmd = MIXER_READ( mixer_channel );
1477
+ ioctl( fd, cmd, &v );
1485
+static int oss_set_volume( int percentdiff )
1487
+ int v, cmd, devs, levelpercentage;
1489
+ levelpercentage = oss_get_volume();
1491
+ levelpercentage += percentdiff;
1492
+ if( levelpercentage > 100 ) levelpercentage = 100;
1493
+ if( levelpercentage < 0 ) levelpercentage = 0;
1495
+ if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
1497
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1498
+ if( devs & mixer_dev_mask ) {
1499
+ cmd = MIXER_WRITE( mixer_channel );
1504
+ v = ( levelpercentage << 8 ) | levelpercentage;
1505
+ ioctl( fd, cmd, &v );
1514
+static void oss_mute( int mute )
1519
+ * Make sure that if multiple users mute the card,
1520
+ * we only honour the last one.
1522
+ if( !mute && mutecount ) mutecount--;
1523
+ if( mutecount ) return;
1525
+ if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
1532
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1533
+ if( devs & mixer_dev_mask ) {
1534
+ cmd = MIXER_READ( mixer_channel );
1539
+ ioctl( fd,cmd,&v );
1542
+ /* Now set volume to 0 */
1543
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1544
+ if( devs & mixer_dev_mask ) {
1545
+ cmd = MIXER_WRITE( mixer_channel );
1551
+ ioctl( fd, cmd, &v );
1558
+ ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
1559
+ if( devs & mixer_dev_mask ) {
1560
+ cmd = MIXER_WRITE( mixer_channel );
1566
+ ioctl( fd, cmd, &v );
1573
+static int oss_ismute( void )
1578
+static char *oss_core_devnames[] = SOUND_DEVICE_NAMES;
1580
+static int oss_set_device( const char *devname )
1582
+ const char *channame;
1586
+ mixer_device = strdup( devname );
1587
+ if( !mixer_device ) return -1;
1589
+ i = strcspn( mixer_device, ":" );
1590
+ if( i == strlen( mixer_device ) ) {
1591
+ channame = "line";
1593
+ mixer_device[ i ] = 0;
1594
+ channame = mixer_device + i + 1;
1596
+ fd = open( mixer_device, O_RDONLY );
1598
+ fprintf( stderr, "mixer: Can't open device %s, "
1599
+ "mixer volume and mute unavailable.\n", mixer_device );
1603
+ mixer_channel = SOUND_MIXER_LINE;
1604
+ for( i = 0; i < SOUND_MIXER_NRDEVICES; i++ ) {
1605
+ if( !strcasecmp( channame, oss_core_devnames[ i ] ) ) {
1606
+ mixer_channel = i;
1612
+ fprintf( stderr, "mixer: No such mixer channel '%s', using channel 'line'.\n", channame );
1615
+ mixer_dev_mask = 1 << mixer_channel;
1619
+static void oss_set_state( int ismuted, int unmute_volume )
1622
+ * 1. we come back unmuted: Don't touch anything
1623
+ * 2. we don't have a saved volume: Don't touch anything
1624
+ * 3. we come back muted and we have a saved volume:
1625
+ * - if gnomeradio muted it, unmute to old volume
1626
+ * - if user did it, remember that we're muted and old volume
1628
+ if( oss_get_volume() == 0 && unmute_volume > 0 ) {
1629
+ saved_volume = unmute_volume;
1638
+static void oss_close_device( void )
1640
+ if( fd >= 0 ) close( fd );
1641
+ saved_volume = (50 << 8 & 0xFF00) | (50 & 0x00FF);
1642
+ mixer_channel = SOUND_MIXER_LINE;
1643
+ mixer_dev_mask = 1 << SOUND_MIXER_LINE;
1649
+struct mixer oss_mixer = {
1650
+ .set_device = oss_set_device,
1651
+ .set_state = oss_set_state,
1652
+ .get_volume = oss_get_volume,
1653
+ .get_unmute_volume = oss_get_unmute_volume,
1654
+ .set_volume = oss_set_volume,
1656
+ .ismute = oss_ismute,
1657
+ .close_device = oss_close_device,