Mescaline.Synth.Pattern.ASTLib
Contents
- data Pattern t
- patch :: Pattern Event -> Tree Event
- data Scalar
- value :: Double -> Pattern Scalar
- data UnaryFunc
- data BinaryFunc
- = F_min
- | F_max
- | F_add
- | F_subtract
- | F_multiply
- | F_divide
- | F_power
- | F_logBase
- map :: UnaryFunc -> Pattern Scalar -> Pattern Scalar
- zip :: BinaryFunc -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- min :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- max :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- truncateP :: Pattern Scalar -> Pattern Scalar
- roundP :: Pattern Scalar -> Pattern Scalar
- ceilingP :: Pattern Scalar -> Pattern Scalar
- floorP :: Pattern Scalar -> Pattern Scalar
- clip :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- wrap :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- fold :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- ampdb :: Pattern Scalar -> Pattern Scalar
- dbamp :: Pattern Scalar -> Pattern Scalar
- rand :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- randi :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- exprand :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- gaussian :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- brown :: Limit -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar
- data Boolean
- (|==|) :: Pattern Scalar -> Pattern Scalar -> Pattern Boolean
- (|>|) :: Pattern Scalar -> Pattern Scalar -> Pattern Boolean
- (|>=|) :: Pattern Scalar -> Pattern Scalar -> Pattern Boolean
- (|<|) :: Pattern Scalar -> Pattern Scalar -> Pattern Boolean
- (|<=|) :: Pattern Scalar -> Pattern Scalar -> Pattern Boolean
- data Coord
- coord :: Pattern Scalar -> Pattern Scalar -> Pattern Coord
- polar :: Pattern Coord -> Pattern Scalar -> Pattern Scalar -> Pattern Coord
- x :: Pattern Coord -> Pattern Scalar
- y :: Pattern Coord -> Pattern Scalar
- center :: Int -> Pattern Coord
- radius :: Int -> Pattern Scalar
- data Event
- rest :: Double -> Pattern Event
- closest :: Int -> Pattern Scalar -> Pattern Scalar -> Pattern Coord -> Pattern Event
- region :: Int -> Pattern Scalar -> Pattern Scalar -> Pattern Event
- data Field
- = Delta
- | Cursor
- | CursorValue
- | Offset
- | Duration
- | Level
- | Pan
- | Rate
- | AttackTime
- | ReleaseTime
- | SendLevel1
- | SendLevel2
- | FXParam1
- | FXParam2
- | Feature Int Int
- get :: Field -> Pattern Event -> Pattern Scalar
- set :: Field -> Pattern Scalar -> Pattern Event -> Pattern Event
- fSpec :: Int -> Field
- fPower :: Field
- fFreq :: Field
- mapf :: UnaryFunc -> Field -> Pattern Event -> Pattern Event
- zipf :: BinaryFunc -> Pattern Scalar -> Field -> Pattern Event -> Pattern Event
- fzip :: BinaryFunc -> Field -> Pattern Scalar -> Pattern Event -> Pattern Event
- add :: Field -> Pattern Scalar -> Pattern Event -> Pattern Event
- multiply :: Field -> Pattern Scalar -> Pattern Event -> Pattern Event
- filter :: Pattern Boolean -> Pattern Event -> Pattern Event
- player :: Pattern Scalar -> Pattern Scalar -> Pattern Event -> Pattern Event
- sequencer :: Pattern Scalar -> Pattern Event -> Pattern Event
- envelope :: Pattern Scalar -> Pattern Scalar -> Pattern Event -> Pattern Event
- cycle :: Stream Pattern a => Pattern a -> Pattern a
- replicate :: Stream Pattern a => Int -> Pattern a -> Pattern a
- times :: Stream Pattern a => Pattern a -> Int -> Pattern a
- take :: Stream Pattern a => Int -> Pattern a -> Pattern a
- only :: Stream Pattern a => Pattern a -> Int -> Pattern a
- restrict :: Stream Pattern a => Int -> Pattern a -> Pattern a
- gimme :: Stream Pattern a => Pattern a -> Int -> Pattern a
- once :: Stream Pattern a => Pattern a -> Pattern a
- o :: Stream Pattern a => Pattern a -> Pattern a
- takeDur :: Double -> Pattern Event -> Pattern Event
- par :: [Pattern Event] -> Pattern Event
- seq :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern a
- seq1 :: (List Pattern a, Stream Pattern a) => Pattern Scalar -> [Pattern a] -> Pattern a
- ser :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern a
- ser1 :: (List Pattern a, Stream Pattern a) => Pattern Scalar -> [Pattern a] -> Pattern a
- choose :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern a
- choose1 :: (List Pattern a, Stream Pattern a) => Pattern Scalar -> [Pattern a] -> Pattern a
- chooseNew :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern a
- chooseNew1 :: (List Pattern a, Stream Pattern a) => Pattern Scalar -> [Pattern a] -> Pattern a
- bind :: Bind Pattern a b => Pattern a -> (Pattern a -> Pattern b) -> Pattern b
- data Limit
- trace :: Trace Pattern a => Pattern a -> Pattern a
Structure
A Pattern is a finite or infinite stream of values of a certain type.
There are four different types in the pattern language, real numbers
(Scalar), boolean values (Boolean), two dimensional coordinates
(Coord) and synthesis events (Event).
The pattern functions in this module can be used to combine patterns in various ways in order to build more complex expressions.
For the Scalar pattern type, many unary functions (UnaryFunc) and binary
functions (BinaryFunc) are mapped to standard Haskell type classes. This allows to
use more descriptive function names and binary operators, in particular the
ones from the Num, Fractional and Floating type classes.
Instances
patch :: Pattern Event -> Tree EventSource
Construct an abstract syntax tree from an event pattern.
This is the main entry point, a patch will always look like this:
it = patch (<expressions>)
Scalar patterns
Scalar expression.
Scalars represent streams of real numbers.
Instances
Unary and binary function application
Constructors
| F_abs | Absolute value |
| F_signum | Sign |
| F_negate | Negation |
| F_recip | Reciprocal |
| F_truncate | Truncation towards zero. |
| F_round | nearest integer to argument. |
| F_ceiling | Least integer not less than argument. |
| F_floor | Truncation towards minus infinity. |
| F_exp | Exponential function. |
| F_sqrt | Square root. |
| F_log | Natural logarithm |
| F_sin | Sine. |
| F_tan | Tangent. |
| F_cos | Cosine. |
| F_asin | Arc sine. |
| F_atan | Arc tangent. |
| F_acos | Arc cosine. |
| F_sinh | Hyperbolic sine. |
| F_tanh | Hyperbolic tangent. |
| F_cosh | Hyperbolic cosine. |
| F_asinh | Arc hyperbolic sine. |
| F_atanh | Arc hyperbolic tangent. |
| F_acosh | Arc hyperbolic cosine. |
data BinaryFunc Source
Constructors
| F_min | Minimum of the arguments. |
| F_max | Maximum of the arguments. |
| F_add | Sum of the arguments. |
| F_subtract | Difference of the arguments. |
| F_multiply | Product of the arguments. |
| F_divide | Division of the arguments. |
| F_power | First argument raised to the power of second argument. |
| F_logBase | Logarithm of the second argument to the base of the first argument. |
Instances
zip :: BinaryFunc -> Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Combine two scalars with a binary function.
min :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Return the smaller of the arguments.
min a b
max :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Return the bigger of the arguments.
max a b
Numeric functions
clip :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Constrain a scalar to the interval [min,max].
clip min max x
wrap :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Wrap a scalar into the interval [min,max].
wrap min max x
fold :: Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Fold a scalar into the interval [min,max].
fold min max x
Scalar conversions
Random functions
rand :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Generate white noise in a given range.
rand min max
-
minMinimum value. -
maxMaximum value.
randi :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Generate integer random value in [min,max[.
randi min max
-
minMinimum value (inclusive). -
maxMaximum value (exclusive).
exprand :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Generate exponential noise in a given range.
exprand min max
-
minMinimum value. -
maxMaximum value.
gaussian :: Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Generate gaussian noise with the given mean and variance.
gaussian mean var
-
meanMean value. -
varVariance, or standard deviation squared.
brown :: Limit -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern Scalar -> Pattern ScalarSource
Generate brown noise in a given range with a given step size.
brown limmit stepMin stepMax min max
-
limitInterval boundary behavior. -
stepMinMinimum step size. -
stepMaxMaximum step size. -
minMinimum value. -
maxMaximum value.
Boolean patterns
Boolean expression.
Instances
Comparisons of scalars
(|==|) :: Pattern Scalar -> Pattern Scalar -> Pattern BooleanSource
Return True if a equals b.
a |==| b
(|>|) :: Pattern Scalar -> Pattern Scalar -> Pattern BooleanSource
Return True if a is greater than b.
a |>| b
(|>=|) :: Pattern Scalar -> Pattern Scalar -> Pattern BooleanSource
Return True if a is greater than or equal to b.
a |>=| b
(|<|) :: Pattern Scalar -> Pattern Scalar -> Pattern BooleanSource
Return True if a is smaller than b.
a |<| b
(|<=|) :: Pattern Scalar -> Pattern Scalar -> Pattern BooleanSource
Return True if a is smaller than or equal to b.
a |<=| b
Coordinates
Coordinate expression.
coord :: Pattern Scalar -> Pattern Scalar -> Pattern CoordSource
Construct a coordinate pattern from a pair of scalar patterns, one for each axis.
coord 0.5 (rand 0.4 0.6)
polar :: Pattern Coord -> Pattern Scalar -> Pattern Scalar -> Pattern CoordSource
Construct a coordinate pattern from a center coordinate, a radius and an angle in radians.
polar (coord 0.5 0.5) 0.5 (pi/2)
Regions
Event patterns
Event expression.
Events can be thought of as notes controlling the synthesizer. They are
either silent, or rests, or carry parameter that affect the synthesis and
the sequencer.
They carry the time to the next event in the stream in the Delta field.
Instances
Event generators
closest :: Int -> Pattern Scalar -> Pattern Scalar -> Pattern Coord -> Pattern EventSource
Select the unit closest to a given coordinate.
closest cursor defaultDelta radius coord
-
cursorCursor id for the generated event. -
defaultDeltaDefault delta time in case no unit is found. -
radiusRadius to restrict the search; if the found unit is outside the given radius around the coordinate, a rest is generated. -
coordCoordinate for nearest neighbor search.
region :: Int -> Pattern Scalar -> Pattern Scalar -> Pattern EventSource
Select a unit from a region according to the iterator.
region cursor defaultDelta iterator
-
cursorCursor and region id for this event. -
defaultDeltaDefault delta time in case the region is empty. -
iteratorScalar pattern in the range [0;1[ that selects a unit from the region.
Event accessors
Represents the various fields in a synthesis event.
Note that some fields can be queried but not modified (Cursor, CursorValue
and Feature).
Constructors
| Delta | Delta time to next event in seconds. |
| Cursor | Cursor id. |
| CursorValue | Value at this cursor. |
| Offset | Playback offset in seconds. |
| Duration | Duration of the event being played. |
| Level | Level between 0 and 1. |
| Pan | Panning coefficient in [-1;1]. |
| Rate | Playback rate (> 0). |
| AttackTime | Envelope attack time in seconds. |
| ReleaseTime | Envelope release time in seconds. |
| SendLevel1 | First send effect level. |
| SendLevel2 | Second send effect level. |
| FXParam1 | Parameter for first send effect. |
| FXParam2 | Parameter for second send effect. |
| Feature Int Int | Feature value. |
get :: Field -> Pattern Event -> Pattern ScalarSource
Return the value of an event field.
get Duration e
set :: Field -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Set the value of an event field
set Duration 0.1 e
Feature field accessors
Event modifiers
zipf :: BinaryFunc -> Pattern Scalar -> Field -> Pattern Event -> Pattern EventSource
Combine a scalar with a field value.
fzip :: BinaryFunc -> Field -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Combine a field value with a scalar.
add :: Field -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Add a scalar to a field value.
multiply :: Field -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Multiply a field value by a scalar.
Event filters
filter :: Pattern Boolean -> Pattern Event -> Pattern EventSource
Filter an event stream with the given boolean pattern.
Events for which the predicate returns True are replaced by rests.
bind (<event expression>) (\e -> filter (get Duration e |>| 0.5) e)
player :: Pattern Scalar -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Filter out events that don't have the cursor set.
stepPlayer rowInc colInc pattern
-
rowIncCursor row increment. -
colIncCursor column increment. -
patternThe pattern to filter.
sequencer :: Pattern Scalar -> Pattern Event -> Pattern EventSource
Given a tick increment in seconds filter the event pattern argument so that only cursor values greater than zero produce events.
sequencer tick pattern
-
tickTick increment in seconds. -
patternThe pattern to filter.
envelope :: Pattern Scalar -> Pattern Scalar -> Pattern Event -> Pattern EventSource
Set envelope attack and release time.
envelope attackTime releaseTime e
Stream functions
replicate :: Stream Pattern a => Int -> Pattern a -> Pattern aSource
Constant signal. constant, c :: Double -> Pattern Scalar constant = cycle . value c = constant
Repeat a pattern n times.
repeat n p
times :: Stream Pattern a => Pattern a -> Int -> Pattern aSource
Repeat a pattern n times.
This is the same as replicate with the arguments flipped in order to allow infix application:
p `times` 4
take :: Stream Pattern a => Int -> Pattern a -> Pattern aSource
Take the first n values of a pattern.
If the pattern is shorter, a smaller number of values is returned.
only :: Stream Pattern a => Pattern a -> Int -> Pattern aSource
Take the n initial values of a pattern repeated infinitely.
This is the same as take with the arguments flipped in order to allow infix application:
p `only` 4
restrict :: Stream Pattern a => Int -> Pattern a -> Pattern aSource
Take the n initial values of a pattern repeated infinitely.
restrict n p = cycle (take n p)
gimme :: Stream Pattern a => Pattern a -> Int -> Pattern aSource
Take the n initial values of a pattern repeated infinitely.
This is the same as restrict with the arguments flipped in order to allow infix application:
p `gimme` 4
o :: Stream Pattern a => Pattern a -> Pattern aSource
Take the first value of a pattern.
Short for once.
Event streams
takeDur :: Double -> Pattern Event -> Pattern EventSource
Limit an event pattern to the first n seconds.
takeDur 2.125 e
par :: [Pattern Event] -> Pattern EventSource
Combine a list of event patterns by merging their event streams.
List patterns
seq :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern aSource
Enumerate a list of patterns sequentially, n times.
seq n ps
-
nNumber of repeats. -
psList of patterns.
ser :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern aSource
Enumerate a list of patterns sequentially, returning n items.
ser n ps
-
nNumber of items to return. -
psList of patterns.
choose :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern aSource
Returns one item from the list at random for each repeat.
choose n ps
-
nNumber of repeats. -
psList of patterns.
chooseNew :: List Pattern a => Pattern Scalar -> [Pattern a] -> Pattern aSource
Returns one item from the list at random for each repeat.
Similar to choose but doesn't return the same item twice in a row.
chooseNew1 :: (List Pattern a, Stream Pattern a) => Pattern Scalar -> [Pattern a] -> Pattern aSource
Bindings
bind :: Bind Pattern a b => Pattern a -> (Pattern a -> Pattern b) -> Pattern bSource
Bind the current value of a pattern to a function argument.
This function is needed to express value sharing (as opposed to expression sharing) in the pattern language.
bind (<event pattern expression>) (\e -> set Delta (get Duration e) e)
Constants
Interval boundary behavior.