midi_msg/
context.rs

1use super::{MidiMsg, TimeCode};
2
3/// Passed to [`MidiMsg::from_midi_with_context`](crate::MidiMsg::from_midi_with_context) to allow
4/// for the capture and use of captured context while reading from a MIDI stream.
5///
6/// This is used to allow for the formation of fully formed `MidiMsg`s when either a running
7/// status is being employed, or when using 14-bit [`ControlChange`](crate::ControlChange) messages.
8///
9/// It's also used to track the current [`TimeCode`](crate::TimeCode)
10/// as sent through [`SystemCommonMsg::TimeCodeQuarterFrame`](crate::SystemCommonMsg::TimeCodeQuarterFrame1)
11/// messages, or [`UniversalRealTimeMsg::TimeCodeFull`](crate::UniversalRealTimeMsg::TimeCodeFull)
12/// messages.
13#[derive(Debug, Clone, PartialEq, Default)]
14pub struct ReceiverContext {
15    pub(crate) previous_channel_message: Option<MidiMsg>,
16    pub(crate) time_code: TimeCode,
17    pub(crate) is_smf_sysex: bool,
18    pub(crate) parsing_smf: bool,
19    /// If true, CC messages will be treated as complex CC messages, with their semantics taken from the Midi spec. Otherwise, they will be treated as simple CC messages - i.e. [`ControlChange::CC`](crate::ControlChange::CC).
20    pub complex_cc: bool,
21}
22
23impl ReceiverContext {
24    pub fn new() -> Self {
25        Self::default()
26    }
27
28    /// Interpret CC messages as complex CC messages.
29    pub fn complex_cc(mut self) -> Self {
30        self.complex_cc = true;
31        self
32    }
33
34    pub(crate) fn parsing_smf(mut self) -> Self {
35        self.parsing_smf = true;
36        self
37    }
38}