From 811aac2944e71e87dc3993df112b85cc8ca71bea Mon Sep 17 00:00:00 2001 From: Jose A Ortega Ruiz Date: Sat, 22 May 2010 01:49:30 +0200 Subject: MPD: new field ppos (playlist position). Ignore-this: 6df60c780a498f6817876fb0ff8ba367 darcs-hash:20100521234930-748be-f530249e276ff2a886b1b5c68706254079cec540.gz --- Plugins/Monitors/MPD.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Plugins/Monitors/MPD.hs') diff --git a/Plugins/Monitors/MPD.hs b/Plugins/Monitors/MPD.hs index 72b73d6..d6f8ec6 100644 --- a/Plugins/Monitors/MPD.hs +++ b/Plugins/Monitors/MPD.hs @@ -21,7 +21,7 @@ import qualified Network.MPD as M mpdConfig :: IO MConfig mpdConfig = mkMConfig "MPD: " [ "bar", "state", "statei", "volume", "length" - , "lapsed", "plength" + , "lapsed", "plength", "ppos" , "name", "artist", "composer", "performer" , "album", "title", "track", "trackno", "file", "genre" ] @@ -56,16 +56,20 @@ mopts argv = parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts -> (Float, [String]) parseMPD (Left e) _ _ = (0, show e:repeat "") -parseMPD (Right st) song opts = (b, [ss, si, vol, len, lap, plen] ++ sf) +parseMPD (Right st) song opts = (b, [ss, si, vol, len, lap, plen, pp] ++ sf) where s = M.stState st ss = show s si = stateGlyph s opts - vol = int2Str $ M.stVolume st + vol = int2str $ M.stVolume st (lap, len) = (showTime p, showTime t) (p, t) = M.stTime st b = if t > 0 then fromIntegral p / fromIntegral t else 0 - plen = int2Str $ M.stPlaylistLength st + plen = int2str $ M.stPlaylistLength st sf = parseSong song + pp = case M.stSongPos st of + Nothing -> "" + Just (M.Pos n) -> int2str $ n + 1 + Just (M.ID n) -> int2str n stateGlyph :: M.State -> MOpts -> String stateGlyph s o = @@ -80,13 +84,13 @@ parseSong (Right Nothing) = repeat "" parseSong (Right (Just s)) = [ M.sgName s, M.sgArtist s, M.sgComposer s, M.sgPerformer s , M.sgAlbum s, M.sgTitle s, track, trackno, M.sgFilePath s, M.sgGenre s] - where (track, trackno) = (int2Str t, int2Str tn) + where (track, trackno) = (show t, show tn) (t, tn) = M.sgTrack s showTime :: Integer -> String -showTime t = int2Str minutes ++ ":" ++ int2Str seconds +showTime t = int2str minutes ++ ":" ++ int2str seconds where minutes = t `div` 60 seconds = t `mod` 60 -int2Str :: (Num a, Ord a) => a -> String -int2Str x = if x < 10 then '0':sx else sx where sx = show x +int2str :: (Num a, Ord a) => a -> String +int2str x = if x < 10 then '0':sx else sx where sx = show x -- cgit v1.2.3