ot_tools_io/projects/settings/
tempo.rs

1/*
2SPDX-License-Identifier: GPL-3.0-or-later
3Copyright © 2024 Mike Robeson [dijksterhuis]
4*/
5
6//! Current settings for the Project Tempo.
7//! **NOTE**: This tempo setting works independently to arrangement mode tempo.
8
9use crate::projects::{parse_hashmap_string_value, parse_hashmap_string_value_bool};
10// use crate::OtToolsIoErrors;
11use crate::projects::ProjectParseError;
12use serde::{Deserialize, Serialize};
13use std::collections::HashMap;
14
15/// Global `TEMPO` UI menu.
16#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17pub struct TempoMenu {
18    /// BPM of the current project tempo setting.
19    /// **NOTE 1**: This can be ignored by using the `pattern_tempo_enabled`.
20    /// **NOTE 2**: Is multiplied by 24 on device.
21    pub tempo: u32,
22
23    /// Whether to use the current pattern's tempo or project tempo.
24    /// - Pattern Tempo: `true`
25    /// - Project Tempo: `false`
26    pub pattern_tempo_enabled: bool,
27}
28
29impl TryFrom<&HashMap<String, String>> for TempoMenu {
30    type Error = ProjectParseError;
31    fn try_from(value: &HashMap<String, String>) -> Result<Self, Self::Error> {
32        let tempo = parse_hashmap_string_value::<u32>(value, "tempox24", None)? / 24;
33        let pattern_tempo_enabled =
34            parse_hashmap_string_value_bool(value, "pattern_tempo_enabled", None)?;
35
36        Ok(Self {
37            tempo,
38            pattern_tempo_enabled,
39        })
40    }
41}