{-# LANGUAGE FlexibleInstances, BangPatterns #-}

{-
    Core.hs - For functions judged to be 'core' to tidal functionality.
    Copyright (C) 2020, Alex McLean and contributors

    This library is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this library.  If not, see <http://www.gnu.org/licenses/>.
-}

module Sound.Tidal.Core where

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

import           Data.Fixed (mod')
import qualified Data.Map.Strict as Map
import           Data.Maybe (fromMaybe)
import           Sound.Tidal.Pattern

-- ** Elemental patterns

-- | An empty pattern
silence :: Pattern a
silence :: forall a. Pattern a
silence = forall a. Pattern a
empty

-- | Takes a function from time to values, and turns it into a 'Pattern'.
sig :: (Time -> a) -> Pattern a
sig :: forall a. (Rational -> a) -> Pattern a
sig Rational -> a
f = forall a. (State -> [Event a]) -> Pattern a
Pattern State -> [EventF (ArcF Rational) a]
q
  where q :: State -> [EventF (ArcF Rational) a]
q (State (Arc Rational
s Rational
e) ValueMap
_)
          | Rational
s forall a. Ord a => a -> a -> Bool
> Rational
e = []
          | Bool
otherwise = [forall a b. Context -> Maybe a -> a -> b -> EventF a b
Event ([((Int, Int), (Int, Int))] -> Context
Context []) forall a. Maybe a
Nothing (forall a. a -> a -> ArcF a
Arc Rational
s Rational
e) (Rational -> a
f (Rational
sforall a. Num a => a -> a -> a
+((Rational
eforall a. Num a => a -> a -> a
-Rational
s)forall a. Fractional a => a -> a -> a
/Rational
2)))]

-- | @sine@ - unipolar sinewave. A pattern of continuous values following a
-- sinewave with frequency of one cycle, and amplitude from 0 to 1.
sine :: Fractional a => Pattern a
sine :: forall a. Fractional a => Pattern a
sine = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> (Double -> a
sin_rat ((forall a. Floating a => a
pi :: Double) forall a. Num a => a -> a -> a
* Double
2 forall a. Num a => a -> a -> a
* forall a. Fractional a => Rational -> a
fromRational Rational
t) forall a. Num a => a -> a -> a
+ a
1) forall a. Fractional a => a -> a -> a
/ a
2
  where sin_rat :: Double -> a
sin_rat = forall a. Fractional a => Rational -> a
fromRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Real a => a -> Rational
toRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Floating a => a -> a
sin

-- | @sine2@ - bipolar sinewave. A pattern of continuous values following a
-- sinewave with frequency of one cycle, and amplitude from -1 to 1.
sine2 :: Fractional a => Pattern a
sine2 :: forall a. Fractional a => Pattern a
sine2 = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> Double -> a
sin_rat ((forall a. Floating a => a
pi :: Double) forall a. Num a => a -> a -> a
* Double
2 forall a. Num a => a -> a -> a
* forall a. Fractional a => Rational -> a
fromRational Rational
t)
  where sin_rat :: Double -> a
sin_rat = forall a. Fractional a => Rational -> a
fromRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Real a => a -> Rational
toRational forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Floating a => a -> a
sin

-- | @cosine@ - unipolar cosine wave. A pattern of continuous values
-- following a cosine with frequency of one cycle, and amplitude from
-- 0 to 1. Equivalent to `0.25 ~> sine`.
cosine :: Fractional a => Pattern a
cosine :: forall a. Fractional a => Pattern a
cosine = Rational
0.25 forall a. Rational -> Pattern a -> Pattern a
`rotR` forall a. Fractional a => Pattern a
sine

-- | @cosine2@ - bipolar cosine wave. A pattern of continuous values
-- following a cosine with frequency of one cycle, and amplitude from
-- -1 to 1. Equivalent to `0.25 ~> sine2`.
cosine2 :: Fractional a => Pattern a
cosine2 :: forall a. Fractional a => Pattern a
cosine2 = Rational
0.25 forall a. Rational -> Pattern a -> Pattern a
`rotR` forall a. Fractional a => Pattern a
sine2

-- | @saw@ - unipolar ascending sawtooth wave. A pattern of continuous values
-- following a sawtooth with frequency of one cycle, and amplitude from
-- 0 to 1.
saw :: (Fractional a, Real a) => Pattern a
saw :: forall a. (Fractional a, Real a) => Pattern a
saw = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> forall a. Real a => a -> a -> a
mod' (forall a. Fractional a => Rational -> a
fromRational Rational
t) a
1

-- | @saw2@ - bipolar ascending sawtooth wave. A pattern of continuous values
-- following a sawtooth with frequency of one cycle, and amplitude from
-- -1 to 1.
saw2 :: (Fractional a, Real a) => Pattern a
saw2 :: forall a. (Fractional a, Real a) => Pattern a
saw2 = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> forall a. Real a => a -> a -> a
mod' (forall a. Fractional a => Rational -> a
fromRational Rational
t) a
1 forall a. Num a => a -> a -> a
* a
2 forall a. Num a => a -> a -> a
- a
1

-- | @isaw@ like @saw@, but a descending (inverse) sawtooth.
isaw :: (Fractional a, Real a) => Pattern a
isaw :: forall a. (Fractional a, Real a) => Pattern a
isaw = (a
1forall a. Num a => a -> a -> a
-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (Fractional a, Real a) => Pattern a
saw

-- | @isaw2@ like @saw2@, but a descending (inverse) sawtooth.
isaw2 :: (Fractional a, Real a) => Pattern a
isaw2 :: forall a. (Fractional a, Real a) => Pattern a
isaw2 = (forall a. Num a => a -> a -> a
*(-a
1)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (Fractional a, Real a) => Pattern a
saw2

-- | @tri@ - unipolar triangle wave. A pattern of continuous values
-- following a triangle wave with frequency of one cycle, and amplitude from
-- 0 to 1.
tri :: (Fractional a, Real a) => Pattern a
tri :: forall a. (Fractional a, Real a) => Pattern a
tri = forall a. Pattern a -> Pattern a -> Pattern a
fastAppend forall a. (Fractional a, Real a) => Pattern a
saw forall a. (Fractional a, Real a) => Pattern a
isaw

-- | @tri2@ - bipolar triangle wave. A pattern of continuous values
-- following a triangle wave with frequency of one cycle, and amplitude from
-- -1 to 1.
tri2 :: (Fractional a, Real a) => Pattern a
tri2 :: forall a. (Fractional a, Real a) => Pattern a
tri2 = forall a. Pattern a -> Pattern a -> Pattern a
fastAppend forall a. (Fractional a, Real a) => Pattern a
saw2 forall a. (Fractional a, Real a) => Pattern a
isaw2

-- | @square@ - unipolar square wave. A pattern of continuous values
-- following a square wave with frequency of one cycle, and amplitude from
-- 0 to 1.
-- | @square@ is like 'sine', for square waves.
square :: (Fractional a) => Pattern a
square :: forall a. Fractional a => Pattern a
square = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$
       \Rational
t -> forall a b. (Integral a, Num b) => a -> b
fromIntegral ((forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ forall a. Real a => a -> a -> a
mod' (forall a. Fractional a => Rational -> a
fromRational Rational
t :: Double) Double
1 forall a. Num a => a -> a -> a
* Double
2) :: Integer)

-- | @square2@ - bipolar square wave. A pattern of continuous values
-- following a square wave with frequency of one cycle, and amplitude from
-- -1 to 1.
square2 :: (Fractional a) => Pattern a
square2 :: forall a. Fractional a => Pattern a
square2 = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$
       \Rational
t -> forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a b. (RealFrac a, Integral b) => a -> b
floor (forall a. Real a => a -> a -> a
mod' (forall a. Fractional a => Rational -> a
fromRational Rational
t :: Double) Double
1 forall a. Num a => a -> a -> a
* Double
2) forall a. Num a => a -> a -> a
* Integer
2 forall a. Num a => a -> a -> a
- Integer
1 :: Integer)

-- | @envL@ is a 'Pattern' of continuous 'Double' values, representing
-- a linear interpolation between 0 and 1 during the first cycle, then
-- staying constant at 1 for all following cycles. Possibly only
-- useful if you're using something like the retrig function defined
-- in tidal.el.
envL :: Pattern Double
envL :: Pattern Double
envL = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> forall a. Ord a => a -> a -> a
max Double
0 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min (forall a. Fractional a => Rational -> a
fromRational Rational
t) Double
1

-- | like 'envL' but reversed.
envLR :: Pattern Double
envLR :: Pattern Double
envLR = (Double
1forall a. Num a => a -> a -> a
-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern Double
envL

-- | 'Equal power' version of 'env', for gain-based transitions
envEq :: Pattern Double
envEq :: Pattern Double
envEq = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> forall a. Floating a => a -> a
sqrt (forall a. Floating a => a -> a
sin (forall a. Floating a => a
piforall a. Fractional a => a -> a -> a
/Double
2 forall a. Num a => a -> a -> a
* forall a. Ord a => a -> a -> a
max Double
0 (forall a. Ord a => a -> a -> a
min (forall a. Fractional a => Rational -> a
fromRational (Rational
1forall a. Num a => a -> a -> a
-Rational
t)) Double
1)))

-- | Equal power reversed
envEqR :: Pattern Double
envEqR :: Pattern Double
envEqR = forall a. (Rational -> a) -> Pattern a
sig forall a b. (a -> b) -> a -> b
$ \Rational
t -> forall a. Floating a => a -> a
sqrt (forall a. Floating a => a -> a
cos (forall a. Floating a => a
piforall a. Fractional a => a -> a -> a
/Double
2 forall a. Num a => a -> a -> a
* forall a. Ord a => a -> a -> a
max Double
0 (forall a. Ord a => a -> a -> a
min (forall a. Fractional a => Rational -> a
fromRational (Rational
1forall a. Num a => a -> a -> a
-Rational
t)) Double
1)))

-- ** Pattern algebra

-- class for types that support a left-biased union
class Unionable a where
  union :: a -> a -> a

-- default union is just to take the left hand side..
instance Unionable a where
  union :: a -> a -> a
union = forall a b. a -> b -> a
const

instance {-# OVERLAPPING #-} Unionable ValueMap where
  union :: ValueMap -> ValueMap -> ValueMap
union = forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union

(|+|) :: (Applicative a, Num b) => a b -> a b -> a b
a b
a |+| :: forall (a :: * -> *) b. (Applicative a, Num b) => a b -> a b -> a b
|+| a b
b = forall a. Num a => a -> a -> a
(+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|+ ) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |+ :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
|+  Pattern a
b = forall a. Num a => a -> a -> a
(+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( +|) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  +| :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
+| Pattern a
b = forall a. Num a => a -> a -> a
(+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||+) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||+ :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
||+ Pattern a
b = forall a. Num a => a -> a -> a
(+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b


(|++|) :: Applicative a => a String -> a String -> a String
a String
a |++| :: forall (a :: * -> *).
Applicative a =>
a String -> a String -> a String
|++| a String
b = forall a. [a] -> [a] -> [a]
(++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a String
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a String
b
(|++ ) :: Pattern String -> Pattern String -> Pattern String
Pattern String
a |++ :: Pattern String -> Pattern String -> Pattern String
|++  Pattern String
b = forall a. [a] -> [a] -> [a]
(++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern String
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern String
b
( ++|) :: Pattern String -> Pattern String -> Pattern String
Pattern String
a  ++| :: Pattern String -> Pattern String -> Pattern String
++| Pattern String
b = forall a. [a] -> [a] -> [a]
(++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern String
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern String
b
(||++) :: Pattern String -> Pattern String -> Pattern String
Pattern String
a ||++ :: Pattern String -> Pattern String -> Pattern String
||++ Pattern String
b = forall a. [a] -> [a] -> [a]
(++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern String
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern String
b

(|/|) :: (Applicative a, Fractional b) => a b -> a b -> a b
a b
a |/| :: forall (a :: * -> *) b.
(Applicative a, Fractional b) =>
a b -> a b -> a b
|/| a b
b = forall a. Fractional a => a -> a -> a
(/) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|/ ) :: Fractional a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |/ :: forall a. Fractional a => Pattern a -> Pattern a -> Pattern a
|/  Pattern a
b = forall a. Fractional a => a -> a -> a
(/) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( /|) :: Fractional a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  /| :: forall a. Fractional a => Pattern a -> Pattern a -> Pattern a
/| Pattern a
b = forall a. Fractional a => a -> a -> a
(/) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||/) :: Fractional a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||/ :: forall a. Fractional a => Pattern a -> Pattern a -> Pattern a
||/ Pattern a
b = forall a. Fractional a => a -> a -> a
(/) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|*|) :: (Applicative a, Num b) => a b -> a b -> a b
a b
a |*| :: forall (a :: * -> *) b. (Applicative a, Num b) => a b -> a b -> a b
|*| a b
b = forall a. Num a => a -> a -> a
(*) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|* ) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |* :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
|*  Pattern a
b = forall a. Num a => a -> a -> a
(*) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( *|) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  *| :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
*| Pattern a
b = forall a. Num a => a -> a -> a
(*) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||*) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||* :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
||* Pattern a
b = forall a. Num a => a -> a -> a
(*) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|-|) :: (Applicative a, Num b) => a b -> a b -> a b
a b
a |-| :: forall (a :: * -> *) b. (Applicative a, Num b) => a b -> a b -> a b
|-| a b
b = (-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|- ) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |- :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
|-  Pattern a
b = (-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( -|) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  -| :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
-| Pattern a
b = (-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||-) :: Num a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||- :: forall a. Num a => Pattern a -> Pattern a -> Pattern a
||- Pattern a
b = (-) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|%|) :: (Applicative a, Moddable b) => a b -> a b -> a b
a b
a |%| :: forall (a :: * -> *) b.
(Applicative a, Moddable b) =>
a b -> a b -> a b
|%| a b
b = forall a. Moddable a => a -> a -> a
gmod forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|% ) :: Moddable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |% :: forall a. Moddable a => Pattern a -> Pattern a -> Pattern a
|%  Pattern a
b = forall a. Moddable a => a -> a -> a
gmod forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( %|) :: Moddable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  %| :: forall a. Moddable a => Pattern a -> Pattern a -> Pattern a
%| Pattern a
b = forall a. Moddable a => a -> a -> a
gmod forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||%) :: Moddable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||% :: forall a. Moddable a => Pattern a -> Pattern a -> Pattern a
||% Pattern a
b = forall a. Moddable a => a -> a -> a
gmod forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|**|) :: (Applicative a, Floating b) => a b -> a b -> a b
a b
a |**| :: forall (a :: * -> *) b.
(Applicative a, Floating b) =>
a b -> a b -> a b
|**| a b
b = forall a. Floating a => a -> a -> a
(**) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|** ) :: Floating a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |** :: forall a. Floating a => Pattern a -> Pattern a -> Pattern a
|**  Pattern a
b = forall a. Floating a => a -> a -> a
(**) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( **|) :: Floating a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  **| :: forall a. Floating a => Pattern a -> Pattern a -> Pattern a
**| Pattern a
b = forall a. Floating a => a -> a -> a
(**) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||**) :: Floating a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||** :: forall a. Floating a => Pattern a -> Pattern a -> Pattern a
||** Pattern a
b = forall a. Floating a => a -> a -> a
(**) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|>|) :: (Applicative a, Unionable b) => a b -> a b -> a b
a b
a |>| :: forall (a :: * -> *) b.
(Applicative a, Unionable b) =>
a b -> a b -> a b
|>| a b
b = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|> ) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |> :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
|>  Pattern a
b = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( >|) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  >| :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
>| Pattern a
b = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||>) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||> :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
||> Pattern a
b = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

(|<|) :: (Applicative a, Unionable b) => a b -> a b -> a b
a b
a |<| :: forall (a :: * -> *) b.
(Applicative a, Unionable b) =>
a b -> a b -> a b
|<| a b
b = forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a b
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a b
b
(|< ) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a |< :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
|<  Pattern a
b = forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<* Pattern a
b
( <|) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a  <| :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
<| Pattern a
b = forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
*> Pattern a
b
(||<) :: Unionable a => Pattern a -> Pattern a -> Pattern a
Pattern a
a ||< :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
||< Pattern a
b = forall a. Unionable a => a -> a -> a
union forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern a
a forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
<<* Pattern a
b

-- Backward compatibility - structure from left, values from right.
(#) :: Unionable b => Pattern b -> Pattern b -> Pattern b
# :: forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
(#) = forall a. Unionable a => Pattern a -> Pattern a -> Pattern a
(|>)



-- ** Constructing patterns

-- | Turns a list of values into a pattern, playing one of them per cycle.
fromList :: [a] -> Pattern a
fromList :: forall a. [a] -> Pattern a
fromList = forall a. [Pattern a] -> Pattern a
cat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Turns a list of values into a pattern, playing all of them per cycle.
fastFromList :: [a] -> Pattern a
fastFromList :: forall a. [a] -> Pattern a
fastFromList = forall a. [Pattern a] -> Pattern a
fastcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | A synonym for 'fastFromList'
listToPat :: [a] -> Pattern a
listToPat :: forall a. [a] -> Pattern a
listToPat = forall a. [a] -> Pattern a
fastFromList

-- | 'fromMaybes; is similar to 'fromList', but allows values to
-- be optional using the 'Maybe' type, so that 'Nothing' results in
-- gaps in the pattern.
fromMaybes :: [Maybe a] -> Pattern a
fromMaybes :: forall a. [Maybe a] -> Pattern a
fromMaybes = forall a. [Pattern a] -> Pattern a
fastcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall {a}. Maybe a -> Pattern a
f
  where f :: Maybe a -> Pattern a
f Maybe a
Nothing = forall a. Pattern a
silence
        f (Just a
x) = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x

-- | A pattern of whole numbers from 0 to the given number, in a single cycle.
run :: (Enum a, Num a) => Pattern a -> Pattern a
run :: forall a. (Enum a, Num a) => Pattern a -> Pattern a
run = (forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. (Enum a, Num a) => a -> Pattern a
_run)

_run :: (Enum a, Num a) => a -> Pattern a
_run :: forall a. (Enum a, Num a) => a -> Pattern a
_run a
n = forall a. [a] -> Pattern a
fastFromList [a
0 .. a
nforall a. Num a => a -> a -> a
-a
1]

-- | From @1@ for the first cycle, successively adds a number until it gets up to @n@
scan :: (Enum a, Num a) => Pattern a -> Pattern a
scan :: forall a. (Enum a, Num a) => Pattern a -> Pattern a
scan = (forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. (Enum a, Num a) => a -> Pattern a
_scan)

_scan :: (Enum a, Num a) => a -> Pattern a
_scan :: forall a. (Enum a, Num a) => a -> Pattern a
_scan a
n = forall a. [Pattern a] -> Pattern a
slowcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. (Enum a, Num a) => a -> Pattern a
_run [a
1 .. a
n]

-- ** Combining patterns

-- | Alternate between cycles of the two given patterns
append :: Pattern a -> Pattern a -> Pattern a
append :: forall a. Pattern a -> Pattern a -> Pattern a
append Pattern a
a Pattern a
b = forall a. [Pattern a] -> Pattern a
cat [Pattern a
a,Pattern a
b]

-- | Like 'append', but for a list of patterns. Interlaces them, playing the first cycle from each
-- in turn, then the second cycle from each, and so on.
cat :: [Pattern a] -> Pattern a
cat :: forall a. [Pattern a] -> Pattern a
cat [] = forall a. Pattern a
silence
cat [Pattern a]
ps = forall a. (State -> [Event a]) -> Pattern a
Pattern State -> [Event a]
q
  where n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Pattern a]
ps
        q :: State -> [Event a]
q State
st = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (State -> ArcF Rational -> [Event a]
f State
st) forall a b. (a -> b) -> a -> b
$ ArcF Rational -> [ArcF Rational]
arcCyclesZW (State -> ArcF Rational
arc State
st)
        f :: State -> ArcF Rational -> [Event a]
f State
st ArcF Rational
a = forall a. Pattern a -> State -> [Event a]
query (forall a. (Rational -> Rational) -> Pattern a -> Pattern a
withResultTime (forall a. Num a => a -> a -> a
+Rational
offset) Pattern a
p) forall a b. (a -> b) -> a -> b
$ State
st {arc :: ArcF Rational
arc = forall a. a -> a -> ArcF a
Arc (forall a. Num a => a -> a -> a
subtract Rational
offset (forall a. ArcF a -> a
start ArcF Rational
a)) (forall a. Num a => a -> a -> a
subtract Rational
offset (forall a. ArcF a -> a
stop ArcF Rational
a))}
          where p :: Pattern a
p = [Pattern a]
ps forall a. [a] -> Int -> a
!! Int
i
                cyc :: Int
cyc = (forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ forall a. ArcF a -> a
start ArcF Rational
a) :: Int
                i :: Int
i = Int
cyc forall a. Integral a => a -> a -> a
`mod` Int
n
                offset :: Rational
offset = (forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int
cyc forall a. Num a => a -> a -> a
- ((Int
cyc forall a. Num a => a -> a -> a
- Int
i) forall a. Integral a => a -> a -> a
`div` Int
n)) :: Time

-- | Alias for 'cat'
slowCat :: [Pattern a] -> Pattern a
slowCat :: forall a. [Pattern a] -> Pattern a
slowCat = forall a. [Pattern a] -> Pattern a
cat
slowcat :: [Pattern a] -> Pattern a
slowcat :: forall a. [Pattern a] -> Pattern a
slowcat = forall a. [Pattern a] -> Pattern a
slowCat

-- | Alias for 'append'
slowAppend :: Pattern a -> Pattern a -> Pattern a
slowAppend :: forall a. Pattern a -> Pattern a -> Pattern a
slowAppend = forall a. Pattern a -> Pattern a -> Pattern a
append
slowappend :: Pattern a -> Pattern a -> Pattern a
slowappend :: forall a. Pattern a -> Pattern a -> Pattern a
slowappend = forall a. Pattern a -> Pattern a -> Pattern a
append

-- | Like 'append', but twice as fast
fastAppend :: Pattern a -> Pattern a -> Pattern a
fastAppend :: forall a. Pattern a -> Pattern a -> Pattern a
fastAppend Pattern a
a Pattern a
b = forall a. Rational -> Pattern a -> Pattern a
_fast Rational
2 forall a b. (a -> b) -> a -> b
$ forall a. Pattern a -> Pattern a -> Pattern a
append Pattern a
a Pattern a
b
fastappend :: Pattern a -> Pattern a -> Pattern a
fastappend :: forall a. Pattern a -> Pattern a -> Pattern a
fastappend = forall a. Pattern a -> Pattern a -> Pattern a
fastAppend

-- | The same as 'cat', but speeds up the result by the number of
-- patterns there are, so the cycles from each are squashed to fit a
-- single cycle.
fastCat :: [Pattern a] -> Pattern a
fastCat :: forall a. [Pattern a] -> Pattern a
fastCat [Pattern a]
ps = forall a. Rational -> Pattern a -> Pattern a
_fast (forall a. Real a => a -> Rational
toTime forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [Pattern a]
ps) forall a b. (a -> b) -> a -> b
$ forall a. [Pattern a] -> Pattern a
cat [Pattern a]
ps

-- | Alias for @fastCat@
fastcat :: [Pattern a] -> Pattern a
fastcat :: forall a. [Pattern a] -> Pattern a
fastcat = forall a. [Pattern a] -> Pattern a
fastCat

-- | Similar to @fastCat@, but each pattern is given a relative duration
timeCat :: [(Time, Pattern a)] -> Pattern a
timeCat :: forall a. [(Rational, Pattern a)] -> Pattern a
timeCat [(Rational, Pattern a)]
tps = forall a. [Pattern a] -> Pattern a
stack forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(Rational
s,Rational
e,Pattern a
p) -> forall a. ArcF Rational -> Pattern a -> Pattern a
compressArc (forall a. a -> a -> ArcF a
Arc (Rational
sforall a. Fractional a => a -> a -> a
/Rational
total) (Rational
eforall a. Fractional a => a -> a -> a
/Rational
total)) Pattern a
p) forall a b. (a -> b) -> a -> b
$ forall a.
Rational
-> [(Rational, Pattern a)] -> [(Rational, Rational, Pattern a)]
arrange Rational
0 [(Rational, Pattern a)]
tps
    where total :: Rational
total = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Rational, Pattern a)]
tps
          arrange :: Time -> [(Time, Pattern a)] -> [(Time, Time, Pattern a)]
          arrange :: forall a.
Rational
-> [(Rational, Pattern a)] -> [(Rational, Rational, Pattern a)]
arrange Rational
_ [] = []
          arrange Rational
t ((Rational
t',Pattern a
p):[(Rational, Pattern a)]
tps') = (Rational
t,Rational
tforall a. Num a => a -> a -> a
+Rational
t',Pattern a
p) forall a. a -> [a] -> [a]
: forall a.
Rational
-> [(Rational, Pattern a)] -> [(Rational, Rational, Pattern a)]
arrange (Rational
tforall a. Num a => a -> a -> a
+Rational
t') [(Rational, Pattern a)]
tps'

-- | Alias for @timeCat@
timecat :: [(Time, Pattern a)] -> Pattern a
timecat :: forall a. [(Rational, Pattern a)] -> Pattern a
timecat = forall a. [(Rational, Pattern a)] -> Pattern a
timeCat

-- | 'overlay' combines two 'Pattern's into a new pattern, so that
-- their events are combined over time. 
overlay :: Pattern a -> Pattern a -> Pattern a
overlay :: forall a. Pattern a -> Pattern a -> Pattern a
overlay = forall a. Semigroup a => a -> a -> a
(<>)

-- | 'stack' combines a list of 'Pattern's into a new pattern, so that
-- their events are combined over time.
stack :: [Pattern a] -> Pattern a
stack :: forall a. [Pattern a] -> Pattern a
stack = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a. Pattern a -> Pattern a -> Pattern a
overlay forall a. Pattern a
silence

-- ** Manipulating time

-- | Shifts a pattern back in time by the given amount, expressed in cycles
(<~) :: Pattern Time -> Pattern a -> Pattern a
<~ :: forall a. Pattern Rational -> Pattern a -> Pattern a
(<~) = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Rational -> Pattern a -> Pattern a
rotL

-- | Shifts a pattern forward in time by the given amount, expressed in cycles
(~>) :: Pattern Time -> Pattern a -> Pattern a
~> :: forall a. Pattern Rational -> Pattern a -> Pattern a
(~>) = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Rational -> Pattern a -> Pattern a
rotR

-- | Speed up a pattern by the given time pattern
fast :: Pattern Time -> Pattern a -> Pattern a
fast :: forall a. Pattern Rational -> Pattern a -> Pattern a
fast = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Rational -> Pattern a -> Pattern a
_fast

-- | Slow down a pattern by the factors in the given time pattern, 'squeezing'
-- the pattern to fit the slot given in the time pattern
fastSqueeze :: Pattern Time -> Pattern a -> Pattern a
fastSqueeze :: forall a. Pattern Rational -> Pattern a -> Pattern a
fastSqueeze = forall a b c.
(a -> Pattern b -> Pattern c)
-> Pattern a -> Pattern b -> Pattern c
tParamSqueeze forall a. Rational -> Pattern a -> Pattern a
_fast

-- | An alias for @fast@
density :: Pattern Time -> Pattern a -> Pattern a
density :: forall a. Pattern Rational -> Pattern a -> Pattern a
density = forall a. Pattern Rational -> Pattern a -> Pattern a
fast

_fast :: Time -> Pattern a -> Pattern a
_fast :: forall a. Rational -> Pattern a -> Pattern a
_fast Rational
rate Pattern a
pat | Rational
rate forall a. Eq a => a -> a -> Bool
== Rational
0 = forall a. Pattern a
silence
               | Rational
rate forall a. Ord a => a -> a -> Bool
< Rational
0 = forall a. Pattern a -> Pattern a
rev forall a b. (a -> b) -> a -> b
$ forall a. Rational -> Pattern a -> Pattern a
_fast (forall a. Num a => a -> a
negate Rational
rate) Pattern a
pat
               | Bool
otherwise = forall a. (Rational -> Rational) -> Pattern a -> Pattern a
withResultTime (forall a. Fractional a => a -> a -> a
/ Rational
rate) forall a b. (a -> b) -> a -> b
$ forall a. (Rational -> Rational) -> Pattern a -> Pattern a
withQueryTime (forall a. Num a => a -> a -> a
* Rational
rate) Pattern a
pat

-- | Slow down a pattern by the given time pattern
slow :: Pattern Time -> Pattern a -> Pattern a
slow :: forall a. Pattern Rational -> Pattern a -> Pattern a
slow = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Rational -> Pattern a -> Pattern a
_slow
_slow :: Time -> Pattern a -> Pattern a
_slow :: forall a. Rational -> Pattern a -> Pattern a
_slow Rational
0 Pattern a
_ = forall a. Pattern a
silence
_slow Rational
r Pattern a
p = forall a. Rational -> Pattern a -> Pattern a
_fast (Rational
1forall a. Fractional a => a -> a -> a
/Rational
r) Pattern a
p

-- | Slow down a pattern by the factors in the given time pattern, 'squeezing'
-- the pattern to fit the slot given in the time pattern
slowSqueeze :: Pattern Time -> Pattern a -> Pattern a
slowSqueeze :: forall a. Pattern Rational -> Pattern a -> Pattern a
slowSqueeze = forall a b c.
(a -> Pattern b -> Pattern c)
-> Pattern a -> Pattern b -> Pattern c
tParamSqueeze forall a. Rational -> Pattern a -> Pattern a
_slow

-- | An alias for @slow@
sparsity :: Pattern Time -> Pattern a -> Pattern a
sparsity :: forall a. Pattern Rational -> Pattern a -> Pattern a
sparsity = forall a. Pattern Rational -> Pattern a -> Pattern a
slow

-- | @rev p@ returns @p@ with the event positions in each cycle
-- reversed (or mirrored).
rev :: Pattern a -> Pattern a
rev :: forall a. Pattern a -> Pattern a
rev Pattern a
p =
  forall a. Pattern a -> Pattern a
splitQueries forall a b. (a -> b) -> a -> b
$ Pattern a
p {
    query :: State -> [Event a]
query = \State
st -> forall a b. (a -> b) -> [a] -> [b]
map forall a. Event a -> Event a
makeWholeAbsolute forall a b. (a -> b) -> a -> b
$
      forall a.
(ArcF Rational -> ArcF Rational) -> [Event a] -> [Event a]
mapParts (Rational -> ArcF Rational -> ArcF Rational
mirrorArc (ArcF Rational -> Rational
midCycle forall a b. (a -> b) -> a -> b
$ State -> ArcF Rational
arc State
st)) forall a b. (a -> b) -> a -> b
$
      forall a b. (a -> b) -> [a] -> [b]
map forall a. Event a -> Event a
makeWholeRelative
      (forall a. Pattern a -> State -> [Event a]
query Pattern a
p State
st
        {arc :: ArcF Rational
arc = Rational -> ArcF Rational -> ArcF Rational
mirrorArc (ArcF Rational -> Rational
midCycle forall a b. (a -> b) -> a -> b
$ State -> ArcF Rational
arc State
st) (State -> ArcF Rational
arc State
st)
        })
    }
  where makeWholeRelative :: Event a -> Event a
        makeWholeRelative :: forall a. Event a -> Event a
makeWholeRelative e :: Event a
e@Event {whole :: forall a b. EventF a b -> Maybe a
whole = Maybe (ArcF Rational)
Nothing} = Event a
e
        makeWholeRelative (Event Context
c (Just (Arc Rational
s Rational
e)) p' :: ArcF Rational
p'@(Arc Rational
s' Rational
e') a
v) =
          forall a b. Context -> Maybe a -> a -> b -> EventF a b
Event Context
c (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> ArcF a
Arc (Rational
s'forall a. Num a => a -> a -> a
-Rational
s) (Rational
eforall a. Num a => a -> a -> a
-Rational
e')) ArcF Rational
p' a
v
        makeWholeAbsolute :: Event a -> Event a
        makeWholeAbsolute :: forall a. Event a -> Event a
makeWholeAbsolute e :: Event a
e@Event {whole :: forall a b. EventF a b -> Maybe a
whole = Maybe (ArcF Rational)
Nothing} = Event a
e
        makeWholeAbsolute (Event Context
c (Just (Arc Rational
s Rational
e)) p' :: ArcF Rational
p'@(Arc Rational
s' Rational
e') a
v) =
          forall a b. Context -> Maybe a -> a -> b -> EventF a b
Event Context
c (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> ArcF a
Arc (Rational
s'forall a. Num a => a -> a -> a
-Rational
e) (Rational
e'forall a. Num a => a -> a -> a
+Rational
s)) ArcF Rational
p' a
v
        midCycle :: Arc -> Time
        midCycle :: ArcF Rational -> Rational
midCycle (Arc Rational
s Rational
_) = Rational -> Rational
sam Rational
s forall a. Num a => a -> a -> a
+ Rational
0.5
        mapParts :: (Arc -> Arc) -> [Event a] -> [Event a]
        mapParts :: forall a.
(ArcF Rational -> ArcF Rational) -> [Event a] -> [Event a]
mapParts ArcF Rational -> ArcF Rational
f [Event a]
es = (\(Event Context
c Maybe (ArcF Rational)
w ArcF Rational
p' a
v) -> forall a b. Context -> Maybe a -> a -> b -> EventF a b
Event Context
c Maybe (ArcF Rational)
w (ArcF Rational -> ArcF Rational
f ArcF Rational
p') a
v) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Event a]
es
        -- | Returns the `mirror image' of a 'Arc' around the given point in time
        mirrorArc :: Time -> Arc -> Arc
        mirrorArc :: Rational -> ArcF Rational -> ArcF Rational
mirrorArc Rational
mid' (Arc Rational
s Rational
e) = forall a. a -> a -> ArcF a
Arc (Rational
mid' forall a. Num a => a -> a -> a
- (Rational
eforall a. Num a => a -> a -> a
-Rational
mid')) (Rational
mid'forall a. Num a => a -> a -> a
+(Rational
mid'forall a. Num a => a -> a -> a
-Rational
s))

{- | Plays a portion of a pattern, specified by a time arc (start and end time).
The new resulting pattern is played over the time period of the original pattern:

@
d1 $ zoom (0.25, 0.75) $ sound "bd*2 hh*3 [sn bd]*2 drum"
@

In the pattern above, `zoom` is used with an arc from 25% to 75%. It is equivalent to this pattern:

@
d1 $ sound "hh*3 [sn bd]*2"
@
-}
zoom :: (Time, Time) -> Pattern a -> Pattern a
zoom :: forall a. (Rational, Rational) -> Pattern a -> Pattern a
zoom (Rational
s,Rational
e) = forall a. ArcF Rational -> Pattern a -> Pattern a
zoomArc (forall a. a -> a -> ArcF a
Arc Rational
s Rational
e)

zoomArc :: Arc -> Pattern a -> Pattern a
zoomArc :: forall a. ArcF Rational -> Pattern a -> Pattern a
zoomArc (Arc Rational
s Rational
e) Pattern a
p = forall a. Pattern a -> Pattern a
splitQueries forall a b. (a -> b) -> a -> b
$
  forall a.
(ArcF Rational -> ArcF Rational) -> Pattern a -> Pattern a
withResultArc ((Rational -> Rational) -> ArcF Rational -> ArcF Rational
mapCycle ((forall a. Fractional a => a -> a -> a
/Rational
d) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => a -> a -> a
subtract Rational
s)) forall a b. (a -> b) -> a -> b
$ forall a.
(ArcF Rational -> ArcF Rational) -> Pattern a -> Pattern a
withQueryArc ((Rational -> Rational) -> ArcF Rational -> ArcF Rational
mapCycle ((forall a. Num a => a -> a -> a
+Rational
s) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
*Rational
d))) Pattern a
p
     where d :: Rational
d = Rational
eforall a. Num a => a -> a -> a
-Rational
s

-- | @fastGap@ is similar to 'fast' but maintains its cyclic
-- alignment. For example, @fastGap 2 p@ would squash the events in
-- pattern @p@ into the first half of each cycle (and the second
-- halves would be empty). The factor should be at least 1
fastGap :: Pattern Time -> Pattern a -> Pattern a
fastGap :: forall a. Pattern Rational -> Pattern a -> Pattern a
fastGap = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Rational -> Pattern a -> Pattern a
_fastGap

-- | An alias for @fastGap@
densityGap :: Pattern Time -> Pattern a -> Pattern a
densityGap :: forall a. Pattern Rational -> Pattern a -> Pattern a
densityGap = forall a. Pattern Rational -> Pattern a -> Pattern a
fastGap

compress :: (Time,Time) -> Pattern a -> Pattern a
compress :: forall a. (Rational, Rational) -> Pattern a -> Pattern a
compress (Rational
s,Rational
e) = forall a. ArcF Rational -> Pattern a -> Pattern a
compressArc (forall a. a -> a -> ArcF a
Arc Rational
s Rational
e)

compressTo :: (Time,Time) -> Pattern a -> Pattern a
compressTo :: forall a. (Rational, Rational) -> Pattern a -> Pattern a
compressTo (Rational
s,Rational
e) = forall a. ArcF Rational -> Pattern a -> Pattern a
compressArcTo (forall a. a -> a -> ArcF a
Arc Rational
s Rational
e)

repeatCycles :: Pattern Int -> Pattern a -> Pattern a
repeatCycles :: forall a. Pattern Int -> Pattern a -> Pattern a
repeatCycles = forall t1 t2 a.
(t1 -> t2 -> Pattern a) -> Pattern t1 -> t2 -> Pattern a
tParam forall a. Int -> Pattern a -> Pattern a
_repeatCycles

_repeatCycles :: Int -> Pattern a -> Pattern a
_repeatCycles :: forall a. Int -> Pattern a -> Pattern a
_repeatCycles Int
n Pattern a
p = forall a. [Pattern a] -> Pattern a
cat (forall a. Int -> a -> [a]
replicate Int
n Pattern a
p)

fastRepeatCycles :: Int -> Pattern a -> Pattern a
fastRepeatCycles :: forall a. Int -> Pattern a -> Pattern a
fastRepeatCycles Int
n Pattern a
p = forall a. [Pattern a] -> Pattern a
cat (forall a. Int -> a -> [a]
replicate Int
n Pattern a
p)

-- | * Higher order functions

-- | Functions which work on other functions (higher order functions)

-- | @every n f p@ applies the function @f@ to @p@, but only affects
-- every @n@ cycles.
every :: Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
every :: forall a.
Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
every Pattern Int
tp Pattern a -> Pattern a
f Pattern a
p = forall a. Pattern (Pattern a) -> Pattern a
innerJoin forall a b. (a -> b) -> a -> b
$ (\Int
t -> forall a. Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every Int
t Pattern a -> Pattern a
f Pattern a
p) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern Int
tp

_every :: Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every :: forall a. Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every Int
0 Pattern a -> Pattern a
_ Pattern a
p = Pattern a
p
_every Int
n Pattern a -> Pattern a
f Pattern a
p = forall a.
(Int -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
when ((forall a. Eq a => a -> a -> Bool
== Int
0) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Integral a => a -> a -> a
`mod` Int
n)) Pattern a -> Pattern a
f Pattern a
p

-- | @every n o f'@ is like @every n f@ with an offset of @o@ cycles
every' :: Pattern Int -> Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
every' :: forall a.
Pattern Int
-> Pattern Int
-> (Pattern a -> Pattern a)
-> Pattern a
-> Pattern a
every' Pattern Int
np Pattern Int
op Pattern a -> Pattern a
f Pattern a
p = do { Int
n <- Pattern Int
np; Int
o <- Pattern Int
op; forall a.
Int -> Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every' Int
n Int
o Pattern a -> Pattern a
f Pattern a
p }

_every' :: Int -> Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every' :: forall a.
Int -> Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
_every' Int
n Int
o = forall a.
(Int -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
when ((forall a. Eq a => a -> a -> Bool
== Int
o) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Integral a => a -> a -> a
`mod` Int
n))

-- | @foldEvery ns f p@ applies the function @f@ to @p@, and is applied for
-- each cycle in @ns@.
foldEvery :: [Int] -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
foldEvery :: forall a.
[Int] -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
foldEvery [Int]
ns Pattern a -> Pattern a
f Pattern a
p = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
`_every` Pattern a -> Pattern a
f) Pattern a
p [Int]
ns

{-|
Only `when` the given test function returns `True` the given pattern
transformation is applied. The test function will be called with the
current cycle as a number.

@
d1 $ when ((elem '4').show)
  (striate 4)
  $ sound "hh hc"
@

The above will only apply `striate 4` to the pattern if the current
cycle number contains the number 4. So the fourth cycle will be
striated and the fourteenth and so on. Expect lots of striates after
cycle number 399.
-}
when :: (Int -> Bool) -> (Pattern a -> Pattern a) ->  Pattern a -> Pattern a
when :: forall a.
(Int -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
when Int -> Bool
test Pattern a -> Pattern a
f Pattern a
p = forall a. Pattern a -> Pattern a
splitQueries forall a b. (a -> b) -> a -> b
$ Pattern a
p {query :: State -> [Event a]
query = State -> [Event a]
apply}
  where apply :: State -> [Event a]
apply State
st | Int -> Bool
test (forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ forall a. ArcF a -> a
start forall a b. (a -> b) -> a -> b
$ State -> ArcF Rational
arc State
st) = forall a. Pattern a -> State -> [Event a]
query (Pattern a -> Pattern a
f Pattern a
p) State
st
                 | Bool
otherwise = forall a. Pattern a -> State -> [Event a]
query Pattern a
p State
st

-- | Like 'when', but works on continuous time values rather than cycle numbers.
whenT :: (Time -> Bool) -> (Pattern a -> Pattern a) ->  Pattern a -> Pattern a
whenT :: forall a.
(Rational -> Bool)
-> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
whenT Rational -> Bool
test Pattern a -> Pattern a
f Pattern a
p = forall a. Pattern a -> Pattern a
splitQueries forall a b. (a -> b) -> a -> b
$ Pattern a
p {query :: State -> [Event a]
query = State -> [Event a]
apply}
  where apply :: State -> [Event a]
apply State
st | Rational -> Bool
test (forall a. ArcF a -> a
start forall a b. (a -> b) -> a -> b
$ State -> ArcF Rational
arc State
st) = forall a. Pattern a -> State -> [Event a]
query (Pattern a -> Pattern a
f Pattern a
p) State
st
                 | Bool
otherwise = forall a. Pattern a -> State -> [Event a]
query Pattern a
p State
st

_getP_ :: (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP_ :: forall a. (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP_ Value -> Maybe a
f Pattern Value
pat = forall a. Pattern (Maybe a) -> Pattern a
filterJust forall a b. (a -> b) -> a -> b
$ Value -> Maybe a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern Value
pat

_getP :: a -> (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP :: forall a. a -> (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP a
d Value -> Maybe a
f Pattern Value
pat = forall a. a -> Maybe a -> a
fromMaybe a
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Maybe a
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern Value
pat

_cX :: a -> (Value -> Maybe a) -> String -> Pattern a
_cX :: forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX a
d Value -> Maybe a
f String
s = forall a. (State -> [Event a]) -> Pattern a
Pattern forall a b. (a -> b) -> a -> b
$ \(State ArcF Rational
a ValueMap
m) -> forall a. Pattern a -> ArcF Rational -> [Event a]
queryArc (forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: * -> *) a. Applicative f => a -> f a
pure a
d) (forall a. a -> (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP a
d Value -> Maybe a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Pattern Value
valueToPattern) forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
s ValueMap
m) ArcF Rational
a

_cX_ :: (Value -> Maybe a) -> String -> Pattern a
_cX_ :: forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe a
f String
s = forall a. (State -> [Event a]) -> Pattern a
Pattern forall a b. (a -> b) -> a -> b
$ \(State ArcF Rational
a ValueMap
m) -> forall a. Pattern a -> ArcF Rational -> [Event a]
queryArc (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Pattern a
silence (forall a. (Value -> Maybe a) -> Pattern Value -> Pattern a
_getP_ Value -> Maybe a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Pattern Value
valueToPattern) forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
s ValueMap
m) ArcF Rational
a

cF :: Double -> String -> Pattern Double
cF :: Double -> String -> Pattern Double
cF Double
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Double
d Value -> Maybe Double
getF
cF_ :: String -> Pattern Double
cF_ :: String -> Pattern Double
cF_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe Double
getF
cF0 :: String -> Pattern Double
cF0 :: String -> Pattern Double
cF0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Double
0 Value -> Maybe Double
getF

cN :: Note -> String -> Pattern Note
cN :: Note -> String -> Pattern Note
cN Note
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Note
d Value -> Maybe Note
getN
cN_ :: String -> Pattern Note
cN_ :: String -> Pattern Note
cN_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe Note
getN
cN0 :: String -> Pattern Note
cN0 :: String -> Pattern Note
cN0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX (Double -> Note
Note Double
0) Value -> Maybe Note
getN

cI :: Int -> String -> Pattern Int
cI :: Int -> String -> Pattern Int
cI Int
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Int
d Value -> Maybe Int
getI
cI_ :: String -> Pattern Int
cI_ :: String -> Pattern Int
cI_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe Int
getI
cI0 :: String -> Pattern Int
cI0 :: String -> Pattern Int
cI0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Int
0 Value -> Maybe Int
getI

cB :: Bool -> String -> Pattern Bool
cB :: Bool -> String -> Pattern Bool
cB Bool
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Bool
d Value -> Maybe Bool
getB
cB_ :: String -> Pattern Bool
cB_ :: String -> Pattern Bool
cB_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe Bool
getB
cB0 :: String -> Pattern Bool
cB0 :: String -> Pattern Bool
cB0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Bool
False Value -> Maybe Bool
getB

cR :: Rational -> String -> Pattern Rational
cR :: Rational -> String -> Pattern Rational
cR Rational
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Rational
d Value -> Maybe Rational
getR
cR_ :: String -> Pattern Rational
cR_ :: String -> Pattern Rational
cR_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe Rational
getR
cR0 :: String -> Pattern Rational
cR0 :: String -> Pattern Rational
cR0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX Rational
0 Value -> Maybe Rational
getR

cT :: Time -> String -> Pattern Time
cT :: Rational -> String -> Pattern Rational
cT = Rational -> String -> Pattern Rational
cR
cT0 :: String -> Pattern Time
cT0 :: String -> Pattern Rational
cT0 = String -> Pattern Rational
cR0
cT_ :: String -> Pattern Time
cT_ :: String -> Pattern Rational
cT_ = String -> Pattern Rational
cR_

cS :: String -> String -> Pattern String
cS :: String -> String -> Pattern String
cS String
d = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX String
d Value -> Maybe String
getS
cS_ :: String -> Pattern String
cS_ :: String -> Pattern String
cS_ = forall a. (Value -> Maybe a) -> String -> Pattern a
_cX_ Value -> Maybe String
getS
cS0 :: String -> Pattern String
cS0 :: String -> Pattern String
cS0 = forall a. a -> (Value -> Maybe a) -> String -> Pattern a
_cX String
"" Value -> Maybe String
getS

-- Default controller inputs (for MIDI)
in0 :: Pattern Double
in0 :: Pattern Double
in0 = Double -> String -> Pattern Double
cF Double
0 String
"0"
in1 :: Pattern Double
in1 :: Pattern Double
in1 = Double -> String -> Pattern Double
cF Double
0 String
"1"
in2 :: Pattern Double
in2 :: Pattern Double
in2 = Double -> String -> Pattern Double
cF Double
0 String
"2"
in3 :: Pattern Double
in3 :: Pattern Double
in3 = Double -> String -> Pattern Double
cF Double
0 String
"3"
in4 :: Pattern Double
in4 :: Pattern Double
in4 = Double -> String -> Pattern Double
cF Double
0 String
"4"
in5 :: Pattern Double
in5 :: Pattern Double
in5 = Double -> String -> Pattern Double
cF Double
0 String
"5"
in6 :: Pattern Double
in6 :: Pattern Double
in6 = Double -> String -> Pattern Double
cF Double
0 String
"6"
in7 :: Pattern Double
in7 :: Pattern Double
in7 = Double -> String -> Pattern Double
cF Double
0 String
"7"
in8 :: Pattern Double
in8 :: Pattern Double
in8 = Double -> String -> Pattern Double
cF Double
0 String
"8"
in9 :: Pattern Double
in9 :: Pattern Double
in9 = Double -> String -> Pattern Double
cF Double
0 String
"9"
in10 :: Pattern Double
in10 :: Pattern Double
in10 = Double -> String -> Pattern Double
cF Double
0 String
"10"
in11 :: Pattern Double
in11 :: Pattern Double
in11 = Double -> String -> Pattern Double
cF Double
0 String
"11"
in12 :: Pattern Double
in12 :: Pattern Double
in12 = Double -> String -> Pattern Double
cF Double
0 String
"12"
in13 :: Pattern Double
in13 :: Pattern Double
in13 = Double -> String -> Pattern Double
cF Double
0 String
"13"
in14 :: Pattern Double
in14 :: Pattern Double
in14 = Double -> String -> Pattern Double
cF Double
0 String
"14"
in15 :: Pattern Double
in15 :: Pattern Double
in15 = Double -> String -> Pattern Double
cF Double
0 String
"15"
in16 :: Pattern Double
in16 :: Pattern Double
in16 = Double -> String -> Pattern Double
cF Double
0 String
"16"
in17 :: Pattern Double
in17 :: Pattern Double
in17 = Double -> String -> Pattern Double
cF Double
0 String
"17"
in18 :: Pattern Double
in18 :: Pattern Double
in18 = Double -> String -> Pattern Double
cF Double
0 String
"18"
in19 :: Pattern Double
in19 :: Pattern Double
in19 = Double -> String -> Pattern Double
cF Double
0 String
"19"
in20 :: Pattern Double
in20 :: Pattern Double
in20 = Double -> String -> Pattern Double
cF Double
0 String
"20"
in21 :: Pattern Double
in21 :: Pattern Double
in21 = Double -> String -> Pattern Double
cF Double
0 String
"21"
in22 :: Pattern Double
in22 :: Pattern Double
in22 = Double -> String -> Pattern Double
cF Double
0 String
"22"
in23 :: Pattern Double
in23 :: Pattern Double
in23 = Double -> String -> Pattern Double
cF Double
0 String
"23"
in24 :: Pattern Double
in24 :: Pattern Double
in24 = Double -> String -> Pattern Double
cF Double
0 String
"24"
in25 :: Pattern Double
in25 :: Pattern Double
in25 = Double -> String -> Pattern Double
cF Double
0 String
"25"
in26 :: Pattern Double
in26 :: Pattern Double
in26 = Double -> String -> Pattern Double
cF Double
0 String
"26"
in27 :: Pattern Double
in27 :: Pattern Double
in27 = Double -> String -> Pattern Double
cF Double
0 String
"27"
in28 :: Pattern Double
in28 :: Pattern Double
in28 = Double -> String -> Pattern Double
cF Double
0 String
"28"
in29 :: Pattern Double
in29 :: Pattern Double
in29 = Double -> String -> Pattern Double
cF Double
0 String
"29"
in30 :: Pattern Double
in30 :: Pattern Double
in30 = Double -> String -> Pattern Double
cF Double
0 String
"30"
in31 :: Pattern Double
in31 :: Pattern Double
in31 = Double -> String -> Pattern Double
cF Double
0 String
"31"
in32 :: Pattern Double
in32 :: Pattern Double
in32 = Double -> String -> Pattern Double
cF Double
0 String
"32"
in33 :: Pattern Double
in33 :: Pattern Double
in33 = Double -> String -> Pattern Double
cF Double
0 String
"33"
in34 :: Pattern Double
in34 :: Pattern Double
in34 = Double -> String -> Pattern Double
cF Double
0 String
"34"
in35 :: Pattern Double
in35 :: Pattern Double
in35 = Double -> String -> Pattern Double
cF Double
0 String
"35"
in36 :: Pattern Double
in36 :: Pattern Double
in36 = Double -> String -> Pattern Double
cF Double
0 String
"36"
in37 :: Pattern Double
in37 :: Pattern Double
in37 = Double -> String -> Pattern Double
cF Double
0 String
"37"
in38 :: Pattern Double
in38 :: Pattern Double
in38 = Double -> String -> Pattern Double
cF Double
0 String
"38"
in39 :: Pattern Double
in39 :: Pattern Double
in39 = Double -> String -> Pattern Double
cF Double
0 String
"39"
in40 :: Pattern Double
in40 :: Pattern Double
in40 = Double -> String -> Pattern Double
cF Double
0 String
"40"
in41 :: Pattern Double
in41 :: Pattern Double
in41 = Double -> String -> Pattern Double
cF Double
0 String
"41"
in42 :: Pattern Double
in42 :: Pattern Double
in42 = Double -> String -> Pattern Double
cF Double
0 String
"42"
in43 :: Pattern Double
in43 :: Pattern Double
in43 = Double -> String -> Pattern Double
cF Double
0 String
"43"
in44 :: Pattern Double
in44 :: Pattern Double
in44 = Double -> String -> Pattern Double
cF Double
0 String
"44"
in45 :: Pattern Double
in45 :: Pattern Double
in45 = Double -> String -> Pattern Double
cF Double
0 String
"45"
in46 :: Pattern Double
in46 :: Pattern Double
in46 = Double -> String -> Pattern Double
cF Double
0 String
"46"
in47 :: Pattern Double
in47 :: Pattern Double
in47 = Double -> String -> Pattern Double
cF Double
0 String
"47"
in48 :: Pattern Double
in48 :: Pattern Double
in48 = Double -> String -> Pattern Double
cF Double
0 String
"48"
in49 :: Pattern Double
in49 :: Pattern Double
in49 = Double -> String -> Pattern Double
cF Double
0 String
"49"
in50 :: Pattern Double
in50 :: Pattern Double
in50 = Double -> String -> Pattern Double
cF Double
0 String
"50"
in51 :: Pattern Double
in51 :: Pattern Double
in51 = Double -> String -> Pattern Double
cF Double
0 String
"51"
in52 :: Pattern Double
in52 :: Pattern Double
in52 = Double -> String -> Pattern Double
cF Double
0 String
"52"
in53 :: Pattern Double
in53 :: Pattern Double
in53 = Double -> String -> Pattern Double
cF Double
0 String
"53"
in54 :: Pattern Double
in54 :: Pattern Double
in54 = Double -> String -> Pattern Double
cF Double
0 String
"54"
in55 :: Pattern Double
in55 :: Pattern Double
in55 = Double -> String -> Pattern Double
cF Double
0 String
"55"
in56 :: Pattern Double
in56 :: Pattern Double
in56 = Double -> String -> Pattern Double
cF Double
0 String
"56"
in57 :: Pattern Double
in57 :: Pattern Double
in57 = Double -> String -> Pattern Double
cF Double
0 String
"57"
in58 :: Pattern Double
in58 :: Pattern Double
in58 = Double -> String -> Pattern Double
cF Double
0 String
"58"
in59 :: Pattern Double
in59 :: Pattern Double
in59 = Double -> String -> Pattern Double
cF Double
0 String
"59"
in60 :: Pattern Double
in60 :: Pattern Double
in60 = Double -> String -> Pattern Double
cF Double
0 String
"60"
in61 :: Pattern Double
in61 :: Pattern Double
in61 = Double -> String -> Pattern Double
cF Double
0 String
"61"
in62 :: Pattern Double
in62 :: Pattern Double
in62 = Double -> String -> Pattern Double
cF Double
0 String
"62"
in63 :: Pattern Double
in63 :: Pattern Double
in63 = Double -> String -> Pattern Double
cF Double
0 String
"63"
in64 :: Pattern Double
in64 :: Pattern Double
in64 = Double -> String -> Pattern Double
cF Double
0 String
"64"
in65 :: Pattern Double
in65 :: Pattern Double
in65 = Double -> String -> Pattern Double
cF Double
0 String
"65"
in66 :: Pattern Double
in66 :: Pattern Double
in66 = Double -> String -> Pattern Double
cF Double
0 String
"66"
in67 :: Pattern Double
in67 :: Pattern Double
in67 = Double -> String -> Pattern Double
cF Double
0 String
"67"
in68 :: Pattern Double
in68 :: Pattern Double
in68 = Double -> String -> Pattern Double
cF Double
0 String
"68"
in69 :: Pattern Double
in69 :: Pattern Double
in69 = Double -> String -> Pattern Double
cF Double
0 String
"69"
in70 :: Pattern Double
in70 :: Pattern Double
in70 = Double -> String -> Pattern Double
cF Double
0 String
"70"
in71 :: Pattern Double
in71 :: Pattern Double
in71 = Double -> String -> Pattern Double
cF Double
0 String
"71"
in72 :: Pattern Double
in72 :: Pattern Double
in72 = Double -> String -> Pattern Double
cF Double
0 String
"72"
in73 :: Pattern Double
in73 :: Pattern Double
in73 = Double -> String -> Pattern Double
cF Double
0 String
"73"
in74 :: Pattern Double
in74 :: Pattern Double
in74 = Double -> String -> Pattern Double
cF Double
0 String
"74"
in75 :: Pattern Double
in75 :: Pattern Double
in75 = Double -> String -> Pattern Double
cF Double
0 String
"75"
in76 :: Pattern Double
in76 :: Pattern Double
in76 = Double -> String -> Pattern Double
cF Double
0 String
"76"
in77 :: Pattern Double
in77 :: Pattern Double
in77 = Double -> String -> Pattern Double
cF Double
0 String
"77"
in78 :: Pattern Double
in78 :: Pattern Double
in78 = Double -> String -> Pattern Double
cF Double
0 String
"78"
in79 :: Pattern Double
in79 :: Pattern Double
in79 = Double -> String -> Pattern Double
cF Double
0 String
"79"
in80 :: Pattern Double
in80 :: Pattern Double
in80 = Double -> String -> Pattern Double
cF Double
0 String
"80"
in81 :: Pattern Double
in81 :: Pattern Double
in81 = Double -> String -> Pattern Double
cF Double
0 String
"81"
in82 :: Pattern Double
in82 :: Pattern Double
in82 = Double -> String -> Pattern Double
cF Double
0 String
"82"
in83 :: Pattern Double
in83 :: Pattern Double
in83 = Double -> String -> Pattern Double
cF Double
0 String
"83"
in84 :: Pattern Double
in84 :: Pattern Double
in84 = Double -> String -> Pattern Double
cF Double
0 String
"84"
in85 :: Pattern Double
in85 :: Pattern Double
in85 = Double -> String -> Pattern Double
cF Double
0 String
"85"
in86 :: Pattern Double
in86 :: Pattern Double
in86 = Double -> String -> Pattern Double
cF Double
0 String
"86"
in87 :: Pattern Double
in87 :: Pattern Double
in87 = Double -> String -> Pattern Double
cF Double
0 String
"87"
in88 :: Pattern Double
in88 :: Pattern Double
in88 = Double -> String -> Pattern Double
cF Double
0 String
"88"
in89 :: Pattern Double
in89 :: Pattern Double
in89 = Double -> String -> Pattern Double
cF Double
0 String
"89"
in90 :: Pattern Double
in90 :: Pattern Double
in90 = Double -> String -> Pattern Double
cF Double
0 String
"90"
in91 :: Pattern Double
in91 :: Pattern Double
in91 = Double -> String -> Pattern Double
cF Double
0 String
"91"
in92 :: Pattern Double
in92 :: Pattern Double
in92 = Double -> String -> Pattern Double
cF Double
0 String
"92"
in93 :: Pattern Double
in93 :: Pattern Double
in93 = Double -> String -> Pattern Double
cF Double
0 String
"93"
in94 :: Pattern Double
in94 :: Pattern Double
in94 = Double -> String -> Pattern Double
cF Double
0 String
"94"
in95 :: Pattern Double
in95 :: Pattern Double
in95 = Double -> String -> Pattern Double
cF Double
0 String
"95"
in96 :: Pattern Double
in96 :: Pattern Double
in96 = Double -> String -> Pattern Double
cF Double
0 String
"96"
in97 :: Pattern Double
in97 :: Pattern Double
in97 = Double -> String -> Pattern Double
cF Double
0 String
"97"
in98 :: Pattern Double
in98 :: Pattern Double
in98 = Double -> String -> Pattern Double
cF Double
0 String
"98"
in99 :: Pattern Double
in99 :: Pattern Double
in99 = Double -> String -> Pattern Double
cF Double
0 String
"99"
in100 :: Pattern Double
in100 :: Pattern Double
in100 = Double -> String -> Pattern Double
cF Double
0 String
"100"
in101 :: Pattern Double
in101 :: Pattern Double
in101 = Double -> String -> Pattern Double
cF Double
0 String
"101"
in102 :: Pattern Double
in102 :: Pattern Double
in102 = Double -> String -> Pattern Double
cF Double
0 String
"102"
in103 :: Pattern Double
in103 :: Pattern Double
in103 = Double -> String -> Pattern Double
cF Double
0 String
"103"
in104 :: Pattern Double
in104 :: Pattern Double
in104 = Double -> String -> Pattern Double
cF Double
0 String
"104"
in105 :: Pattern Double
in105 :: Pattern Double
in105 = Double -> String -> Pattern Double
cF Double
0 String
"105"
in106 :: Pattern Double
in106 :: Pattern Double
in106 = Double -> String -> Pattern Double
cF Double
0 String
"106"
in107 :: Pattern Double
in107 :: Pattern Double
in107 = Double -> String -> Pattern Double
cF Double
0 String
"107"
in108 :: Pattern Double
in108 :: Pattern Double
in108 = Double -> String -> Pattern Double
cF Double
0 String
"108"
in109 :: Pattern Double
in109 :: Pattern Double
in109 = Double -> String -> Pattern Double
cF Double
0 String
"109"
in110 :: Pattern Double
in110 :: Pattern Double
in110 = Double -> String -> Pattern Double
cF Double
0 String
"110"
in111 :: Pattern Double
in111 :: Pattern Double
in111 = Double -> String -> Pattern Double
cF Double
0 String
"111"
in112 :: Pattern Double
in112 :: Pattern Double
in112 = Double -> String -> Pattern Double
cF Double
0 String
"112"
in113 :: Pattern Double
in113 :: Pattern Double
in113 = Double -> String -> Pattern Double
cF Double
0 String
"113"
in114 :: Pattern Double
in114 :: Pattern Double
in114 = Double -> String -> Pattern Double
cF Double
0 String
"114"
in115 :: Pattern Double
in115 :: Pattern Double
in115 = Double -> String -> Pattern Double
cF Double
0 String
"115"
in116 :: Pattern Double
in116 :: Pattern Double
in116 = Double -> String -> Pattern Double
cF Double
0 String
"116"
in117 :: Pattern Double
in117 :: Pattern Double
in117 = Double -> String -> Pattern Double
cF Double
0 String
"117"
in118 :: Pattern Double
in118 :: Pattern Double
in118 = Double -> String -> Pattern Double
cF Double
0 String
"118"
in119 :: Pattern Double
in119 :: Pattern Double
in119 = Double -> String -> Pattern Double
cF Double
0 String
"119"
in120 :: Pattern Double
in120 :: Pattern Double
in120 = Double -> String -> Pattern Double
cF Double
0 String
"120"
in121 :: Pattern Double
in121 :: Pattern Double
in121 = Double -> String -> Pattern Double
cF Double
0 String
"121"
in122 :: Pattern Double
in122 :: Pattern Double
in122 = Double -> String -> Pattern Double
cF Double
0 String
"122"
in123 :: Pattern Double
in123 :: Pattern Double
in123 = Double -> String -> Pattern Double
cF Double
0 String
"123"
in124 :: Pattern Double
in124 :: Pattern Double
in124 = Double -> String -> Pattern Double
cF Double
0 String
"124"
in125 :: Pattern Double
in125 :: Pattern Double
in125 = Double -> String -> Pattern Double
cF Double
0 String
"125"
in126 :: Pattern Double
in126 :: Pattern Double
in126 = Double -> String -> Pattern Double
cF Double
0 String
"126"
in127 :: Pattern Double
in127 :: Pattern Double
in127 = Double -> String -> Pattern Double
cF Double
0 String
"127"