Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ejconlon committed Feb 16, 2024
1 parent 05771a1 commit c44829c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion minipat-dirt/src/Minipat/Dirt/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Minipat.Dirt.Attrs (Attrs)
import Minipat.Dirt.Logger (LogAction, logError, logInfo, newLogger)
import Minipat.Dirt.Osc (PlayEnv (..), PlayErr, Timed (..), convertTape, handshakePacket, playPacket)
import Minipat.Dirt.Resources (RelVar, acquireAsync, relVarAcquire, relVarDispose, relVarInit)
import Minipat.EStream (EStream (..))
import Minipat.Print (prettyPrint)
import Minipat.Stream (Stream (..), streamRun)
import Minipat.Time (Arc (..), bpmToCps, cpsToBpm)
Expand Down Expand Up @@ -122,6 +123,7 @@ data Domain = Domain
, domAhead :: !(TVar TimeDelta)
, domPlaying :: !(TVar Bool)
, domCycle :: !(TVar Integer)
, domAbsCycle :: !(TVar Integer)
, domOrbits :: !(TVar (Map Integer (Stream Attrs)))
, domStream :: !(TVar (Stream Attrs))
, domQueue :: !(TQueue (Timed Packet))
Expand All @@ -135,6 +137,7 @@ newDomain =
<*> newTVarIO 0
<*> newTVarIO False
<*> newTVarIO 0
<*> newTVarIO 0
<*> newTVarIO mempty
<*> newTVarIO mempty
<*> newTQueueIO
Expand Down Expand Up @@ -169,6 +172,9 @@ getStream = readTVarIO . domStream . stDom
getCycle :: St -> IO Integer
getCycle = readTVarIO . domCycle . stDom

getAbsCycle :: St -> IO Integer
getAbsCycle = readTVarIO . domAbsCycle . stDom

getTempo :: St -> IO Rational
getTempo = fmap (cpsToBpm 4) . getCps

Expand Down Expand Up @@ -198,6 +204,13 @@ updateOrbits st f = atomically $ do
setOrbit :: St -> Integer -> Stream Attrs -> IO ()
setOrbit st o s = updateOrbits st (Map.insert o s)

-- TODO Move to this one
setOrbit' :: St -> Integer -> EStream Attrs -> IO ()
setOrbit' st o es =
case unEStream es of
Left e -> throwIO e
Right s -> updateOrbits st (Map.insert o s)

clearOrbit :: St -> Integer -> IO ()
clearOrbit st o = updateOrbits st (Map.delete o)

Expand Down Expand Up @@ -262,7 +275,9 @@ genEventsSTM dom now = do
pure (penv, mpevs)

advanceCycleSTM :: Domain -> STM ()
advanceCycleSTM dom = modifyTVar' (domCycle dom) (+ 1)
advanceCycleSTM dom = do
modifyTVar' (domCycle dom) (+ 1)
modifyTVar' (domAbsCycle dom) (+ 1)

data OscConn = OscConn
{ ocTargetAddr :: !NS.SockAddr
Expand Down

0 comments on commit c44829c

Please sign in to comment.