~pvsr/mpd-status

ab436ef72b0c26066623e44caf9a7f23f8b26c3a — Peter Rice 1 year, 3 months ago c48cb75
make playlist optional for album shuffle mode
2 files changed, 14 insertions(+), 3 deletions(-)

M Config.hs
M Operation.hs
M Config.hs => Config.hs +5 -1
@@ 1,8 1,12 @@
{-# LANGUAGE OverloadedStrings #-}

module Config(buttonToOp, volStep) where

import Click
import Operation

import Network.MPD (PlaylistName(..))

volStep :: Int
volStep = 5



@@ 16,7 20,7 @@ buttonToOp Back = Just Previous
--buttonToOp Forward = Just Next

-- TODO maybe there should be some notion of album mode vs single mode
buttonToOp MiddleClick = Just AlbumShuffle
buttonToOp MiddleClick = Just $ AlbumShuffle (Just $ PlaylistName "album-shuffle")
buttonToOp Forward = Just NextAlbum

buttonToOp _ = Nothing

M Operation.hs => Operation.hs +9 -2
@@ 23,7 23,7 @@ data Operation = Toggle
               | Next
               | NextAlbum
               | AllRandom
               | AlbumShuffle
               | AlbumShuffle (Maybe PlaylistName)

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


@@ 37,8 37,15 @@ op Previous = previous
op Next = next
op PreviousAlbum = previous
op NextAlbum = nextAlbum
-- TODO handle bad playlist argument
op (AlbumShuffle (Just pl)) = listPlaylistInfo pl >>= albumShuffle
op (AlbumShuffle Nothing) = (filterSongs <$> listAllInfo "") >>= albumShuffle
  where filterSongs :: [LsResult] -> [Song]
        filterSongs ls = [song | (LsSong song) <- ls]

-- really pining for the elegance of `mpc playlist -f %album% album-shuffle | uniq | sort -R` here
op AlbumShuffle = clear >> random False >> listPlaylistInfo "album-shuffle" >>= (liftIO . Shuffle.shuffle . (queries . uniqAlbums)) >>= mapM_ findAdd >> play Nothing
albumShuffle :: [Song] -> MPD ()
albumShuffle songs = clear >> random False >> (liftIO . Shuffle.shuffle . queries $ uniqAlbums songs) >>= mapM_ findAdd >> play Nothing
  where uniqAlbums = L.nub . concat . mapMaybe (M.lookup Album . sgTags)
        queries = map (Album =?)