From 468ce4ed391fdf4bc06cf8be6987c876729d173e Mon Sep 17 00:00:00 2001 From: beau trepp Date: Sun, 12 Jan 2020 16:43:08 +0800 Subject: [PATCH] Adds in some derivation traits This allows other structs to easily copy the data around --- Cargo.toml | 2 +- src/data/midi/channel.rs | 2 +- src/data/midi/notes.rs | 2 +- src/data/usb_midi/cable_number.rs | 2 +- src/data/usb_midi/usb_midi_event_packet.rs | 12 ++++++++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b4a58f4..4756664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "usbd-midi" -version = "0.1.0" +version = "0.2.0" authors = ["beau trepp "] edition = "2018" description = "A usb-midi implementation for usb-device" diff --git a/src/data/midi/channel.rs b/src/data/midi/channel.rs index 6b6fc97..49ed33d 100644 --- a/src/data/midi/channel.rs +++ b/src/data/midi/channel.rs @@ -3,7 +3,7 @@ use core::convert::TryFrom; /// The Channel is a value ranging from 0x0 to 0xF /// This is a standard midi concept /// Note Channel1 = 0 on the wire -#[derive(Debug)] +#[derive(Debug,Copy,Clone)] #[repr(u8)] pub enum Channel { Channel1 = 0x0, Channel2 = 0x1, Channel3 = 0x2, Channel4 = 0x3, diff --git a/src/data/midi/notes.rs b/src/data/midi/notes.rs index b610c46..225a15e 100644 --- a/src/data/midi/notes.rs +++ b/src/data/midi/notes.rs @@ -4,7 +4,7 @@ use crate::data::byte::from_traits::FromOverFlow; /// note the flat versions are associated constants /// but can be referenced like Note::Bb3 /// C1m is the C-1 -#[derive(Debug)] +#[derive(Debug,Copy,Clone)] #[repr(u8)] pub enum Note { C1m, Cs1m, D1m, Ds1m, E1m, F1m, Fs1m, G1m, Gs1m, A1m, As1m, B1m, diff --git a/src/data/usb_midi/cable_number.rs b/src/data/usb_midi/cable_number.rs index 3be05f2..1fff8a3 100644 --- a/src/data/usb_midi/cable_number.rs +++ b/src/data/usb_midi/cable_number.rs @@ -4,7 +4,7 @@ use crate::data::byte::u4::U4; /// The Cable Number (CN) is a value ranging from 0x0 to 0xF /// indicating the number assignment of the Embedded MIDI Jack associated /// with the endpoint that is transferring the data -#[derive(Debug)] +#[derive(Debug,Clone,Copy)] #[repr(u8)] pub enum CableNumber { Cable0 = 0x0, Cable1 = 0x1, Cable2 = 0x2, Cable3 = 0x3, diff --git a/src/data/usb_midi/usb_midi_event_packet.rs b/src/data/usb_midi/usb_midi_event_packet.rs index 76b3523..cffdd1b 100644 --- a/src/data/usb_midi/usb_midi_event_packet.rs +++ b/src/data/usb_midi/usb_midi_event_packet.rs @@ -4,6 +4,7 @@ use crate::data::midi::message::Message; use crate::data::byte::u4::U4; use crate::data::midi::message::raw::{Payload,Raw}; + /// A packet that communicates with the host /// Currently supported is sending the specified normal midi /// message over the supplied cable number @@ -34,4 +35,15 @@ impl From for [u8;4] { [header,status,byte1.into(),byte2.into()] } } +} + +impl UsbMidiEventPacket{ + + pub fn from_midi(cable:CableNumber, midi:Message) + -> UsbMidiEventPacket{ + UsbMidiEventPacket{ + cable_number : cable, + message : midi + } + } } \ No newline at end of file