gled-core 2.32.1

The engine of gled without a user interface: inputs, timing, rendering, Art-Net/DMX output and storage
Documentation
//! `/project/...`: the main dimmer, blackout, the project palette, Art-Net
//! control and the project's trigger inputs.

use rosc::OscMessage;

use super::args::{parse_bool, parse_f32, parse_index, parse_optional_uuid, parse_rgb, parse_u16};
use super::unknown_address;
use crate::action::UiAction;
use crate::storage::asset::palette::Palette;
use crate::storage::asset_id::AssetId;

pub(super) fn parse_project_message(msg: &OscMessage, path: &[&str]) -> Result<UiAction, ()> {
    match path {
        ["project", "main_dimmer"] => Ok(UiAction::SetMainDimmer(parse_f32(msg, 0)?)),
        ["project", "blackout"] => Ok(UiAction::SetBlackout(parse_bool(msg, 0)?)),
        ["project", "palette"] => Ok(UiAction::SetProjectPaletteFromAsset(
            parse_optional_palette_id(msg, 0)?,
        )),
        ["project", "palette", "primary"] => {
            Ok(UiAction::SetProjectPalettePrimary(parse_rgb(msg)?))
        }
        ["project", "palette", "secondary"] => {
            Ok(UiAction::SetProjectPaletteSecondary(parse_rgb(msg)?))
        }
        ["project", "palette", "gradient", gradient_index] => Ok(
            UiAction::SetProjectPaletteGradient(parse_index(gradient_index)?, parse_rgb(msg)?),
        ),
        ["project", "artnet_control", "active"] => {
            Ok(UiAction::SetProjectArtnetControlActive(parse_bool(msg, 0)?))
        }
        ["project", "artnet_control", "universe"] => Ok(UiAction::SetProjectArtnetControlUniverse(
            parse_u16(msg, 0)?,
        )),
        ["project", "input", event_kind, "clear"] => parse_project_input_clear(event_kind),
        ["project", "input", event_kind, "add", "artnet"] => {
            parse_project_input_add_artnet(event_kind, parse_u16(msg, 0)?)
        }
        ["project", "input", event_kind, "remove", "artnet"] => {
            parse_project_input_remove_artnet(event_kind, parse_u16(msg, 0)?)
        }
        _ => unknown_address(msg),
    }
}

fn parse_project_input_clear(event_kind: &str) -> Result<UiAction, ()> {
    match event_kind {
        "tap" => Ok(UiAction::ClearProjectTapInput),
        "blackout" => Ok(UiAction::ClearProjectBlackoutInput),
        "blackout_hold" => Ok(UiAction::ClearProjectBlackoutHoldInput),
        "half" => Ok(UiAction::ClearProjectHalfInput),
        "double" => Ok(UiAction::ClearProjectDoubleInput),
        _ => Err(()),
    }
}

fn parse_project_input_add_artnet(event_kind: &str, channel: u16) -> Result<UiAction, ()> {
    match event_kind {
        "tap" => Ok(UiAction::AddProjectTapInputArtnet(channel)),
        "blackout" => Ok(UiAction::AddProjectBlackoutInputArtnet(channel)),
        "blackout_hold" => Ok(UiAction::AddProjectBlackoutHoldInputArtnet(channel)),
        "half" => Ok(UiAction::AddProjectHalfInputArtnet(channel)),
        "double" => Ok(UiAction::AddProjectDoubleInputArtnet(channel)),
        _ => Err(()),
    }
}

fn parse_project_input_remove_artnet(event_kind: &str, channel: u16) -> Result<UiAction, ()> {
    match event_kind {
        "tap" => Ok(UiAction::RemoveProjectTapInputArtnet(channel)),
        "blackout" => Ok(UiAction::RemoveProjectBlackoutInputArtnet(channel)),
        "blackout_hold" => Ok(UiAction::RemoveProjectBlackoutHoldInputArtnet(channel)),
        "half" => Ok(UiAction::RemoveProjectHalfInputArtnet(channel)),
        "double" => Ok(UiAction::RemoveProjectDoubleInputArtnet(channel)),
        _ => Err(()),
    }
}

fn parse_optional_palette_id(
    msg: &OscMessage,
    index: usize,
) -> Result<Option<AssetId<Palette>>, ()> {
    parse_optional_uuid(msg, index).map(|id| id.map(AssetId::from_uuid))
}