module Sound.Conductive.IOI where
import Control.Concurrent.MVar
import Data.List
import Data.List.Utils
import Data.Maybe
import Sound.Conductive.ConductiveBaseData
import Sound.Conductive.MusicalEnvironment
import Sound.Conductive.MusicalTime
import Sound.Conductive.Player
makeIOIList :: (Num a) => a -> [a] -> [a]
makeIOIList start source = deltasToAbsolutes start $ cycle source
iOIFromList
:: MVar MusicalEnvironment -> Player -> String -> IO Double
iOIFromList e p m = let
minDiff = 0.125
start = playerStartingBeat p
b = playerBeat p
nextBeat pb bs = find (> (pbstart)) bs
beatDiff opb pb bs = (fromJust $ nextBeat pb bs) (opb start)
in do il <- getIOIList e m
let thisBeatDiff = beatDiff b b $ il
if (thisBeatDiff < minDiff)
then do let nb = sum [minDiff,thisBeatDiff,b]
let newBeatDiff = (beatDiff b nb il)
return newBeatDiff
else return thisBeatDiff
newIOIFunctionAndIOIList
:: MVar MusicalEnvironment
-> String
-> Double
-> [Double]
-> IO MusicalEnvironment
newIOIFunctionAndIOIList env name startingBeat deltas = let
newFunc e p = iOIFromList e p name
newIOIList = makeIOIList startingBeat deltas
in do addIOIList env (name,newIOIList)
addIOI env (name,newFunc)