summaryrefslogtreecommitdiff
path: root/src/Trivstream/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Trivstream/Types.hs')
-rw-r--r--src/Trivstream/Types.hs92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/Trivstream/Types.hs b/src/Trivstream/Types.hs
new file mode 100644
index 0000000..8cdd592
--- /dev/null
+++ b/src/Trivstream/Types.hs
@@ -0,0 +1,92 @@
1{-# LANGUAGE TemplateHaskell #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving, DeriveGeneric #-}
3
4module Trivstream.Types
5 ( AudioConfig(..)
6 , AudioBackend(..)
7 , SampleRate(..)
8 , Configuration(..)
9 , Mode (..)
10 ) where
11
12
13import Control.Lens
14import Control.Lens.TH
15import Data.Default.Class (Default(..))
16import Data.Serialize (Serialize)
17import GHC.Generics (Generic)
18
19import Foreign.C.Types (CInt(..))
20
21import Sound.Pulse.Simple (ChannelPosition(..), ChannelPan(..))
22import Sound.JACK ()
23
24import Network.Socket (Family(..), SocketType(..), ProtocolNumber(..), SockAddr(..))
25
26
27deriving instance Generic ChannelPan
28instance Serialize ChannelPan
29
30deriving instance Generic ChannelPosition
31instance Serialize ChannelPosition
32
33
34data AudioBackend = Pulse | Jack
35 deriving (Enum, Eq, Generic)
36
37instance Default AudioBackend where
38 def = Pulse
39
40instance Serialize AudioBackend
41
42
43-- | Numeric instances consider this value to be in `kHz`
44newtype SampleRate = SampleRate Int
45 deriving (Eq, Ord, Enum, Num, Real, Integral, Generic)
46makePrisms ''SampleRate
47
48instance Default SampleRate where
49 def = 44100
50
51instance Serialize SampleRate
52
53
54data AudioConfig = AudioConfig
55 { _aBackend :: AudioBackend
56 , _aChannels :: [Maybe ChannelPosition]
57 , _aRate :: SampleRate
58 } deriving (Generic)
59makeLenses ''AudioConfig
60
61instance Default AudioConfig where
62 def = AudioConfig
63 { _aBackend = def
64 , _aChannels = [Just $ ChannelNormal PanLeft, Just $ ChannelNormal PanRight]
65 , _aRate = def
66 }
67
68instance Serialize AudioConfig
69
70
71data Mode = Server | Client
72 deriving (Enum, Eq, Generic, Show)
73
74instance Default Mode where
75 def = Server
76
77instance Serialize Mode
78
79
80data Configuration = Configuration
81 { _cMode :: Mode
82 , _cSocketDesc :: Maybe (Family, SocketType, ProtocolNumber, SockAddr)
83 , _cAudio :: AudioConfig
84 } deriving (Generic)
85makeLenses ''Configuration
86
87instance Default Configuration where
88 def = Configuration
89 { _cMode = def
90 , _cSocketDesc = Nothing
91 , _cAudio = def
92 }