lighthouse_protocol/input/midi_event.rs
1use serde::{Deserialize, Serialize};
2
3use super::EventSource;
4
5/// A MIDI message event.
6#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
7pub struct MidiEvent {
8 /// The client identifier. Also unique per MIDI input device.
9 pub source: EventSource,
10 /// The binary MIDI message.
11 ///
12 /// The first byte is a status byte (first/most significant bit = 1), the
13 /// remaining bytes are data bytes (first/most significant bit = 0).
14 ///
15 /// To give a simple example, pressing C5 on a MIDI keyboard would generate the
16 /// following message:
17 ///
18 /// ```plaintext
19 /// [0x90, 0x48, 0x64]
20 /// Ch.1 Note 72 Velocity 100
21 /// NoteOn i.e. C5
22 /// ```
23 ///
24 /// The note values can be looked up online:
25 ///
26 /// - https://www.phys.unsw.edu.au/jw/notes.html
27 ///
28 /// Same goes for a full description of the packet structure:
29 ///
30 /// - https://www.w3.org/TR/webmidi/#terminology
31 /// - http://www.opensound.com/pguide/midi/midi5.html
32 /// - https://www.songstuff.com/recording/article/midi-message-format/
33 #[serde(with = "serde_bytes")]
34 pub data: Vec<u8>,
35}