netclock 0.1 → 0.2
raw patch · 2 files changed
+11/−13 lines, 2 filesdep ~hoscPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hosc
API changes (from Hackage documentation)
- Network.Netclock.Client: clocked :: String -> String -> String -> Int -> (Int -> IO ()) -> IO ()
+ Network.Netclock.Client: clocked :: String -> String -> String -> Int -> (BpsChange -> Int -> IO ()) -> IO ()
Files
- Network/Netclock/Client.hs +9/−11
- netclock.cabal +2/−2
Network/Netclock/Client.hs view
@@ -1,10 +1,8 @@ module Network.Netclock.Client where import Sound.OpenSoundControl-import Control.Concurrent (threadDelay)-import Sound.OpenSoundControl+import Control.Concurrent (threadDelay, forkIO) import Control.Concurrent.MVar-import Control.Concurrent (forkIO) import Data.List import Data.Maybe import qualified Network.Socket as N@@ -17,7 +15,7 @@ } instance Show BpsChange where- show change = "bps " ++ show (changeBps change)+ show change = "bps " ++ show (changeBps change) ++ " time " ++ show (changeTime change) ++ " beat " ++ show (changeBeat change) @@ -31,6 +29,8 @@ -- Wait until the the given beat value. +scport = 57120+ waitBeat :: BpsChange -> Double -> IO () waitBeat change beat = do let logicalTime = changeTime change + ((beat - changeBeat change) / changeBps change)@@ -40,8 +40,7 @@ when (diff > 0) $ threadDelay delay return () --clocked :: String -> String -> String -> Int -> (Int -> IO ()) -> IO ()+clocked :: String -> String -> String -> Int -> (BpsChange -> Int -> IO ()) -> IO () clocked username clientIp serverIp tpb f = do mBps <- newEmptyMVar forkIO $ bpsListen username clientIp serverIp mBps@@ -51,15 +50,15 @@ bps = changeBps change beat = changeBeat change + (diff * bps) tick = floor beat * tpb- forkIO $ loop mBps tick- return ()+ loop mBps tick where loop :: MVar (BpsChange, [BpsChange]) -> Int -> IO () loop mBps tick = do let beat = fromIntegral tick / fromIntegral tpb current <- updateBps mBps beat+ let bps = changeBps current waitBeat current beat- f tick+ f current tick loop mBps (tick + 1) updateBps :: MVar (BpsChange, [BpsChange]) -> Double -> IO (BpsChange)@@ -96,7 +95,7 @@ register :: String -> String -> String -> Int -> IO (UDP) register username clientIp serverIp localPort = - do sc <- openUDP serverIp 57120+ do sc <- openUDP serverIp scport let m = Message "/clock/register" [String username, String clientIp, Int localPort,@@ -104,7 +103,6 @@ ] send sc m return sc- toFloat (Float f) = f toFloat (Int f) = fromIntegral f
netclock.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: Netclock protocol@@ -51,7 +51,7 @@ Exposed-modules: Network.Netclock.Client -- Packages needed in order to build this package.- Build-depends: base < 5, network, hosc+ Build-depends: base < 5, network, hosc >= 0.7 -- Modules not exported by this package. -- Other-modules: