module Sound.Conductive.MusicalEnvironment ( actions
, addAction
, addDoubleGenerator
, addIOI
, addIOIList
, addInterrupt
, addNewGenerator
, addPlayer
, addTempoClock
, changeActions
, changeDoubleGenerators
, changeEnvironment
, changeIOILists
, changeIOIs
, changeInterrupts
, changePlayers
, changeTempoClocks
, deleteAction
, deleteDoubleGenerator
, deleteIOI
, deleteIOIList
, deleteInterrupt
, deletePlayer
, deleteTempoClock
, doubleGenerators
, eChangeTempo
, eChangeTimeSignature
, eCurrentTempo
, eCurrentTimeSignature
, eElapsedBeats
, eElapsedTime
, getAction
, getCurrentTime
, getDoubleGenerator
, getIOI
, getIOIList
, getInterrupt
, getPlayer
, getTempoClock
, iOIs
, iOILists
, interrupts
, players
, showCurrentTime
, tempoClocks
, withAction
, withDoubleGenerator
, withEnvironment
, withIOI
, withIOIList
, withInterrupt
, withPlayer
, withTempoClock
) where
import Control.Concurrent.MVar
import Data.Map
import Sound.Conductive.ConductiveBaseData
import Sound.Conductive.Generator
import Sound.Conductive.MusicalTime
import Sound.Conductive.MVarUtils
environmentStoreKeys
:: MVar a -> (a -> Data.Map.Map k a1) -> IO [k]
environmentStoreKeys e sRecord = wm e $ (\x -> keys $ sRecord x)
withEnvironment :: MVar a -> (a -> a1) -> IO a1
withEnvironment e func = wm e func
changeEnvironment :: MVar a -> (a -> a) -> IO a
changeEnvironment e func = wcm e func
withStore :: (t -> a) -> (a -> b) -> t -> b
withStore store func e = func $ store e
withMEStore :: (a -> a1) -> (a1 -> b) -> MVar a -> IO b
withMEStore store func e = withEnvironment e $ withStore store func
getItem
:: (Ord k) => (a -> Data.Map.Map k a1) -> k -> MVar a -> IO a1
getItem store item e = withMEStore store (\x -> x ! item) e
getPlayer :: MVar MusicalEnvironment -> String -> IO Player
getPlayer e n = getItem playerStore n e
getTempoClock :: MVar MusicalEnvironment -> String -> IO TempoClock
getTempoClock e n = getItem tempoClockStore n e
getIOI
:: MVar MusicalEnvironment
-> String
-> IO (MVar MusicalEnvironment -> Player -> IO Double)
getIOI e n = getItem iOIStore n e
getAction
:: MVar MusicalEnvironment
-> String
-> IO (MVar MusicalEnvironment -> Player -> IO ())
getAction e n = getItem actionStore n e
getInterrupt :: MVar MusicalEnvironment -> String -> IO [IO ()]
getInterrupt e n = getItem interruptStore n e
getDoubleGenerator
:: MVar MusicalEnvironment -> String -> IO (Generator Double)
getDoubleGenerator e n = getItem doubleGeneratorStore n e
getIOIList :: MVar MusicalEnvironment -> String -> IO [Double]
getIOIList e n = getItem iOIListStore n e
withItem
:: (Ord k) =>
(a -> Data.Map.Map k a1) -> k -> (a1 -> IO b) -> MVar a -> IO b
withItem store item func e = getItem store item e >>= \i -> func i
withPlayer
:: (Player -> IO b) -> MVar MusicalEnvironment -> String -> IO b
withPlayer func e n = withItem playerStore n func e
withTempoClock
:: (TempoClock -> IO b)
-> MVar MusicalEnvironment
-> String
-> IO b
withTempoClock func e n = withItem tempoClockStore n func e
withIOI
:: ((MVar MusicalEnvironment -> Player -> IO Double) -> IO b)
-> MVar MusicalEnvironment
-> String
-> IO b
withIOI func e n = withItem iOIStore n func e
withAction
:: ((MVar MusicalEnvironment -> Player -> IO ()) -> IO b)
-> MVar MusicalEnvironment
-> String
-> IO b
withAction func e n = withItem actionStore n func e
withInterrupt
:: ([IO ()] -> IO b) -> MVar MusicalEnvironment -> String -> IO b
withInterrupt func e n = withItem interruptStore n func e
withDoubleGenerator
:: (Generator Double -> IO b)
-> MVar MusicalEnvironment
-> String
-> IO b
withDoubleGenerator func e n = withItem doubleGeneratorStore n func e
withIOIList
:: ([Double] -> IO b) -> MVar MusicalEnvironment -> String -> IO b
withIOIList func e n = withItem iOIListStore n func e
storeKeys :: (a -> Data.Map.Map k a1) -> MVar a -> IO [k]
storeKeys store e = withMEStore store keys e
players :: MVar MusicalEnvironment -> IO [String]
players e = storeKeys playerStore e
tempoClocks :: MVar MusicalEnvironment -> IO [String]
tempoClocks e = storeKeys tempoClockStore e
iOIs :: MVar MusicalEnvironment -> IO [String]
iOIs e = storeKeys iOIStore e
actions :: MVar MusicalEnvironment -> IO [String]
actions e = storeKeys actionStore e
interrupts :: MVar MusicalEnvironment -> IO [String]
interrupts e = storeKeys interruptStore e
doubleGenerators :: MVar MusicalEnvironment -> IO [String]
doubleGenerators e = storeKeys doubleGeneratorStore e
iOILists :: MVar MusicalEnvironment -> IO [String]
iOILists e = storeKeys iOIListStore e
changePlayers
:: (Data.Map.Map String Player -> Data.Map.Map String Player)
-> MusicalEnvironment
-> MusicalEnvironment
changePlayers func e = e { playerStore = func $ playerStore e }
changeTempoClocks
:: (Data.Map.Map String TempoClock
-> Data.Map.Map String TempoClock)
-> MusicalEnvironment
-> MusicalEnvironment
changeTempoClocks func e = e { tempoClockStore = func $ tempoClockStore e }
changeIOIs
:: (Data.Map.Map String (MVar MusicalEnvironment -> Player -> IO Double)
-> Data.Map.Map String (MVar MusicalEnvironment -> Player -> IO Double))
-> MusicalEnvironment
-> MusicalEnvironment
changeIOIs func e = e { iOIStore = func $ iOIStore e }
changeActions
:: (Data.Map.Map String (MVar MusicalEnvironment -> Player -> IO ())
-> Data.Map.Map String (MVar MusicalEnvironment -> Player -> IO ()))
-> MusicalEnvironment
-> MusicalEnvironment
changeActions func e = e { actionStore = func $ actionStore e }
changeInterrupts
:: (Data.Map.Map String [IO ()] -> Data.Map.Map String [IO ()])
-> MusicalEnvironment
-> MusicalEnvironment
changeInterrupts func e = e { interruptStore = func $ interruptStore e }
changeDoubleGenerators
:: (Data.Map.Map String (Generator Double)
-> Data.Map.Map String (Generator Double))
-> MusicalEnvironment
-> MusicalEnvironment
changeDoubleGenerators func e = e { doubleGeneratorStore = func $ doubleGeneratorStore e }
changeIOILists
:: (Data.Map.Map String [Double] -> Data.Map.Map String [Double])
-> MusicalEnvironment
-> MusicalEnvironment
changeIOILists func e = e { iOIListStore = func $ iOIListStore e }
addPlayer
:: MVar MusicalEnvironment
-> (String, Player)
-> IO MusicalEnvironment
addPlayer e (k,v) = changeEnvironment e $ changePlayers (insert k v)
addTempoClock
:: MVar MusicalEnvironment
-> (String, TempoClock)
-> IO MusicalEnvironment
addTempoClock e (k,v) = changeEnvironment e $ changeTempoClocks (insert k v)
addIOI
:: MVar MusicalEnvironment
-> (String, MVar MusicalEnvironment -> Player -> IO Double)
-> IO MusicalEnvironment
addIOI e (k,v) = changeEnvironment e $ changeIOIs (insert k v)
addAction
:: MVar MusicalEnvironment
-> (String, MVar MusicalEnvironment -> Player -> IO ())
-> IO MusicalEnvironment
addAction e (k,v) = changeEnvironment e $ changeActions (insert k v)
addInterrupt
:: MVar MusicalEnvironment
-> (String, [IO ()])
-> IO MusicalEnvironment
addInterrupt e (k,v) = changeEnvironment e $ changeInterrupts (insert k v)
addDoubleGenerator
:: MVar MusicalEnvironment
-> (String, Generator Double)
-> IO MusicalEnvironment
addDoubleGenerator e (k,v) = changeEnvironment e $ changeDoubleGenerators (insert k v)
addIOIList
:: MVar MusicalEnvironment
-> (String, [Double])
-> IO MusicalEnvironment
addIOIList e (k,v) = changeEnvironment e $ changeIOILists (insert k v)
addNewGenerator
:: MVar MusicalEnvironment
-> (String, [Double])
-> IO MusicalEnvironment
addNewGenerator e (n,x) = newGenerator x >>= \g -> addDoubleGenerator e (n,g)
deleteItem
:: (Ord k) =>
((Data.Map.Map k a -> Data.Map.Map k a) -> t -> t1) -> k -> t -> t1
deleteItem changeFunc k e = changeFunc (delete k) e
deletePlayer
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deletePlayer e k = changeEnvironment e $ deleteItem (changePlayers) k
deleteTempoClock
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteTempoClock e k = changeEnvironment e $ deleteItem (changeTempoClocks) k
deleteIOI
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteIOI e k = changeEnvironment e $ deleteItem (changeIOIs) k
deleteAction
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteAction e k = changeEnvironment e $ deleteItem (changeActions) k
deleteInterrupt
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteInterrupt e k = changeEnvironment e $ deleteItem (changeInterrupts) k
deleteDoubleGenerator
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteDoubleGenerator e k = changeEnvironment e $ deleteItem (changeDoubleGenerators) k
deleteIOIList
:: MVar MusicalEnvironment -> String -> IO MusicalEnvironment
deleteIOIList e k = changeEnvironment e $ deleteItem (changeIOILists) k
eElapsedTime :: MVar MusicalEnvironment -> String -> IO Double
eElapsedTime e clock = withTempoClock elapsedTime e clock
eElapsedBeats :: MVar MusicalEnvironment -> String -> IO Double
eElapsedBeats e clock = withTempoClock elapsedBeats e clock
getCurrentTime
:: MVar MusicalEnvironment -> String -> IO MusicalTime
getCurrentTime e clock = withTempoClock currentMusicalTime e clock
showCurrentTime :: MVar MusicalEnvironment -> String -> IO [Char]
showCurrentTime e clock = withTempoClock currentMusicalTime2 e clock
eCurrentTempo :: MVar MusicalEnvironment -> String -> IO Double
eCurrentTempo e clock = do
c <- getTempoClock e clock
return $ currentTempo c
eCurrentTimeSignature
:: MVar MusicalEnvironment -> String -> IO Int
eCurrentTimeSignature e clock = withTempoClock currentTimeSignature e clock
eChangeTempo
:: MVar MusicalEnvironment
-> String
-> Double
-> IO MusicalEnvironment
eChangeTempo e clock nt = do
tc <- getItem tempoClockStore clock e
ntc <- changeTempo tc nt
addTempoClock e (clock,ntc)
eChangeTimeSignature
:: MVar MusicalEnvironment
-> String
-> Int
-> IO MusicalEnvironment
eChangeTimeSignature e clock nts = do
tc <- getItem tempoClockStore clock e
ntc <- changeTimeSignature tc nts
addTempoClock e (clock,ntc)