Skip to content

Commit 7381b6f

Browse files
author
Ben Leadbetter
committed
Merge branch 'release/0.4.0'
2 parents e01f358 + feb34da commit 7381b6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+219
-129
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.4.0
2+
feat: top level messages implement From for all messages
3+
fix: ⚠️ utility messages should be excluded when feature is not enabled
4+
refactor: remove some unused code
5+
refactor: ⚠️ hide private utility submodules
6+
17
# 0.3.1
28
docs: fix typos in readme
39
fix: panic on empty flex-data text iterator

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "midi2"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "Ergonomic, versatile, strong types wrapping MIDI 2.0 message data."
55
edition = "2021"
66
readme = "README.md"
@@ -35,7 +35,7 @@ utility = []
3535

3636
[dependencies]
3737
derive_more = { version = "0.99.17", features = ["from"], default-features = false }
38-
midi2_proc = { version = "0.3.1", path = "midi2_proc" }
38+
midi2_proc = { version = "0.4.0", path = "midi2_proc" }
3939
ux = "0.1.6"
4040

4141
[dev-dependencies]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ You'll want to setup midi2 without default features to compile
156156
without the `std` feature.
157157

158158
```toml
159-
midi2 = { version = "0.3.1", default-features = false, features = ["channel-voice2", "sysex7"], }
159+
midi2 = { version = "0.4.0", default-features = false, features = ["channel-voice2", "sysex7"], }
160160
```
161161

162162
### Generic Representation

midi2_proc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "midi2_proc"
33
description = "Internal procedural macro crate. Only intended for use with midi2"
4-
version = "0.3.1"
4+
version = "0.4.0"
55
edition = "2021"
66
readme = "README.md"
77
license = "MIT OR Apache-2.0"

midi2_proc/src/derives.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,6 @@ pub fn data(item: TokenStream1) -> TokenStream1 {
3131
.into()
3232
}
3333

34-
pub fn jitter_reduced(item: TokenStream1) -> TokenStream1 {
35-
let input = parse_macro_input!(item as ItemEnum);
36-
let ident = &input.ident;
37-
let mut match_arms_setter = TokenStream::new();
38-
let mut match_arms_getter = TokenStream::new();
39-
for variant in &input.variants {
40-
let variant_ident = &variant.ident;
41-
match_arms_getter.extend(quote! {
42-
#variant_ident(m) => m.jitter_reduction(),
43-
});
44-
match_arms_setter.extend(quote! {
45-
#variant_ident(m) => m.set_jitter_reduction(jr),
46-
});
47-
}
48-
quote! {
49-
impl<B: crate::buffer::Ump> crate::traits::JitterReduced<B> for #ident<B> {
50-
fn jitter_reduction(&self) -> Option<crate::utility::JitterReduction> {
51-
use #ident::*;
52-
match self {
53-
#match_arms_getter
54-
}
55-
}
56-
fn set_jitter_reduction(&mut self, jr: Option<crate::utility::JitterReduction>)
57-
where
58-
B: crate::buffer::BufferMut
59-
{
60-
use #ident::*;
61-
match self {
62-
#match_arms_setter
63-
}
64-
}
65-
}
66-
}
67-
.into()
68-
}
69-
7034
pub fn from_bytes(item: TokenStream1) -> TokenStream1 {
7135
let input = parse_macro_input!(item as ItemEnum);
7236
let ident = &input.ident;

midi2_proc/src/generate_message.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct GenerateMessageArgs {
102102
fixed_size: bool,
103103
min_size_ump: Option<usize>,
104104
min_size_bytes: Option<usize>,
105+
via: Option<syn::Type>,
105106
}
106107

107108
impl GenerateMessageArgs {
@@ -124,7 +125,9 @@ impl syn::parse::Parse for GenerateMessageArgs {
124125
break;
125126
};
126127

127-
let ident = ident.to_string();
128+
if ident == "Via" {
129+
args.via = Some(parse_via_args(input));
130+
}
128131
if ident == "FixedSize" {
129132
args.fixed_size = true;
130133
}
@@ -163,6 +166,22 @@ fn parse_fixed_size(input: syn::parse::ParseStream) -> usize {
163166
.expect("Valid base 10 literal size")
164167
}
165168

169+
fn parse_via_args(input: syn::parse::ParseStream) -> syn::Type {
170+
let syn::ExprParen { expr, .. } = input
171+
.parse()
172+
.expect("Bracketed expression should follow size arg");
173+
174+
let syn::Expr::Path(path) = *expr
175+
else {
176+
panic!("Via argument should contain a path type");
177+
};
178+
179+
syn::Type::Path(syn::TypePath{
180+
qself: path.qself,
181+
path: path.path,
182+
})
183+
}
184+
166185
fn imports() -> TokenStream {
167186
quote! {
168187
use crate::buffer::UnitPrivate as UnitPrivateGenMessage;
@@ -692,6 +711,26 @@ fn try_from_ump_impl(root_ident: &syn::Ident, properties: &Vec<Property>) -> Tok
692711
}
693712
}
694713

714+
fn ump_message_via(root_ident: &syn::Ident, via_type: &syn::Type) -> TokenStream {
715+
quote! {
716+
impl<B: crate::buffer::Ump> core::convert::From<#root_ident<B>> for crate::message::UmpMessage<B> {
717+
fn from(value: #root_ident<B>) -> Self {
718+
<#via_type<B> as core::convert::From<#root_ident<B>>>::from(value).into()
719+
}
720+
}
721+
}
722+
}
723+
724+
fn bytes_message_via(root_ident: &syn::Ident, via_type: &syn::Type) -> TokenStream {
725+
quote! {
726+
impl<B: crate::buffer::Bytes> core::convert::From<#root_ident<B>> for crate::message::BytesMessage<B> {
727+
fn from(value: #root_ident<B>) -> Self {
728+
<#via_type<B> as core::convert::From<#root_ident<B>>>::from(value).into()
729+
}
730+
}
731+
}
732+
}
733+
695734
pub fn generate_message(attrs: TokenStream1, item: TokenStream1) -> TokenStream1 {
696735
let input = syn::parse_macro_input!(item as syn::ItemStruct);
697736
let args = syn::parse_macro_input!(attrs as GenerateMessageArgs);
@@ -753,6 +792,16 @@ pub fn generate_message(attrs: TokenStream1, item: TokenStream1) -> TokenStream1
753792
tokens.extend(try_from_ump_impl(root_ident, &properties));
754793
}
755794
}
795+
if let Some(via_type) = args.via.as_ref() {
796+
match args.representation() {
797+
Representation::Ump => tokens.extend(ump_message_via(root_ident, &via_type)),
798+
Representation::Bytes => tokens.extend(bytes_message_via(root_ident, &via_type)),
799+
Representation::UmpOrBytes => {
800+
tokens.extend(ump_message_via(root_ident, &via_type));
801+
tokens.extend(bytes_message_via(root_ident, &via_type));
802+
}
803+
}
804+
}
756805

757806
tokens.into()
758807
}

midi2_proc/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ pub fn derive_data(item: TokenStream1) -> TokenStream1 {
1414
derives::data(item)
1515
}
1616

17-
#[proc_macro_derive(JitterReduced)]
18-
pub fn derive_jitter_reduced(item: TokenStream1) -> TokenStream1 {
19-
derives::jitter_reduced(item)
20-
}
21-
2217
#[proc_macro_derive(Grouped)]
2318
pub fn derive_grouped(item: TokenStream1) -> TokenStream1 {
2419
derives::grouped(item)

src/channel_voice1/channel_pressure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55

66
pub(crate) const STATUS: u8 = 0b1101;
77

8-
#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
8+
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
99
struct ChannelPressure {
1010
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
1111
ump_type: (),

src/channel_voice1/control_change.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use crate::{
55

66
pub(crate) const STATUS: u8 = 0b1011;
77

8-
#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
8+
#[midi2_proc::generate_message(
9+
Via(crate::channel_voice1::ChannelVoice1),
10+
FixedSize,
11+
MinSizeUmp(1),
12+
MinSizeBytes(3)
13+
)]
914
struct ControlChange {
1015
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
1116
ump_type: (),

src/channel_voice1/key_pressure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55

66
pub(crate) const STATUS: u8 = 0b1010;
77

8-
#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
8+
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
99
struct KeyPressure {
1010
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
1111
ump_type: (),

0 commit comments

Comments
 (0)