xsynth_core/channel/
event.rs

1use std::sync::Arc;
2
3use crate::soundfont::SoundfontBase;
4
5/// MIDI events for a single key in a channel.
6#[derive(Clone, Copy, Debug, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8pub enum KeyNoteEvent {
9    /// Starts a new note voice with a velocity
10    On(u8),
11
12    /// Signals off to a note voice
13    Off,
14
15    /// Signals off to all note voices
16    AllOff,
17
18    /// Kills all note voices without decay
19    AllKilled,
20}
21
22/// Events to modify parameters of a channel.
23#[derive(Clone, Debug)]
24#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
25pub enum ChannelConfigEvent {
26    /// Sets the soundfonts for the channel
27    #[cfg_attr(feature = "serde", serde(skip))]
28    SetSoundfonts(Vec<Arc<dyn SoundfontBase>>),
29
30    /// Sets the layer count for the soundfont
31    SetLayerCount(Option<usize>),
32
33    /// Controls whether the channel will be standard or percussion.
34    /// Setting to `true` will make the channel only use percussion patches.
35    SetPercussionMode(bool),
36}
37
38/// MIDI events for a channel.
39#[derive(Clone, Copy, Debug, PartialEq)]
40#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
41pub enum ChannelAudioEvent {
42    /// Starts a new note voice
43    NoteOn { key: u8, vel: u8 },
44
45    /// Signals off to a note voice
46    NoteOff { key: u8 },
47
48    /// Signal off to all voices
49    AllNotesOff,
50
51    /// Kill all voices without decay
52    AllNotesKilled,
53
54    /// Resets all CC to their default values
55    ResetControl,
56
57    /// Control event for the channel
58    Control(ControlEvent),
59
60    /// Program change event
61    ProgramChange(u8),
62}
63
64/// Wrapper enum for various events for a channel.
65#[derive(Clone, Debug)]
66#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
67pub enum ChannelEvent {
68    /// Audio event
69    Audio(ChannelAudioEvent),
70
71    /// Configuration event for the channel
72    Config(ChannelConfigEvent),
73}
74
75/// MIDI control events for a channel.
76#[derive(Clone, Copy, Debug, PartialEq)]
77#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
78pub enum ControlEvent {
79    /// A raw control change event
80    Raw(u8, u8),
81
82    /// The pitch bend strength, in tones
83    PitchBendSensitivity(f32),
84
85    /// The pitch bend value, between -1 and 1
86    PitchBendValue(f32),
87
88    /// The pitch bend, product of value * sensitivity
89    PitchBend(f32),
90
91    /// Fine tune value in cents
92    FineTune(f32),
93
94    /// Coarse tune value in semitones
95    CoarseTune(f32),
96}