Skip to content

Add setCycle #969

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 1 commit into from
Nov 17, 2022
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
1 change: 1 addition & 0 deletions BootTidal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let only = (hush >>)
nudgeAll = streamNudgeAll tidal
all = streamAll tidal
resetCycles = streamResetCycles tidal
setCycle = streamSetCycle tidal
setcps = asap . cps
getcps = streamGetcps tidal
getnow = streamGetnow tidal
Expand Down
5 changes: 4 additions & 1 deletion src/Sound/Tidal/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,10 @@ streamNudgeAll :: Stream -> Double -> IO ()
streamNudgeAll s nudge = T.setNudge (sActionsMV s) nudge

streamResetCycles :: Stream -> IO ()
streamResetCycles s =T.resetCycles (sActionsMV s)
streamResetCycles s = streamSetCycle s 0

streamSetCycle :: Stream -> Time -> IO ()
streamSetCycle s cyc = T.setCycle cyc (sActionsMV s)

hasSolo :: Map.Map k PlayState -> Bool
hasSolo = (>= 1) . length . filter solo . Map.elems
Expand Down
14 changes: 8 additions & 6 deletions src/Sound/Tidal/Tempo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ instance Show O.UDP where
type TransitionMapper = P.Time -> [P.ControlPattern] -> P.ControlPattern

data TempoAction =
ResetCycles
SetCycle P.Time
| SingleTick P.ControlPattern
| SetNudge Double
| StreamReplace ID P.ControlPattern
Expand Down Expand Up @@ -76,8 +76,8 @@ data LinkOperations =
cyclesToBeat :: CDouble -> CDouble
}

resetCycles :: MVar [TempoAction] -> IO ()
resetCycles actionsMV = modifyMVar_ actionsMV (\actions -> return $ ResetCycles : actions)
setCycle :: P.Time -> MVar [TempoAction] -> IO ()
setCycle cyc actionsMV = modifyMVar_ actionsMV (\actions -> return $ SetCycle cyc : actions)

setNudge :: MVar [TempoAction] -> Double -> IO ()
setNudge actionsMV nudge = modifyMVar_ actionsMV (\actions -> return $ SetNudge nudge : actions)
Expand Down Expand Up @@ -209,20 +209,22 @@ clocked config stateMV mapMV actionsMV ac abletonLink
return $! st'
handleActions :: State -> [TempoAction] -> P.ValueMap -> IO (State, P.ValueMap)
handleActions st [] streamState = return (st, streamState)
handleActions st (ResetCycles : otherActions) streamState =
handleActions st (SetCycle cyc : otherActions) streamState =
do
(st', streamState') <- handleActions st otherActions streamState
sessionState <- Link.createAndCaptureAppSessionState abletonLink

now <- Link.clock abletonLink
let startAt = now + processAhead
Link.requestBeatAtTime sessionState 0 startAt quantum
beat = (fromRational cyc) * (cBeatsPerCycle config)
Link.requestBeatAtTime sessionState beat startAt quantum
Link.commitAndDestroyAppSessionState abletonLink sessionState


let st'' = st' {
ticks = 0,
start = now,
nowArc = P.Arc 0 0
nowArc = P.Arc cyc cyc
}

return (st'', streamState')
Expand Down