1 {-# LANGUAGE Arrows, TupleSections #-}
3 module RMCA.Layer.LayerConf where
5 import Data.IntMap (IntMap)
7 import Data.ReactiveValue
10 import RMCA.Global.Clock
12 import RMCA.Translator.Message
14 -- | Datatype representing dynamically modifiable characteristics for a layer.
15 data DynLayerConf = DynLayerConf { layerBeat :: Rational
16 , relPitch :: RelPitch
17 , strength :: Strength
18 } deriving (Show, Read, Eq)
20 -- | Datatype representing statically modifiable characteristics for a layer.
21 data StaticLayerConf = StaticLayerConf { beatsPerBar :: BeatsPerBar
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) 1 -< 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
68 defaultDynLayerConf :: DynLayerConf
69 defaultDynLayerConf = DynLayerConf { layerBeat = 1 % 4
73 defaultSynthConf :: SynthConf
74 defaultSynthConf = SynthConf { volume = 127