From 495004dfe17f85d370b7f5237d5e71b367af98ca Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 7 Jun 2015 21:46:59 +0200 Subject: automatic connections --- src/Trivmix.hs | 23 +++++++++++++++++++---- trivmix.cabal | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Trivmix.hs b/src/Trivmix.hs index f7ae1eb..a139a15 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -18,6 +18,7 @@ import Control.Concurrent import Control.Concurrent.MVar import qualified Control.Monad.Trans.Class as Trans +import qualified Control.Monad.Exception.Synchronous as Sync import Control.Exception import System.IO.Error @@ -28,6 +29,8 @@ data Options = Options { input :: String , output :: String , client :: String + , connFrom :: Maybe String + , connTo :: Maybe String , initialLevel :: Float , stateDir :: FilePath } @@ -43,6 +46,12 @@ optionParser = Options <$> <*> strOption ( long "client" <> metavar "STRING" ) + <*> optional (strOption ( long "input-from" + <> metavar "STRING" + )) + <*> optional (strOption ( long "output-to" + <> metavar "STRING" + )) <*> (fromMaybe 0 <$> optional (option auto ( long "level" <> metavar "FLOAT" ) @@ -71,10 +80,16 @@ trivmix Options{..} = do Jack.handleExceptions $ Jack.withClientDefault client $ \client -> Jack.withPort client input $ \input' -> - Jack.withPort client output $ \output' -> - Audio.withProcessMono client input' (mix level) output' $ - Jack.withActivation client $ Trans.lift $ do - Jack.waitForBreak + Jack.withPort client output $ \output' -> do + case connFrom of + Nothing -> return () + Just f -> Jack.connect client input f + case connTo of + Nothing -> return () + Just t -> Jack.connect client t output + Audio.withProcessMono client input' (mix level) output' $ + Jack.withActivation client $ Trans.lift $ do + Jack.waitForBreak mix :: MVar Float -> CFloat -> IO CFloat mix level input = do diff --git a/trivmix.cabal b/trivmix.cabal index 8eee4f0..3031c98 100644 --- a/trivmix.cabal +++ b/trivmix.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: trivmix -version: 0.1.0 +version: 0.2.0 -- synopsis: -- description: license: PublicDomain @@ -27,6 +27,7 @@ executable trivmix , unix >=2.7 && <3 , hinotify >=0.3 && <1 , transformers >=0.3 && <1 + , explicit-exception >=0.1 && <1 hs-source-dirs: src default-language: Haskell2010 -- cgit v1.2.3