Tidal
Tidal copied to clipboard
Arbitrary Tempo Callback
Following up on a discussion in the Discord, it seems to me like there's value in being able to schedule callbacks that run synchronously with the clock. In particular, it strikes me as a little weird that StreamReplace and Transition are synced to the clock while all the other functions that modify the PlayMap are not, leading to unintuitive results like this:
do
d1 $ s "bd sn"
mute 1 -- Won't have an effect if d1 hasn't been previously called
I'd propose something like the following:
-- Tempo.hs --
data TempoAction =
SetCycle P.Time
| SingleTick P.ControlSignal
| SetNudge Double
| SyncIO (Time -> IO())
----
syncIO :: MVar [TempoAction] -> (Time -> IO ()) -> IO ()
This moves all of the PlayMap code into the Stream module (which also might mean that StreamTypes.hs isn't necessary any more), and generally opens up a hook for implementing custom stream/clock extensions.
I can submit a PR along these lines, but I wanted to know what you all (though mostly @Zalastax) think.
I like it a lot! But do we perhaps want two different action types? One for triggering the callback once (on a specific time) and another for triggering the callback repeatedly? And do we want the ability to de-register the callback? From inside or outside the callback? Both?