module Rhs.Score ( Score(Score) , writeScore , playScore ) where import Data.Maybe import Sound.OpenSoundControl import Sound.SC3 import Rhs.Schedule data Score = Score [OSC] deriving (Eq, Show) -- | Shift timestamp by given interval. offset :: Double -> OSC -> OSC offset n o = bundle (n + t o) (m o) where t = fromJust . timestamp m = fromJust . messages writeScore :: FilePath -> Score -> IO () writeScore fn (Score s) = writeNRT fn s -- | Latency value. latency :: Double latency = 0.1 playBundle :: Transport t => t -> OSC -> IO () playBundle fd o = do pauseThreadUntil t send fd (offset latency o) where t = fromJust (timestamp o) playScore :: Transport t => t -> Score -> IO () playScore fd (Score e) = do now <- utc mapM_ (playBundle fd) (map (offset now) e) {-- -- | Initial timestamp of sequence. startTime :: [OSC] -> Double startTime ((Bundle t _) : _) = t startTime _ = 0.0 -- | Offset by initial timestamp (make zero based). zero :: [OSC] -> [OSC] zero s = offset (negate (startTime s)) s --}