]> mj.ucw.cz Git - ursary.git/blobdiff - ursaryd.c
MPD controls
[ursary.git] / ursaryd.c
index b2cd009a3988223944cbbaebae744041d8c8f3b8..3b1d051313cd4b6eeffe5fd3004e9d2f36708311 100644 (file)
--- a/ursaryd.c
+++ b/ursaryd.c
@@ -335,6 +335,55 @@ static void update_default_sink_from_button(int button, int on)
     }
 }
 
+/*** MPD controls ***/
+
+static void update_mpd(void)
+{
+  const char *state = mpd_get_player_state();
+  if (!strcmp(state, "play"))
+    noct_set_button(12, 1);
+  else
+    noct_set_button(12, 0);
+}
+
+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,
+  };
+
+  if (!on)
+    {
+      timer_del(&mpd_button_timer);
+      return;
+    }
+
+  const char *state = mpd_get_player_state();
+  if (!strcmp(state, "stop"))
+    {
+      DBG("MPD play");
+      mpd_play();
+    }
+  else if (!strcmp(state, "play"))
+    {
+      DBG("MPD pause");
+      timer_add_rel(&mpd_button_timer, 1000);
+      mpd_pause(1);
+    }
+  else if (!strcmp(state, "pause"))
+    {
+      DBG("MPD resume");
+      mpd_pause(0);
+    }
+}
+
 /*** Main update routines ***/
 
 static struct main_timer update_timer;
@@ -381,6 +430,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 +483,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 +514,7 @@ int main(int argc UNUSED, char **argv)
 
   noct_init();
   pulse_init();
+  mpd_init();
 
   msg(L_DEBUG, "Entering main loop");
   main_loop();