Trait Pattern

Source
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§

Source

type Value

The type of the values emitted in the pattern’s events.

Source

type Events: Iterator<Item = Event<Self::Value>>

An iterator yielding the events occuring within a query’s span.

Required Methods§

Source

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§

Source

fn query_cycle(&self) -> Self::Events

Query the pattern for events within a single cycle, (i.e. span!(0/1, 1/1)).

Source

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.

Source

fn map<T, F>(self, map: F) -> MapValues<Self, F>
where Self: Sized, F: Fn(Self::Value) -> T,

Map the values produced by pattern queries with the given function.

Source

fn map_query_points<F>(self, map: F) -> MapQueryPoints<Self, F>
where Self: Sized, F: Fn(Rational) -> Rational,

Map the start and end points of the pattern’s query spans.

Source

fn map_event_points<F>(self, map: F) -> MapEventPoints<Self, F>
where Self: Sized, F: Fn(Rational) -> Rational,

Map the active and whole span start and end points of events produced by pattern queries with the given function. Useful for mapping time.

Source

fn map_event_lens<F>(self, map: F) -> impl Pattern<Value = Self::Value>
where Self: Sized, F: Fn(Rational) -> Rational,

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.

Source

fn map_events<F, T>(self, map: F) -> MapEvents<Self, F>
where Self: Sized, F: Fn(Event<Self::Value>) -> Event<T>,

Map the events produced by pattern queries with the given function.

Source

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>>,

Map the events iterator produced by the pattern queries with the given function.

Source

fn rate(self, rate: Rational) -> Rate<Self>
where Self: Sized,

Increase or decrease the rate of event emission by the given value.

Source

fn shift(self, amount: Rational) -> impl Pattern<Value = Self::Value>
where Self: 'static + Sized,

Shift the pattern by the given amount.

Source

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>),

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.

Source

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,

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.

Source

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,

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.

Source

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,

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).

Source

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,

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).

Source

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,

Merge the given pattern by calling the given function for each value at each active span intersection.

Source

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,

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.

Source

fn polar(self) -> impl Pattern<Value = Self::Value>
where Self: Sized, Self::Value: Polar,

Assuming a pattern of values in the range 0 to 1, produces a pattern in the range -1 to 1.

Source

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.

Source

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.

Source

fn debug(&self) -> 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 for a single cycle.

Implementations on Foreign Types§

Source§

impl<'a, T> Pattern for &'a [Event<T>]

Source§

fn query(&self, span: Span) -> Self::Events

Assumes all events are ordered (at least by their spans).

Source§

type Value = &'a T

Source§

type Events = SliceEvents<'a, T>

Implementors§

Source§

impl<F, I, T> Pattern for F
where F: Fn(Span) -> I, I: Iterator<Item = Event<T>>,

Source§

type Value = T

Source§

type Events = I

Source§

impl<P> Pattern for Rate<P>
where P: Pattern,

Source§

impl<P, F> Pattern for MapEventPoints<P, F>
where P: Pattern, F: Fn(Rational) -> Rational,

Source§

impl<P, F> Pattern for MapQueryPoints<P, F>
where P: Pattern, F: Fn(Rational) -> Rational,

Source§

impl<P, F, E, T> Pattern for MapEventsIter<P, F>
where P: Pattern, F: Fn(P::Events) -> E, E: Iterator<Item = Event<T>>,

Source§

type Value = T

Source§

type Events = E

Source§

impl<P, F, T> Pattern for MapEvents<P, F>
where P: Pattern, F: Fn(Event<P::Value>) -> Event<T>,

Source§

impl<P, F, T> Pattern for MapValues<P, F>
where P: Pattern, F: Fn(P::Value) -> T,

Source§

impl<S: Sample> Pattern for Signal<S>

Source§

impl<T> Pattern for DynPattern<T>