Skip to main content

sim_lib_music_transform/
player.rs

1use sim_lib_music_core::{Music, MusicObject};
2
3use crate::{PatternMutatorConfig, TransformError};
4
5/// Player that applies a [`PatternMutatorConfig`] to incoming material.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct PatternMutatorPlayer {
8    /// Mutator configuration this player applies.
9    pub config: PatternMutatorConfig,
10}
11
12impl PatternMutatorPlayer {
13    /// Wraps a mutator configuration in a player.
14    pub fn new(config: PatternMutatorConfig) -> Self {
15        Self { config }
16    }
17
18    /// Applies the configured mutation to the input and returns the result.
19    pub fn play(&self, input: &dyn MusicObject) -> Result<Music, TransformError> {
20        self.config.apply(input)
21    }
22
23    /// Serializes the underlying configuration to its wire string.
24    pub fn to_wire(&self) -> String {
25        self.config.to_wire()
26    }
27}
28
29/// Builds a [`PatternMutatorPlayer`] from a mutator configuration.
30pub fn player_mutator(config: PatternMutatorConfig) -> PatternMutatorPlayer {
31    PatternMutatorPlayer::new(config)
32}