1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::sync::Arc;

use crate::soundfont::SoundfontBase;

/// MIDI events for a single key in a channel.
#[derive(Debug, Clone)]
pub enum KeyNoteEvent {
    /// Starts a new note voice with a velocity
    On(u8),

    /// Signals off to a note voice
    Off,

    /// Signals off to all note voices
    AllOff,

    /// Kills all note voices without decay
    AllKilled,
}

/// Events to modify parameters of a channel.
#[derive(Debug, Clone)]
pub enum ChannelConfigEvent {
    /// Sets the soundfonts for the channel
    SetSoundfonts(Vec<Arc<dyn SoundfontBase>>),

    /// Sets the layer count for the soundfont
    SetLayerCount(Option<usize>),
}

/// MIDI events for a channel.
#[derive(Debug, Clone)]
pub enum ChannelAudioEvent {
    /// Starts a new note voice
    NoteOn { key: u8, vel: u8 },

    /// Signals off to a note voice
    NoteOff { key: u8 },

    /// Signal off to all voices
    AllNotesOff,

    /// Kill all voices without decay
    AllNotesKilled,

    /// Resets all CC to their default values
    ResetControl,

    /// Control event for the channel
    Control(ControlEvent),

    /// Program change event
    ProgramChange(u8),
}

/// Wrapper enum for various events for a channel.
#[derive(Debug, Clone)]
pub enum ChannelEvent {
    /// Audio event
    Audio(ChannelAudioEvent),

    /// Configuration event for the channel
    Config(ChannelConfigEvent),
}

/// MIDI control events for a channel.
#[derive(Debug, Clone)]
pub enum ControlEvent {
    /// A raw control change event
    Raw(u8, u8),

    /// The pitch bend strength, in tones
    PitchBendSensitivity(f32),

    /// The pitch bend value, between -1 and 1
    PitchBendValue(f32),

    /// The pitch bend, product of value * sensitivity
    PitchBend(f32),

    /// Fine tune value in cents
    FineTune(f32),

    /// Coarse tune value in semitones
    CoarseTune(f32),
}