[Tkabber-dev] r54 - trunk/plugins/now_playing

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Sep 26 02:47:16 MSD 2007


Author: kostix
Date: 2007-09-26 02:47:15 +0400 (Wed, 26 Sep 2007)
New Revision: 54

Modified:
   trunk/plugins/now_playing/mpd.tcl
Log:
now_playing/mpd.tcl: implemented proper state transition tracking.



Modified: trunk/plugins/now_playing/mpd.tcl
===================================================================
--- trunk/plugins/now_playing/mpd.tcl	2007-09-25 00:03:01 UTC (rev 53)
+++ trunk/plugins/now_playing/mpd.tcl	2007-09-25 22:47:15 UTC (rev 54)
@@ -158,6 +158,10 @@
 	fconfigure $sock -buffering line -translation lf -encoding utf-8
 
 	laststate set unknown
+	array set mpd {
+		playlist -1
+		songid   -1
+	}
 
 	poll using [mycmd mpd_yield $sock]
 }
@@ -172,7 +176,6 @@
 }
 
 proc now_playing::mpd_yield sock {
-	variable mpd
 	variable options
 	variable lasttime
 
@@ -213,9 +216,19 @@
 	switch -- $state {
 		stop  -
 		pause {
+			if {[laststate is inactive]} return
 			set newstate inactive
 		}
 		play {
+			if {[laststate is active]} {
+				variable mpd
+
+				if {$mpd(playlist) == $playlist
+				&& $mpd(songid)    == $songid} return
+
+				set mpd(playlist) $playlist
+				set mpd(songid)   $songid
+			}
 			set newstate active
 		}
 		default {
@@ -224,8 +237,6 @@
 		}
 	}
 
-	if {[laststate is $newstate]} return
-
 	if {[clock seconds] - $lasttime < $options(update_threshold)} return
 
 	switch -- $newstate {
@@ -236,25 +247,8 @@
 			}
 		}
 		active {
-			set unseen no
-			if {![info exists mpd(playlist)]} {
-				set mpd(playlist) $playlist
-				set unseen yes
-			}
-			if {![info exists mpd(songid)]} {
-				set mpd(songid) $songid
-				set unseen yes
-			}
-
-			if {$unseen
-			|| $mpd(playlist) != $playlist
-			|| $mpd(songid) != $songid} {
-				set mpd(playlist) $playlist
-				set mpd(songid)   $songid
-
-				mpd_get_songinfo $sock info
-				mpd_publish_songinfo info
-			}
+			mpd_get_songinfo $sock info
+			mpd_publish_songinfo info
 		}
 	}
 



More information about the Tkabber-dev mailing list