Crate cycles

Source
Expand description

§cycles crates.io docs.rs

A cyclic pattern abstraction, heavily inspired by TidalCycles.

Started as an attempt at porting the Pattern abstraction and related items from the TidalCycles’ Haskell implementation, though some liberties have been taken in order to achieve a more Rust-esque API.

The goal of this crate is to aim for a similar level of ergonomics to TidalCycles (it’s hard to compete with Haskell!), while taking advantage of Rust’s ability to provide low-to-zero-cost abstractions.

§The Pattern trait

The essence of this crate is the Pattern trait. Patterns are types that can be queried with a Span to produce a sequence of Events. All other items are related to constructing, applying, modifying or mapping types implementing Pattern.

Re-exports§

pub use bjorklund::bjorklund;
pub use bjorklund::Bjorklund;
pub use slice::SliceEvents;

Modules§

bjorklund
ctrl
Control patterns and related items.
mini
A mini-notation implementation inspired by tidalcycles’.
prelude
slice
Items related to the Pattern implementation for slices.

Macros§

m
A mini-notation implementation inspired by tidalcycles’.
span
A shorthand macro for constructing spans from rationals, e.g. span!(0/1, 3/1).

Structs§

ApplyEvent
Context given to a Pattern::apply_with function that can be used to produce the applied event along with its associated structure.
BoxEvents
A dynamic representation of a pattern’s associated events iterator.
DynPattern
A dynamic representation of a Pattern.
Event
An event yielded by a pattern query, see Pattern::query.
EventCache
EventSpan
The span associated with a single event.
EventsMap
The Pattern::Events type for MapEvents.
EventsMapPoints
The Pattern::Events type for MapEventPoints.
EventsMapValues
The Pattern::Events type for MapValues.
EventsRate
The Pattern::Events type for Rate.
MapEventPoints
See Pattern::map_event_points.
MapEvents
See Pattern::map_events.
MapEventsIter
See Pattern::map_events_iter.
MapQueryPoints
See Pattern::map_query_points.
MapValues
See Pattern::map.
PatternDebug
A type providing a std::fmt::Debug implementation for types implementing Pattern.
Rate
See Pattern::rate.
Signal
See the signal pattern constructor.
Span
A rational range over a single dimension, represented with a start and end.

Traits§

One
Types that can represent the value 1.
Pattern
A composable abstraction for 1-dimensional patterns.
Polar
Types that can represent a polar value.
Sample
Types that can be sampled with a rational to produce a value.
ToF64Lossy
Types convertible to a lossy representation of the same value.

Functions§

atom
Repeats a given discrete value once per cycle.
euclid
Divides up the cycle into n equal events, evenly distributing k number of true values between them using bjorklund’s algorithm, and filters out the false events.
euclid_bool
Divides up the cycle into n equal events, evenly distributing k number of true values between them using bjorklund’s algorithm.
euclid_bool_dist
Divides up the cycle into n equal events, evenly distributing k number of true values between them using bjorklund’s algorithm. Also provides the distance until the next onset, inclusive of the current event.
euclid_full
The same as euclid, but elongates the true event spans to fill the silence left by the filtered out false events.
euclid_full_off
The same as euclid_full, but allows providing an offset (or “rotation”) for the euclidean rhythm.
euclid_off
The same as euclid, but allows providing an offset (or “rotation”) for the euclidean rhythm.
euclid_off_bool
The same as euclid_bool, but allows providing an offset (or “rotation”) for the euclidean rhythm.
euclid_off_bool_dist
The same as euclid_bool, but allows providing an offset (or “rotation”) for the euclidean rhythm.
fastcat
Concatenate the given sequence of patterns into a single pattern so that all patterns fit to a single cycle.
fit_cycle
The same as [fit_span_to], but assumes the src span is a single cycle.
fit_span
Fit the src span of the given pattern to the dst span by first adjusting the rate and then shifting the pattern.
indices
A pattern producing an index per cycle.
inner_join
Similar to join, but the structure only comes from the inner pattern.
join
Joins a pattern of patterns into a single pattern.
outer_join
Similar to join, but the structure only comes from the outer pattern.
saw
A signal pattern that produces a saw wave in the range 0..=1.
saw2
A signal pattern that produces a saw wave in the range -1..=1.
signal
A pattern that, when queried, always produces a single event sampled from the given function.
silence
When queried, always produces an empty event iterator.
slowcat
Concatenate the given sequence of patterns into a single pattern whose total unique span covers a number of cycles equal to the number of patterns in the sequence.
stack
Combine the patterns into a single “stacked” pattern, where each query is equivalent to querying each of the inner patterns and concatenating their produced events.
steady
When queried, always returns a single event with a clone of the given value.
timecat
Like fastcat but allows the user to provide proportionate sizes for each pattern.

Type Aliases§

Rational
The rational value type used throughout the library to represent a point along a single dimension.
Scalar
The scalar type associated with Rational.