packages feed

sox 0.2.1.1 → 0.2.2

raw patch · 3 files changed

+91/−3 lines, 3 filesdep +utility-htdep ~containersPVP ok

version bump matches the API change (PVP)

Dependencies added: utility-ht

Dependency ranges changed: containers

API changes (from Hackage documentation)

+ Sound.Sox.Information: Cons :: (ReaderT FilePath IO a) -> T a
+ Sound.Sox.Information: bitsPerSample :: T Int
+ Sound.Sox.Information: exampleMulti :: IO (String, Int, Int)
+ Sound.Sox.Information: exampleSingle :: IO Int
+ Sound.Sox.Information: format :: T String
+ Sound.Sox.Information: get :: T a -> FilePath -> IO a
+ Sound.Sox.Information: instance Applicative T
+ Sound.Sox.Information: instance Functor T
+ Sound.Sox.Information: length :: T Int
+ Sound.Sox.Information: newtype T a
+ Sound.Sox.Information: numberOfChannels :: T Int
+ Sound.Sox.Information: sampleRate :: T Int
+ Sound.Sox.Information: simple :: Read a => (String -> Maybe a) -> String -> T a
+ Sound.Sox.Option.Format: bitsPerSample :: Int -> T

Files

sox.cabal view
@@ -1,5 +1,5 @@ Name:             sox-Version:          0.2.1.1+Version:          0.2.2 License:          GPL License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -46,11 +46,12 @@     explicit-exception >= 0.1.3 && < 0.2,     -- that's the way to get compatibility between GHC 6.10 and 6.12     extensible-exceptions >=0.1.1 && <0.2,-    transformers >=0.2 && <0.4+    transformers >=0.2 && <0.4,+    utility-ht >=0.0.5 && <0.1   If flag(splitBase)     Build-Depends:       process >=1.0 && <1.2,-      containers >=0.1 && <0.5,+      containers >=0.1 && <0.6,       base >=2 && <5   Else     Build-Depends:@@ -76,6 +77,7 @@     Sound.Sox.Frame     Sound.Sox.Frame.Stereo     Sound.Sox.Signal.List+    Sound.Sox.Information   Other-Modules:     Sound.Sox.Private.Option     Sound.Sox.Private.Arguments
+ src/Sound/Sox/Information.hs view
@@ -0,0 +1,82 @@+{- |+This module calls the 'soxi' command+which is available since 'sox' version 14.++We have to call 'soxi' for every option.+However we hide this in our interface,+such that we could do more efficiently,+if 'soxi' supports multiple outputs in future.+-}+module Sound.Sox.Information where++import qualified Control.Monad.Trans.Reader as MR+import Control.Applicative (Applicative, pure, liftA3, (<*>), )+import Text.Read.HT (maybeRead, )++import qualified System.Process as Proc+import qualified System.IO as IO+import Control.Exception (bracket, )+-- import System.IO.Error (ioError, userError, )+-- import System.Exit (ExitCode, )++import Prelude hiding (length, )+++newtype T a =+   Cons (MR.ReaderT FilePath IO a)++instance Functor T where+   {-# INLINE fmap #-}+   fmap f (Cons m) = Cons (fmap f m)++instance Applicative T where+   {-# INLINE pure #-}+   {-# INLINE (<*>) #-}+   pure = Cons . pure+   (Cons f) <*> (Cons x) = Cons (f <*> x)+++simple :: Read a => (String -> Maybe a) -> String -> T a+simple rd option =+   Cons $ MR.ReaderT $ \fileName ->+      bracket+         (Proc.runInteractiveProcess "soxi"+             (option : fileName : [])+             Nothing Nothing)+         (\(input,output,err,proc) ->+             mapM_ IO.hClose [input, output, err] >>+             Proc.terminateProcess proc)+         (\(_,output,_,_) ->+            maybe+               (ioError (userError "soxi returned rubbish"))+               return .+            rd =<<+            IO.hGetContents output)++format :: T String+format = simple Just "-t"++sampleRate :: T Int+sampleRate = simple maybeRead "-r"++numberOfChannels :: T Int+numberOfChannels = simple maybeRead "-c"++length :: T Int+length = simple maybeRead "-s"++bitsPerSample :: T Int+bitsPerSample = simple maybeRead "-b"++++get :: T a -> FilePath -> IO a+get (Cons act) = MR.runReaderT act++exampleMulti :: IO (String, Int, Int)+exampleMulti =+   get (liftA3 (,,) format sampleRate bitsPerSample) "test.aiff"++exampleSingle :: IO Int+exampleSingle =+   get sampleRate "test.aiff"
src/Sound/Sox/Option/Format.hs view
@@ -26,6 +26,10 @@ sampleRate r =    single "-r" [show r] +bitsPerSample :: Int -> T+bitsPerSample b =+   single "-b" [show b]+ format :: Format.T -> T format fmt =    single "-t" [Format.decons fmt]