{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving, DeriveGeneric #-} module Trivstream.Types ( AudioConfig(..) , AudioBackend(..) , SampleRate(..) , Configuration(..) , Mode (..) , module Data.Default.Class ) where import Control.Lens import Control.Lens.TH import Data.Default.Class (Default(..)) import Data.Serialize (Serialize) import GHC.Generics (Generic) import Foreign.C.Types (CInt(..)) import Sound.Pulse.Simple (ChannelPosition(..), ChannelPan(..)) import Sound.JACK () import Network.Socket (Family(..), SocketType(..), ProtocolNumber(..), SockAddr(..)) deriving instance Generic ChannelPan instance Serialize ChannelPan deriving instance Generic ChannelPosition instance Serialize ChannelPosition data AudioBackend = Pulse | Jack deriving (Enum, Eq, Generic, Show, Read) instance Default AudioBackend where def = Pulse instance Serialize AudioBackend -- | Numeric instances consider this value to be in `kHz` newtype SampleRate = SampleRate Int deriving (Eq, Ord, Enum, Num, Real, Integral, Generic) makePrisms ''SampleRate instance Default SampleRate where def = 44100 instance Serialize SampleRate data AudioConfig = AudioConfig { _aBackend :: AudioBackend , _aChannels :: [Maybe ChannelPosition] , _aRate :: Maybe SampleRate } deriving (Generic) makeLenses ''AudioConfig instance Default AudioConfig where def = AudioConfig { _aBackend = def , _aChannels = [Just $ ChannelNormal PanLeft, Just $ ChannelNormal PanRight] , _aRate = Just def } instance Serialize AudioConfig data Mode = Server | Client deriving (Enum, Eq, Generic, Show, Read) instance Default Mode where def = Server instance Serialize Mode data Configuration = Configuration { _cMode :: Mode , _cSocketDesc :: Maybe (Family, SocketType, ProtocolNumber, SockAddr) , _cAudio :: AudioConfig } deriving (Generic) makeLenses ''Configuration instance Default Configuration where def = Configuration { _cMode = def , _cSocketDesc = Nothing , _cAudio = def }