gled-core 2.31.2

The engine of gled without a user interface: inputs, timing, rendering, Art-Net/DMX output and storage
Documentation
//! Turns incoming OSC messages into actions. The first address segment picks
//! the family: project settings, animation assets, timing or scenes.

mod animation;
mod args;
mod effect;
mod project;
mod scene;
mod target;
#[cfg(test)]
mod tests;

use rosc::OscMessage;
use tracing::warn;

use crate::action::UiAction;

use args::parse_f32;

pub(super) fn parse_message(msg: &OscMessage) -> Result<UiAction, ()> {
    let path: Vec<&str> = msg
        .addr
        .split('/')
        .filter(|segment| !segment.is_empty())
        .collect();
    match path.as_slice() {
        ["project", ..] => project::parse_project_message(msg, &path),
        ["asset", "animation", ..] => animation::parse_animation_message(msg, &path),
        ["timing", "tap"] => Ok(UiAction::Tap),
        ["timing", "speed", "add"] => Ok(UiAction::SpeedAdd(parse_f32(msg, 0)?)),
        ["timing", "speed", "multiply"] => Ok(UiAction::SpeedMultiply(parse_f32(msg, 0)?)),
        ["scene", ..] => scene::parse_scene_message(msg, &path),
        _ => unknown_address(msg),
    }
}

/// An address no family understands.
fn unknown_address(msg: &OscMessage) -> Result<UiAction, ()> {
    warn!("Received unknown osc message: {}", msg.addr);
    Err(())
}