ot-tools-io 0.10.1

A library crate for reading/writing binary data files used by the Elektron Octatrack DPS-1.
Documentation
/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2026 Mike Robeson [dijksterhuis]
*/

//! Current settings for the Project Tempo.
//! **NOTE**: This tempo setting works independently to arrangement mode tempo.

use crate::projects::{parse_hashmap_string_value, parse_hashmap_string_value_bool};
use ot_tools_io_derive::{AsMutDerive, AsRefDerive};
// use crate::OtToolsIoErrors;
use crate::projects::ProjectParseError;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Global `TEMPO` UI menu.
#[derive(
    Copy,
    Clone,
    Debug,
    Eq,
    Hash,
    Ord,
    PartialEq,
    PartialOrd,
    Serialize,
    Deserialize,
    AsMutDerive,
    AsRefDerive,
)]
pub struct TempoMenu {
    /// BPM of the current project tempo setting.
    /// **NOTE 1**: This can be ignored by using the `pattern_tempo_enabled`.
    /// **NOTE 2**: Is multiplied by 24 on device.
    pub tempo: u32,

    /// Whether to use the current pattern's tempo or project tempo.
    /// - Pattern Tempo: `true`
    /// - Project Tempo: `false`
    pub pattern_tempo_enabled: bool,
}

impl Default for TempoMenu {
    fn default() -> Self {
        Self {
            tempo: 120,
            pattern_tempo_enabled: false,
        }
    }
}

impl TryFrom<&HashMap<String, String>> for TempoMenu {
    type Error = ProjectParseError;
    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
        let tempo = parse_hashmap_string_value::<u32>(value, "tempox24", None)? / 24;
        let pattern_tempo_enabled =
            parse_hashmap_string_value_bool(value, "pattern_tempo_enabled", None)?;

        Ok(Self {
            tempo,
            pattern_tempo_enabled,
        })
    }
}