~ubuntu-branches/ubuntu/trusty/gnomeradio/trusty

« back to all changes in this revision

Viewing changes to debian/patches/gnomeradio-alsamixer.patch

  • Committer: Package Import Robot
  • Author(s): POJAR GEORGE
  • Date: 2013-03-03 10:18:52 UTC
  • Revision ID: package-import@ubuntu.com-20130303101852-bx3zfgkl3652beps
Tags: 1.8-2ubuntu8
* debian/patches/gnomeradio-alsa.patch: Added support for looping back audio
  through alsa devices. (LP: #1154029)
* debian/patches/gnomeradio-alsamixer.patch: Added support to use the ALSA
  mixer APIs. (LP: #613809)
* debian/patches/gnomeradio-media_profile.patch: Replaced GnomeMediaProfile
  with GstEncodingProfile. (LP: #1154028)
* debian/patches/gnomeradio-documentation.patch: Use new documentation
  infrastructure. (LP: #1091476)
* debian/rules: Removed obsolete --disable-scrollkeeper configure flag.
* debian/control: Build-Depends: added libasound2-dev, yelp-tools, removed 
  libgnome-media-profiles-dev, gnome-doc-utils, scrollkeeper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
8
@@ -0,0 +1,125 @@
 
9
+/**
 
10
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
 
11
+ *
 
12
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
 
13
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
 
14
+ *
 
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.
 
19
+ *
 
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.
 
24
+ *
 
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.
 
28
+ */
 
29
+
 
30
+#include "mixer.h"
 
31
+
 
32
+/**
 
33
+ * Sets the mixer device and channel.
 
34
+ */
 
35
+static int null_set_device( const char *devname )
 
36
+{
 
37
+       return 0;
 
38
+}
 
39
+
 
40
+/**
 
41
+ * Sets the initial state of the mixer device.
 
42
+ */
 
43
+static void null_set_state( int ismuted, int unmute_volume )
 
44
+{
 
45
+}
 
46
+
 
47
+/**
 
48
+ * Returns the current volume setting.
 
49
+ */
 
50
+static int null_get_volume( void )
 
51
+{
 
52
+       return 0;
 
53
+}
 
54
+
 
55
+/**
 
56
+ * Returns the volume that would be used to restore the unmute state.
 
57
+ */
 
58
+static int null_get_unmute_volume( void )
 
59
+{
 
60
+       return 0;
 
61
+}
 
62
+
 
63
+/**
 
64
+ * Tunes the relative volume.
 
65
+ */
 
66
+static int null_set_volume( int percentdiff )
 
67
+{
 
68
+       return 0;
 
69
+}
 
70
+
 
71
+/**
 
72
+ * Sets the mute state.
 
73
+ */
 
74
+static void null_mute( int mute )
 
75
+{
 
76
+}
 
77
+
 
78
+/**
 
79
+ * Returns true if the mixer is muted.
 
80
+ */
 
81
+static int null_ismute( void )
 
82
+{
 
83
+       return 0;
 
84
+}
 
85
+
 
86
+/**
 
87
+ * Closes the mixer device if it is open.
 
88
+ */
 
89
+static void null_close_device( void )
 
90
+{
 
91
+}
 
92
+
 
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,
 
100
+       .mute = null_mute,
 
101
+       .ismute = null_ismute,
 
102
+       .close_device = null_close_device,
 
103
+};
 
104
+
 
105
+/* List of all available access methods.
 
106
+ * Uses weak symbols: NULL is not linked in. */
 
107
+static struct mixer *mixers[] = {
 
108
+       &alsa_mixer,
 
109
+       &oss_mixer,
 
110
+       &null_mixer /* LAST */
 
111
+};
 
112
+/* The actual access method. */
 
113
+struct mixer *mixer = &null_mixer;
 
114
+
 
115
+/**
 
116
+ * Sets the mixer device and channel.
 
117
+ * Try each access method until one succeeds.
 
118
+ */
 
119
+int mixer_set_device( const char *devname )
 
120
+{
 
121
+       int i;
 
122
+       mixer->close_device();
 
123
+       for (i = 0; i < sizeof(mixers)/sizeof(mixers[0]); i++) {
 
124
+               mixer = mixers[i];
 
125
+               if (!mixer)
 
126
+                       continue;
 
127
+               if (mixer->set_device(devname) == 0)
 
128
+                       break;
 
129
+               else
 
130
+                       return -1;
 
131
+       }
 
132
+       return 0;
 
133
+}
 
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
 
138
@@ -0,0 +1,86 @@
 
139
+/**
 
140
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
 
141
+ *
 
142
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
 
143
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
 
144
+ *
 
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.
 
149
+ *
 
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.
 
154
+ *
 
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.
 
158
+ */
 
159
+
 
160
+#ifndef MIXER_H_INCLUDED
 
161
+#define MIXER_H_INCLUDED
 
162
+
 
163
+#ifdef __cplusplus
 
164
+extern "C" {
 
165
+#endif
 
166
+
 
167
+/**
 
168
+ * Sets the mixer device and channel.
 
169
+ * All interfaces are scanned until one succeeds.
 
170
+ */
 
171
+int mixer_set_device( const char *devname );
 
172
+
 
173
+struct mixer {
 
174
+/**
 
175
+ * Sets the mixer device and channel.
 
176
+ */
 
177
+int (* set_device)( const char *devname );
 
178
+
 
179
+/**
 
180
+ * Sets the initial state of the mixer device.
 
181
+ */
 
182
+void (* set_state)( int ismuted, int unmute_volume );
 
183
+
 
184
+/**
 
185
+ * Returns the current volume setting.
 
186
+ */
 
187
+int (* get_volume)( void );
 
188
+
 
189
+/**
 
190
+ * Returns the volume that would be used to restore the unmute state.
 
191
+ */
 
192
+int (* get_unmute_volume)( void );
 
193
+
 
194
+/**
 
195
+ * Tunes the relative volume.
 
196
+ */
 
197
+int (* set_volume)( int percentdiff );
 
198
+
 
199
+/**
 
200
+ * Sets the mute state.
 
201
+ */
 
202
+void (* mute)( int mute );
 
203
+
 
204
+/**
 
205
+ * Returns true if the mixer is muted.
 
206
+ */
 
207
+int (* ismute)( void );
 
208
+
 
209
+/**
 
210
+ * Closes the mixer device if it is open.
 
211
+ */
 
212
+void (* close_device)( void );
 
213
+};
 
214
+
 
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;
 
220
+
 
221
+#ifdef __cplusplus
 
222
+};
 
223
+#endif
 
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
 
229
@@ -1,171 +0,0 @@
 
230
-/*
 
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.
 
235
- *
 
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.
 
240
- *
 
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.
 
244
- */
 
245
-
 
246
-#include <stdio.h>
 
247
-#include <stdlib.h>
 
248
-#include <unistd.h>
 
249
-#include <string.h>
 
250
-#include <math.h>
 
251
-#include <fcntl.h>
 
252
-#include <sys/ioctl.h>
 
253
-#include <assert.h>
 
254
-
 
255
-#include <sys/soundcard.h>
 
256
-
 
257
-#include "tech.h"
 
258
-
 
259
-static int mixer_fd = -1, mixer_src = -1;
 
260
-static char *devices[] = SOUND_DEVICE_NAMES;
 
261
-
 
262
-/*
 
263
- * These functions handle the mixer device
 
264
- */
 
265
 
266
-int mixer_init(char *mixer_device, char *mixer_source)
 
267
-{
 
268
-       int i;
 
269
-       
 
270
-       mixer_src = -1;
 
271
-       
 
272
-       for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
 
273
-               if (strcmp(mixer_source, devices[i]) == 0) 
 
274
-                       mixer_src = i;
 
275
-
 
276
-       mixer_fd = open(mixer_device, O_RDWR);
 
277
-
 
278
-       if (mixer_src < 0)      
 
279
-               return -1;
 
280
-                       
 
281
-       if (mixer_fd < 0)
 
282
-               return 0;
 
283
-       return 1;
 
284
-}
 
285
-
 
286
-char* mixer_get_sndcard_name(void)
 
287
-{
 
288
-       mixer_info info;
 
289
-       char *result = NULL;
 
290
-
 
291
-       if (ioctl(mixer_fd, SOUND_MIXER_INFO, &info) == -1)
 
292
-               return NULL;
 
293
-
 
294
-       result = strdup(info.name);     
 
295
-       
 
296
-       return result;
 
297
-}
 
298
-
 
299
-char** mixer_get_rec_devices(void)
 
300
-{
 
301
-       int i, o, devmask, res;
 
302
-       char** result;
 
303
-       
 
304
-       if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
 
305
-               return NULL;
 
306
-       else
 
307
-       {
 
308
-               result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
 
309
-               o = 0;
 
310
-               for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
 
311
-                       {
 
312
-                               res = (devmask >> i)%2;
 
313
-                               if (res)
 
314
-                               {
 
315
-                                       result[o] = malloc(strlen(devices[i])+1);
 
316
-                                       sprintf(result[o], "%s", devices[i]); 
 
317
-                                       o++;
 
318
-                               }
 
319
-                               result[o] = NULL;       
 
320
-                       }
 
321
-       }
 
322
-       return result;
 
323
-}
 
324
-
 
325
-int mixer_set_rec_device(void)
 
326
-{
 
327
-       int devmask, recmask;
 
328
-
 
329
-       if (mixer_fd <= 0)
 
330
-               return 0;
 
331
-
 
332
-       if (mixer_src < 0)
 
333
-               return 0;
 
334
-
 
335
-       if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
 
336
-               return 0;
 
337
-       
 
338
-       recmask = 1 << mixer_src;
 
339
-       if (!(recmask & devmask))
 
340
-               return 0;
 
341
-
 
342
-       if ((ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &recmask)) == -1)
 
343
-               return 0;
 
344
-
 
345
-       return 1;
 
346
-}                      
 
347
-
 
348
-int mixer_close(void)
 
349
-{
 
350
-       if (mixer_fd > 0)
 
351
-               close(mixer_fd);
 
352
-       
 
353
-       return 1;
 
354
-}
 
355
-               
 
356
-int mixer_set_volume(int volume)
 
357
-{
 
358
-       int i_vol;
 
359
-       if (mixer_fd<0)
 
360
-               return -1;
 
361
-
 
362
-       assert(volume <= 100);
 
363
-       assert(volume >= 0);
 
364
-
 
365
-
 
366
-       if (mixer_src<0) 
 
367
-               return -1;
 
368
-       
 
369
-       i_vol = volume;  
 
370
-       i_vol += volume << 8;
 
371
-
 
372
-       /*printf("Setting %s to vol %i\n", devices[mixer_src], volume);*/
 
373
-       if ((ioctl(mixer_fd, MIXER_WRITE(mixer_src), &i_vol)) < 0)
 
374
-               return 0;
 
375
-               
 
376
-       return 1;
 
377
-}
 
378
-
 
379
-int mixer_get_volume(void)
 
380
-{
 
381
-       int i_vol = 0, r, l, volume;
 
382
-       
 
383
-       if (mixer_fd<0)
 
384
-               return -1;
 
385
-
 
386
-       if (mixer_src<0) 
 
387
-               return -1;
 
388
-       
 
389
-       if ((ioctl(mixer_fd, MIXER_READ(mixer_src), &i_vol)) < 0)
 
390
-               return 0;
 
391
-
 
392
-       r = i_vol >> 8;
 
393
-       l = i_vol % (1 << 8);
 
394
-       volume = (r + l)/2;
 
395
-       /*printf("%d %d %d %d\n", r, l, volume, i_vol);*/
 
396
-       
 
397
-       assert((volume >= 0) && (volume <= 100));
 
398
-       
 
399
-       return volume;
 
400
-}
 
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
 
405
@@ -1,34 +0,0 @@
 
406
-/*
 
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.
 
411
- *
 
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.
 
416
- *
 
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.
 
420
- */
 
421
-
 
422
-#ifndef _TECH_H
 
423
-#define _TECH_H
 
424
-
 
425
-int mixer_init(char *mixer_device, char *mixer_source);
 
426
-
 
427
-char* mixer_get_sndcard_name(void);
 
428
-
 
429
-char** mixer_get_rec_devices(void);
 
430
-
 
431
-int mixer_close(void);
 
432
-
 
433
-int mixer_set_volume(int volume);
 
434
-
 
435
-int mixer_get_volume(void);
 
436
-
 
437
-int mixer_set_rec_device(void);
 
438
-
 
439
-#endif
 
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
 
444
@@ -30,7 +30,7 @@
 
445
 #include <stdlib.h>
 
446
 #include "gui.h"
 
447
 #include "trayicon.h"
 
448
-#include "tech.h"
 
449
+#include "mixer.h"
 
450
 #include "radio.h"
 
451
 #include "rec_tech.h"
 
452
 #include "lirc.h"
 
453
@@ -61,7 +61,7 @@
 
454
 int alsa_latency = DEFAULT_LATENCY;
 
455
 int debug = 0;
 
456
 
 
457
-GtkWidget* mute_button, *preset_combo;
 
458
+GtkWidget* volume_button, *preset_combo;
 
459
 GtkAdjustment *adj;
 
460
 GtkWidget* app;
 
461
 
 
462
@@ -256,22 +256,22 @@
 
463
 
 
464
 void start_radio(gboolean restart, GtkWidget *app)
 
465
 {
 
466
-    DriverType driver = DRIVER_ANY;
 
467
+       DriverType driver = DRIVER_ANY;
 
468
        if (restart)
 
469
                radio_stop();
 
470
        
 
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;
 
476
-    }
 
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;
 
482
+       }
 
483
 
 
484
-       if (!radio_init(settings.device, driver))
 
485
-       {
 
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);
 
494
                g_free(caption);
 
495
                g_free(detail);
 
496
@@ -286,51 +286,30 @@
 
497
        gint res, vol;
 
498
        
 
499
        if (restart)
 
500
-               mixer_close();
 
501
+               mixer->close_device();
 
502
        
 
503
-       res = mixer_init(settings.mixer_dev, settings.mixer);
 
504
-       if (res <1) 
 
505
-       {
 
506
-               char *buffer;
 
507
-               
 
508
-               if (res == -1)
 
509
-                       buffer = g_strdup_printf(_("Mixer source \"%s\" is not a valid source!"), settings.mixer);
 
510
-               else 
 
511
-                       buffer = g_strdup_printf(_("Could not open \"%s\"!"), settings.mixer_dev);
 
512
-               
 
513
-               show_error_message(buffer, NULL);
 
514
+       res = mixer_set_device(settings.mixer);
 
515
+       if (res == -1) {
 
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);
 
522
+               g_free(caption);
 
523
+               g_free(detail);
 
524
+
 
525
+               gtk_widget_set_sensitive(volume_button, FALSE);
 
526
                
 
527
-               g_free(buffer);
 
528
-       }               
 
529
-       vol = mixer_get_volume();
 
530
-       if (vol >= 0) {
 
531
-               gtk_volume_button_set_value(mute_button, vol);
 
532
-               /*gtk_adjustment_set_value(volume, (double)vol);*/
 
533
-       }
 
534
-}
 
535
+               if (!restart)
 
536
+                       prefs_button_clicked_cb(NULL, app);
 
537
 
 
538
-GList* get_mixer_recdev_list(void)
 
539
-{
 
540
-       int i;
 
541
-       char **array, *dev;
 
542
-       GList *result = NULL;
 
543
-       
 
544
-       array = mixer_get_rec_devices();
 
545
-       if (!array)
 
546
-               return NULL;
 
547
-       
 
548
-       i = 0;  
 
549
-       dev = array[i];
 
550
-       while (dev)
 
551
-       {
 
552
-               char *text = g_strdup(dev);
 
553
-               result = g_list_append(result, text);
 
554
-               free(dev);
 
555
-               dev = array[++i];
 
556
-       }                       
 
557
-       free(array);
 
558
-       
 
559
-       return result;
 
560
+       } else {
 
561
+               vol = mixer->get_volume();
 
562
+               if (vol >= 0)
 
563
+                       gtk_volume_button_set_value(volume_button, vol);
 
564
+               gtk_widget_set_sensitive(volume_button, TRUE);
 
565
+       }
 
566
 }
 
567
 
 
568
 static gboolean redraw_status_window(void)
 
569
@@ -433,7 +412,7 @@
 
570
                radio_mute(alsa_loopback);
 
571
                radio_stop();
 
572
        }
 
573
-       mixer_close();
 
574
+       mixer->close_device();
 
575
        save_settings();
 
576
        gtk_main_quit();
 
577
 }
 
578
@@ -484,27 +463,22 @@
 
579
 
 
580
 static void volume_value_changed_cb(GtkVolumeButton *button, gpointer user_data)
 
581
 {
 
582
-       /* char *text; */
 
583
-       int vol = (int)(gtk_volume_button_get_value(mute_button) + 0.5f);
 
584
-       
 
585
-       mixer_set_volume(vol);
 
586
-       
 
587
-/*     text = g_strdup_printf(_("Volume: %d%%"), vol);
 
588
-       gtk_widget_set_tooltip_text(vol_scale, text);
 
589
-       g_free(text);*/
 
590
-       
 
591
-    if (tray_menu) {
 
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);
 
595
-    }
 
596
+       int vol = (int)(gtk_volume_button_get_value(volume_button) + 0.5f);
 
597
+
 
598
+       mixer->set_volume(vol - mixer->get_volume());
 
599
+
 
600
+       if (tray_menu) {
 
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);
 
604
+       }
 
605
 }
 
606
 
 
607
 #if 0
 
608
 static gboolean poll_volume_change(gpointer data)
 
609
 {
 
610
        int vol;
 
611
-       if ((vol = mixer_get_volume()) < 0)
 
612
+       if ((vol = mixer->get_volume()) < 0)
 
613
                return FALSE;
 
614
        
 
615
        if (vol != (int)volume->value)
 
616
@@ -729,16 +703,6 @@
 
617
        Recording* recording;
 
618
        char *filename;
 
619
        
 
620
-       if (!mixer_set_rec_device())
 
621
-       {
 
622
-               GtkWidget *dialog;
 
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);
 
627
-               return -1;
 
628
-       }
 
629
-       
 
630
        /* You can translate the filename for a recording:
 
631
         * args for this format are: path, station title, time 
 
632
         */ 
 
633
@@ -796,7 +760,7 @@
 
634
 void toggle_volume(void)
 
635
 {
 
636
        static int old_vol;
 
637
-       int vol = mixer_get_volume();
 
638
+       int vol = mixer->get_volume();
 
639
        
 
640
        if (vol) {
 
641
                old_vol = vol;
 
642
@@ -815,21 +779,21 @@
 
643
                        alsa_thread_startup(alsa_playback, alsa_capture,
 
644
                                            alsa_latency, stderr, debug);
 
645
        }       
 
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);*/
 
651
 }      
 
652
 
 
653
 /*
 
654
-static void mute_button_toggled_cb(GtkButton *button, gpointer data)
 
655
+static void volume_button_toggled_cb(GtkButton *button, gpointer data)
 
656
 {
 
657
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mute_button)))
 
658
+       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(volume_button)))
 
659
        {       
 
660
-               gtk_widget_set_tooltip_text(mute_button, _("Unmute"));  
 
661
+               gtk_widget_set_tooltip_text(volume_button, _("Unmute"));
 
662
        }
 
663
        else
 
664
        {
 
665
-               gtk_widget_set_tooltip_text(mute_button, _("Mute"));
 
666
+               gtk_widget_set_tooltip_text(volume_button, _("Mute"));
 
667
        }
 
668
        toggle_volume();
 
669
 }
 
670
@@ -991,9 +955,10 @@
 
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();*/
 
683
 
 
684
@@ -1004,7 +969,7 @@
 
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);*/
 
692
 
 
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);
 
696
 
 
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);*/
 
699
 
 
700
        gtk_widget_set_size_request(drawing_area, DIGIT_WIDTH*6+10+SIGNAL_WIDTH+STEREO_WIDTH, DIGIT_HEIGTH+10);
 
701
 
 
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);
 
731
                radio_stop();
 
732
        }
 
733
-       mixer_close();
 
734
+       mixer->close_device();
 
735
        gtk_main_quit();
 
736
        exit (0);
 
737
 }
 
738
@@ -1178,7 +1143,7 @@
 
739
 gboolean
 
740
 key_press_event_cb(GtkWidget *app, GdkEventKey *event, gpointer data)
 
741
 {
 
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);
 
744
        
 
745
        switch (event->keyval)
 
746
        {
 
747
@@ -1210,12 +1175,12 @@
 
748
                                break;
 
749
                case GDK_KEY_KP_Add:
 
750
                case GDK_KEY_plus:      
 
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);*/
 
754
                                break;
 
755
                case GDK_KEY_minus:
 
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);*/
 
760
                                break;
 
761
        }
 
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
 
766
@@ -30,10 +30,9 @@
 
767
 struct Gnomeradio_Settings
 
768
 {
 
769
        gchar *device;
 
770
-       gchar *mixer_dev;
 
771
        gchar *mixer;
 
772
        gboolean mute_on_exit;
 
773
-    gchar *driver;
 
774
+       gchar *driver;
 
775
        
 
776
        GList *presets;
 
777
 };
 
778
@@ -48,8 +47,6 @@
 
779
 
 
780
 void start_mixer(gboolean restart, GtkWidget *app);
 
781
 
 
782
-GList* get_mixer_recdev_list(void);
 
783
-
 
784
 void exit_gnome_radio(void);
 
785
 
 
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
 
791
@@ -26,7 +26,7 @@
 
792
 #include "gui.h"
 
793
 #include "rec_tech.h"
 
794
 
 
795
-extern GtkWidget* mute_button, *preset_combo;
 
796
+extern GtkWidget *preset_combo;
 
797
 extern GtkAdjustment *adj;
 
798
 
 
799
 extern int mom_ps;
 
800
@@ -34,8 +34,7 @@
 
801
 
 
802
 extern gboolean main_visible;
 
803
 
 
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;
 
810
@@ -60,7 +59,6 @@
 
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);
 
818
@@ -123,10 +121,7 @@
 
819
                settings.driver = g_strdup("any");
 
820
        settings.mixer = gconf_client_get_string(client, "/apps/gnomeradio/mixer", NULL);
 
821
        if (!settings.mixer)
 
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 @@
 
831
        return FALSE;
 
832
 }
 
833
 
 
834
-static gboolean mixer_combo_change_cb(GtkComboBox *combo, gpointer data)
 
835
+static gboolean mixer_entry_activate_cb(GtkWidget *widget, gpointer data)
 
836
 {
 
837
-       GList *mixer_devs;
 
838
-       int active;
 
839
-       gchar *mixer_dev, *tmp;
 
840
-       
 
841
-       g_assert(combo);
 
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);
 
845
-       
 
846
-       mixer_dev = (gchar*)g_list_nth_data(mixer_devs, active);
 
847
-       g_assert(mixer_dev);
 
848
-       
 
849
-       if (g_str_equal(mixer_dev, settings.mixer))
 
850
-               return FALSE;
 
851
+       const gchar *text = gtk_entry_get_text(GTK_ENTRY(mixer_entry));
 
852
 
 
853
-       if (settings.mixer) g_free(settings.mixer);
 
854
-       settings.mixer = g_strdup(mixer_dev);
 
855
+       if (!strcmp(settings.mixer, text)) return FALSE;
 
856
        
 
857
-       if ((tmp = strstr(settings.mixer, " (")))
 
858
-               tmp[0] = '\0';
 
859
+       if (settings.mixer) g_free(settings.mixer);
 
860
+       settings.mixer = g_strdup(text);
 
861
        
 
862
        start_mixer(TRUE, data);
 
863
        
 
864
@@ -692,13 +673,6 @@
 
865
        gtk_widget_set_sensitive(save_button, sel);
 
866
 }
 
867
 
 
868
-static void free_string_list(GList *list)
 
869
-{
 
870
-       if (!list) return;
 
871
-       g_list_foreach(list, (GFunc)g_free, NULL);
 
872
-       g_list_free(list);
 
873
-}
 
874
-
 
875
 static void free_preset_list(gpointer data, gpointer user_data)
 
876
 {
 
877
        preset *ps;
 
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;
 
891
-       gint i, active;
 
892
+       gint i;
 
893
        char *settings_hdr, *presets_hdr, *record_hdr;
 
894
        preset* ps;
 
895
        
 
896
@@ -1052,20 +1025,11 @@
 
897
 
 
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;
 
907
-               ++i;
 
908
-       }
 
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);
 
913
        
 
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);
 
917
 
 
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 @@
 
921
 
 
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);
 
928
 
 
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"));
 
936
 
 
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"));
 
945
 
 
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);
 
955
 
 
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);
 
960
 
 
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);
 
963
 
 
964
        /* The record settings part */
 
965
        record_hdr = g_strconcat("<span weight=\"bold\">", _("Record Settings"), "</span>", NULL);
 
966
@@ -1245,8 +1209,8 @@
 
967
 
 
968
        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(destination_button), rec_settings.destination);
 
969
 
 
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"));
 
974
        
 
975
        gtk_widget_show_all(dialog);
 
976
 
 
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
 
981
@@ -27,7 +27,6 @@
 
982
 #include <gtk/gtk.h>
 
983
 #include <glib/gi18n.h>
 
984
 #include "gui.h"
 
985
-#include "tech.h"
 
986
 #include "rec_tech.h"
 
987
 #include "prefs.h"
 
988
 
 
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
 
993
@@ -23,7 +23,7 @@
 
994
 #include <gtk/gtk.h>
 
995
 #include "gui.h"
 
996
 #include "trayicon.h"
 
997
-#include "tech.h"
 
998
+#include "mixer.h"
 
999
 
 
1000
 extern GtkAdjustment *adj;
 
1001
 
 
1002
@@ -83,7 +83,7 @@
 
1003
        gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), gtk_separator_menu_item_new());
 
1004
 
 
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
 
1015
@@ -22,13 +22,12 @@
 
1016
 #include <fcntl.h>
 
1017
 #include <stdlib.h>
 
1018
 #include <gtk/gtk.h>
 
1019
-
 
1020
 #include <lirc/lirc_client.h>
 
1021
 
 
1022
 #include "lirc.h"
 
1023
 #include "gui.h"
 
1024
 
 
1025
-extern GtkWidget* mute_button;
 
1026
+extern GtkWidget* volume_button;
 
1027
 extern GtkWidget *app;
 
1028
 
 
1029
 static int fd = -1;
 
1030
@@ -37,7 +36,7 @@
 
1031
 static void execute_lirc_command (char *cmd)
 
1032
 {
 
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);
 
1036
 
 
1037
        if (strcasecmp (cmd, "tune up") == 0) 
 
1038
        {
 
1039
@@ -49,12 +48,12 @@
 
1040
        }
 
1041
        else if (strcasecmp (cmd, "volume up") == 0) 
 
1042
        {
 
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);*/
 
1046
        }
 
1047
        else if (strcasecmp (cmd, "volume down") == 0) 
 
1048
        {
 
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);*/
 
1052
        }
 
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
 
1058
@@ -8,7 +8,7 @@
 
1059
       <default>TRUE</default>
 
1060
       <locale name="C">
 
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>
 
1064
       </locale>
 
1065
     </schema>
 
1066
 
 
1067
@@ -32,7 +32,7 @@
 
1068
       <default>/dev/radio0</default>
 
1069
       <locale name="C">
 
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>
 
1073
       </locale>
 
1074
     </schema>
 
1075
 
 
1076
@@ -44,7 +44,7 @@
 
1077
       <default>any</default>
 
1078
       <locale name="C">
 
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>
 
1082
       </locale>
 
1083
     </schema>
 
1084
 
 
1085
@@ -53,22 +53,10 @@
 
1086
       <applyto>/apps/gnomeradio/mixer</applyto>
 
1087
       <owner>gnomeradio</owner>
 
1088
       <type>string</type>
 
1089
-      <default>line</default>
 
1090
+      <default>hw:0/Line</default>
 
1091
       <locale name="C">
 
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>
 
1094
-      </locale>
 
1095
-    </schema>
 
1096
-
 
1097
-    <schema>
 
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>
 
1103
-      <locale name="C">
 
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>
 
1107
       </locale>
 
1108
     </schema>
 
1109
 
 
1110
@@ -92,7 +80,7 @@
 
1111
       <default>-1</default>
 
1112
       <locale name="C">
 
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>
 
1116
       </locale>
 
1117
     </schema>
 
1118
        
 
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
 
1123
@@ -15,11 +15,11 @@
 
1124
        get_media_devices.h     \
 
1125
        gui.h                   \
 
1126
        lirc.h                  \
 
1127
+       mixer.h                 \
 
1128
        prefs.h                 \
 
1129
        radio.h                 \
 
1130
        rec_tech.h              \
 
1131
        record.h                \
 
1132
-       tech.h                  \
 
1133
        trayicon.h              \
 
1134
        v4l1.h                  \
 
1135
        v4l2.h                  \
 
1136
@@ -27,11 +27,13 @@
 
1137
        get_media_devices.c     \
 
1138
        gui.c                   \
 
1139
        lirc.c                  \
 
1140
+       mixer.c                 \
 
1141
+       mixer-alsa.c            \
 
1142
+       mixer-oss.c             \
 
1143
        prefs.c                 \
 
1144
        radio.c                 \
 
1145
        rec_tech.c              \
 
1146
        record.c                \
 
1147
-       tech.c                  \
 
1148
        trayicon.c              \
 
1149
        v4l1.c                  \
 
1150
        v4l2.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
 
1155
@@ -0,0 +1,237 @@
 
1156
+/**
 
1157
+ * Copyright (C) 2006 Philipp Hahn <pmhahn@users.sourceforge.net>
 
1158
+ *
 
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.
 
1163
+ *
 
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.
 
1168
+ *
 
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.
 
1172
+ */
 
1173
+
 
1174
+#include <stdio.h>
 
1175
+#include <sys/types.h>
 
1176
+#include <string.h>
 
1177
+#include <math.h>
 
1178
+#include <alsa/asoundlib.h>
 
1179
+#include "mixer.h"
 
1180
+
 
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;
 
1187
+
 
1188
+static long alsa_min, alsa_max, alsa_vol;
 
1189
+
 
1190
+static void alsa_open_mixer( void )
 
1191
+{
 
1192
+       int err;
 
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));
 
1196
+               return;
 
1197
+       }
 
1198
+       if ((err = snd_mixer_attach (handle, card)) < 0) {
 
1199
+               fprintf(stderr, "mixer: attach error: %s\n", snd_strerror(err));
 
1200
+               goto error;
 
1201
+       }
 
1202
+       if ((err = snd_mixer_selem_register (handle, NULL, NULL)) < 0) {
 
1203
+               fprintf(stderr, "mixer: register error: %s\n", snd_strerror(err));
 
1204
+               goto error;
 
1205
+       }
 
1206
+       if ((err = snd_mixer_load (handle)) < 0) {
 
1207
+               fprintf(stderr, "mixer: load error: %s\n", snd_strerror(err));
 
1208
+               goto error;
 
1209
+       }
 
1210
+       snd_mixer_selem_id_malloc(&sid);
 
1211
+       if (sid == NULL)
 
1212
+               goto error;
 
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));
 
1216
+               goto error;
 
1217
+       }
 
1218
+       if (!snd_mixer_selem_has_playback_volume(elem)) {
 
1219
+               fprintf(stderr, "mixer: no playback\n");
 
1220
+               goto error;
 
1221
+       }
 
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");
 
1225
+               goto error;
 
1226
+       }
 
1227
+       snd_mixer_selem_id_free(sid);
 
1228
+       return;
 
1229
+
 
1230
+error:
 
1231
+       if (handle) {
 
1232
+               snd_mixer_close(handle);
 
1233
+               handle = NULL;
 
1234
+       }
 
1235
+       return;
 
1236
+}
 
1237
+
 
1238
+/* Volume saved to file */
 
1239
+static int alsa_get_unmute_volume( void )
 
1240
+{
 
1241
+       long val;
 
1242
+       if (elem == NULL)
 
1243
+               return -1;
 
1244
+
 
1245
+       if (snd_mixer_selem_is_playback_mono(elem)) {
 
1246
+               snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &val);
 
1247
+               return val;
 
1248
+       } else {
 
1249
+               int c, n = 0;
 
1250
+               long sum = 0;
 
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);
 
1254
+                               sum += val;
 
1255
+                               n++;
 
1256
+                       }
 
1257
+               }
 
1258
+               if (! n) {
 
1259
+                       return 0;
 
1260
+               }
 
1261
+
 
1262
+               val = sum / n;
 
1263
+               sum = (long)((double)(alsa_vol * (alsa_max - alsa_min)) / 100. + 0.5);
 
1264
+
 
1265
+               if (sum != val) {
 
1266
+                  alsa_vol = (long)(((val * 100.) / (alsa_max - alsa_min)) + 0.5);
 
1267
+               }
 
1268
+               return alsa_vol;
 
1269
+       }
 
1270
+}
 
1271
+
 
1272
+static int alsa_get_volume( void )
 
1273
+{
 
1274
+       if (muted)
 
1275
+               return 0;
 
1276
+       else
 
1277
+               return alsa_get_unmute_volume();
 
1278
+}
 
1279
+
 
1280
+static int alsa_set_volume( int percentdiff )
 
1281
+{
 
1282
+       long volume;
 
1283
+
 
1284
+       alsa_get_volume();
 
1285
+
 
1286
+       alsa_vol += percentdiff;
 
1287
+       if( alsa_vol > 100 ) alsa_vol = 100;
 
1288
+       if( alsa_vol < 0 ) alsa_vol = 0;
 
1289
+
 
1290
+       volume = (long)((alsa_vol * (alsa_max - alsa_min) / 100.) + 0.5);
 
1291
+
 
1292
+       snd_mixer_selem_set_playback_volume_all(elem, volume + alsa_min);
 
1293
+       snd_mixer_selem_set_playback_switch_all(elem, 1);
 
1294
+       muted = 0;
 
1295
+       mutecount = 0;
 
1296
+
 
1297
+       return alsa_vol;
 
1298
+}
 
1299
+
 
1300
+static void alsa_mute( int mute )
 
1301
+{
 
1302
+       /**
 
1303
+        * Make sure that if multiple users mute the card,
 
1304
+        * we only honour the last one.
 
1305
+        */
 
1306
+       if( !mute && mutecount ) mutecount--;
 
1307
+       if( mutecount ) return;
 
1308
+
 
1309
+       if( mute ) {
 
1310
+               mutecount++;
 
1311
+               muted = 1;
 
1312
+               if (snd_mixer_selem_has_playback_switch(elem))
 
1313
+                       snd_mixer_selem_set_playback_switch_all(elem, 0);
 
1314
+               else
 
1315
+                       fprintf(stderr, "mixer: mute not implemented\n");
 
1316
+       } else {
 
1317
+               muted = 0;
 
1318
+               if (snd_mixer_selem_has_playback_switch(elem))
 
1319
+                       snd_mixer_selem_set_playback_switch_all(elem, 1);
 
1320
+               else
 
1321
+                       fprintf(stderr, "mixer: mute not implemented\n");
 
1322
+       }
 
1323
+}
 
1324
+
 
1325
+static int alsa_ismute( void )
 
1326
+{
 
1327
+       return muted;
 
1328
+}
 
1329
+
 
1330
+static int alsa_set_device( const char *devname )
 
1331
+{
 
1332
+       int i;
 
1333
+
 
1334
+       if (card) free(card);
 
1335
+       card = strdup( devname );
 
1336
+       if( !card ) return -1;
 
1337
+
 
1338
+       i = strcspn( card, "/" );
 
1339
+       if( i == strlen( card ) ) {
 
1340
+               channel = "Line";
 
1341
+       } else {
 
1342
+               card[i] = 0;
 
1343
+               channel = card + i + 1;
 
1344
+       }
 
1345
+       alsa_open_mixer();
 
1346
+       if (!handle) {
 
1347
+               fprintf( stderr, "mixer: Can't open mixer %s, "
 
1348
+                                "mixer volume and mute unavailable.\n", card );
 
1349
+               return -1;
 
1350
+       }
 
1351
+       return 0;
 
1352
+}
 
1353
+
 
1354
+static void alsa_set_state( int ismuted, int unmute_volume )
 
1355
+{
 
1356
+       /**
 
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
 
1362
+        */
 
1363
+       if( alsa_get_volume() == 0 && unmute_volume > 0 ) {
 
1364
+               snd_mixer_selem_set_playback_volume_all(elem, unmute_volume);
 
1365
+               muted = 1;
 
1366
+
 
1367
+               if( !ismuted ) {
 
1368
+                       alsa_mute( 0 );
 
1369
+               }
 
1370
+       }
 
1371
+}
 
1372
+
 
1373
+static void alsa_close_device( void )
 
1374
+{
 
1375
+       elem = NULL;
 
1376
+       if (handle)
 
1377
+               snd_mixer_close(handle);
 
1378
+       handle = NULL;
 
1379
+       muted = 0;
 
1380
+       mutecount = 0;
 
1381
+}
 
1382
+
 
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,
 
1392
+};
 
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
 
1397
@@ -0,0 +1,261 @@
 
1398
+/**
 
1399
+ * Copyright (C) 2002, 2003 Doug Bell <drbell@users.sourceforge.net>
 
1400
+ *
 
1401
+ * Some mixer routines from mplayer, http://mplayer.sourceforge.net.
 
1402
+ * Copyright (C) 2000-2002. by A'rpi/ESP-team & others
 
1403
+ *
 
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.
 
1408
+ *
 
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.
 
1413
+ *
 
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.
 
1417
+ */
 
1418
+
 
1419
+#include <stdio.h>
 
1420
+#include <fcntl.h>
 
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>
 
1428
+#include "mixer.h"
 
1429
+
 
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;
 
1437
+
 
1438
+static int oss_get_volume( void )
 
1439
+{
 
1440
+       int v, cmd, devs;
 
1441
+       int curvol = 0;
 
1442
+
 
1443
+       if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
 
1444
+       if( fd != -1 ) {
 
1445
+
 
1446
+               ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
 
1447
+               if( devs & mixer_dev_mask ) {
 
1448
+                       cmd = MIXER_READ( mixer_channel );
 
1449
+               } else {
 
1450
+                       return curvol;
 
1451
+               }
 
1452
+
 
1453
+               ioctl( fd, cmd, &v );
 
1454
+               curvol = ( v & 0xFF00 ) >> 8;
 
1455
+       }
 
1456
+
 
1457
+       return curvol;
 
1458
+}
 
1459
+
 
1460
+static int oss_get_unmute_volume( void )
 
1461
+{
 
1462
+       if( muted ) {
 
1463
+               return saved_volume;
 
1464
+       } else {
 
1465
+               int v, cmd, devs;
 
1466
+
 
1467
+               if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
 
1468
+               if( fd != -1 ) {
 
1469
+
 
1470
+                       ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
 
1471
+                       if( devs & mixer_dev_mask ) {
 
1472
+                               cmd = MIXER_READ( mixer_channel );
 
1473
+                       } else {
 
1474
+                               return -1;
 
1475
+                       }
 
1476
+
 
1477
+                       ioctl( fd, cmd, &v );
 
1478
+                       return v;
 
1479
+               }
 
1480
+       }
 
1481
+
 
1482
+       return -1;
 
1483
+}
 
1484
+
 
1485
+static int oss_set_volume( int percentdiff )
 
1486
+{
 
1487
+       int v, cmd, devs, levelpercentage;
 
1488
+
 
1489
+       levelpercentage = oss_get_volume();
 
1490
+
 
1491
+       levelpercentage += percentdiff;
 
1492
+       if( levelpercentage > 100 ) levelpercentage = 100;
 
1493
+       if( levelpercentage < 0 ) levelpercentage = 0;
 
1494
+
 
1495
+       if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
 
1496
+       if( fd != -1 ) {
 
1497
+               ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
 
1498
+               if( devs & mixer_dev_mask ) {
 
1499
+                       cmd = MIXER_WRITE( mixer_channel );
 
1500
+               } else {
 
1501
+                       return 0;
 
1502
+               }
 
1503
+
 
1504
+               v = ( levelpercentage << 8 ) | levelpercentage;
 
1505
+               ioctl( fd, cmd, &v );
 
1506
+               muted = 0;
 
1507
+               mutecount = 0;
 
1508
+               return v;
 
1509
+       }
 
1510
+
 
1511
+       return 0;
 
1512
+}
 
1513
+
 
1514
+static void oss_mute( int mute )
 
1515
+{
 
1516
+       int v, cmd, devs;
 
1517
+
 
1518
+       /**
 
1519
+        * Make sure that if multiple users mute the card,
 
1520
+        * we only honour the last one.
 
1521
+        */
 
1522
+       if( !mute && mutecount ) mutecount--;
 
1523
+       if( mutecount ) return;
 
1524
+
 
1525
+       if( fd < 0 ) fd = open( mixer_device, O_RDONLY );
 
1526
+
 
1527
+       if( mute ) {
 
1528
+               mutecount++;
 
1529
+               if( fd != -1 ) {
 
1530
+
 
1531
+                       /* Save volume */
 
1532
+                       ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
 
1533
+                       if( devs & mixer_dev_mask ) {
 
1534
+                               cmd = MIXER_READ( mixer_channel );
 
1535
+                       } else {
 
1536
+                               return;
 
1537
+                       }
 
1538
+
 
1539
+                       ioctl( fd,cmd,&v );
 
1540
+                       saved_volume = v;
 
1541
+
 
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 );
 
1546
+                       } else {
 
1547
+                               return;
 
1548
+                       }
 
1549
+
 
1550
+                       v = 0;
 
1551
+                       ioctl( fd, cmd, &v );
 
1552
+
 
1553
+                       muted = 1;
 
1554
+                       return;
 
1555
+               }
 
1556
+       } else {
 
1557
+               if( fd != -1 ) {
 
1558
+                       ioctl( fd, SOUND_MIXER_READ_DEVMASK, &devs );
 
1559
+                       if( devs & mixer_dev_mask ) {
 
1560
+                               cmd = MIXER_WRITE( mixer_channel );
 
1561
+                       } else {
 
1562
+                               return;
 
1563
+                       }
 
1564
+
 
1565
+                       v = saved_volume;
 
1566
+                       ioctl( fd, cmd, &v );
 
1567
+                       muted = 0;
 
1568
+                       return;
 
1569
+               }
 
1570
+       }
 
1571
+}
 
1572
+
 
1573
+static int oss_ismute( void )
 
1574
+{
 
1575
+       return muted;
 
1576
+}
 
1577
+
 
1578
+static char *oss_core_devnames[] = SOUND_DEVICE_NAMES;
 
1579
+
 
1580
+static int oss_set_device( const char *devname )
 
1581
+{
 
1582
+       const char *channame;
 
1583
+       int found = 0;
 
1584
+       int i;
 
1585
+
 
1586
+       mixer_device = strdup( devname );
 
1587
+       if( !mixer_device ) return -1;
 
1588
+
 
1589
+       i = strcspn( mixer_device, ":" );
 
1590
+       if( i == strlen( mixer_device ) ) {
 
1591
+               channame = "line";
 
1592
+       } else {
 
1593
+               mixer_device[ i ] = 0;
 
1594
+               channame = mixer_device + i + 1;
 
1595
+       }
 
1596
+       fd = open( mixer_device, O_RDONLY );
 
1597
+       if( fd == 0 ) {
 
1598
+               fprintf( stderr, "mixer: Can't open device %s, "
 
1599
+                                "mixer volume and mute unavailable.\n", mixer_device );
 
1600
+               return -1;
 
1601
+       }
 
1602
+
 
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;
 
1607
+                       found = 1;
 
1608
+                       break;
 
1609
+               }
 
1610
+       }
 
1611
+       if( !found ) {
 
1612
+               fprintf( stderr, "mixer: No such mixer channel '%s', using channel 'line'.\n", channame );
 
1613
+               return -1;
 
1614
+       }
 
1615
+       mixer_dev_mask = 1 << mixer_channel;
 
1616
+       return 0;
 
1617
+}
 
1618
+
 
1619
+static void oss_set_state( int ismuted, int unmute_volume )
 
1620
+{
 
1621
+       /**
 
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
 
1627
+        */
 
1628
+       if( oss_get_volume() == 0 && unmute_volume > 0 ) {
 
1629
+               saved_volume = unmute_volume;
 
1630
+               muted = 1;
 
1631
+
 
1632
+               if( !ismuted ) {
 
1633
+                       oss_mute( 0 );
 
1634
+               }
 
1635
+       }
 
1636
+}
 
1637
+
 
1638
+static void oss_close_device( void )
 
1639
+{
 
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;
 
1644
+       muted = 0;
 
1645
+       mutecount = 0;
 
1646
+       fd = -1;
 
1647
+}
 
1648
+
 
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,
 
1655
+       .mute = oss_mute,
 
1656
+       .ismute = oss_ismute,
 
1657
+       .close_device = oss_close_device,
 
1658
+};