packages feed

sound-collage-0.1: src/Option.hs

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" )