[Rhythmbox-devel] [PATCH] add lirc support



Greetings,

The attached patch against latest .8 CVS adds support for lirc.  Support
can be enabled with ./configure --enable-lirc.  

Implemented functions include play, pause, stop, shuffle (toggle),
repeat (toggle), next, previous, seek forward/backward (by 10 seconds),
volume up/down (by .1 units),  and mute/unmute (restores to previous
volume).

It's been thoroughly tested and works great with my ATI remote wonder. 
Please consider for inclusion...I can't live without it now that I have
my remote! :)

BTW, is there a CVS repository for the .9 branch or is it only available
via arch?

Regards,
Jon Oberheide
jon focalhost com
diff -ur rhythmbox.old/configure.ac rhythmbox.cvs/configure.ac
--- rhythmbox.old/configure.ac	2004-06-03 11:30:56.427871296 -0500
+++ rhythmbox.cvs/configure.ac	2004-06-03 11:31:24.669577904 -0500
@@ -214,11 +214,23 @@
   AC_DEFINE_UNQUOTED(RB_HAVE_ATOMIC_INT, 1, [Some atomic integer implementation present])
 fi
 
-dnl AC_CHECK_LIB(lirc_client, lirc_init,
-dnl 		[ AC_CHECK_HEADER(lirc/lirc_client.h,
-dnl 			[ RHYTHMBOX_LIBS="$RHYTHMBOX_LIBS -llirc_client"
-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 libid3tag
 
@@ -589,6 +601,11 @@
 else
 	AC_MSG_NOTICE([   iPod integration 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])
diff -ur rhythmbox.old/shell/rb-remote.c rhythmbox.cvs/shell/rb-remote.c
--- rhythmbox.old/shell/rb-remote.c	2004-06-03 11:30:56.388877224 -0500
+++ rhythmbox.cvs/shell/rb-remote.c	2004-06-03 14:45:09.428345952 -0500
@@ -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;
@@ -67,6 +67,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)
@@ -85,8 +87,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;
 }
diff -ur rhythmbox.old/shell/rb-remote.h rhythmbox.cvs/shell/rb-remote.h
--- rhythmbox.old/shell/rb-remote.h	2004-06-03 11:30:56.388877224 -0500
+++ rhythmbox.cvs/shell/rb-remote.h	2004-06-03 13:36:16.464651936 -0500
@@ -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,
@@ -49,7 +50,6 @@
 	RB_REMOTE_COMMAND_VOLUME_UP,
 	RB_REMOTE_COMMAND_VOLUME_DOWN,
 	RB_REMOTE_COMMAND_MUTE,
-	RB_REMOTE_COMMAND_QUIT
 } RBRemoteCommand;
 
 typedef struct
diff -ur rhythmbox.old/shell/rb-shell-player.c rhythmbox.cvs/shell/rb-shell-player.c
--- rhythmbox.old/shell/rb-shell-player.c	2004-06-03 11:30:56.388877224 -0500
+++ rhythmbox.cvs/shell/rb-shell-player.c	2004-06-03 14:58:50.100584808 -0500
@@ -169,6 +169,10 @@
 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);
 static GdkFilterReturn filter_mmkeys (GdkXEvent *xevent,
@@ -248,6 +252,7 @@
 	GtkWidget *magic_button;
 
 	RBRemote *remote;
+	float muted_volume;
 
 	guint gconf_play_order_id;
 	guint gconf_state_id;
@@ -567,6 +572,17 @@
 					    (GConfClientNotifyFunc) rb_shell_player_state_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 */
 	rb_shell_player_init_mmkeys (player);
@@ -2108,6 +2124,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, NULL);
+		break;
+	case RB_REMOTE_COMMAND_PAUSE:
+		rb_shell_player_cmd_pause (NULL, player, NULL);
+		break;
+	case RB_REMOTE_COMMAND_STOP:
+		rb_shell_player_cmd_stop (NULL, player, NULL);
+		break;
+	case RB_REMOTE_COMMAND_SHUFFLE:
+		rb_shell_player_shuffle_changed_cb (NULL, NULL, 0, NULL, player);
+		break;
+	case RB_REMOTE_COMMAND_REPEAT:
+		rb_shell_player_repeat_changed_cb (NULL, NULL, 0, NULL, player);
+		break;
+	case RB_REMOTE_COMMAND_NEXT:
+		rb_shell_player_cmd_next (NULL, player, NULL);
+		break;
+	case RB_REMOTE_COMMAND_PREVIOUS:
+		rb_shell_player_cmd_previous (NULL, player, NULL);
+		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)

Attachment: signature.asc
Description: This is a digitally signed message part



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