modify lirc module to use pa_sink_mute() for muting and unmuting
authorLennart Poettering <lennart@poettering.net>
Wed, 17 May 2006 21:07:46 +0000 (21:07 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 May 2006 21:07:46 +0000 (21:07 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@924 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/modules/module-lirc.c

index 918177a..009c2e4 100644 (file)
@@ -88,7 +88,14 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
         pa_xfree(c);
         
         while (lirc_code2char(u->config, code, &name) == 0 && name) {
-            enum { INVALID, UP, DOWN, MUTE, RESET, MUTE_TOGGLE } volchange = INVALID;
+            enum {
+                INVALID,
+                UP,
+                DOWN,
+                MUTE,
+                RESET,
+                MUTE_TOGGLE
+            } volchange = INVALID;
             
             pa_log_info(__FILE__": translated IR code '%s'", name);
             
@@ -111,51 +118,56 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC
                 if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK, 1)))
                     pa_log(__FILE__": failed to get sink '%s'", u->sink_name);
                 else {
-                    pa_volume_t v = pa_cvolume_avg(pa_sink_get_volume(s, PA_MIXER_HARDWARE));
-                    pa_cvolume cv;
+                    int i;
+                    pa_cvolume cv = *pa_sink_get_volume(s, PA_MIXER_HARDWARE);
+
 #define DELTA (PA_VOLUME_NORM/20)
 
                     switch (volchange) {
                         case UP:
-                            v += PA_VOLUME_NORM/20;
+                            for (i = 0; i < cv.channels; i++) {
+                                cv.values[i] += DELTA;
+
+                                if (cv.values[i] > PA_VOLUME_NORM)
+                                    cv.values[i] = PA_VOLUME_NORM;
+                            }
+
+                            pa_sink_set_volume(s, PA_MIXER_HARDWARE, &cv);
                             break;
                             
                         case DOWN:
-                            if (v > DELTA)
-                                v -= DELTA;
-                            else
-                                v = PA_VOLUME_MUTED;
+                            for (i = 0; i < cv.channels; i++) {
+                                if (cv.values[i] >= DELTA)
+                                    cv.values[i] -= DELTA;
+                                else
+                                    cv.values[i] = PA_VOLUME_MUTED;
+                            }
                             
+                            pa_sink_set_volume(s, PA_MIXER_HARDWARE, &cv);
                             break;
                             
                         case MUTE:
-                            v  = PA_VOLUME_MUTED;
+                            pa_sink_set_mute(s, PA_MIXER_HARDWARE, 0);
                             break;
                             
                         case RESET:
-                            v  = PA_VOLUME_NORM;
+                            pa_sink_set_mute(s, PA_MIXER_HARDWARE, 1);
                             break;
                             
-                        case MUTE_TOGGLE: {
-
-                            if (v > 0) {
-                                u->mute_toggle_save = v;
-                                v = PA_VOLUME_MUTED;
-                            } else
-                                v = u->mute_toggle_save;
-                        }
-                        default:
+                        case MUTE_TOGGLE:
+
+                            pa_sink_set_mute(s, PA_MIXER_HARDWARE, !pa_sink_get_mute(s, PA_MIXER_HARDWARE));
+                            break;
+
+                        case INVALID:
                             ;
                     }
-
-                    pa_cvolume_set(&cv, PA_CHANNELS_MAX, v);
-                    pa_sink_set_volume(s, PA_MIXER_HARDWARE, &cv);
                 }
             }
         }
     }
 
-    free(code);
+    pa_xfree(code);
 
     return;