midi_msg/context.rs
1use super::{MidiMsg, TimeCode, TimeCodeType};
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 const fn new() -> Self {
25 Self {
26 previous_channel_message: None,
27 time_code: TimeCode {
28 frames: 0,
29 seconds: 0,
30 minutes: 0,
31 hours: 0,
32 code_type: TimeCodeType::NDF30,
33 },
34 is_smf_sysex: false,
35 parsing_smf: false,
36 complex_cc: false,
37 }
38 }
39
40 /// Interpret CC messages as complex CC messages.
41 pub fn complex_cc(mut self) -> Self {
42 self.complex_cc = true;
43 self
44 }
45
46 #[cfg(feature = "file")]
47 pub(crate) fn parsing_smf(mut self) -> Self {
48 self.parsing_smf = true;
49 self
50 }
51}