packages feed

conductive-base 0.1 → 0.2

raw patch · 4 files changed

+90/−39 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Sound.Conductive.MusicalEnvironment: eElapsedBeats :: MVar MusicalEnvironment -> String -> IO Double
+ Sound.Conductive.Player: pauseAll :: MVar MusicalEnvironment -> IO ()
+ Sound.Conductive.Player: pauseN :: MVar MusicalEnvironment -> [String] -> IO ()
+ Sound.Conductive.Player: playAll :: MVar MusicalEnvironment -> IO ()
+ Sound.Conductive.Player: playAllAt :: MVar MusicalEnvironment -> [Char] -> IO ()
+ Sound.Conductive.Player: playN :: MVar MusicalEnvironment -> [String] -> IO ()
+ Sound.Conductive.Player: playNAt :: MVar MusicalEnvironment -> [Char] -> [String] -> IO ()
+ Sound.Conductive.Player: resetAll :: MVar MusicalEnvironment -> IO ()
+ Sound.Conductive.Player: resetN :: MVar MusicalEnvironment -> [String] -> IO ()
+ Sound.Conductive.Player: stopAll :: MVar MusicalEnvironment -> IO ()
+ Sound.Conductive.Player: stopN :: MVar MusicalEnvironment -> [String] -> IO ()
+ Sound.Conductive.Player: timeDiff :: TempoClock -> Double -> IO Double

Files

Sound/Conductive/IOI.hs view
@@ -31,18 +31,17 @@ iOIFromList   :: MVar MusicalEnvironment -> Player -> String -> IO Double iOIFromList e p m = let-    minDiff = 0.125+    minDiff = 0.1     start = playerStartingBeat p     b = playerBeat p-    nextBeat pb bs = find (> (pb-start)) bs-    beatDiff opb pb bs = (fromJust $ nextBeat pb bs) - (opb - start)+    nextBeat currentBeat iOIList = let+        nextTwoBeats = take 2 $ dropWhile (<= currentBeat) iOIList+        in if ((head nextTwoBeats) - currentBeat) < minDiff+                then (nextTwoBeats!!1)+                else (head nextTwoBeats)     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+            return $ nextBeat b il+              -- | Creates an IOI list, adds it to the environment, and adds a lookup function for it to the MusicalEnvironment. @@ -58,4 +57,6 @@     in do addIOIList env (name,newIOIList)           addIOI env (name,newFunc) -+addIOIs e iois = let +    addIOI e (x,y,z) = newIOIFunctionAndIOIList e x y z+    in mapM_ (addIOI e) iois
Sound/Conductive/MusicalEnvironment.hs view
@@ -34,6 +34,7 @@                                             , eChangeTimeSignature                                             , eCurrentTempo                                             , eCurrentTimeSignature+                                            , eElapsedBeats                                             , eElapsedTime                                             , getAction                                             , getCurrentTime@@ -437,6 +438,11 @@  eElapsedTime :: MVar MusicalEnvironment -> String -> IO Double eElapsedTime e clock = withTempoClock elapsedTime e clock ++-- | convenience function for returning elapsed beats from a stored TempoClock++eElapsedBeats :: MVar MusicalEnvironment -> String -> IO Double+eElapsedBeats e clock = withTempoClock elapsedBeats e clock   -- | convenience function for returning elapsed MusicalTime from a stored TempoClock 
Sound/Conductive/Player.hs view
@@ -13,12 +13,22 @@                                 , newPlayer                                 , newPlayerStore                                 , pause+                                , pauseN+                                , pauseAll                                 , play+                                , playN+                                , playAll                                 , playAt+                                , playNAt+                                , playAllAt                                 , playAtTimeString                                 , reset+                                , resetN+                                , resetAll                                 , sleep                                 , stop+                                , stopN+                                , stopAll                                 , swapActions                                 , swapBeat                                 , swapClock@@ -28,6 +38,7 @@                                 , swapName                                 , swapPauseTime                                 , swapStatus+                                , timeDiff                                 )where  import Control.Concurrent@@ -182,19 +193,13 @@  ------------------------------------------------------------------------------ -timeDiff :: TempoClock -> Double -> Double -> Double-timeDiff t b actualTime = let-    s = timeOfTempoChange $ head $ tempoChanges t-    beatDiff = b - (beatOfTempoChange $ head $ tempoChanges t)-    supposedTime = s + (beatsToDelta t beatDiff)-    in actualTime - supposedTime--correctJitter :: TempoClock -> Double -> Double -> Double -> Double-correctJitter t b delta actualTime = let-    s = timeOfTempoChange $ head $ tempoChanges t+timeDiff :: TempoClock -> Double -> IO Double+timeDiff t b = let+    st = timeOfTempoChange $ head $ tempoChanges t     beatDiff = b - (beatOfTempoChange $ head $ tempoChanges t)-    supposedTime = s + (beatsToDelta t $ beatDiff + delta)-    in supposedTime - actualTime+    in do actualTime <- currentTime+          let d = actualTime - st+          return $ d - (beatsToDelta t beatDiff)  -- | Plays a player, specified by the string, from a MusicalEnvironment. The start time is determined by the playerBeat field of the player. @@ -236,25 +241,44 @@ basicPlay e player Playing = do     p <- getPlayer e player     tc <- getTempoClock e $ playerClock p-    actualTime <- currentTime-    let diff = timeDiff tc (playerBeat p) actualTime+    diff <- timeDiff tc (playerBeat p)      if (diff < 0)-        then do sleep $ abs diff-                p1 <- getPlayer e player-                basicPlay e player $ playerStatus p1-        else do interrupt <- getInterrupt e $ playerInterrupt p-                sequence_ interrupt-                d <- getIOI e $ playerIOI p-                delta <- d e p-                a <- getAction e $ playerAction p-                forkIO $ a e p >> return ()-                tc2 <- getTempoClock e $ playerClock p-                actualTime <- currentTime-                swapBeat e player $ (playerBeat p) + delta-                swapCounter e player $ 1 + (playerCounter p)-                sleep $ correctJitter tc2 (playerBeat p) delta actualTime+        then do putStrLn $ show player+                putStrLn "The beat to play on is in the future!"+                putStrLn $ "diff = " ++ show diff+                sleep $ abs diff                 p1 <- getPlayer e player                 basicPlay e player $ playerStatus p1+        else do +                iOIFunc <- getIOI e $ playerIOI p+                beatOfNextEvent <- iOIFunc e p+                st <- (timeDiff tc beatOfNextEvent)+                let sleepTime = (-1) * st+                -- putStrLn $ "sleep time = " ++ show sleepTime+                if (sleepTime < 0.025)+                    then do -- putStrLn "\n"+                            -- putStrLn "-------------------------------------------------"+                            -- putStrLn "sleep time was too short!"+                            -- putStrLn $ playerName p+                            -- putStrLn $ show tc+                            -- putStrLn $ "playerBeat = " ++ (show $ playerBeat p)+                            -- putStrLn $ "nextBeat = " ++ (show $ beatOfNextEvent)+                            -- putStrLn $ "sleepTime = " ++ show sleepTime+                            -- putStrLn "-------------------------------------------------"+                            --swapStatus e player Stopping+                            --basicPlay e player Stopping+                            swapBeat e player beatOfNextEvent+                            p1 <- getPlayer e player+                            basicPlay e player $ playerStatus p+                    else do interrupt <- getInterrupt e $ playerInterrupt p+                            sequence_ interrupt+                            a <- getAction e $ playerAction p+                            forkIO $ a e p >> return ()+                            swapBeat e player beatOfNextEvent+                            swapCounter e player $ 1 + (playerCounter p)+                            sleep sleepTime+                            p1 <- getPlayer e player+                            basicPlay e player $ playerStatus p  basicPlay e player Pausing = do     actualTime <- currentTime@@ -319,6 +343,26 @@         then do swapStatus e player Resetting                 basicPlay e player Resetting         else do putStrLn "The player is not paused. Nothing has been done."++playN e ps = mapM_ (play e) ps++playAll e = players e >>= \x -> mapM_ (play e) $ x++playNAt e timestring ps = mapM_ (playAtTimeString timestring e) ps++playAllAt e timestring = players e >>= \x -> mapM_ (playAtTimeString timestring e) $ x++pauseN e ps = mapM_ (pause e) ps++pauseAll e = players e >>= \x -> mapM_ (pause e) $ x++stopN e ps = mapM_ (stop e) ps++stopAll e = players e >>= \x -> mapM_ (stop e) $ x++resetN e ps = mapM_ (reset e) ps++resetAll e = players e >>= \x -> mapM_ (reset e) $ x  -- | Used for setting up the playerStore of a MusicalEnvironment. It automatically creates one player according to the arguments it is given. 
conductive-base.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.1+Version:             0.2  -- A short (one-line) description of the package. Synopsis:            a library for livecoding and real-time musical applications