|
| 1 | +MIDI 2.0 Channel Voice Messages |
| 2 | + |
| 3 | +## Basic Usage |
| 4 | + |
| 5 | +```rust |
| 6 | +use midi2::{ |
| 7 | + prelude::*, |
| 8 | + channel_voice2::NoteOn, |
| 9 | +}; |
| 10 | + |
| 11 | +let mut message = ControlChange::<[u32; 4]>::new(); |
| 12 | +message.set_channel(u4::new(0xA)); |
| 13 | +message.set_group(u4::new(0xC)); |
| 14 | +message.set_control(u7::new(0x36)); |
| 15 | +message.set_control_data(u7::new(0x37)); |
| 16 | + |
| 17 | +assert_eq!(message.data(), &[0x2CBA_3637]); |
| 18 | +``` |
| 19 | + |
| 20 | +## Channeled |
| 21 | + |
| 22 | +`channel_voice1` messages are [Channeled](crate::Channeled). |
| 23 | + |
| 24 | +## Grouped |
| 25 | + |
| 26 | +`channel_voice1` messages are [Grouped](crate::Grouped) |
| 27 | +when backed with [Ump](crate::buffer::Ump) buffers. |
| 28 | + |
| 29 | +## Aggregate Message |
| 30 | + |
| 31 | +There is a single aggregate [ChannelVoice1] enum type which |
| 32 | +can represent an arbitrary `channel_voice1` message. |
| 33 | + |
| 34 | +```rust |
| 35 | +use midi2::{ |
| 36 | + prelude::*, |
| 37 | + channel_voice1::ChannelVoice1, |
| 38 | +}; |
| 39 | + |
| 40 | +let mut message = ChannelVoice1::try_from(&[0x2CBA_3637_u32][..]).expect("Valid data"); |
| 41 | + |
| 42 | +match message { |
| 43 | + ChannelVoice1::ChannelPressure(m) => println!("channel_pressure {:?}", m.data()), |
| 44 | + ChannelVoice1::ControlChange(m) => println!("control_change {:?}", m.data()), |
| 45 | + ChannelVoice1::KeyPressure(m) => println!("key_pressure {:?}", m.data()), |
| 46 | + ChannelVoice1::NoteOff(m) => println!("note_off {:?}", m.data()), |
| 47 | + ChannelVoice1::NoteOn(m) => println!("note_on {:?}", m.data()), |
| 48 | + ChannelVoice1::PitchBend(m) => println!("pitch_bend {:?}", m.data()), |
| 49 | + ChannelVoice1::ProgramChange(m) => println!("program_change {:?}", m.data()), |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Generic Over [Unit](crate::buffer::Unit) |
| 54 | + |
| 55 | +`channel_voice1` messages can also be represented with [Bytes](crate::buffer::Bytes) buffers |
| 56 | + as well as [Ump](crate::buffer::Ump) buffers. |
| 57 | + |
| 58 | +```rust |
| 59 | +use midi2::{ |
| 60 | + prelude::*, |
| 61 | + channel_voice1::ControlChange, |
| 62 | +}; |
| 63 | + |
| 64 | +let mut message = ControlChange::<[u8; 3]>::new(); |
| 65 | +message.set_channel(u4::new(0xA)); |
| 66 | +message.set_control(u7::new(0x36)); |
| 67 | +message.set_control_data(u7::new(0x37)); |
| 68 | + |
| 69 | +assert_eq!(message.data(), &[0xBA, 0x36, 0x37]); |
| 70 | +``` |
| 71 | + |
| 72 | +## Fixed Size |
| 73 | + |
| 74 | +All `channel_voice1` messages are Fixed size. |
| 75 | + |
| 76 | +```rust |
| 77 | +use midi2::channel_voice1::KeyPressure; |
| 78 | + |
| 79 | + |
| 80 | +// All channel_voice1 bytes-backed messages fit into a `[u8; 3]` |
| 81 | +let _ = KeyPressure::<[u8; 3]>::new(); |
| 82 | + |
| 83 | +// All channel_voice1 ump-backed messages fit into a `[u32; 1]` |
| 84 | +let _ = KeyPressure::<[u32; 1]>::new(); |
| 85 | +``` |
0 commit comments