hCsound 0.3.0 → 0.3.1
raw patch · 4 files changed
+25/−43 lines, 4 files
Files
- examples/simple.hs +4/−9
- examples/test2.hs +9/−19
- examples/test3.hs +11/−14
- hCsound.cabal +1/−1
examples/simple.hs view
@@ -1,19 +1,14 @@ module Main where import Sound.Csound-import Sound.Csound.Interface (csoundCreate, csoundDestroy, csoundCompile, csoundPerform, CsoundPerformStatus) import Control.Monad.Error main :: IO ()-main = (runErrorT $ runCsound "-W -otest.wav test1.csd") >>= reportResult+main = runner "-W -otest.wav test1.csd" >>= reportResult -runCsound :: String -> CsoundMonad ()-runCsound args = do- ptr <- csoundCreate- csoundCompile ptr args- csoundPerform ptr- csoundDestroy ptr+runner :: String -> IO (Either CsoundError ())+runner args = runCsound (compile args >> perform >> destroy) -reportResult :: Either String () -> IO ()+reportResult :: Either CsoundError () -> IO () reportResult (Right _) = putStrLn ("Csound Ran! " ) reportResult (Left e) = putStrLn ("csound didn't run... " ++ (show e))
examples/test2.hs view
@@ -1,24 +1,14 @@ module Main where -import Prelude-import Sound.Csound-import Sound.Csound.Interface-import Control.Monad.Error-import Data.Binary.Put-import Data.Word-import qualified Data.ByteString.Lazy as L-import Foreign.Marshal.Array (peekArray, pokeArray)+import Sound.Csound+import qualified Data.Vector.Storable as V main :: IO ()-main = do- runErrorT (runCsound "-W -o test2.wav test1.csd")- return ()--runCsound :: String -> CsoundMonad ()-runCsound args = do- ptr <- csoundCreate- liftIO $ csoundSetHostImplementedAudioIO ptr 1 512- csoundCompile ptr args- csoundPerformKsmpsIO ptr (\x _ -> return $ replicate x 1) (\_ _ _ -> return () )- csoundDestroy ptr+main = runCsound (runner "-W -o test2.wav test1.csd")+ >>= either print (const $ print "ok") +runner :: String -> Csound ()+runner args = do+ setHostImplementedAudioIO 1 512+ compile args+ performKsmpsIO (\x _ -> return $ V.replicate x 1) (\_ _ _ -> return () )
examples/test3.hs view
@@ -1,24 +1,21 @@ module Main where -import Prelude-import Sound.Csound-import Sound.Csound.Interface-import Control.Monad.Error+import Sound.Csound+import qualified Data.Vector.Storable as V main :: IO ()-main = (runErrorT $ runCsound "-W -otest3.wav test1.csd") >>= reportResult+main = (runCsound $ runner "-W -otest3.wav test1.csd") >>= reportResult -runCsound :: String -> CsoundMonad ()-runCsound args = do- ptr <- csoundCreate- csoundPreCompile ptr- liftIO $ csoundSetHostImplementedAudioIO ptr 1 512- csoundCompile ptr args- csoundPerformBufferIO ptr (\x y -> return $ replicate x 1) (\_ _ _ -> return ())- csoundDestroy ptr+runner :: String -> Csound ()+runner args = do+ preCompile+ setHostImplementedAudioIO 1 512+ compile args+ performBufferIO (\x y -> return $ V.replicate x 1) (\_ _ _ -> return ())+ destroy outFn l i b = putStrLn ("Buffer Length: " ++ (show l) ++ "Position: " ++ (show i)) -reportResult :: Either String a -> IO ()+reportResult :: Either CsoundError a -> IO () reportResult (Right _) = (putStrLn "Csound Ran! ") reportResult (Left e) = putStrLn ("csound didn't run... " ++ (show e))
hCsound.cabal view
@@ -1,5 +1,5 @@ Name: hCsound-Version: 0.3.0+Version: 0.3.1 Cabal-Version: >= 1.2 Description: Haskell interface to Csound API. License: LGPL