midi2/ump_stream/
stream_configuration_request.rs

1use crate::{
2    detail::{common_properties, schema},
3    ump_stream,
4    ump_stream::UMP_MESSAGE_TYPE,
5};
6
7pub(crate) const STATUS: u16 = 0x5;
8
9#[midi2_proc::generate_message(Via(ump_stream::UmpStream), FixedSize, MinSizeUmp(1))]
10struct StreamConfigurationRequest {
11    #[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
12    ump_type: (),
13    #[property(ump_stream::StatusProperty<STATUS>)]
14    status: (),
15    #[property(ump_stream::ConsistentFormatsProperty)]
16    consistent_formats: (),
17    #[property(common_properties::UmpSchemaProperty<u8, schema::Ump<0x0000_FF00, 0x0, 0x0, 0x0>>)]
18    protocol: u8,
19    #[property(common_properties::UmpSchemaProperty<bool, schema::Ump<0b0000_0000_0000_0000_0000_0000_0000_0010, 0x0, 0x0, 0x0>>)]
20    receive_jr_timestamps: bool,
21    #[property(common_properties::UmpSchemaProperty<bool, schema::Ump<0b0000_0000_0000_0000_0000_0000_0000_0001, 0x0, 0x0, 0x0>>)]
22    send_jr_timestamps: bool,
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use pretty_assertions::assert_eq;
29
30    #[test]
31    fn builder() {
32        let mut message = StreamConfigurationRequest::<[u32; 4]>::new();
33        message.set_protocol(0x2);
34        message.set_receive_jr_timestamps(true);
35        message.set_send_jr_timestamps(true);
36        assert_eq!(
37            message,
38            StreamConfigurationRequest([0xF005_0203, 0x0, 0x0, 0x0,]),
39        );
40    }
41
42    #[test]
43    fn protocol() {
44        assert_eq!(
45            StreamConfigurationRequest::try_from(&[0xF005_0203][..])
46                .unwrap()
47                .protocol(),
48            0x2
49        );
50    }
51
52    #[test]
53    fn receive_jr_timestamps() {
54        assert_eq!(
55            StreamConfigurationRequest::try_from(&[0xF005_0203][..])
56                .unwrap()
57                .receive_jr_timestamps(),
58            true
59        );
60    }
61
62    #[test]
63    fn send_jr_timestamps() {
64        assert_eq!(
65            StreamConfigurationRequest::try_from(&[0xF005_0203][..])
66                .unwrap()
67                .send_jr_timestamps(),
68            true
69        );
70    }
71}