First reimplementation of the translator.
[tmp/julm/arpeggigon.git] / Reactogon / Global / Clock.hs
index 673ba150ef222ac79f89b2074105405caf69b6b1..511f00ba979995e5e4e408247ade36c82cefbd6b 100644 (file)
@@ -1,10 +1,27 @@
-module Reactogon.Global.Clock where
+module Reactogon.Global.Clock ( tempo
+                              , metronome
+                              , tempoToDTime
+                              ) where
 
+import Reactogon.Auxiliary.Auxiliary
 import Reactogon.Semantics
 import FRP.Yampa
 
-tempo :: SF () Tempo
-tempo = constant 96
+import Debug.Trace
 
+tempo :: Tempo -> SF () Tempo
+tempo = constant
+
+-- The initial value is arbitrary but never appears because the switch
+-- is immediate.
 metronome :: SF Tempo (Event Beat)
-metronome = undefined
+metronome = switch ((repeatedly (tempoToDTime 60) ())
+                     &&&
+                    (onChange')) (metronome')
+  where metronome' :: Tempo -> SF Tempo (Event Beat)
+        metronome' t = (switch ((repeatedly (tempoToDTime t) ())
+                                 &&&
+                                 onChange) (metronome'))
+
+tempoToDTime :: Tempo -> DTime
+tempoToDTime = (60/) . fromIntegral