packages feed

alsa-seq-0.5.1: examples/list-subscribers.hs

import qualified Sound.ALSA.Sequencer.Address as Addr
import qualified Sound.ALSA.Sequencer.Subscribe.Query as Query
import qualified Sound.ALSA.Sequencer as SndSeq
import qualified Sound.ALSA.Exception as AlsaExc
import System.Environment (getArgs, )
import Control.Monad ((<=<), forM_, )

main :: IO ()
main = (do
  args <- getArgs
  SndSeq.with SndSeq.defaultName SndSeq.Block $ \h -> forM_ args $ \arg -> do
  a <- Addr.parse (h :: SndSeq.T SndSeq.InputMode) arg
  let showQ q = do
	ad <- Query.getAddr q
	qq <- Query.getQueue q
	ex <- Query.getExclusive q
	tu <- Query.getTimeUpdate q
	tr <- Query.getTimeReal q
	return (show ad ++ ":" ++ show qq 
	  ++ (if tu then " update" else "")
	  ++ (if tr then " realtime" else "")
	  ++ (if ex then " exclusive" else ""))
      list t = do
	putStrLn ("subscribers of " ++ show a ++ " for " ++ show t ++ ":")
	mapM_ (putStrLn . (' ':) <=< showQ) =<< Query.queryAll h a t
  mapM_ list [Query.Read, Query.Write])
  `AlsaExc.catch` \e ->
     putStrLn $ "alsa_exception: " ++ AlsaExc.show e