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 , repeatCount :: Maybe Int
23 } deriving (Show, Read, Eq)
25 -- | Datatype containing informations useful for the synthetizer.
26 data SynthConf = SynthConf { volume :: Int
27 , instrument :: InstrumentNo
28 } deriving (Show, Read, Eq)
30 synthMessage :: Int -> SynthConf -> [Message]
31 synthMessage chan (SynthConf { volume = v
33 }) = [ Volume (mkChannel chan) v
34 , Instrument (mkChannel chan) (mkProgram i)
37 type LayerConf = (StaticLayerConf, DynLayerConf, SynthConf)
39 dynConf :: LayerConf -> DynLayerConf
42 staticConf :: LayerConf -> StaticLayerConf
43 staticConf (s,_,_) = s
45 synthConf :: LayerConf -> SynthConf
48 layerMetronome :: StaticLayerConf
49 -> SF (Event AbsBeat, DynLayerConf) (Event BeatNo)
50 layerMetronome StaticLayerConf { beatsPerBar = bpb
52 proc (eb, DynLayerConf { layerBeat = r
54 ewbno <- accumFilter (\_ (ab,r) -> ((),selectBeat (ab,r))) () -< (,r) <$> eb
55 accumBy (flip nextBeatNo) 1 -< ewbno `tag` bpb
56 where selectBeat (absBeat, layBeat) =
57 maybeIf ((absBeat - 1) `mod`
58 floor (fromIntegral maxAbsBeat * layBeat) == 0)
60 getDefaultLayerConfRV :: IO (ReactiveFieldReadWrite IO LayerConf)
61 getDefaultLayerConfRV = newCBMVarRW defaultLayerConf
63 defaultLayerConf :: LayerConf
64 defaultLayerConf = (defaultStaticLayerConf,defaultDynLayerConf,defaultSynthConf)
66 defaultStaticLayerConf :: StaticLayerConf
67 defaultStaticLayerConf = StaticLayerConf { beatsPerBar = 4
68 , repeatCount = Nothing
70 defaultDynLayerConf :: DynLayerConf
71 defaultDynLayerConf = DynLayerConf { layerBeat = 1 % 4
75 defaultSynthConf :: SynthConf
76 defaultSynthConf = SynthConf { volume = 127