Module sorceress::pattern::player[][src]

Play patterns using the scheduler module.

This module implements a Job plays patterns using the scheduler module.

At a high level, this module converts the events yielded by patterns into timestamped events that can be sent to the SuperCollider server in OSC bundles. Specifically, it converts the relative, floating point “delta” values on pattern::Event into the SystemTime values given to the EventHandler::handle method. The player uses a Tempo to convert the deltas into concrete Duration values, then uses the logical time provided by a Scheduler to turn those durations into SystemTime values.

Once the event has been given a timestamp, the player sends the event to an EventHandler. The EventHandler can do whatever it wants with the event, but it usually involves converting the event into a server command then sending it to the SuperCollider server in a bundle with the timestamp.

The scheduler runs the player on every beat. On each beat the player will process all of the events that occur during that beat and will immediately send them to this player’s EventHandler. This means that changes made to patters as they are playing will only be heard after the next downbeat.

Examples

use sorceress::{
    pattern::{player::Player, sequence, Pattern},
    scheduler::Scheduler,
};
use std::time::SystemTime;

let pattern: Pattern<String> = sequence(|s| {
    for _ in 0..4 {
        s.play(2.0, "2.0");
        s.play(1.0, "1.0");
        s.play(0.5, "0.5");
        s.play(0.5, "0.5");
    }
});

let event_handler = |_, event| println!("{}", event);
Scheduler::new().run(Player::new(pattern, event_handler))?;

Structs

Player

A scheduler job definition for playing patterns.

PlayerJob

The job created by a Player.

PlayerSnapshot

A snapshot of the interal state of a Player.

Tempo

A musical tempo.

Traits

EventHandler

Processes the events yielded by the player.