packages feed

libmpd 0.1.2 → 0.1.3

raw patch · 5 files changed

+33/−43 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

ChangeLog view
@@ -1,3 +1,6 @@+* v0.1.3, 2007-10-02+	- Bugfixes.+ * v0.1.2, 2007-09-29 	- Changed name to libmpd. 
Network/MPD/Commands.hs view
@@ -65,7 +65,7 @@  import Control.Monad (liftM, unless) import Prelude hiding (repeat)-import Data.List (findIndex)+import Data.List (findIndex, intersperse) import Data.Maybe  --@@ -190,25 +190,13 @@            , dOutputEnabled :: Bool }     deriving Show -class Parsable a where-    parse :: [String] -> a--parseResponse :: (Parsable a) => String -> MPD a-parseResponse = liftM parse . getResponse--instance Parsable () where-    parse = const ()--instance Parsable [String] where-    parse = takeValues- -- -- Admin commands --  -- | Turn off an output device. disableoutput :: Int -> MPD ()-disableoutput = parseResponse . ("disableoutput " ++) . show+disableoutput = getResponse_ . ("disableoutput " ++) . show  -- | Turn on an output device. enableoutput :: Int -> MPD ()@@ -216,7 +204,7 @@  -- | Retrieve information for all output devices. outputs :: MPD [Device]-outputs = liftM (map takeDevInfo . splitGroups . kvise)+outputs = liftM (map takeDevInfo . splitGroups . toAssoc)     (getResponse "outputs")     where         takeDevInfo xs = Device {@@ -252,7 +240,7 @@  -- | List the songs (without metadata) in a database directory recursively. listAll :: Maybe String -> MPD [String]-listAll path = liftM (map snd . filter ((== "file") . fst) . kvise)+listAll path = liftM (map snd . filter ((== "file") . fst) . toAssoc)                      (getResponse ("listall " ++ maybe "" show path))  -- | Recursive 'lsinfo'.@@ -273,7 +261,7 @@  -- | Count the number of entries matching a query. count :: Query -> MPD Count-count query = liftM (takeCountInfo . kvise)+count query = liftM (takeCountInfo . toAssoc)                     (getResponse ("count " ++ show query))     where takeCountInfo xs = Count { cSongs    = takeNum "songs" xs,                                      cPlaytime = takeNum "playtime" xs }@@ -288,7 +276,7 @@ -- | Like 'add', but returns a playlist id. addid :: String -> MPD Integer addid x =-    liftM (read . snd . head . kvise) (getResponse ("addid " ++ show x))+    liftM (read . snd . head . toAssoc) (getResponse ("addid " ++ show x))  -- | Like 'add_' but returns a list of the files added. add :: Maybe String -> String -> MPD [String]@@ -400,7 +388,7 @@ -- | Like 'plchanges' but only returns positions and ids. plchangesposid :: Integer -> MPD [(PLIndex, PLIndex)] plchangesposid plver =-    liftM (map takePosid . splitGroups . kvise) (getResponse cmd)+    liftM (map takePosid . splitGroups . toAssoc) (getResponse cmd)     where cmd          = "plchangesposid " ++ show plver           takePosid xs = (Pos $ takeNum "cpos" xs, ID $ takeNum "Id" xs) @@ -419,7 +407,7 @@     currStatus <- status     if stState currStatus == Stopped         then return Nothing-        else do ls <- liftM kvise (getResponse "currentsong")+        else do ls <- liftM toAssoc (getResponse "currentsong")                 return $ if null ls then Nothing                                     else Just (takeSongInfo ls) @@ -520,7 +508,7 @@  -- | Get server statistics. stats :: MPD Stats-stats = liftM (parseStats . kvise) (getResponse "stats")+stats = liftM (parseStats . toAssoc) (getResponse "stats")     where parseStats xs =                 Stats { stsArtists = takeNum "artists" xs,                         stsAlbums = takeNum "albums" xs,@@ -532,7 +520,7 @@  -- | Get the server's status. status :: MPD Status-status = liftM (parseStatus . kvise) (getResponse "status")+status = liftM (parseStatus . toAssoc) (getResponse "status")     where parseStatus xs =               Status { stState = maybe Stopped parseState $ lookup "state" xs,                      stVolume = takeNum "volume" xs,@@ -571,11 +559,8 @@  -- | Toggles play\/pause. Plays if stopped. toggle :: MPD ()-toggle = do-    st <- status-    case stState st of-         Playing -> pause True-         _       -> play Nothing+toggle = status >>= \st -> case stState st of Playing -> pause True+                                              _       -> play Nothing  -- | Add a list of songs\/folders to a playlist. -- Should be more efficient than running 'add' many times.@@ -700,13 +685,13 @@  -- Get the lines of the daemon's response to a list of commands. getResponses :: [String] -> MPD [String]-getResponses cmds = getResponse .-    unlines $ "command_list_begin" : cmds ++ ["command_list_end"]+getResponses cmds = getResponse (concat . intersperse "\n" $ cmds')+    where cmds' = "command_list_begin" : cmds ++ ["command_list_end"]  -- Break up a list of strings into an assoc. list, separating at -- the first ':'.-kvise :: [String] -> [(String, String)]-kvise = map f+toAssoc :: [String] -> [(String, String)]+toAssoc = map f     where f x = let (k,v) = break (== ':') x in                 (k,dropWhile (== ' ') $ drop 1 v) @@ -722,23 +707,23 @@ splitGroups (x:xs) = ((x:us):splitGroups vs)     where (us,vs) = break (\y -> fst x == fst y) xs --- Run 'kvise' and return only the values.+-- Run 'toAssoc' and return only the values. takeValues :: [String] -> [String]-takeValues = snd . unzip . kvise+takeValues = snd . unzip . toAssoc  -- Separate the result of an lsinfo\/listallinfo call into directories, -- playlists, and songs. takeEntries :: [String] -> ([String], [String], [Song]) takeEntries s =     (dirs, playlists, map takeSongInfo . splitGroups $ reverse filedata)-    where (dirs, playlists, filedata) = foldl split ([], [], []) $ kvise s+    where (dirs, playlists, filedata) = foldl split ([], [], []) $ toAssoc s           split (ds, pls, ss) x@(k, v) | k == "directory" = (v:ds, pls, ss)                                        | k == "playlist"  = (ds, v:pls, ss)                                        | otherwise        = (ds, pls, x:ss)  -- Build a list of song instances from a response. takeSongs :: [String] -> [Song]-takeSongs = map takeSongInfo . splitGroups . kvise+takeSongs = map takeSongInfo . splitGroups . toAssoc  -- Builds a song instance from an assoc. list. takeSongInfo :: [(String,String)] -> Song
Network/MPD/Prim.hs view
@@ -55,8 +55,10 @@ -- Data types. -- +-- The field names should not be exported.+-- The accessors 'connPortNum' and 'connHandle' are not used, though+-- the fields are used (see 'reconnect'). -- | A connection to an MPD server.--- don't export the field names. data Connection = Conn { connHostName :: String                        , connPortNum  :: Integer                        , connHandle   :: IORef (Maybe Handle)
README view
@@ -1,6 +1,6 @@ -           libmpd-haskell : An MPD client library for Haskell-         ------------------------------------------------------+              libmpd : An MPD client library for Haskell+             --------------------------------------------  Dependencies:     The Glasgow Haskell Compiler >= 6.4       http://haskell.org/ghc@@ -18,16 +18,16 @@     default with newer GHCs.  Use:-    Import the MPD module and specify the mpd package (-package mpd)-    when compiling, or add it to the `Build-Depends' list in your-    `_.cabal' file.+    Import the Network.MPD module and specify the libmpd package+    (-package libmpd) when compiling, or add it to the `Build-Depends'+    list in your `_.cabal' file.  Limitations:     Most of the API is complete, but some parts, most notably parsing, are     not yet as good as they could be.  Platforms:-    libmpd-haskell has been confirmed to work on:+    libmpd has been confirmed to work on:         Linux/x86     Seems to work on Windows XP as well, but there is no MPD support for     that platform.
libmpd.cabal view
@@ -1,5 +1,5 @@ Name:               libmpd-Version:            0.1.2+Version:            0.1.3 License:            LGPL License-file:       LICENSE Copyright:          Ben Sinclair 2005-2007