midix/
channel.rs

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
#![doc = r#"
# Identifier for a MIDI Channel
"#]

use core::fmt;

/// Identifies a channel for MIDI, it's u4
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct Channel(u8);

impl Channel {
    ///Identify a channel
    pub fn new(channel: impl Into<u8>) -> Self {
        Self(channel.into())
    }

    /// Returns the 4-bit channel number
    pub fn bits(&self) -> u8 {
        self.0
    }
}

impl fmt::Display for Channel {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(f)
    }
}