Skip to content

Commit be1db4c

Browse files
committed
remove num_enum dep
1 parent 177d5e3 commit be1db4c

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude = ["assets/*"]
1515

1616
[features]
1717
default = ["std"]
18-
std = ["thiserror/std", "num_enum/std", "crossbeam-channel/std"]
18+
std = ["thiserror/std"]
1919
web = ["bevy_platform/web"]
2020
bevy = ["dep:bevy"]
2121
bevy_asset = ["bevy/bevy_asset"]
@@ -28,15 +28,9 @@ optional = true
2828
default-features = false
2929

3030
[dependencies]
31-
num_enum = { version = "0.7.3", default-features = false }
3231
thiserror = { version = "2.0", default-features = false }
3332
# Bevy feature deps
34-
crossbeam-channel = { version = "0.5.15", optional = true, default-features = false }
35-
midir = { version = "0.10", optional = true }
36-
tinyaudio = { version = "1.1.0", optional = true }
37-
itertools = { version = "0.14.0", optional = true }
38-
rustysynth = { version = "1.3.5", optional = true }
39-
bevy_platform = { version = "0.17.0-rc.1", default-features = false, features = [
33+
bevy_platform = { version = "0.17.0-rc", optional = true, default-features = false, features = [
4034
"alloc",
4135
] }
4236
serde = {version = "1.0", features = ["derive"], optional = true}

src/channel.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ use core::{
77
ops::{Add, AddAssign, Sub, SubAssign},
88
};
99

10-
use num_enum::{IntoPrimitive, TryFromPrimitive};
11-
1210
use crate::message::{ChannelVoiceMessage, VoiceEvent};
1311

1412
/// Identifies a channel for MIDI.
1513
///
1614
/// To get this channel from a `u8`, use [`Channel::try_from_primitive`].
17-
#[derive(
18-
Clone, Copy, PartialEq, Eq, Debug, Hash, IntoPrimitive, TryFromPrimitive, PartialOrd, Ord,
19-
)]
15+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
2016
#[cfg_attr(
2117
feature = "bevy",
2218
derive(bevy::prelude::Component, bevy::prelude::Reflect)
@@ -76,6 +72,33 @@ impl Channel {
7672
pub const fn send_event(self, event: VoiceEvent) -> ChannelVoiceMessage {
7773
ChannelVoiceMessage::new(self, event)
7874
}
75+
/// Create a `Channel` from a byte.
76+
///
77+
/// 0 -> `Channel::One`
78+
/// ..
79+
/// 15 -> `Channel::Sixteen`
80+
pub const fn try_from_byte(byte: u8) -> Option<Channel> {
81+
let channel = match byte {
82+
0 => Channel::One,
83+
1 => Channel::Two,
84+
2 => Channel::Three,
85+
3 => Channel::Four,
86+
4 => Channel::Five,
87+
5 => Channel::Six,
88+
6 => Channel::Seven,
89+
7 => Channel::Eight,
90+
8 => Channel::Nine,
91+
9 => Channel::Ten,
92+
10 => Channel::Eleven,
93+
11 => Channel::Twelve,
94+
12 => Channel::Thirteen,
95+
13 => Channel::Fourteen,
96+
14 => Channel::Fifteen,
97+
15 => Channel::Sixteen,
98+
_ => return None,
99+
};
100+
Some(channel)
101+
}
79102

80103
/// Given a status byte from some [`ChannelVoiceMessage`], perform bitwise ops
81104
/// to get the channel
@@ -97,7 +120,7 @@ impl Channel {
97120

98121
impl fmt::Display for Channel {
99122
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
100-
let res: u8 = (*self).into();
123+
let res: u8 = *self as u8;
101124
res.fmt(f)
102125
}
103126
}

src/file_repr/meta/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Contains types that deal with file ['MetaMessage']s
55
mod tempo;
66

77
use alloc::borrow::Cow;
8-
use num_enum::TryFromPrimitive;
98
pub use tempo::*;
109
mod time_signature;
1110
pub use time_signature::*;
@@ -99,12 +98,12 @@ impl<'a> MetaMessage<'a> {
9998
}
10099
//TODO: need to test thsi
101100
let c = data.first().unwrap();
102-
MetaMessage::MidiChannel(Channel::try_from_primitive(*c).map_err(|e| {
101+
MetaMessage::MidiChannel(Channel::try_from_byte(*c).ok_or(
103102
ReaderError::parse_error(
104103
reader.buffer_position(),
105-
ParseError::InvalidChannel(e.number),
106-
)
107-
})?)
104+
ParseError::InvalidChannel(*c),
105+
),
106+
)?)
108107
}
109108
0x21 => {
110109
if data.len() != 1 {

0 commit comments

Comments
 (0)