Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geikha committed Jul 19, 2024
1 parent 8b66019 commit da741d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Sound/Tidal/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,8 @@ eventHasOnset e | isAnalog e = False

-- | Given any event, return it as if it was queried between the given arc
encloseEvent :: Arc -> Event a -> Maybe (Event a)
encloseEvent _ (Event _ Nothing _ _) = Nothing
encloseEvent (Arc as ae) ev@(Event ctx (Just (Arc ws we)) part val)
encloseEvent _ (Event _ Nothing _ _) = Nothing -- TODO how to handle analogs
encloseEvent (Arc as ae) ev@(Event _ (Just (Arc ws we)) _ _)
| we <= as = Nothing
| ws >= ae = Nothing
| ws >= as && we <= ae = Just ev -- fully within
Expand All @@ -926,8 +926,8 @@ encloseEvent (Arc as ae) ev@(Event ctx (Just (Arc ws we)) part val)

-- | If an event ends before it starts, switch starts with ends
unflipEvent :: Event a -> Event a
unflipEvent ev@(Event _ (Just (Arc ws we)) (Arc ps pe) _) | we >= ws = ev
| ws > we = ev { whole = (Just (Arc we ws)), part = (Arc pe ps) }
unflipEvent ev@(Event _ (Just (Arc ws we)) (Arc ps pe) _) = if we >= ws then ev else ev { whole = (Just (Arc we ws)), part = (Arc pe ps) }
unflipEvent ev@(Event _ Nothing (Arc ps pe) _) = if pe >= ps then ev else ev { part = (Arc pe ps) }

-- TODO - Is this used anywhere? Just tests, it seems
-- TODO - support 'context' field
Expand Down
6 changes: 3 additions & 3 deletions src/Sound/Tidal/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Data.Bool (bool)
import Data.Fixed (mod')
import Data.List (elemIndex, findIndex, findIndices,
groupBy, intercalate, sort, sortOn,
transpose)
sortBy, transpose)
import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes, fromJust, fromMaybe, isJust,
mapMaybe)
Expand Down Expand Up @@ -2072,7 +2072,7 @@ _fill :: Time -> Time -> Pattern a -> Pattern a
_fill l m pat =
withEventsOnArc (map multiplyEvent . updateEvents . sortEvents) (lookahead) pat
where lookahead a = a { start = (`subtract` l) $ start a, stop = (+l) $ stop a }
sortEvents = Data.List.sortBy (\e0 e1 -> compare (start $ part e0) (start $ part e1))
sortEvents = sortBy (\e0 e1 -> compare (start $ part e0) (start $ part e1))
updateEvents es = (zipWith updatePair es (drop 1 es)) ++ safeLast es
safeLast [] = []
safeLast es = [last es]
Expand All @@ -2088,7 +2088,7 @@ fill' :: Pattern Time -> Pattern Time -> Pattern a -> Pattern a
fill' = patternify2 _fill

alterT :: (Time -> Time) -> Pattern a -> Pattern a
alter f pat =
alterT f pat =
withEventOnArc (unflipEvent . alterEvent) (timeToCycleArc . start) pat
where alterEvent ev = ev { whole = (fmap alterTime <$> whole ev) }
alterTime w = (sam $ w) + (f $ cyclePos $ w)
Expand Down

0 comments on commit da741d6

Please sign in to comment.