Skip to content

Commit e63b954

Browse files
author
Ben Leadbetter
committed
Merge branch 'release/0.3.0'
2 parents 76f784a + 3b7d34d commit e63b954

Some content is hidden

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

66 files changed

+282
-1364
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.3.0
2+
docs: fix further readme typos
3+
feat: utility messages are integrated into top level aggregate
4+
fix: ⚠️ hide some leaked private types and constants
5+
revert: ⚠️ remove jr timestamp headers and trait
6+
17
# 0.2.4
28
ci: add standard cargo github actions
39
docs: fix various typos
@@ -22,4 +28,4 @@ fix: repository url must be http
2228
refactor: repo is handled as a cargo workspace
2329

2430
# 0.2.1
25-
fix: default fetures build
31+
fix: default features build

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.2.4"
3+
version = "0.3.0"
44
description = "Ergonomic, versatile, strong types wrapping MIDI 2.0 message data."
55
edition = "2021"
66
readme = "README.md"
@@ -31,10 +31,11 @@ sysex7 = []
3131
sysex8 = []
3232
system-common = []
3333
ump-stream = []
34+
utility = []
3435

3536
[dependencies]
3637
derive_more = { version = "0.99.17", features = ["from"], default-features = false }
37-
midi2_proc = { version = "0.2.4", path = "midi2_proc" }
38+
midi2_proc = { version = "0.3.0", path = "midi2_proc" }
3839
ux = "0.1.6"
3940

4041
[dev-dependencies]

README.md

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ assert_eq!(
5858
All message wrappers are grouped into aggregate enum types.
5959
There's a top level enum type which can represent all messages,
6060
and there's sub enum types for each different UMP type specified
61-
by the MIDI 2.0 documentation.
61+
by the MIDI 2.0 specification.
6262

6363
```rust
6464
fn handle_message(buffer: &[u32]) {
@@ -146,26 +146,6 @@ assert_eq!(
146146
);
147147
```
148148

149-
## Jitter Ruduction Support
150-
151-
All ump messages have an optional jitter reduction header
152-
prepended before its message packets.
153-
154-
```rust
155-
use midi2::prelude::*;
156-
157-
let mut message = channel_voice1::ChannelPressure::new_arr();
158-
assert_eq!(message.data(), &[0x20D0_0000]);
159-
160-
message.set_jitter_reduction(Some(JitterReduction::Timestamp(0x1234)));
161-
assert_eq!(message.data(), &[0x0020_1234, 0x20D0_0000]);
162-
```
163-
164-
NOTE: For this reason all messages need an extra `u32` at the
165-
start of their buffers to accomodate the header data.
166-
For example, the minimum size buffer for a ChannelVoice2 message
167-
is 3, rather than 2.
168-
169149
## Almost Entirely `#![no_std]` Friendly
170150

171151
`#![no_std]` is a first class use case in midi2.
@@ -176,7 +156,7 @@ You'll want to setup midi2 without default features to compile
176156
without the `std` feature.
177157

178158
```toml
179-
midi2 = { version = "0.2.4", default-features = false, features = ["channel-voice2", "sysex7"], }
159+
midi2 = { version = "0.3.0", default-features = false, features = ["channel-voice2", "sysex7"], }
180160
```
181161

182162
### Generic Representation
@@ -188,15 +168,15 @@ represent messages within a fixed size array.
188168
```rust
189169
use midi2::prelude::*;
190170

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

194174
// in this mode methods which would require a
195175
// buffer resize are fallible
196176
assert_eq!(message.try_set_payload(0..50), Ok(()));
197177

198178
// if there's not enough room in the buffer to
199-
// accomodate the resize then an overflow error is returned.
179+
// accommodate the resize then an overflow error is returned.
200180
assert_eq!(message.try_set_payload(0..60), Err(midi2::error::BufferOverflow));
201181
```
202182

@@ -239,18 +219,21 @@ To remedy this messages can be `rebuffered` into a different
239219
generic backing buffer type.
240220

241221
```rust
242-
use midi2::prelude::*;
222+
use midi2::{
223+
prelude::*,
224+
channel_voice2::NoteOn,
225+
};
243226

244-
let mut owned: UmpMessage::<[u32; 5]> = {
245-
let buffer = [0x1AF3_4F00_u32];
227+
let mut owned: NoteOn::<[u32; 4]> = {
228+
let buffer = [0x4898_5E03_u32, 0x6A14_E98A];
246229
// the borrowed message is imutable and cannot outlive `buffer`
247-
let borrowed = UmpMessage::try_from(&buffer[..]).expect("Data is valid");
230+
let borrowed = NoteOn::try_from(&buffer[..]).expect("Data is valid");
248231
borrowed.try_rebuffer_into().expect("Buffer is large enough")
249232
};
250233

251234
// the owned message is mutable an liberated from the buffer lifetime.
252-
owned.set_jitter_reduction(Some(JitterReduction::Timestamp(0x1234)));
253-
assert_eq!(owned.data(), &[0x0020_1234, 0x1AF3_4F00])
235+
owned.set_channel(u4::new(0x9));
236+
assert_eq!(owned.data(), &[0x4899_5E03, 0x6A14_E98A])
254237
```
255238

256239
## Support For Classical MIDI Byte Stream Messages
@@ -268,7 +251,7 @@ message.set_pressure(u7::new(0x09));
268251
assert_eq!(message.data(), &[0xD6, 0x09]);
269252
```
270253

271-
Messages represented in bytes can be transformed to ump and back using convertion traits.
254+
Messages represented in bytes can be transformed to ump and back using conversion traits.
272255

273256
```rust
274257
use midi2::{
@@ -277,7 +260,7 @@ use midi2::{
277260
};
278261

279262
let message = ChannelPressure::new_arr_bytes();
280-
let message: ChannelPressure<[u32; 5]> = message.try_into_ump().
263+
let message: ChannelPressure<[u32; 4]> = message.try_into_ump().
281264
expect("Buffer is large enough");
282265

283266
assert_eq!(message.data(), &[0x20D0_0000]);

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

midi2_proc/src/generate_message.rs

Lines changed: 14 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ struct Property {
1616

1717
impl Property {
1818
fn implement_via_trait(&self) -> bool {
19-
self.is_group()
20-
|| self.is_channel()
21-
|| self.is_sysex_payload()
22-
|| self.is_jitter_reduction()
19+
self.is_group() || self.is_channel() || self.is_sysex_payload()
2320
}
2421
fn is_group(&self) -> bool {
2522
self.ident == "group"
@@ -30,9 +27,6 @@ impl Property {
3027
fn is_sysex_payload(&self) -> bool {
3128
self.ident == "sysex_payload"
3229
}
33-
fn is_jitter_reduction(&self) -> bool {
34-
self.ident == "jitter_reduction"
35-
}
3630
}
3731

3832
fn has_attr(field: &syn::Field, id: &str) -> bool {
@@ -350,7 +344,7 @@ fn secondary_new_arr_impl(root_ident: &syn::Ident, properties: &Vec<Property>) -
350344
}
351345

352346
fn arr_type_ump() -> TokenStream {
353-
quote! { [u32; 5] }
347+
quote! { [u32; 4] }
354348
}
355349

356350
fn arr_type_bytes() -> TokenStream {
@@ -362,20 +356,7 @@ fn size_impl(root_ident: &syn::Ident, args: &GenerateMessageArgs) -> TokenStream
362356
quote! {
363357
impl<B: #constraint> crate::traits::Size<B> for #root_ident<B> {
364358
fn size(&self) -> usize {
365-
match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
366-
crate::buffer::UNIT_ID_U32 => {
367-
// account for jitter reduction header
368-
use crate::buffer::UmpPrivate;
369-
<Self as crate::traits::MinSize<B>>::min_size()
370-
+ self.buffer_access().specialise_u32().jitter_reduction().len()
371-
}
372-
crate::buffer::UNIT_ID_U8 => {
373-
// simple case
374-
// no jitter reduction logic here
375-
<Self as crate::traits::MinSize<B>>::min_size()
376-
}
377-
_ => unreachable!(),
378-
}
359+
<Self as crate::traits::MinSize<B>>::min_size()
379360
}
380361
}
381362
}
@@ -426,32 +407,7 @@ fn data_impl(root_ident: &syn::Ident, args: &GenerateMessageArgs) -> TokenStream
426407
quote! {
427408
impl<B: #constraint> crate::traits::Data<B> for #root_ident<B> {
428409
fn data(&self) -> &[B::Unit] {
429-
match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
430-
crate::buffer::UNIT_ID_U32 => {
431-
use crate::buffer::UmpPrivate;
432-
use crate::detail::BitOps;
433-
434-
// account for jitter reduction header
435-
let buffer = self.buffer_access().specialise_u32();
436-
let jr_slice = buffer.jitter_reduction();
437-
let jr_offset = match jr_slice.len() {
438-
0 => 0,
439-
_ => {
440-
match u8::from(jr_slice[0].nibble(2)) {
441-
0 => 1, // the jr header is noop - skip from the data slice
442-
_ => 0, // the jr header has data - include it!
443-
}
444-
}
445-
};
446-
&self.buffer_access().buffer()[jr_offset..self.size()]
447-
}
448-
crate::buffer::UNIT_ID_U8 => {
449-
// simple case
450-
// no jitter reduction logic here
451-
&self.buffer_access().buffer()[..self.size()]
452-
}
453-
_ => unreachable!(),
454-
}
410+
&self.buffer_access().buffer()[..self.size()]
455411
}
456412
}
457413
}
@@ -502,34 +458,9 @@ fn rebuffer_from_impl(root_ident: &syn::Ident, args: &GenerateMessageArgs) -> To
502458
{
503459
fn rebuffer_from(other: #root_ident<A>) -> Self {
504460
let mut buffer = <B as crate::buffer::BufferDefault>::default();
505-
match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
506-
crate::buffer::UNIT_ID_U32 => {
507-
// account for jitter reduction header
508-
use crate::buffer::UmpPrivate;
509-
let message_size = other.data().len();
510-
let jr_offset: usize = match other.data()
511-
.specialise_u32()
512-
.jitter_reduction()
513-
.len() {
514-
0 => {
515-
// other message had no jitter reduction header
516-
// -> we add it in on our side
517-
1
518-
},
519-
_ => 0,
520-
};
521-
buffer.resize(message_size + jr_offset);
522-
buffer.buffer_mut()[jr_offset..(message_size + jr_offset)].copy_from_slice(other.data());
523-
}
524-
crate::buffer::UNIT_ID_U8 => {
525-
// simple case
526-
// no jitter reduction logic here
527-
let message_size = other.data().len();
528-
buffer.resize(message_size);
529-
buffer.buffer_mut()[..message_size].copy_from_slice(other.data());
530-
}
531-
_ => unreachable!(),
532-
}
461+
let message_size = other.data().len();
462+
buffer.resize(message_size);
463+
buffer.buffer_mut()[..message_size].copy_from_slice(other.data());
533464
#root_ident(buffer)
534465
}
535466
}
@@ -543,34 +474,9 @@ fn try_rebuffer_from_impl(root_ident: &syn::Ident, args: &GenerateMessageArgs) -
543474
{
544475
fn try_rebuffer_from(other: #root_ident<A>) -> core::result::Result<Self, crate::error::BufferOverflow> {
545476
let mut buffer = <B as crate::buffer::BufferDefault>::default();
546-
match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
547-
crate::buffer::UNIT_ID_U32 => {
548-
// account for jitter reduction header
549-
use crate::buffer::UmpPrivate;
550-
let message_size = other.data().len();
551-
let jr_offset: usize = match other.data()
552-
.specialise_u32()
553-
.jitter_reduction()
554-
.len() {
555-
0 => {
556-
// other message had no jitter reduction header
557-
// -> we add it in on our side
558-
1
559-
},
560-
_ => 0,
561-
};
562-
buffer.try_resize(message_size + jr_offset)?;
563-
buffer.buffer_mut()[jr_offset..(message_size + jr_offset)].copy_from_slice(other.data());
564-
}
565-
crate::buffer::UNIT_ID_U8 => {
566-
// simple case
567-
// no jitter reduction logic here
568-
let message_size = other.data().len();
569-
buffer.try_resize(message_size)?;
570-
buffer.buffer_mut()[..message_size].copy_from_slice(other.data());
571-
}
572-
_ => unreachable!(),
573-
}
477+
let message_size = other.data().len();
478+
buffer.try_resize(message_size)?;
479+
buffer.buffer_mut()[..message_size].copy_from_slice(other.data());
574480
Ok(#root_ident(buffer))
575481
}
576482
}
@@ -594,13 +500,7 @@ fn new_impl(
594500
pub fn new() -> #root_ident<B>
595501
{
596502
let mut buffer = <B as crate::buffer::BufferDefault>::default();
597-
let jr_offset = match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
598-
// account for jitter reduction header
599-
crate::buffer::UNIT_ID_U32 => 1,
600-
crate::buffer::UNIT_ID_U8 => 0,
601-
_ => unreachable!(),
602-
};
603-
buffer.resize(<Self as crate::traits::MinSize<B>>::min_size() + jr_offset);
503+
buffer.resize(<Self as crate::traits::MinSize<B>>::min_size());
604504
#initialise_properties
605505
#root_ident::<B>(buffer)
606506
}
@@ -625,13 +525,7 @@ fn try_new_impl(
625525
pub fn try_new() -> core::result::Result<#root_ident<B>, crate::error::BufferOverflow>
626526
{
627527
let mut buffer = <B as crate::buffer::BufferDefault>::default();
628-
let jr_offset = match <B::Unit as crate::buffer::UnitPrivate>::UNIT_ID {
629-
// account for jitter reduction header
630-
crate::buffer::UNIT_ID_U32 => 1,
631-
crate::buffer::UNIT_ID_U8 => 0,
632-
_ => unreachable!(),
633-
};
634-
buffer.try_resize(<Self as crate::traits::MinSize<B>>::min_size() + jr_offset)?;
528+
buffer.try_resize(<Self as crate::traits::MinSize<B>>::min_size())?;
635529
#initialise_properties
636530
Ok(#root_ident::<B>(buffer))
637531
}
@@ -681,17 +575,6 @@ fn grouped_impl(root_ident: &syn::Ident, property: &Property) -> TokenStream {
681575
}
682576
}
683577

684-
fn jitter_reduction_impl(root_ident: &syn::Ident, property: &Property) -> TokenStream {
685-
let setter = property_setter(property, false);
686-
let getter = property_getter(property, false);
687-
quote! {
688-
impl<B: crate::buffer::Ump> crate::traits::JitterReduced<B> for #root_ident<B> {
689-
#getter
690-
#setter
691-
}
692-
}
693-
}
694-
695578
fn channeled_impl(
696579
root_ident: &syn::Ident,
697580
property: &Property,
@@ -721,10 +604,7 @@ fn from_bytes_impl(root_ident: &syn::Ident, properties: &Vec<Property>) -> Token
721604
{
722605
fn from_bytes(other: #root_ident<A>) -> Self {
723606
let mut buffer = <B as crate::buffer::BufferDefault>::default();
724-
buffer.resize(
725-
<#root_ident<B> as crate::traits::MinSize<B>>::min_size()
726-
+ crate::buffer::OFFSET_FOR_JITTER_REDUCTION
727-
);
607+
buffer.resize(<#root_ident<B> as crate::traits::MinSize<B>>::min_size());
728608
#convert_properties
729609
Self(buffer)
730610
}
@@ -745,10 +625,7 @@ fn try_from_bytes_impl(root_ident: &syn::Ident, properties: &Vec<Property>) -> T
745625
{
746626
fn try_from_bytes(other: #root_ident<A>) -> core::result::Result<Self, crate::error::BufferOverflow> {
747627
let mut buffer = <B as crate::buffer::BufferDefault>::default();
748-
buffer.try_resize(
749-
<#root_ident<B> as crate::traits::MinSize<B>>::min_size()
750-
+ crate::buffer::OFFSET_FOR_JITTER_REDUCTION
751-
)?;
628+
buffer.try_resize(<#root_ident<B> as crate::traits::MinSize<B>>::min_size())?;
752629
#convert_properties
753630
Ok(Self(buffer))
754631
}
@@ -860,9 +737,6 @@ pub fn generate_message(attrs: TokenStream1, item: TokenStream1) -> TokenStream1
860737
if args.fixed_size {
861738
tokens.extend(size_impl(root_ident, &args))
862739
}
863-
if let Some(property) = properties.iter().find(|p| p.is_jitter_reduction()) {
864-
tokens.extend(jitter_reduction_impl(root_ident, property));
865-
}
866740
if let Some(property) = properties.iter().find(|p| p.is_group()) {
867741
tokens.extend(grouped_impl(root_ident, property));
868742
}

0 commit comments

Comments
 (0)