pub trait Pattern {
type Value;
type Events: Iterator<Item = Event<Self::Value>>;
Show 22 methods
// Required method
fn query(&self, span: Span) -> Self::Events;
// Provided methods
fn query_cycle(&self) -> Self::Events { ... }
fn into_dyn(self) -> DynPattern<Self::Value>
where Self: 'static + Sized { ... }
fn map<T, F>(self, map: F) -> MapValues<Self, F>
where Self: Sized,
F: Fn(Self::Value) -> T { ... }
fn map_query_points<F>(self, map: F) -> MapQueryPoints<Self, F>
where Self: Sized,
F: Fn(Rational) -> Rational { ... }
fn map_event_points<F>(self, map: F) -> MapEventPoints<Self, F>
where Self: Sized,
F: Fn(Rational) -> Rational { ... }
fn map_event_lens<F>(self, map: F) -> impl Pattern<Value = Self::Value>
where Self: Sized,
F: Fn(Rational) -> Rational { ... }
fn map_events<F, T>(self, map: F) -> MapEvents<Self, F>
where Self: Sized,
F: Fn(Event<Self::Value>) -> Event<T> { ... }
fn map_events_iter<E, F, T>(self, map: F) -> MapEventsIter<Self, F>
where Self: Sized,
F: Fn(Self::Events) -> E,
E: Iterator<Item = Event<T>> { ... }
fn rate(self, rate: Rational) -> Rate<Self>
where Self: Sized { ... }
fn shift(self, amount: Rational) -> impl Pattern<Value = Self::Value>
where Self: 'static + Sized { ... }
fn apply_with<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern<Value = F>,
F: Fn(ApplyEvent<Self::Value>) -> (B, Option<Span>) { ... }
fn apply<P, F, G, B>(
self,
apply: P,
structure: G,
) -> impl Pattern<Value = B>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern<Value = F>,
F: Fn(Self::Value) -> B,
G: 'static + Fn(Span, Span) -> Span { ... }
fn app<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern<Value = F>,
F: Fn(Self::Value) -> B { ... }
fn appl<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern<Value = F>,
F: Fn(Self::Value) -> B { ... }
fn appr<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern<Value = F>,
F: Fn(Self::Value) -> B { ... }
fn merge_with<P, F, T>(self, other: P, merge: F) -> impl Pattern<Value = T>
where Self: 'static + Sized,
Self::Value: Clone,
P: 'static + Pattern,
P::Value: Clone,
F: 'static + Fn(Self::Value, P::Value) -> T { ... }
fn merge_extend<P>(self, other: P) -> impl Pattern<Value = Self::Value>
where Self: 'static + Sized,
Self::Value: Clone + Extend<<P::Value as IntoIterator>::Item>,
P: 'static + Pattern,
P::Value: Clone + IntoIterator { ... }
fn polar(self) -> impl Pattern<Value = Self::Value>
where Self: Sized,
Self::Value: Polar { ... }
fn phase(self) -> impl Pattern<Value = [Rational; 2]>
where Self: Sized { ... }
fn debug_span(
&self,
span: Span,
) -> PatternDebug<'_, Self::Value, Self::Events>
where Self: Sized { ... }
fn debug(&self) -> PatternDebug<'_, Self::Value, Self::Events>
where Self: Sized { ... }
}Expand description
A composable abstraction for 1-dimensional patterns.
A Pattern is any type that may be queried with a
Span to produce a sequence of Event<Self::Value>s.
Required Associated Types§
Required Methods§
Sourcefn query(&self, span: Span) -> Self::Events
fn query(&self, span: Span) -> Self::Events
Query the pattern for events within the given span.
§Example
use cycles::{atom, saw, span, Pattern, Rational};
let pattern = atom("hello");
let mut events = pattern.query(span!(0/1, 1/1));
assert_eq!(events.next().unwrap().value, "hello");
assert_eq!(events.next(), None);
let pattern = saw();
assert_eq!(pattern.query(span!(0/1)).next().unwrap().value, (0, 1).into());
assert_eq!(pattern.query(span!(1/2)).next().unwrap().value, (1, 2).into());Provided Methods§
Sourcefn query_cycle(&self) -> Self::Events
fn query_cycle(&self) -> Self::Events
Query the pattern for events within a single cycle, (i.e. span!(0/1, 1/1)).
Sourcefn into_dyn(self) -> DynPattern<Self::Value>where
Self: 'static + Sized,
fn into_dyn(self) -> DynPattern<Self::Value>where
Self: 'static + Sized,
Convert the pattern to a trait object behind an Arc and dynamically
box queries in order to represent the pattern with a known, sized type.
This is useful for storing multiple patterns within a single collection, or passing patterns between threads, etc.
Sourcefn map<T, F>(self, map: F) -> MapValues<Self, F>
fn map<T, F>(self, map: F) -> MapValues<Self, F>
Map the values produced by pattern queries with the given function.
Sourcefn map_query_points<F>(self, map: F) -> MapQueryPoints<Self, F>
fn map_query_points<F>(self, map: F) -> MapQueryPoints<Self, F>
Map the start and end points of the pattern’s query spans.
Sourcefn map_event_points<F>(self, map: F) -> MapEventPoints<Self, F>
fn map_event_points<F>(self, map: F) -> MapEventPoints<Self, F>
Map the active and whole span start and end points of events produced by pattern queries with the given function. Useful for mapping time.
Sourcefn map_event_lens<F>(self, map: F) -> impl Pattern<Value = Self::Value>
fn map_event_lens<F>(self, map: F) -> impl Pattern<Value = Self::Value>
Map the length of the active and whole spans of all events produced by self.
The end of the resulting whole span is adjusted to achieve the returned len.
Sourcefn map_events<F, T>(self, map: F) -> MapEvents<Self, F>
fn map_events<F, T>(self, map: F) -> MapEvents<Self, F>
Map the events produced by pattern queries with the given function.
Sourcefn map_events_iter<E, F, T>(self, map: F) -> MapEventsIter<Self, F>
fn map_events_iter<E, F, T>(self, map: F) -> MapEventsIter<Self, F>
Map the events iterator produced by the pattern queries with the given function.
Sourcefn rate(self, rate: Rational) -> Rate<Self>where
Self: Sized,
fn rate(self, rate: Rational) -> Rate<Self>where
Self: Sized,
Increase or decrease the rate of event emission by the given value.
Sourcefn shift(self, amount: Rational) -> impl Pattern<Value = Self::Value>where
Self: 'static + Sized,
fn shift(self, amount: Rational) -> impl Pattern<Value = Self::Value>where
Self: 'static + Sized,
Shift the pattern by the given amount.
Sourcefn apply_with<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
fn apply_with<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
Apply the given pattern of functions to self.
The resulting pattern yields an event at each the intersection of each
of the active spans. The function must return the value along with the
whole span, which should either come from one of the intersecting
events, or the intersection of the two.
Sourcefn apply<P, F, G, B>(self, apply: P, structure: G) -> impl Pattern<Value = B>
fn apply<P, F, G, B>(self, apply: P, structure: G) -> impl Pattern<Value = B>
Apply the given pattern of functions to self.
Yields an event at each intersection between the active spans of self and apply.
The resulting structure is determined by the given function structure
which provides the whole spans of the intersecting events produced by
self and apply respectively.
Sourcefn app<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
fn app<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
Apply the given pattern of functions to self.
Yields an event at each intersection between the active spans of self and apply.
The resulting structure is the intersection of self and apply.
Sourcefn appl<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
fn appl<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
Apply the given pattern of functions to self.
Yields an event at each intersection between the active spans of self and apply.
The resulting structure is carried from the left (i.e. self).
Sourcefn appr<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
fn appr<P, F, B>(self, apply: P) -> impl Pattern<Value = B>
Apply the given pattern of functions to self.
Yields an event at each intersection between the active spans of self and apply.
The resulting structure is carried from the right (i.e. the apply pattern).
Sourcefn merge_with<P, F, T>(self, other: P, merge: F) -> impl Pattern<Value = T>
fn merge_with<P, F, T>(self, other: P, merge: F) -> impl Pattern<Value = T>
Merge the given pattern by calling the given function for each value at each active span intersection.
Sourcefn merge_extend<P>(self, other: P) -> impl Pattern<Value = Self::Value>
fn merge_extend<P>(self, other: P) -> impl Pattern<Value = Self::Value>
Merge the given pattern by calling Extend<P::Value> for each value at
intersections of active spans.
Useful for applying one control pattern to another and producing the union between values.
Sourcefn polar(self) -> impl Pattern<Value = Self::Value>
fn polar(self) -> impl Pattern<Value = Self::Value>
Assuming a pattern of values in the range 0 to 1, produces a pattern in the range -1 to 1.
Sourcefn phase(self) -> impl Pattern<Value = [Rational; 2]>where
Self: Sized,
fn phase(self) -> impl Pattern<Value = [Rational; 2]>where
Self: Sized,
Map a pattern’s active spans to start and end phases through their
corresponding whole events.
Sourcefn debug_span(&self, span: Span) -> PatternDebug<'_, Self::Value, Self::Events>where
Self: Sized,
fn debug_span(&self, span: Span) -> PatternDebug<'_, Self::Value, Self::Events>where
Self: Sized,
Return a wrapper providing a fmt::Debug implementation for the pattern.
Formats events resulting from a query to the given span.