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
71
72
use crate::{
    detail::{common_properties, schema},
    ump_stream,
    ump_stream::UMP_MESSAGE_TYPE,
};

pub(crate) const STATUS: u16 = 0x10;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1))]
struct FunctionBlockDiscovery {
    #[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
    ump_type: (),
    #[property(ump_stream::StatusProperty<STATUS>)]
    status: (),
    #[property(ump_stream::ConsistentFormatsProperty)]
    consistent_formats: (),

    #[property(common_properties::UmpSchemaProperty<u8, schema::Ump<0x0000_FF00, 0x0, 0x0, 0x0>>)]
    function_block_number: u8,
    #[property(common_properties::UmpSchemaProperty<bool, schema::Ump<0b0000_0000_0000_0000_0000_0000_0000_0010, 0x0, 0x0, 0x0>>)]
    requesting_function_block_info: bool,
    #[property(common_properties::UmpSchemaProperty<bool, schema::Ump<0b0000_0000_0000_0000_0000_0000_0000_0001, 0x0, 0x0, 0x0>>)]
    requesting_function_block_name: bool,
}

#[cfg(test)]
mod tests {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn setters() {
        let mut message = FunctionBlockDiscovery::new_arr();
        message.set_function_block_number(0x09);
        message.set_requesting_function_block_info(true);
        message.set_requesting_function_block_name(true);
        assert_eq!(
            message,
            FunctionBlockDiscovery([0xF010_0903, 0x0, 0x0, 0x0])
        );
    }

    #[test]
    fn function_block_number() {
        assert_eq!(
            FunctionBlockDiscovery::try_from(&[0xF010_0903][..])
                .unwrap()
                .function_block_number(),
            0x09,
        );
    }

    #[test]
    fn requesting_function_block_info() {
        assert_eq!(
            FunctionBlockDiscovery::try_from(&[0xF010_0903][..])
                .unwrap()
                .requesting_function_block_info(),
            true
        );
    }

    #[test]
    fn requesting_function_block_name() {
        assert_eq!(
            FunctionBlockDiscovery::try_from(&[0xF010_0903][..])
                .unwrap()
                .requesting_function_block_name(),
            true
        );
    }
}