Re: [Rhythmbox-devel] ANN: RhythmboxLIRC -- a program to control Rhythmbox with a remote control



Hi,

Attached is the Lirc patch for Rhythmbox 0.9.0:

 configure.ac            |   24 ++++++
 shell/rb-remote.c       |   10 +-
 shell/rb-remote.h       |    4 -
 shell/rb-shell-player.c |  106 ++++++++++++++++++++++++++++
 4 files changed, 136 insertions(+), 8 deletions(-)

Fredrik

--- rhythmbox-0.9.0/configure.ac	2005-08-10 15:07:31.000000000 +0200
+++ rhythmbox-0.9.0.lirc/configure.ac	2005-09-10 08:50:58.000000000 +0200
@@ -163,6 +163,23 @@
 dnl 			AC_DEFINE(HAVE_REMOTE)]
 dnl 			,,) ] ,)
 
+dnl Check for lirc
+
+AC_ARG_ENABLE(lirc, AC_HELP_STRING([--enable-lirc],
+                               [build with lirc support]))
+if test x"$enable_lirc" = xyes; then
+       AC_CHECK_HEADER(lirc/lirc_client.h,[enable_lirc=yes],[enable_lirc=no])
+       if test x"$enable_lirc" = xyes; then
+              AC_CHECK_LIB(lirc_client,lirc_init,[enable_lirc=yes],[enable_lirc=no])
+       fi
+       if test x"$enable_lirc" = xyes; then
+               RHYTHMBOX_LIBS="$RHYTHMBOX_LIBS -llirc_client"
+               AC_DEFINE(HAVE_REMOTE,1,[Define if you have lirc support])
+       else
+               AC_MSG_ERROR([Cannot find lirc on your system])
+       fi
+fi
+AM_CONDITIONAL(HAVE_REMOTE, test x"$enable_lirc" = xyes)
 
 dnl Check for Musicbrainz
 dnl DISABLED
@@ -496,7 +513,12 @@
 else
 	AC_MSG_NOTICE([   D-BUS control/activation disabled])
 fi
-
+if test x"$enable_lirc" = xyes; then
+       AC_MSG_NOTICE([** lirc remote support enabled])
+else
+       AC_MSG_NOTICE([   lirc remote support disabled])
+fi
+	
 dnl if test "x$enable_audiocd" != "xyes"; then
 dnl 	AC_MSG_NOTICE([   Audio CD support is disabled])
 dnl else
--- rhythmbox-0.9.0/shell/rb-remote.c	2005-07-10 14:20:55.000000000 +0200
+++ rhythmbox-0.9.0.lirc/shell/rb-remote.c	2005-09-10 08:58:05.000000000 +0200
@@ -26,7 +26,7 @@
 
 #include "rb-remote.h"
 
-#ifdef HAVE_REMOTE
+// #ifdef HAVE_REMOTE
 
 #include <stdio.h>
 #include <lirc/lirc_client.h>
@@ -34,6 +34,7 @@
 /* strings that we recognize as commands from lirc */
 #define RB_IR_COMMAND_PLAY "play"
 #define RB_IR_COMMAND_PAUSE "pause"
+#define RB_IR_COMMAND_STOP "stop"
 #define RB_IR_COMMAND_SHUFFLE "shuffle"
 #define RB_IR_COMMAND_REPEAT "repeat"
 #define RB_IR_COMMAND_NEXT "next"
@@ -43,7 +44,6 @@
 #define RB_IR_COMMAND_VOLUME_UP "volume_up"
 #define RB_IR_COMMAND_VOLUME_DOWN "volume_down"
 #define RB_IR_COMMAND_MUTE "mute"
-#define RB_IR_COMMAND_QUIT "quit"
 
 struct _RBRemote {
 	GObject parent;
@@ -69,6 +69,8 @@
 		return RB_REMOTE_COMMAND_PLAY;
 	else if (strcmp (str, RB_IR_COMMAND_PAUSE) == 0)
 		return RB_REMOTE_COMMAND_PAUSE;
+	else if (strcmp (str, RB_IR_COMMAND_STOP) == 0)
+		return RB_REMOTE_COMMAND_STOP;
 	else if (strcmp (str, RB_IR_COMMAND_SHUFFLE) == 0)
 		return RB_REMOTE_COMMAND_SHUFFLE;
 	else if (strcmp (str, RB_IR_COMMAND_REPEAT) == 0)
@@ -87,8 +89,6 @@
 		return RB_REMOTE_COMMAND_VOLUME_DOWN;
 	else if (strcmp (str, RB_IR_COMMAND_MUTE) == 0)
 		return RB_REMOTE_COMMAND_MUTE;
-	else if (strcmp (str, RB_IR_COMMAND_QUIT) == 0)
-		return RB_REMOTE_COMMAND_QUIT;
 	else
 		return RB_REMOTE_COMMAND_UNKNOWN;
 }
@@ -260,4 +260,4 @@
 	return g_object_new (RB_TYPE_REMOTE, NULL);
 }
 
-#endif /* HAVE_REMOTE */
+// #endif /* HAVE_REMOTE */
--- rhythmbox-0.9.0/shell/rb-remote.h	2003-09-01 06:21:13.000000000 +0200
+++ rhythmbox-0.9.0.lirc/shell/rb-remote.h	2005-09-10 08:58:35.000000000 +0200
@@ -40,6 +40,7 @@
 	RB_REMOTE_COMMAND_UNKNOWN,
 	RB_REMOTE_COMMAND_PLAY,
 	RB_REMOTE_COMMAND_PAUSE,
+	RB_REMOTE_COMMAND_STOP,
 	RB_REMOTE_COMMAND_SHUFFLE,
 	RB_REMOTE_COMMAND_REPEAT,
 	RB_REMOTE_COMMAND_NEXT,
@@ -48,8 +49,7 @@
 	RB_REMOTE_COMMAND_SEEK_BACKWARD,
 	RB_REMOTE_COMMAND_VOLUME_UP,
 	RB_REMOTE_COMMAND_VOLUME_DOWN,
-	RB_REMOTE_COMMAND_MUTE,
-	RB_REMOTE_COMMAND_QUIT
+	RB_REMOTE_COMMAND_MUTE
 } RBRemoteCommand;
 
 typedef struct
--- rhythmbox-0.9.0/shell/rb-shell-player.c	2005-08-01 22:36:03.000000000 +0200
+++ rhythmbox-0.9.0.lirc/shell/rb-shell-player.c	2005-09-10 08:54:03.000000000 +0200
@@ -153,6 +153,9 @@
 
 static void gconf_play_order_changed (GConfClient *client,guint cnxn_id,
 				      GConfEntry *entry, RBShellPlayer *player);
+#ifdef HAVE_REMOTE
+static void button_pressed_cb (RBRemote *remote, RBRemoteCommand cmd, gpointer data);
+#endif /* HAVE_REMOTE */
 
 #ifdef HAVE_MMKEYS
 static void grab_mmkey (int key_code, GdkWindow *root);
@@ -226,6 +229,7 @@
 	GtkWidget *magic_button;
 
 	RBRemote *remote;
+	float muted_volume;
 
 	guint gconf_play_order_id;
 	guint gconf_state_id;
@@ -679,6 +683,16 @@
 		eel_gconf_notification_add (CONF_STATE_VOLUME,
 					    (GConfClientNotifyFunc) rb_shell_player_volume_changed_cb,
 					    player);
+#ifdef HAVE_REMOTE
+       /* Enable lirc remote support */
+       player->priv->remote = rb_remote_new ();
+       player->priv->muted_volume = -1;
+
+       g_signal_connect_object (G_OBJECT (player->priv->remote),
+                                "button_pressed",
+                                G_CALLBACK (button_pressed_cb),
+                                player, 0);
+#endif /* HAVE_REMOTE */
 
 #ifdef HAVE_MMKEYS
 	/* Enable Multimedia Keys */
@@ -2259,6 +2273,98 @@
 	return shell_player->priv->url;
 }
 
+#ifdef HAVE_REMOTE
+static void
+button_pressed_cb (RBRemote *remote, RBRemoteCommand cmd, gpointer data)
+{
+       long time;
+       float volume;
+       RBPlayer *mmplayer;
+       RBShellPlayer *player = RB_SHELL_PLAYER (data);
+
+       switch (cmd)
+       {
+       case RB_REMOTE_COMMAND_PLAY:
+               rb_shell_player_cmd_play (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_PAUSE:
+               rb_shell_player_cmd_pause (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_STOP:
+               rb_shell_player_cmd_stop (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_SHUFFLE:
+               rb_shell_player_shuffle_changed_cb (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_REPEAT:
+               rb_shell_player_repeat_changed_cb (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_NEXT:
+               rb_shell_player_cmd_next (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_PREVIOUS:
+               rb_shell_player_cmd_previous (NULL, player);
+               break;
+       case RB_REMOTE_COMMAND_SEEK_FORWARD:
+               time = rb_shell_player_get_playing_time (player) + 10;
+               rb_shell_player_set_playing_time (player, time);
+               break;
+       case RB_REMOTE_COMMAND_SEEK_BACKWARD:
+               time = rb_shell_player_get_playing_time (player) - 10;
+
+               if (time < 0)
+                       time = 0;
+
+               rb_shell_player_set_playing_time (player, time);
+               break;
+       case RB_REMOTE_COMMAND_VOLUME_UP:
+               mmplayer = rb_shell_player_get_mm_player (player);
+               volume = rb_player_get_volume (mmplayer) + .1;
+
+               if (volume > 1.0)
+                       volume = 1.0;
+
+               if (player->priv->muted_volume == -1) {
+                       rb_player_set_volume (mmplayer, volume);
+               } else {
+                       rb_player_set_volume (mmplayer, player->priv->muted_volume);
+                       player->priv->muted_volume = -1;
+               }
+
+               break;
+       case RB_REMOTE_COMMAND_VOLUME_DOWN:
+               mmplayer = rb_shell_player_get_mm_player (player);
+               volume = rb_player_get_volume (mmplayer) - .1;
+
+               if (volume < 0.0)
+                       volume = 0.0;
+
+               if (player->priv->muted_volume == -1) {
+                       rb_player_set_volume (mmplayer, volume);
+               } else {
+                       rb_player_set_volume (mmplayer, player->priv->muted_volume);
+                       player->priv->muted_volume = -1;
+               }
+
+               break;
+       case RB_REMOTE_COMMAND_MUTE:
+               mmplayer = rb_shell_player_get_mm_player (player);
+
+               if (player->priv->muted_volume == -1) {
+                       player->priv->muted_volume = rb_player_get_volume (mmplayer);
+                       rb_player_set_volume (mmplayer, 0.0);
+               } else {
+                       rb_player_set_volume (mmplayer, player->priv->muted_volume);
+                       player->priv->muted_volume = -1;
+               }
+
+               break;
+       case RB_REMOTE_COMMAND_UNKNOWN:
+               break;
+       }
+}
+#endif /* HAVE_REMOTE */
+
 #ifdef HAVE_MMKEYS
 static void
 grab_mmkey (int key_code, GdkWindow *root)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]