alsa-core-0.5.0.1/0000755000000000000000000000000011746475661011730 5ustar0000000000000000alsa-core-0.5.0.1/Setup.lhs0000644000000000000000000000015711746475661013543 0ustar0000000000000000#!/usr/bin/env runghc > module Main where > import Distribution.Simple > main :: IO () > main = defaultMain alsa-core-0.5.0.1/LICENSE0000644000000000000000000000216211746475661012736 0ustar0000000000000000Copyright (c) 2009-2010 Henning Thielemann Copyright (c) 2006 Bjorn Bringert Copyright (c) 2006 Iavor S. Diatchki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. alsa-core-0.5.0.1/alsa-core.cabal0000644000000000000000000000246111746475661014565 0ustar0000000000000000Name: alsa-core Version: 0.5.0.1 Copyright: Bjorn Bringert, Iavor S. Diatchki, Henning Thielemann Maintainer: Henning Thielemann Author: Henning Thielemann , Bjorn Bringert , Iavor S. Diatchki Category: Sound, Music License: BSD3 License-file: LICENSE Homepage: http://www.haskell.org/haskellwiki/ALSA Stability: Experimental Build-Type: Simple Cabal-Version: >= 1.8 Synopsis: Binding to the ALSA Library API (Exceptions). Description: This package provides access to ALSA infrastructure, that is needed by both alsa-seq and alsa-pcm. Source-Repository head type: darcs location: http://code.haskell.org/alsa/core/ Source-Repository this type: darcs location: http://code.haskell.org/alsa/core/ tag: 0.5.0.1 Flag pkgConfig Description: use pkg-config if it works -- http://hackage.haskell.org/trac/hackage/ticket/170 Default: True Library Build-depends: extensible-exceptions >=0.1.1 && <0.2, base >= 3 && <5 Hs-Source-Dirs: src Exposed-Modules: Sound.ALSA.Exception GHC-Options: -Wall If flag(pkgConfig) PkgConfig-depends: alsa >= 1.0.14 Else Includes: alsa/asoundlib.h Extra-Libraries: asound alsa-core-0.5.0.1/src/0000755000000000000000000000000011746475661012517 5ustar0000000000000000alsa-core-0.5.0.1/src/Sound/0000755000000000000000000000000011746475661013607 5ustar0000000000000000alsa-core-0.5.0.1/src/Sound/ALSA/0000755000000000000000000000000011746475661014327 5ustar0000000000000000alsa-core-0.5.0.1/src/Sound/ALSA/Exception.hs0000644000000000000000000000520111746475661016617 0ustar0000000000000000{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE DeriveDataTypeable #-} {- | ALSA does not distinguish between programming errors and runtime exceptions, which is sad, but we have to cope with it. -} module Sound.ALSA.Exception where import qualified Control.Exception.Extensible as Exc import Control.Exception.Extensible (Exception, ) import Data.Typeable (Typeable, ) import Foreign.C.Error (Errno(Errno), ePIPE, errnoToIOError, ) import Foreign.C.String (CString, peekCString, ) import qualified Foreign.C.Types as C import Prelude hiding (catch, show, ) import qualified Prelude as P data T = Cons { location :: String, description :: String, code :: Errno } deriving (Typeable) instance Show T where showsPrec p (Cons l d (Errno c)) = showParen (p>10) (showString "AlsaException.Cons " . shows l . showString " " . shows d . showString " " . showParen True (showString "Errno " . shows c)) instance Exception T where checkResult :: Integral a => String -> a -> IO a checkResult f r = if r < 0 then throw f (Errno (negate (fromIntegral r))) else return r checkResult_ :: Integral a => String -> a -> IO () checkResult_ f r = checkResult f r >> return () checkResultMaybe :: String -> (C.CInt -> a) -> (C.CInt -> Maybe a) -> C.CInt -> IO a checkResultMaybe f ok err x = if x >= 0 then return (ok x) else case err x of Just a -> return a _ -> throw f (Errno x) throw :: String -> Errno -> IO a throw fun err = do d <- strerror err Exc.throw Cons { location = fun , description = d , code = err } catch :: IO a -> (T -> IO a) -> IO a catch = Exc.catch catchErrno :: Errno -> IO a -- ^ Action -> IO a -- ^ Handler -> IO a catchErrno e x h = catch x (\ex -> if code ex == e then h else Exc.throw ex) catchXRun :: IO a -- ^ Action -> IO a -- ^ Handler -> IO a catchXRun = catchErrno ePIPE showErrno :: Errno -> String showErrno (Errno n) = P.show n show :: T -> String show e = location e ++ ": " ++ description e ++ " (" ++ showErrno (code e) ++ ")" -- | Converts any 'AlsaException.T' into an 'IOError'. -- This produces better a error message than letting an uncaught -- 'AlsaException.T' propagate to the top. rethrow :: IO a -> IO a rethrow x = catch x $ \e -> ioError (errnoToIOError (location e) (code e) Nothing Nothing) -- | Returns the message for an error code. strerror :: Errno -> IO String strerror x = peekCString =<< snd_strerror x foreign import ccall "alsa/asoundlib.h snd_strerror" snd_strerror :: Errno -> IO CString