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