1 {-# LANGUAGE Arrows, TupleSections #-}
3 module RMCA.Layer.LayerConf where
6 import Data.ReactiveValue
9 import RMCA.Global.Clock
11 import RMCA.Translator.Message
13 -- | Datatype representing dynamically modifiable characteristics for a layer.
14 data DynLayerConf = DynLayerConf { layerBeat :: Rational
15 , relPitch :: RelPitch
16 , strength :: Strength
17 } deriving (Show, Read, Eq)
19 -- | Datatype representing statically modifiable characteristics for a layer.
20 data StaticLayerConf = StaticLayerConf { beatsPerBar :: BeatsPerBar
21 , repeatCount :: Maybe Int
22 } deriving (Show, Read, Eq)
24 -- | Datatype containing informations useful for the synthetizer.
25 data SynthConf = SynthConf { volume :: Int
26 , instrument :: InstrumentNo
27 } deriving (Show, Read, Eq)
29 synthMessage :: Int -> SynthConf -> [Message]
30 synthMessage chan SynthConf { volume = v
32 } = [ Volume (mkChannel chan) v
33 , Instrument (mkChannel chan) (mkProgram i)
36 type LayerConf = (StaticLayerConf, DynLayerConf, SynthConf)
38 dynConf :: LayerConf -> DynLayerConf
41 staticConf :: LayerConf -> StaticLayerConf
42 staticConf (s,_,_) = s
44 synthConf :: LayerConf -> SynthConf
47 layerMetronome :: StaticLayerConf
48 -> SF (Event AbsBeat, DynLayerConf) (Event BeatNo)
49 layerMetronome StaticLayerConf { beatsPerBar = bpb
51 proc (eb, DynLayerConf { layerBeat = r
53 ewbno <- accumFilter (\_ (ab,r) -> ((),selectBeat (ab,r))) () -< (,r) <$> eb
54 accumBy (flip nextBeatNo) 0 -< ewbno `tag` bpb
55 where selectBeat (absBeat, layBeat) =
56 maybeIf ((absBeat - 1) `mod`
57 floor (fromIntegral maxAbsBeat * layBeat) == 0)
59 getDefaultLayerConfRV :: IO (ReactiveFieldReadWrite IO LayerConf)
60 getDefaultLayerConfRV = newCBMVarRW defaultLayerConf
62 defaultLayerConf :: LayerConf
63 defaultLayerConf = (defaultStaticLayerConf,defaultDynLayerConf,defaultSynthConf)
65 defaultStaticLayerConf :: StaticLayerConf
66 defaultStaticLayerConf = StaticLayerConf { beatsPerBar = 4
67 , repeatCount = Nothing
69 defaultDynLayerConf :: DynLayerConf
70 defaultDynLayerConf = DynLayerConf { layerBeat = 1 % 4
74 defaultSynthConf :: SynthConf
75 defaultSynthConf = SynthConf { volume = 127