Skip to content

Commit bc08348

Browse files
author
Ben Leadbetter
committed
Merge branch 'release/0.5.0'
2 parents 7381b6f + 9ad26be commit bc08348

Some content is hidden

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

81 files changed

+1822
-451
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 0.5.0
2+
docs: generally improve documentation of public modules and traits
3+
feat: infallible constructors and converters for array backed messages
4+
feat: new `Packets` trait implemented by all ump messages
5+
fix: flex data text bytes iterator is public
6+
refactor!: ⚠️ remove dedicated array constructors in favour of unified generic constructors
7+
refactor!: ⚠️ remove redundant aggregate error type and result
8+
refactor!: ⚠️ rename DeltaClockstampTPQ -> DeltaClockstampTpq
9+
refactor: switching implementation from mod.rs to file names based on module name
10+
111
# 0.4.0
212
feat: top level messages implement From for all messages
313
fix: ⚠️ utility messages should be excluded when feature is not enabled

Cargo.toml

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

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

4141
[dev-dependencies]
4242
pretty_assertions = "1.4.0"
4343

4444
[package.metadata.docs.rs]
4545
all-features = true
46+
rustdoc-args = ["--cfg", "docsrs"]

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Ergonomic, versatile, strong types wrapping MIDI 2.0 message data.
44

55
This implementation of MIDI 2.0 is based on the 1.1 revision of the specifications.
6-
For detailed midi2 specification see [the documentation](https://midi.org/)
7-
on which this crate is based.
6+
See [the official MIDI 2.0 specification](https://midi.org/)
7+
for more details on the data protocol standard.
88

99
## ⚠️ **Note!** ⚠️
1010

@@ -23,7 +23,7 @@ A strongly typed message wrapper is provided for every message in the MIDI 2.0 s
2323
use midi2::prelude::*;
2424

2525
// Messages have a simple setter / getter interface
26-
let mut note_on = channel_voice2::NoteOn::new_arr();
26+
let mut note_on = channel_voice2::NoteOn::<[u32; 4]>::new();
2727
note_on.set_group(u4::new(0x8));
2828
note_on.set_channel(u4::new(0xA));
2929
note_on.set_note(u7::new(0x5E));
@@ -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.4.0", default-features = false, features = ["channel-voice2", "sysex7"], }
159+
midi2 = { version = "0.5.0", default-features = false, features = ["channel-voice2", "sysex7"], }
160160
```
161161

162162
### Generic Representation
@@ -168,8 +168,7 @@ represent messages within a fixed size array.
168168
```rust
169169
use midi2::prelude::*;
170170

171-
let mut message = sysex8::Sysex8::<[u32; 16]>::try_new()
172-
.expect("Buffer is large enough for min message size");
171+
let mut message = sysex8::Sysex8::<[u32; 16]>::new();
173172

174173
// in this mode methods which would require a
175174
// buffer resize are fallible
@@ -182,7 +181,7 @@ assert_eq!(message.try_set_payload(0..60), Err(midi2::error::BufferOverflow));
182181

183182
A more advanced use case might be to make a custom buffer which
184183
uses an arena allocater to back your messages.
185-
See the [buffer](crate::buffer) docs for more info.
184+
See the [buffer] docs for more info.
186185

187186
### Borrowed Messages
188187

@@ -226,7 +225,7 @@ let mut owned: NoteOn::<[u32; 4]> = {
226225
let buffer = [0x4898_5E03_u32, 0x6A14_E98A];
227226
// the borrowed message is immutable and cannot outlive `buffer`
228227
let borrowed = NoteOn::try_from(&buffer[..]).expect("Data is valid");
229-
borrowed.try_rebuffer_into().expect("Buffer is large enough")
228+
borrowed.rebuffer_into()
230229
};
231230

232231
// the owned message is mutable and liberated from the buffer lifetime.
@@ -236,13 +235,13 @@ assert_eq!(owned.data(), &[0x4899_5E03, 0x6A14_E98A])
236235

237236
## Support For Classical MIDI Byte Stream Messages
238237

239-
Messages which can be represented in classical midi byte stream format are also supported.
238+
Messages which can be represented in classical MIDI byte stream format are also supported.
240239
To do this simply use a backing buffer over `u8` instead of `u32`! ✨🎩
241240

242241
```rust
243242
use midi2::prelude::*;
244243

245-
let mut message = channel_voice1::ChannelPressure::new_arr_bytes();
244+
let mut message = channel_voice1::ChannelPressure::<[u8; 3]>::new();
246245
message.set_channel(u4::new(0x6));
247246
message.set_pressure(u7::new(0x09));
248247

@@ -257,22 +256,21 @@ use midi2::{
257256
channel_voice1::ChannelPressure,
258257
};
259258

260-
let message = ChannelPressure::new_arr_bytes();
261-
let message: ChannelPressure<[u32; 4]> = message.try_into_ump().
262-
expect("Buffer is large enough");
259+
let message = ChannelPressure::<[u8; 3]>::new();
260+
let message: ChannelPressure<[u32; 4]> = message.into_ump();
263261

264262
assert_eq!(message.data(), &[0x20D0_0000]);
265263
```
266264

267265
## Cargo Features
268266

269-
midi2 provides several compile-time features that you can enable or disable to customize
270-
its functionality according to your needs.
267+
Several compile-time features are provided that you can enable or disable to customize
268+
functionality according to your needs.
271269

272270
Here's a list of available features:
273271

274272
- `default`:
275-
- **std** - Include [buffer](crate::buffer) integration for `std::vec::Vec` and enable allocating getters for values which return `std::string::String` values.
273+
- **std** - Include [buffer] integration for `std::vec::Vec` and enable allocating getters for values which return `std::string::String` values.
276274
- **channel-voice2** — Include message wrappers for the MIDI 2.0 channel voice message type.
277275
- **sysex7** — Include message wrappers for the MIDI 7bit system exclusive message type.
278276
- **ci** — 🚧 WIP 🚧

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.4.0"
4+
version = "0.5.0"
55
edition = "2021"
66
readme = "README.md"
77
license = "MIT OR Apache-2.0"

midi2_proc/src/common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ impl BufferGeneric {
2222
Self::Bytes(param) => param.ident.clone(),
2323
}
2424
}
25+
pub fn type_param(&self) -> syn::TypeParam {
26+
match self {
27+
Self::UmpOrBytes(param) => param.clone(),
28+
Self::Ump(param) => param.clone(),
29+
Self::Bytes(param) => param.clone(),
30+
}
31+
}
2532
}
2633

2734
pub fn buffer_generic(generics: &syn::Generics) -> Option<BufferGeneric> {

midi2_proc/src/derives.rs

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

34+
pub fn packets(item: TokenStream1) -> TokenStream1 {
35+
let input = parse_macro_input!(item as ItemEnum);
36+
let ident = &input.ident;
37+
let mut match_arms = TokenStream::new();
38+
for variant in &input.variants {
39+
let variant_ident = &variant.ident;
40+
match_arms.extend(quote! {
41+
#variant_ident(m) => m.packets(),
42+
});
43+
}
44+
quote! {
45+
impl<B: crate::buffer::Ump> crate::Packets for #ident<B> {
46+
fn packets(&self) -> crate::PacketsIterator {
47+
use #ident::*;
48+
match self {
49+
#match_arms
50+
}
51+
}
52+
}
53+
}
54+
.into()
55+
}
56+
3457
pub fn from_bytes(item: TokenStream1) -> TokenStream1 {
3558
let input = parse_macro_input!(item as ItemEnum);
3659
let ident = &input.ident;
@@ -182,6 +205,33 @@ pub fn rebuffer_from(item: TokenStream1) -> TokenStream1 {
182205
.into()
183206
}
184207

208+
pub fn rebuffer_from_array(item: TokenStream1) -> TokenStream1 {
209+
let input = parse_macro_input!(item as ItemEnum);
210+
let ident = &input.ident;
211+
let mut match_arms = TokenStream::new();
212+
for variant in &input.variants {
213+
let variant_ident = &variant.ident;
214+
match_arms.extend(quote! {
215+
#ident::#variant_ident(m) => #ident::#variant_ident(m.rebuffer_into()),
216+
});
217+
}
218+
let buffer_generic = common::buffer_generic(&input.generics).expect("Expected buffer generic");
219+
let buffer_generic_id = buffer_generic.ident();
220+
let buffer_generic_type_param = buffer_generic.type_param();
221+
let arr_type = quote! { [<#buffer_generic_id as crate::buffer::Buffer>::Unit; SIZE] };
222+
quote! {
223+
impl<const SIZE: usize, #buffer_generic_type_param> crate::RebufferFrom<#ident<#buffer_generic_id>> for #ident<#arr_type> {
224+
fn rebuffer_from(other: #ident<#buffer_generic_id>) -> Self {
225+
use crate::RebufferInto;
226+
match other {
227+
#match_arms
228+
}
229+
}
230+
}
231+
}
232+
.into()
233+
}
234+
185235
pub fn try_rebuffer_from(item: TokenStream1) -> TokenStream1 {
186236
let input = parse_macro_input!(item as ItemEnum);
187237
let ident = &input.ident;

0 commit comments

Comments
 (0)