Skip to content

avoid loading stream module in other modules, so hint wont crash #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Sound/Tidal/Control.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Data.Ratio

import Sound.Tidal.Pattern
import Sound.Tidal.Core
import Sound.Tidal.Stream (patternTimeID)
import Sound.Tidal.StreamTypes (patternTimeID)
import Sound.Tidal.UI
import qualified Sound.Tidal.Params as P
import Sound.Tidal.Utils
Expand Down Expand Up @@ -422,16 +422,16 @@ trigger = triggerWith id
-- | (Alias @__qt__@) Quantise trigger. Aligns the start of the pattern
-- with the next cycle boundary. For example, this pattern will fade in
-- starting with the next cycle after the pattern is evaluated:
--
--
-- @
-- d1 $ qtrigger $ s "hh(5, 8)" # amp envL
-- @
--
--
-- Note that the pattern will start playing immediately. The /start/ of the
-- pattern aligns with the next cycle boundary, but events will play before
-- if the pattern has events at negative timestamps (which most loops do).
-- These events can be filtered out, for example:
--
--
-- @
-- d1 $ qtrigger $ filterWhen (>= 0) $ s "hh(5, 8)"
-- @
Expand Down
18 changes: 8 additions & 10 deletions src/Sound/Tidal/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ defaultCps = 0.5625
-- Spawns a thread within Tempo that acts as the clock
-- Spawns a thread that listens to and acts on OSC control messages
startStream :: Config -> [(Target, [OSC])] -> IO Stream
startStream config oscmap
startStream config oscmap
= do sMapMV <- newMVar Map.empty
pMapMV <- newMVar Map.empty
bussesMV <- newMVar []
Expand All @@ -219,7 +219,7 @@ startStream config oscmap
u <- O.udp_socket (\sock sockaddr -> do N.setSocketOption sock N.Broadcast broadcast
N.connect sock sockaddr
) (oAddress target) (oPort target)
return $ Cx {cxUDP = u, cxAddr = remote_addr, cxBusAddr = remote_bus_addr, cxTarget = target, cxOSCs = os}
return $ Cx {cxUDP = u, cxAddr = remote_addr, cxBusAddr = remote_bus_addr, cxTarget = target, cxOSCs = os}
) oscmap
let bpm = (coerce defaultCps) * 60 * (cBeatsPerCycle config)
abletonLink <- Link.create bpm
Expand Down Expand Up @@ -249,7 +249,7 @@ startStream config oscmap
sendHandshakes :: Stream -> IO ()
sendHandshakes stream = mapM_ sendHandshake $ filter (oHandshake . cxTarget) (sCxs stream)
where sendHandshake cx = if (isJust $ sListen stream)
then
then
do -- send it _from_ the udp socket we're listening to, so the
-- replies go back there
sendO False (sListen stream) cx $ O.Message "/dirt/handshake" []
Expand Down Expand Up @@ -290,7 +290,7 @@ toDatum (VB True) = O.int32 (1 :: Int)
toDatum (VB False) = O.int32 (0 :: Int)
toDatum (VX xs) = O.Blob $ O.blob_pack xs
toDatum _ = error "toDatum: unhandled value"

toData :: OSC -> Event ValueMap -> Maybe [O.Datum]
toData (OSC {args = ArgList as}) e = fmap (fmap (toDatum)) $ sequence $ map (\(n,v) -> Map.lookup n (value e) <|> v) as
toData (OSC {args = Named rqrd}) e
Expand Down Expand Up @@ -362,7 +362,7 @@ toOSC busses pe osc@(OSC _ _)
-- If there is already cps in the event, the union will preserve that.
let extra = Map.fromList [("cps", (VF (coerce $! peCps pe))),
("delta", VF (T.addMicrosToOsc (peDelta pe) 0)),
("cycle", VF (fromRational (peCycle pe)))
("cycle", VF (fromRational (peCycle pe)))
]
addExtra = Map.union playmap' extra
ts = (peOnWholeOrPartOsc pe) + nudge -- + latency
Expand Down Expand Up @@ -399,8 +399,6 @@ toOSC _ pe (OSCContext oscpath)
ident = fromMaybe "unknown" $ Map.lookup "_id_" (value $ peEvent pe) >>= getS
ts = (peOnWholeOrPartOsc pe) + nudge -- + latency

patternTimeID :: String
patternTimeID = "_t_pattern"

-- Used for Tempo callback
updatePattern :: Stream -> ID -> Time -> ControlPattern -> IO ()
Expand Down Expand Up @@ -431,7 +429,7 @@ processCps ops = mapM processEvent
onPart <- (T.timeAtBeat ops) partStartBeat
when (eventHasOnset e) (do
let cps' = Map.lookup "cps" (value e) >>= getF
maybe (return ()) (\newCps -> (T.setTempo ops) ((T.cyclesToBeat ops) (newCps * 60)) on) $ coerce cps'
maybe (return ()) (\newCps -> (T.setTempo ops) ((T.cyclesToBeat ops) (newCps * 60)) on) $ coerce cps'
)
off <- (T.timeAtBeat ops) offBeat
bpm <- (T.getTempo ops)
Expand Down Expand Up @@ -491,7 +489,7 @@ onSingleTick stream ops s pat = do
-- If an exception occurs during sending,
-- this functions prints a warning and continues, because
-- the likely reason is that the backend (supercollider) isn't running.
--
--
-- If any exception occurs before or outside sending
-- (e.g., while querying the pattern, while computing a message),
-- this function prints a warning and resets the current pattern
Expand Down Expand Up @@ -691,7 +689,7 @@ ctrlResponder waits c (stream@(Stream {sListen = Just sock}))
-- Only report the first time..
when (null prev) $ verbose c $ "Connected to SuperDirt."
return ()
where
where
bufferIndices [] = []
bufferIndices (x:xs') | x == (O.AsciiString $ O.ascii "&controlBusIndices") = catMaybes $ takeWhile isJust $ map O.datum_integral xs'
| otherwise = bufferIndices xs'
Expand Down
3 changes: 3 additions & 0 deletions src/Sound/Tidal/StreamTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ data TickState = TickState {
tickNudge :: Double
}
deriving Show

patternTimeID :: String
patternTimeID = "_t_pattern"