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
73
use crate::message::Channel;
use crate::util::*;
#[derive(Debug, Clone, PartialEq)]
pub struct KeyBasedInstrumentControl {
pub channel: Channel,
pub key: u8,
pub control_values: Vec<(u8, u8)>,
}
impl KeyBasedInstrumentControl {
pub(crate) fn extend_midi(&self, v: &mut Vec<u8>) {
v.push(self.channel as u8);
push_u7(self.key, v);
for (cc, x) in self.control_values.iter().cloned() {
if cc == 0x06 || cc == 0x26 || cc == 0x60 || cc == 0x65 || cc >= 0x78 {
v.push(1);
} else {
v.push(cc);
}
push_u7(x, v);
}
}
pub(crate) fn from_midi(_m: &[u8]) -> Result<(Self, usize), &str> {
Err("TODO: not implemented")
}
}
#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn serialize_controller_destination() {
assert_eq!(
MidiMsg::SystemExclusive {
msg: SystemExclusiveMsg::UniversalRealTime {
device: DeviceID::AllCall,
msg: UniversalRealTimeMsg::KeyBasedInstrumentControl(
KeyBasedInstrumentControl {
channel: Channel::Ch2,
key: 0x60,
control_values: vec![
(0x06, 0x40),
(ControlNumber::Effects4Depth as u8, 0x20),
]
}
),
}
}
.to_midi(),
vec![
0xF0, 0x7F, 0x7F,
0x0A, 01,
01, 0x60, 0x01, 0x40, 94, 0x20, 0xF7
]
);
}
}