]> mj.ucw.cz Git - ursary.git/blobdiff - ursaryd.c
Nocturn: Do not write to a missing USB device
[ursary.git] / ursaryd.c
index b2cd009a3988223944cbbaebae744041d8c8f3b8..eaa56542b46eec0f4ce81333ec81dcc414d8bce2 100644 (file)
--- a/ursaryd.c
+++ b/ursaryd.c
 
 #include "ursaryd.h"
 
+/*
+ *     Map of all controls
+ *
+ *             rotary          red button      green button
+ *     0       sink Ursarium   mute            select as default (or assign to client selected by touch)
+ *     1       sink Catarium   mute            dtto
+ *     2       -               -               -
+ *     3       -               -               -
+ *     4       MPD             mute            play/pause/stop
+ *     5       Albireo         mute            -
+ *     6       Ogion           mute            -
+ *     7       Ursula          mute            -
+ *
+ *     center  all sinks
+ *     slider  -
+ */
+
 /*** Sink controls ***/
 
 static double volume_from_pa(pa_volume_t vol)
@@ -335,6 +352,90 @@ static void update_default_sink_from_button(int button, int on)
     }
 }
 
+/*** MPD controls ***/
+
+static bool mpd_flash_state;
+
+static void mpd_flash_timeout(struct main_timer *t)
+{
+  mpd_flash_state ^= 1;
+  noct_set_button(12, mpd_flash_state);
+  timer_add_rel(t, 500);
+}
+
+static struct main_timer mpd_flash_timer = {
+  .handler = mpd_flash_timeout,
+};
+
+static void update_mpd(void)
+{
+  const char *state = mpd_get_player_state();
+  if (!strcmp(state, "play"))
+    {
+      noct_set_button(12, 1);
+      timer_del(&mpd_flash_timer);
+    }
+  else if (!strcmp(state, "pause"))
+    {
+      if (!timer_is_active(&mpd_flash_timer))
+       {
+         mpd_flash_state = 1;
+         mpd_flash_timeout(&mpd_flash_timer);
+       }
+    }
+  else
+    {
+      noct_set_button(12, 0);
+      timer_del(&mpd_flash_timer);
+    }
+}
+
+static void mpd_button_timeout(struct main_timer *t)
+{
+  DBG("MPD stop");
+  timer_del(t);
+  mpd_stop();
+}
+
+static void update_mpd_from_button(int button UNUSED, int on)
+{
+  static struct main_timer mpd_button_timer = {
+    .handler = mpd_button_timeout,
+  };
+
+  const char *state = mpd_get_player_state();
+
+  if (!on)
+    {
+      if (timer_is_active(&mpd_button_timer))
+       {
+         timer_del(&mpd_button_timer);
+         if (!strcmp(state, "play"))
+           {
+             DBG("MPD pause");
+             mpd_pause(1);
+           }
+         else if (!strcmp(state, "pause"))
+           {
+             DBG("MPD resume");
+             mpd_pause(0);
+           }
+       }
+      return;
+    }
+
+  if (!strcmp(state, "stop"))
+    {
+      DBG("MPD play");
+      mpd_play();
+    }
+  else
+    {
+      DBG("MPD starting button timer");
+      timer_add_rel(&mpd_button_timer, 1000);
+    }
+}
+
 /*** Main update routines ***/
 
 static struct main_timer update_timer;
@@ -381,6 +482,7 @@ static void do_update(struct main_timer *t)
   update_ring_from_sink(1, "catarium");
   update_clients();
   update_default_sink();
+  update_mpd();
 }
 
 void schedule_update(void)
@@ -433,6 +535,9 @@ void notify_button(int button, int on)
     case 9:
       update_default_sink_from_button(button, on);
       break;
+    case 12:
+      update_mpd_from_button(button, on);
+      break;
     default:
       update_client_from_button(button, on);
     }
@@ -461,6 +566,7 @@ int main(int argc UNUSED, char **argv)
 
   noct_init();
   pulse_init();
+  mpd_init();
 
   msg(L_DEBUG, "Entering main loop");
   main_loop();