Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Leadbetter committed May 12, 2024
2 parents e01f358 + feb34da commit 7381b6f
Show file tree
Hide file tree
Showing 57 changed files with 219 additions and 129 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.4.0
feat: top level messages implement From for all messages
fix: ⚠️ utility messages should be excluded when feature is not enabled
refactor: remove some unused code
refactor: ⚠️ hide private utility submodules

# 0.3.1
docs: fix typos in readme
fix: panic on empty flex-data text iterator
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "midi2"
version = "0.3.1"
version = "0.4.0"
description = "Ergonomic, versatile, strong types wrapping MIDI 2.0 message data."
edition = "2021"
readme = "README.md"
Expand Down Expand Up @@ -35,7 +35,7 @@ utility = []

[dependencies]
derive_more = { version = "0.99.17", features = ["from"], default-features = false }
midi2_proc = { version = "0.3.1", path = "midi2_proc" }
midi2_proc = { version = "0.4.0", path = "midi2_proc" }
ux = "0.1.6"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ You'll want to setup midi2 without default features to compile
without the `std` feature.

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

### Generic Representation
Expand Down
2 changes: 1 addition & 1 deletion midi2_proc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "midi2_proc"
description = "Internal procedural macro crate. Only intended for use with midi2"
version = "0.3.1"
version = "0.4.0"
edition = "2021"
readme = "README.md"
license = "MIT OR Apache-2.0"
Expand Down
36 changes: 0 additions & 36 deletions midi2_proc/src/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,6 @@ pub fn data(item: TokenStream1) -> TokenStream1 {
.into()
}

pub fn jitter_reduced(item: TokenStream1) -> TokenStream1 {
let input = parse_macro_input!(item as ItemEnum);
let ident = &input.ident;
let mut match_arms_setter = TokenStream::new();
let mut match_arms_getter = TokenStream::new();
for variant in &input.variants {
let variant_ident = &variant.ident;
match_arms_getter.extend(quote! {
#variant_ident(m) => m.jitter_reduction(),
});
match_arms_setter.extend(quote! {
#variant_ident(m) => m.set_jitter_reduction(jr),
});
}
quote! {
impl<B: crate::buffer::Ump> crate::traits::JitterReduced<B> for #ident<B> {
fn jitter_reduction(&self) -> Option<crate::utility::JitterReduction> {
use #ident::*;
match self {
#match_arms_getter
}
}
fn set_jitter_reduction(&mut self, jr: Option<crate::utility::JitterReduction>)
where
B: crate::buffer::BufferMut
{
use #ident::*;
match self {
#match_arms_setter
}
}
}
}
.into()
}

pub fn from_bytes(item: TokenStream1) -> TokenStream1 {
let input = parse_macro_input!(item as ItemEnum);
let ident = &input.ident;
Expand Down
51 changes: 50 additions & 1 deletion midi2_proc/src/generate_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct GenerateMessageArgs {
fixed_size: bool,
min_size_ump: Option<usize>,
min_size_bytes: Option<usize>,
via: Option<syn::Type>,
}

impl GenerateMessageArgs {
Expand All @@ -124,7 +125,9 @@ impl syn::parse::Parse for GenerateMessageArgs {
break;
};

let ident = ident.to_string();
if ident == "Via" {
args.via = Some(parse_via_args(input));
}
if ident == "FixedSize" {
args.fixed_size = true;
}
Expand Down Expand Up @@ -163,6 +166,22 @@ fn parse_fixed_size(input: syn::parse::ParseStream) -> usize {
.expect("Valid base 10 literal size")
}

fn parse_via_args(input: syn::parse::ParseStream) -> syn::Type {
let syn::ExprParen { expr, .. } = input
.parse()
.expect("Bracketed expression should follow size arg");

let syn::Expr::Path(path) = *expr
else {
panic!("Via argument should contain a path type");
};

syn::Type::Path(syn::TypePath{
qself: path.qself,
path: path.path,
})
}

fn imports() -> TokenStream {
quote! {
use crate::buffer::UnitPrivate as UnitPrivateGenMessage;
Expand Down Expand Up @@ -692,6 +711,26 @@ fn try_from_ump_impl(root_ident: &syn::Ident, properties: &Vec<Property>) -> Tok
}
}

fn ump_message_via(root_ident: &syn::Ident, via_type: &syn::Type) -> TokenStream {
quote! {
impl<B: crate::buffer::Ump> core::convert::From<#root_ident<B>> for crate::message::UmpMessage<B> {
fn from(value: #root_ident<B>) -> Self {
<#via_type<B> as core::convert::From<#root_ident<B>>>::from(value).into()
}
}
}
}

fn bytes_message_via(root_ident: &syn::Ident, via_type: &syn::Type) -> TokenStream {
quote! {
impl<B: crate::buffer::Bytes> core::convert::From<#root_ident<B>> for crate::message::BytesMessage<B> {
fn from(value: #root_ident<B>) -> Self {
<#via_type<B> as core::convert::From<#root_ident<B>>>::from(value).into()
}
}
}
}

pub fn generate_message(attrs: TokenStream1, item: TokenStream1) -> TokenStream1 {
let input = syn::parse_macro_input!(item as syn::ItemStruct);
let args = syn::parse_macro_input!(attrs as GenerateMessageArgs);
Expand Down Expand Up @@ -753,6 +792,16 @@ pub fn generate_message(attrs: TokenStream1, item: TokenStream1) -> TokenStream1
tokens.extend(try_from_ump_impl(root_ident, &properties));
}
}
if let Some(via_type) = args.via.as_ref() {
match args.representation() {
Representation::Ump => tokens.extend(ump_message_via(root_ident, &via_type)),
Representation::Bytes => tokens.extend(bytes_message_via(root_ident, &via_type)),
Representation::UmpOrBytes => {
tokens.extend(ump_message_via(root_ident, &via_type));
tokens.extend(bytes_message_via(root_ident, &via_type));
}
}
}

tokens.into()
}
5 changes: 0 additions & 5 deletions midi2_proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ pub fn derive_data(item: TokenStream1) -> TokenStream1 {
derives::data(item)
}

#[proc_macro_derive(JitterReduced)]
pub fn derive_jitter_reduced(item: TokenStream1) -> TokenStream1 {
derives::jitter_reduced(item)
}

#[proc_macro_derive(Grouped)]
pub fn derive_grouped(item: TokenStream1) -> TokenStream1 {
derives::grouped(item)
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/channel_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
struct ChannelPressure {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
7 changes: 6 additions & 1 deletion src/channel_voice1/control_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
#[midi2_proc::generate_message(
Via(crate::channel_voice1::ChannelVoice1),
FixedSize,
MinSizeUmp(1),
MinSizeBytes(3)
)]
struct ControlChange {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/key_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
struct KeyPressure {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/note_off.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1000;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
struct NoteOff {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/note_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1001;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
struct NoteOn {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/pitch_bend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1110;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(3))]
struct PitchBend {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice1/program_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1100;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice1::ChannelVoice1), FixedSize, MinSizeUmp(1), MinSizeBytes(2))]
struct ProgramChange {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/assignable_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0011;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct AssignableController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/assignable_per_note_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0001;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct AssignablePerNoteController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/channel_pitch_bend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1110;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct ChannelPitchBend {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/channel_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct ChannelPressure {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/control_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct ControlChange {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/key_pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

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

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct KeyPressure {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/note_off.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1000;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct NoteOff {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/note_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) const STATUS: u8 = 0b1001;
///
/// assert_eq!(message.data(), &[0x4898_5E03, 0x6A14_E98A]);
/// ```
#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct NoteOn {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/per_note_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1111;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(1))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(1))]
struct PerNoteManagement {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/per_note_pitch_bend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0110;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct PerNotePitchBend {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/program_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b1100;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct ProgramChange {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/registered_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0010;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct RegisteredController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/registered_per_note_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0000;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct RegisteredPerNoteController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/relative_assignable_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0101;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct RelativeAssignableController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
2 changes: 1 addition & 1 deletion src/channel_voice2/relative_registered_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{

pub(crate) const STATUS: u8 = 0b0100;

#[midi2_proc::generate_message(FixedSize, MinSizeUmp(2))]
#[midi2_proc::generate_message(Via(crate::channel_voice2::ChannelVoice2), FixedSize, MinSizeUmp(2))]
struct RelativeRegisteredController {
#[property(common_properties::UmpMessageTypeProperty<UMP_MESSAGE_TYPE>)]
ump_type: (),
Expand Down
Loading

0 comments on commit 7381b6f

Please sign in to comment.