midi2/channel_voice2/
control_change.rs

1use crate::{
2    channel_voice2::UMP_MESSAGE_TYPE,
3    detail::{common_properties, schema},
4    ux::{u4, u7},
5};
6
7pub(crate) const STATUS: u8 = 0b1011;
8
9/// MIDI 2.0 Channel Voice Control Change Message
10///
11/// See the [module docs](crate::channel_voice2) for more info.
12#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
13struct ControlChange {
14    #[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
15    ump_type: (),
16    #[property(common_properties::ChannelVoiceStatusProperty<STATUS>)]
17    status: (),
18    #[property(common_properties::UmpSchemaProperty<u4, schema::Ump<0x000F_0000, 0x0, 0x0, 0x0>>)]
19    channel: u4,
20    #[property(common_properties::GroupProperty)]
21    group: u4,
22    #[property(common_properties::UmpSchemaProperty<u7, schema::Ump<0x0000_7F00, 0x0, 0x0, 0x0>>)]
23    control: u7,
24    #[property(common_properties::UmpSchemaProperty<u32, schema::Ump<0x0000_0000, 0xFFFF_FFFF, 0x0, 0x0>>)]
25    control_change_data: u32,
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31    use pretty_assertions::assert_eq;
32
33    #[test]
34    fn setters() {
35        use crate::traits::{Channeled, Grouped};
36        let mut message = ControlChange::<[u32; 4]>::new();
37        message.set_group(u4::new(0x3));
38        message.set_channel(u4::new(0x9));
39        message.set_control(u7::new(0x30));
40        message.set_control_change_data(0x2468_1012);
41
42        assert_eq!(message, ControlChange([0x43B9_3000, 0x2468_1012, 0x0, 0x0]));
43    }
44
45    #[test]
46    fn control() {
47        assert_eq!(
48            ControlChange::try_from(&[0x43B9_3000, 0x2468_1012][..])
49                .unwrap()
50                .control(),
51            u7::new(0x30),
52        );
53    }
54
55    #[test]
56    fn control_change_data() {
57        assert_eq!(
58            ControlChange::try_from(&[0x43B9_3000, 0x2468_1012][..])
59                .unwrap()
60                .control_change_data(),
61            0x2468_1012,
62        );
63    }
64}