~pvsr/mpd-status

29db5bea986842d181a6f4f75d65a980465f5c7d — Peter Rice 1 year, 3 months ago 9c59f06
add an operation to play a pre-selected list of albums
2 files changed, 10 insertions(+), 1 deletions(-)

M Config.hs
M Operation.hs
M Config.hs => Config.hs +1 -1
@@ 8,7 8,7 @@ volStep = 5

buttonToOp :: Button -> Maybe Operation
buttonToOp LeftClick = Just Toggle
buttonToOp MiddleClick = Just AllRandom
buttonToOp MiddleClick = Just AlbumShuffle
buttonToOp RightClick = Just Stop
buttonToOp ScrollUp = Just $ VolumeUp volStep
buttonToOp ScrollDown = Just $ VolumeDown volStep

M Operation.hs => Operation.hs +9 -0
@@ 2,6 2,10 @@

module Operation(Operation(..), op) where

import qualified Data.Map as M
import Data.Maybe (mapMaybe)
import Data.List (nub)

import Network.MPD
import Network.MPD.Commands.Extensions



@@ 13,6 17,7 @@ data Operation = Toggle
               | Previous
               | Next
               | AllRandom
               | AlbumShuffle

op :: Operation -> MPD ()
op Toggle = toggle


@@ 24,6 29,10 @@ op (VolumeDown volStep) = status >>= maybe (return ()) (setVolume . dec volStep)
op Mute = setVolume 0
op Previous = previous
op Next = next
op AlbumShuffle = clear >> consume True >> random False >> listPlaylistInfo "album-shuffle" >>= mapM_ findAdd . (queries . uniqAlbums) >> play Nothing
  -- TODO shuffle the results of uniqAlbums
  where uniqAlbums = nub . concat . mapMaybe (M.lookup Album . sgTags)
        queries = map (Album =?)

inc :: Int -> Int -> Int
inc step vol = min 100 $ (vol `div` step + 1) * step