packages feed

sound-collage 0.0 → 0.1

raw patch · 3 files changed

+102/−24 lines, 3 filesdep +optparse-applicative

Dependencies added: optparse-applicative

Files

sound-collage.cabal view
@@ -1,5 +1,5 @@ Name:           sound-collage-Version:        0.0+Version:        0.1 License:        BSD3 License-File:   LICENSE Author:         Henning Thielemann <haskell@henning-thielemann.de>@@ -12,7 +12,7 @@ Build-Type:     Simple  Source-Repository this-  Tag:         0.0+  Tag:         0.1   Type:        darcs   Location:    http://code.haskell.org/~thielema/sound-collage/ @@ -31,6 +31,7 @@     soxlib >=0.0.1 && <0.1,     sample-frame >=0.0 && <0.1,     numeric-prelude >=0.4.1 && <0.5,+    optparse-applicative >=0.11 && <0.12,     filepath >=1.3 && <1.4,     temporary >=1.1 && <1.3,     directory >=1.1 && <1.3,@@ -41,4 +42,6 @@   GHC-Options:    -Wall   Hs-source-dirs: src   Main-Is:        Main.hs-  Other-Modules:  SoundCollage+  Other-Modules:+    SoundCollage+    Option
src/Main.hs view
@@ -1,10 +1,11 @@ module Main where  import qualified SoundCollage+import qualified Option+import qualified Options.Applicative as OP  import qualified System.Exit as Exit import qualified System.IO as IO-import System.Environment (getArgs, ) import System.FilePath ((</>), ) import System.IO.Temp (withSystemTempDirectory, ) @@ -14,29 +15,39 @@    IO.hPutStrLn IO.stderr msg    Exit.exitFailure +setChunkSize :: Int -> SoundCollage.Parameters -> SoundCollage.Parameters+setChunkSize chunkSize params =+   params {+      SoundCollage.paramShift =+         div chunkSize (SoundCollage.paramOverlap params)+   }++makeParams :: Maybe Int -> SoundCollage.Parameters+makeParams maybeChunkSize =+   maybe+      SoundCollage.defltParams+      (flip setChunkSize SoundCollage.defltParams)+      maybeChunkSize+ main :: IO () main = do-   args <- getArgs-   case args of-      [] -> exitFailureMsg "action, source and destination missing"-      [_] -> exitFailureMsg "source and destination missing"-      [_,_] -> exitFailureMsg "destination missing"-      ["--decompose", src, dst] ->-         SoundCollage.runDecompose SoundCollage.defltParams src dst-      ["--compose", src, dst] ->-         SoundCollage.runCompose SoundCollage.defltParams src dst-      ["--associate", pool, src, dst] ->-         SoundCollage.runAssociate SoundCollage.defltParams pool src dst-      [pool, src, dst] ->+   Option.Cons maybeChunkSize action src dst <- OP.execParser Option.info+   case action of+      Option.Decompose ->+         SoundCollage.runDecompose (makeParams maybeChunkSize) src dst+      Option.Compose ->+         SoundCollage.runCompose (makeParams maybeChunkSize) src dst+      Option.Associate pool ->+         SoundCollage.runAssociate (makeParams maybeChunkSize) pool src dst+      Option.Batch pool ->          withSystemTempDirectory "sound-chunks" $ \chunkDir ->          withSystemTempDirectory "sound-collage" $ \collDir -> do-            chunkSize <- SoundCollage.chunkSizeFromPool pool-            let params =-                  SoundCollage.defltParams {-                     SoundCollage.paramShift =-                        div chunkSize-                           (SoundCollage.paramOverlap SoundCollage.defltParams)-                  }+            chunkSize <-+               maybe+                  (SoundCollage.chunkSizeFromPool pool)+                  return+                  maybeChunkSize+            let params = setChunkSize chunkSize SoundCollage.defltParams             putStrLn $ "determined chunk size: " ++ show chunkSize             putStrLn $ "decompose to " ++ chunkDir             SoundCollage.runDecompose params src@@ -45,4 +56,3 @@             SoundCollage.runAssociate params pool chunkDir collDir             putStrLn "compose"             SoundCollage.runCompose params collDir dst-      _ -> exitFailureMsg "too many arguments"
+ src/Option.hs view
@@ -0,0 +1,65 @@+module Option where++import qualified Options.Applicative as OP+import Options.Applicative+          (Parser, long, help, flag', metavar, strOption, option, strArgument, )++import Control.Applicative (pure, (<*>), (<|>), (<$>), )+import Data.Monoid ((<>), )+++data Action =+     Decompose+   | Compose+   | Associate FilePath+   | Batch FilePath+   deriving (Show)++data T =+   Cons {+      chunkSize :: Maybe Int,+      action :: Action,+      src, dst :: FilePath+   }+   deriving (Show)+++parseAction :: Parser Action+parseAction =+   (flag' Decompose+        ( long "decompose"+       <> help "Chop audio file in chunks and add them to the pool" ))+   <|>+   (Associate <$>+    strOption+        ( long "associate"+       <> metavar "POOL"+       <> help "Associate chunks with chunks from the pool" ))+   <|>+   (flag' Compose+        ( long "compose"+       <> help "Compose audio file from selected pool chunks" ))+   <|>+   (Batch <$>+    strArgument+        ( metavar "POOL"+       <> help "Automatically perform 'decompose', 'associate', 'compose'" ))++parseAll :: Parser T+parseAll =+   pure Cons+    <*> option (fmap Just OP.auto)+           ( OP.value Nothing+          <> long "chunksize"+          <> metavar "NUMSAMPLES"+          <> help "size of decomposed chunks" )+    <*> parseAction+    <*> strArgument ( metavar "SRC" )+    <*> strArgument ( metavar "DST" )+++info :: OP.ParserInfo T+info =+   OP.info (OP.helper <*> parseAll)+       ( OP.fullDesc+      <> OP.progDesc "Approximate an audio file by a collection of chunks" )