Skip to content

Commit

Permalink
better quant performance
Browse files Browse the repository at this point in the history
  • Loading branch information
geikha committed Aug 9, 2024
1 parent da741d6 commit e4aa2d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/Sound/Tidal/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,10 @@ 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 -- 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
| ws >= as && we > ae = Just ev { part = Arc ws ae } -- starts within, ends outside
| ws < as && we > ae = Just ev { part = Arc as ae } -- starts outside, ends outside
| ws < as && we <= ae = Just ev { part = Arc as we } -- starts outside, ends within
| otherwise = Nothing
encloseEvent a@(Arc as ae) ev@(Event ctx (Just w@(Arc ws we)) part val)

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Defined but not used: ‘val’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘ctx’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

This binding for ‘part’ shadows the existing binding

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘part’

Check warning on line 918 in src/Sound/Tidal/Pattern.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

Defined but not used: ‘val’
| we <= as || ws >= ae = Nothing -- outside
| ws >= as && we <= ae = Just ev -- fully within
| otherwise = Just ev { part = sect w a } -- intersects

-- | If an event ends before it starts, switch starts with ends
unflipEvent :: Event a -> Event a
Expand Down
19 changes: 13 additions & 6 deletions src/Sound/Tidal/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module Sound.Tidal.UI where

import Prelude hiding ((*>), (<*))

import Control.Applicative (liftA2)

import Data.Bits (Bits, shiftL, shiftR, testBit, xor)
import Data.Char (digitToInt, isDigit, ord)

Expand Down Expand Up @@ -2060,10 +2062,16 @@ fill p' p = struct (splitQueries $ p {query = q, pureValue = Nothing}) p'
_quant :: Time -> Pattern a -> Pattern a
_quant 0 pat = pat
_quant k pat =
withEventOnArc (quantEvent k) (timeToCycleArc . start) pat
withEventOnArc (quantEvent k) (surround) pat
where
surround qa@(Arc qs qe) = Arc (qs - lookahead) (qe + lookahead)
lookahead = 1/k
quantEvent k ev = ev { whole = (fmap rounding <$> whole ev) }
rounding n = toTime $ ((/ k) $ fromIntegral $ round $ (* k) n)
rounding n = (roundNumerator n) % k'
roundNumerator n = (nn * k' + (nd `div` 2)) `div` nd
where nn = numerator n

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

• Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Variable not in scope: numerator :: p -> t

Check failure on line 2072 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: numerator :: p -> t
nd = denominator n

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

• Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Variable not in scope: denominator :: p -> t

Check failure on line 2073 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: denominator :: p -> t
k' = numerator k

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal latest - ghc latest

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.10.1

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.8.3

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 9.0.1

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.4.0.0 - ghc 8.6.5

• Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / cabal 3.8.1.0 - ghc 9.4.1

Variable not in scope: numerator :: Time -> t

Check failure on line 2074 in src/Sound/Tidal/UI.hs

View workflow job for this annotation

GitHub Actions / build (9.0.1, 3.4.0.0)

• Variable not in scope: numerator :: Time -> t

quant :: Pattern Time -> Pattern a -> Pattern a
quant = patternify _quant
Expand All @@ -2090,14 +2098,13 @@ fill' = patternify2 _fill
alterT :: (Time -> Time) -> Pattern a -> Pattern a
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)
where alterEvent ev = ev { whole = (fmap (mapCycle f) $ whole ev) }

alterF :: (Double -> Double) -> Pattern a -> Pattern a
alterF f pat =
withEventOnArc (unflipEvent . alterEvent) (timeToCycleArc . start) pat
where alterEvent ev = ev { whole = (fmap alterTime <$> whole ev) }
alterTime t = (sam $ t) + (toRational $ f $ fromRational $ cyclePos $ t)
where alterEvent ev = ev { whole = (fmap (mapCycle f') $ whole ev) }
f' = toRational . f . fromRational

{- | @ply n@ repeats each event @n@ times within its arc.
Expand Down

0 comments on commit e4aa2d6

Please sign in to comment.