1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::{
    detail::{common_properties, schema},
    system_common::{self, UMP_MESSAGE_TYPE},
};

pub const STATUS: u8 = 0xF1;

/// MIDI 2.0 Channel Voice Time Code Message
///
/// See the [module docs](crate::system_common) for more info.
#[midi2_proc::generate_message(
    Via(system_common::SystemCommon),
    FixedSize,
    MinSizeUmp(1),
    MinSizeBytes(3)
)]
struct TimeCode {
    #[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
    ump_type: (),
    #[property(system_common::SystemCommonStatus<{STATUS}>)]
    status: (),
    #[property(common_properties::GroupProperty)]
    group: crate::ux::u4,
    #[property(common_properties::HybridSchemaProperty<
        crate::ux::u7,
        schema::Bytes<0x0, 0x7F, 0x0>,
        schema::Ump<0x0000_7F00, 0x0, 0x0, 0x0>,
    >)]
    time_code: crate::ux::u7,
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{traits::Grouped, ux::*};
    use pretty_assertions::assert_eq;

    #[test]
    fn setter() {
        let mut message = TimeCode::<[u32; 4]>::new();
        message.set_group(u4::new(0x5));
        message.set_time_code(u7::new(0x5F));
        assert_eq!(message, TimeCode([0x15F1_5F00, 0x0, 0x0, 0x0]),);
    }

    #[test]
    fn setters_bytes() {
        let mut message = TimeCode::<[u8; 3]>::new();
        message.set_time_code(u7::new(0x5F));
        assert_eq!(message, TimeCode([0xF1, 0x5F, 0x0,]),);
    }

    #[test]
    fn group() {
        assert_eq!(
            TimeCode::try_from(&[0x15F1_5F00_u32][..]).unwrap().group(),
            u4::new(0x5),
        );
    }

    #[test]
    fn time_code() {
        assert_eq!(
            TimeCode::try_from(&[0x15F1_5F00_u32][..])
                .unwrap()
                .time_code(),
            u7::new(0x5F),
        );
    }
}