[][src]Struct rhythms::Pattern

pub struct Pattern { /* fields omitted */ }

The main pattern building block

Implementations

impl Pattern[src]

pub fn new(length: usize, pulses: usize, rotation: isize) -> Self[src]

Returns a pattern with given length, number of pulses and rotation

Arguments

  • length - Total number of steps
  • pulses - The number of pulses
  • rotation - Number of rotation steps. Polarity represents direction

Examples

use rhythms::Pattern;
let pattern = Pattern::new(4, 2, 0);
assert_eq!([true, false, true, false], pattern.as_slice());

pub fn with_length(length: usize) -> Self[src]

Returns a pattern with given length

Arguments

  • length - Total number of steps

Examples

use rhythms::Pattern;
let pattern = Pattern::with_length(8);
assert_eq!(8, pattern.len());

pub fn from_slice(slice: &[bool]) -> Self[src]

Returns a pattern based on a boolean slice

Arguments

  • slice - A boolean slice holding the initial pattern

Examples

use rhythms::Pattern;
let pattern = Pattern::from_slice(&[false, false, false, true]);
assert_eq!([false, false, false, true], pattern.as_slice());

pub fn pulses(&mut self, pulses: usize)[src]

Updates the current pattern with a evenly distributed number of pulses, using an abstraction based on Bjorklund's Euclidean algorithm.

Arguments

  • pulses - Total number of pulses, from 0 to the pattern length. If pulses exceeds the pattern length, the max value will be used

Examples

use rhythms::Pattern;
let mut pattern = Pattern::with_length(4);
pattern.pulses(2);
assert_eq!([true, false, true, false], pattern.as_slice());
// or
let mut pattern = Pattern::new(4, 4, 0);
assert_eq!([true, true, true, true], pattern.as_slice());
pattern.pulses(2);
assert_eq!([true, false, true, false], pattern.as_slice());

pub fn rotate(&mut self, rotation: isize)[src]

Rotates the current pattern

Arguments

  • rotation - Number of rotation steps. Polarity represents direction

Examples

use rhythms::Pattern;
let mut pattern = Pattern::with_length(3);
pattern.pulses(1);
assert_eq!([false, true, false], pattern.as_slice());
pattern.rotate(-1);
assert_eq!([true, false, false], pattern.as_slice());
// or
let pattern = Pattern::new(3, 1, -1);
assert_eq!([true, false, false], pattern.as_slice());

pub fn clear(&mut self)[src]

Clears all pulses from a pattern

Examples

use rhythms::Pattern;
let mut pattern = Pattern::new(4, 2, 0);
assert_eq!([true, false, true, false], pattern.as_slice());
pattern.clear();
assert_eq!([false, false, false, false], pattern.as_slice());

pub fn resize(&mut self, length: usize)[src]

Resize the current pattern. If length is

Arguments

  • length - Total number of steps

Examples

use rhythms::Pattern;
let mut pattern = Pattern::with_length(1);
assert_eq!([false], pattern.as_slice());
pattern.resize(4);
assert_eq!(4, pattern.len());
assert_eq!([false, false, false, false], pattern.as_slice());

pub fn reset(&mut self)[src]

Moves the pattern cursor to the first step

Examples

use rhythms::Pattern;
let mut pattern = Pattern::new(4, 2, 0);
assert_eq!([true, false, true, false], pattern.as_slice());
assert_eq!(Some(true), pattern.next());
pattern.reset();
assert_eq!(Some(true), pattern.next());

pub fn move_cursor(&mut self, step: usize)[src]

Moves the pattern cursor to a given step. If step overflows, it will move to the last step

Arguments

  • step - Step identifiyer. Range starts at 0

Examples

use rhythms::Pattern;
let mut pattern = Pattern::new(4, 2, 0);
assert_eq!([true, false, true, false], pattern.as_slice());
assert_eq!(Some(true), pattern.next());
assert_eq!(Some(false), pattern.next());
pattern.move_cursor(1);
assert_eq!(Some(false), pattern.next());

pub fn step(&self, step: usize) -> Option<bool>[src]

Returns the state of a step

Arguments

  • step - Step identifiyer. Range starts at 0

Examples

use rhythms::Pattern;
let pattern = Pattern::new(4, 2, 0);
assert_eq!(Some(true), pattern.step(0));
assert_eq!(Some(false), pattern.step(1));
assert_eq!(None, pattern.step(4));

pub fn len(&self) -> usize[src]

Returns length of current pattern

Examples

use rhythms::Pattern;
let pattern = Pattern::new(8, 2, 0);
assert_eq!(8, pattern.len());

pub fn as_slice(&self) -> &[bool][src]

Returns a boolean slice reprensenting the pattern

Examples

use rhythms::Pattern;
let pattern = Pattern::new(4, 2, 1);
assert_eq!([false, true, false, true], pattern.as_slice());

pub fn next_looped(&mut self) -> bool[src]

Returns the next step in a pattern. If the end of the pattern is reached, it resets the cursor and will return the first step

Examples

use rhythms::Pattern;
let mut pattern = Pattern::new(2, 1, 0);
assert_eq!(true, pattern.next_looped());
assert_eq!(false, pattern.next_looped());
assert_eq!(true, pattern.next_looped());
assert_eq!(false, pattern.next_looped());
// ...

Trait Implementations

impl Clone for Pattern[src]

impl Debug for Pattern[src]

impl Iterator for Pattern[src]

Iterate over a pattern

use rhythms::Pattern;
let pattern = Pattern::new(8, 2, 0);
for step in pattern {
    println!("{}", step);
}

type Item = bool

The type of the elements being iterated over.

Auto Trait Implementations

impl Send for Pattern

impl Sync for Pattern

impl Unpin for Pattern

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.