opensoundcontrol-ht 0.1.1.2 → 0.3
raw patch · 7 files changed
Files
- opensoundcontrol-ht.cabal +15/−17
- src/Sound/OSC/Transport/File.hs +36/−0
- src/Sound/OSC/Transport/Monad/ByteString.hs +50/−0
- src/Sound/OpenSoundControl/Transport/File.hs +0/−34
- src/Sound/OpenSoundControl/Transport/Monad.hs +0/−48
- src/Sound/OpenSoundControl/Transport/Monad/ByteString.hs +0/−33
- src/Sound/OpenSoundControl/Transport/Monad/IO.hs +0/−20
opensoundcontrol-ht.cabal view
@@ -1,25 +1,24 @@ Name: opensoundcontrol-ht-Version: 0.1.1.2+Version: 0.3 License: GPL License-File: LICENSE-Copyright: Henning Thielemann, 2009 Author: Henning Thielemann <supercollider@henning-thielemann.de> Maintainer: Henning Thielemann <supercollider@henning-thielemann.de> Stability: Experimental Homepage: http://www.haskell.org/haskellwiki/SuperCollider Synopsis: Haskell OpenSoundControl utilities Description:- Some additional modules I regular use+ Some additional modules I use in connection with the SuperCollider wrapper hsc3 by Rohan Drape. It contains: .- * a @Transport@ type for writing to files (that's however less important, since @hsc3@ itself does now support SuperCollider Non-Real-Time mode)+ * a @Transport@ handle type for writing to files .- * a @Transport@ monad class that can be used to hide the handle of the SuperCollider connection, simulate communication without I\/O (e.g. testing) and maybe others.+ * a @Transport@ monad type for writing to a bytestring without IO. . Also see the supercollider-ht package which uses this one. Category: Sound-Tested-With: GHC==6.4.1, GHC==6.8.2+Tested-With: GHC==7.4.2, GHC==7.8.3 Cabal-Version: >=1.6 Build-Type: Simple Source-Repository head@@ -29,30 +28,29 @@ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/opensoundcontrol/- tag: 0.1.1.2+ tag: 0.3 Flag splitBase description: Choose the new smaller, split-up base package. Library- Build-Depends: hosc >=0.1 && <0.9- Build-Depends: transformers >=0.2 && <0.4- Build-Depends: binary >=0.2 && <1, bytestring >=0.9 && <0.11- Build-Depends: utility-ht >=0.0.1 && <0.1+ Build-Depends:+ hosc >=0.15 && <0.16,+ transformers >=0.2 && <0.5,+ binary >=0.7 && <0.8,+ bytestring >=0.9 && <0.11,+ utility-ht >=0.0.1 && <0.1 If flag(splitBase) Build-Depends: random >=1.0 && <2,- process >=1.0 && <1.2,+ process >=1.0 && <1.3, base >=2 && <5 Else Build-Depends: base >=1.0 && <2 GHC-Options: -Wall- Extensions: GeneralizedNewtypeDeriving Hs-source-dirs: src Exposed-modules:- Sound.OpenSoundControl.Transport.File- Sound.OpenSoundControl.Transport.Monad- Sound.OpenSoundControl.Transport.Monad.IO- Sound.OpenSoundControl.Transport.Monad.ByteString+ Sound.OSC.Transport.File+ Sound.OSC.Transport.Monad.ByteString
+ src/Sound/OSC/Transport/File.hs view
@@ -0,0 +1,36 @@+module Sound.OSC.Transport.File (T, open, ) where++import qualified Sound.OSC.Type as OSC+import Sound.OSC.Coding.Byte (encode_u32, )+import Sound.OSC.Class (encodeOSC, )+import Sound.OSC.Transport.FD (Transport(..), )++import qualified Data.ByteString.Lazy as B+import System.IO (Handle, openBinaryFile, hClose, IOMode(WriteMode), )+import Control.Monad (liftM, )+++-- | The File transport handle data type.+data T = Cons OSC.Packet Handle+ deriving (Eq, Show)+++instance Transport T where+ sendOSC (Cons _ h) msg =+ let b = encodeOSC msg+ n = fromIntegral (B.length b)+ in B.hPut h (B.append (encode_u32 n) b)++ recvPacket (Cons msg _) = return msg++ close (Cons _ h) = hClose h++++{- |+Open a command file.+All 'recv' calls are answered with @msg@.+-}+open :: OSC.Packet -> FilePath -> IO T+open msg fileName =+ liftM (Cons msg) $ openBinaryFile fileName WriteMode
+ src/Sound/OSC/Transport/Monad/ByteString.hs view
@@ -0,0 +1,50 @@+module Sound.OSC.Transport.Monad.ByteString (T, run, ) where++import qualified Sound.OSC.Transport.Monad as TM++import qualified Sound.OSC.Type as OSC+import Sound.OSC.Class (encodeOSC, )++import qualified Data.ByteString.Lazy as B+import qualified Data.Binary.Put as Put++import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask, )+import Control.Monad.Trans.Class (lift, )+import Control.Monad (ap, )+import Control.Applicative (Applicative, pure, (<*>), )+++newtype T a = Cons {decons :: ReaderT OSC.Packet Put.PutM a}+++instance Functor T where+ fmap f (Cons act) = Cons $ fmap f act++instance Applicative T where+ pure = return+ (<*>) = ap++instance Monad T where+ return = Cons . return+ Cons x >>= k =+ Cons $ decons . k =<< x+++instance TM.SendOSC T where+ sendOSC msg = Cons $ lift $+ let b = encodeOSC msg+ in Put.putWord32be (fromIntegral (B.length b)) >>+ Put.putLazyByteString b++instance TM.RecvOSC T where+ recvPacket = Cons ask++instance TM.DuplexOSC T where+++{- |+Write sent messages to a ByteString.+All 'recv' calls are answered with @msg@.+-}+run :: OSC.Packet -> T () -> B.ByteString+run msg (Cons m) = Put.runPut (runReaderT m msg)
− src/Sound/OpenSoundControl/Transport/File.hs
@@ -1,34 +0,0 @@-module Sound.OpenSoundControl.Transport.File (T, open, ) where--import Sound.OpenSoundControl.Transport (Transport(..), )-import Sound.OpenSoundControl.Byte (encode_u32, )-import Sound.OpenSoundControl.OSC (encodeOSC, OSC, )--import Control.Monad (liftM, )-import qualified Data.ByteString.Lazy as B-import System.IO (Handle, openBinaryFile, hClose, IOMode(WriteMode), )---- | The File transport handle data type.-data T = Cons OSC Handle- deriving (Eq, Show)---instance Transport T where- send (Cons _ h) msg =- let b = encodeOSC msg- n = fromIntegral (B.length b)- in B.hPut h (B.append (encode_u32 n) b)-- recv (Cons msg _) = return msg-- close (Cons _ h) = hClose h----{- |-Open a command file.-All 'recv' calls are answered with @msg@.--}-open :: OSC -> FilePath -> IO T-open msg fileName =- liftM (Cons msg) $ openBinaryFile fileName WriteMode
− src/Sound/OpenSoundControl/Transport/Monad.hs
@@ -1,48 +0,0 @@-{- |-Monad class for monads that are able to do or simulate communication-via Open Sound Control.--}-module Sound.OpenSoundControl.Transport.Monad (- C, send, recv, waitFor, wait,- ) where--import qualified Sound.OpenSoundControl.Transport as Trans-import Sound.OpenSoundControl.Transport (Transport)-import Sound.OpenSoundControl.OSC (OSC(Message))--import Control.Monad.Trans.Reader (ReaderT(ReaderT))-import Control.Monad.IO.Class (MonadIO, liftIO, )--import Data.Maybe.HT (toMaybe, )---class Monad m => C m where- -- | Encode and send an OSC packet.- send :: OSC -> m ()- -- | Receive and decode an OSC packet.- recv :: m OSC--instance (Transport t, MonadIO io) => C (ReaderT t io) where- send osc = ReaderT $ liftIO . flip Trans.send osc- recv = ReaderT $ liftIO . Trans.recv----- Does the OSC message have the specified address.-hasAddress :: String -> OSC -> Bool-hasAddress x (Message y _) = x == y-hasAddress _ _ = False---- Repeat action until function does not give Nothing when applied to result.-untilM :: Monad m => (a -> Maybe b) -> m a -> m b-untilM f act =- let go = maybe go return . f =<< act- in go---- | Wait for an OSC message where the supplied function does not give--- Nothing, discarding intervening messages.-waitFor :: C m => (OSC -> Maybe a) -> m a-waitFor f = untilM f recv---- | A 'waitFor' for variant matching on address string of messages.-wait :: C m => String -> m OSC-wait s = waitFor (\o -> toMaybe (hasAddress s o) o)
− src/Sound/OpenSoundControl/Transport/Monad/ByteString.hs
@@ -1,33 +0,0 @@-module Sound.OpenSoundControl.Transport.Monad.ByteString (run, ) where--import qualified Sound.OpenSoundControl.Transport.Monad as TM--import Sound.OpenSoundControl.OSC (encodeOSC, OSC, )--import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask, )-import Control.Monad.Trans.Class (lift, )--import qualified Data.ByteString.Lazy as B-import qualified Data.Binary.Put as Put---newtype T a = Cons (ReaderT OSC Put.PutM a)- deriving (Functor, Monad)---instance TM.C T where- send msg = Cons $ lift $- let b = encodeOSC msg- in Put.putWord32be (fromIntegral (B.length b)) >>- Put.putLazyByteString b-- recv = Cons ask----{- |-Write sent messages to a ByteString.-All 'recv' calls are answered with @msg@.--}-run :: OSC -> T () -> B.ByteString-run msg (Cons m) = Put.runPut (runReaderT m msg)
− src/Sound/OpenSoundControl/Transport/Monad/IO.hs
@@ -1,20 +0,0 @@-{- |-Run a generic Transport monad action in the IO monad-using the IO transport types, e.g. TCP, UDP, or File.--}-module Sound.OpenSoundControl.Transport.Monad.IO- (T, Transport, send, recv, wait, waitFor, with, ) where--import qualified Sound.OpenSoundControl.Transport as Trans-import Sound.OpenSoundControl.Transport.Monad (C, send, recv, wait, waitFor, )-import Sound.OpenSoundControl.Transport (Transport)--import Control.Monad.Trans.Reader (ReaderT(runReaderT))---type T t = ReaderT t IO----- | Bracket Open Sound Control communication.-with :: Transport t => IO t -> T t a -> IO a-with u = Trans.withTransport u . runReaderT