Skip to content

Commit

Permalink
Renamed MidiClass to UsbMidiClass
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcebox committed Dec 29, 2024
1 parent 9b57fdc commit f718a27
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ This release focuses on:

### Changed

- Set edition to 2021.
- Renamed `MidiClass::send_message` function to `MidiClass::send_packet`.
- Renamed `MidiClass` to `UsbMidiClass`.
- Renamed `UsbMidiClass::send_message` function to `UsbMidiClass::send_packet`.
- Renamed `midi_device` module to `class`.
- Renamed `usb_midi` module to `packet` and moved it into crate root.
- Renamed `midi_packet_reader` module to `reader`.
Expand All @@ -58,6 +58,7 @@ This release focuses on:
- Consolidated separate `InvalidCodeIndexNumber` struct into `UsbMidiEventPacketError`.
- Converted `CodeIndexNumber` struct to enum.
- Moved descriptor constants into class module and made them private.
- Set edition to 2021.

### Removed

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use usb_device::prelude::*;
use usbd_midi::{
message::{channel::Channel, notes::Note},
Message,
MidiClass,
UsbMidiClass,
UsbMidiPacketReader,
};

Expand All @@ -26,7 +26,7 @@ let mut led = todo!(); // Must implement `embedded_hal::digital::OutputPin`.
let usb_bus = todo!(); // Must be of type `usb_device::bus::UsbBusAllocator`.

// Create a MIDI class with 1 input and 1 output jack.
let mut midi = MidiClass::new(&usb_bus, 1, 1).unwrap();
let mut midi = UsbMidiClass::new(&usb_bus, 1, 1).unwrap();

let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x5e4))
.device_class(0)
Expand Down
4 changes: 2 additions & 2 deletions examples/example-esp32s3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use heapless::Vec;
use midi_convert::midi_types::{Channel, MidiMessage, Note, Value7};
use midi_convert::{parse::MidiTryParseSlice, render_slice::MidiRenderSlice};
use usb_device::prelude::*;
use usbd_midi::{CableNumber, MidiClass, UsbMidiEventPacket, UsbMidiPacketReader};
use usbd_midi::{CableNumber, UsbMidiClass, UsbMidiEventPacket, UsbMidiPacketReader};

static mut EP_MEMORY: [u32; 1024] = [0; 1024];

Expand All @@ -32,7 +32,7 @@ fn main() -> ! {
);

// Create a MIDI class with 1 input and 1 output jack.
let mut midi_class = MidiClass::new(&usb_bus_allocator, 1, 1).unwrap();
let mut midi_class = UsbMidiClass::new(&usb_bus_allocator, 1, 1).unwrap();

// Build the device. It's important to use `0` for the class and subclass fields because
// otherwise the device will not enumerate correctly on certain hosts.
Expand Down
14 changes: 7 additions & 7 deletions src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const MIDI_PACKET_SIZE: usize = 4;
pub const MAX_PACKET_SIZE: usize = 64;

/// Packet-level implementation of a USB MIDI device.
pub struct MidiClass<'a, B: UsbBus> {
pub struct UsbMidiClass<'a, B: UsbBus> {
standard_ac: InterfaceNumber,
standard_mc: InterfaceNumber,
standard_bulkout: EndpointOut<'a, B>,
Expand All @@ -47,23 +47,23 @@ pub enum UsbMidiReadError {
UsbError(UsbError),
}

/// Error returned when passing invalid arguments to `MidiClass::new`.
/// Error returned when passing invalid arguments to `UsbMidiClass::new`.
#[derive(Debug)]
pub struct InvalidArguments;

impl<B: UsbBus> MidiClass<'_, B> {
/// Creates a new MidiClass with the provided UsbBus and `n_in/out_jacks` embedded input/output jacks
impl<B: UsbBus> UsbMidiClass<'_, B> {
/// Creates a new UsbMidiClass with the provided UsbBus and `n_in/out_jacks` embedded input/output jacks
/// (or "cables", depending on the terminology).
/// Note that a maximum of 16 in and 16 out jacks is supported.
pub fn new(
alloc: &UsbBusAllocator<B>,
n_in_jacks: u8,
n_out_jacks: u8,
) -> core::result::Result<MidiClass<'_, B>, InvalidArguments> {
) -> core::result::Result<UsbMidiClass<'_, B>, InvalidArguments> {
if n_in_jacks > 16 || n_out_jacks > 16 {
return Err(InvalidArguments);
}
Ok(MidiClass {
Ok(UsbMidiClass {
standard_ac: alloc.interface(),
standard_mc: alloc.interface(),
standard_bulkout: alloc.bulk(MAX_PACKET_SIZE as u16),
Expand Down Expand Up @@ -114,7 +114,7 @@ impl<B: UsbBus> MidiClass<'_, B> {
}
}

impl<B: UsbBus> UsbClass<B> for MidiClass<'_, B> {
impl<B: UsbBus> UsbClass<B> for UsbMidiClass<'_, B> {
fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter) -> Result<()> {
// AUDIO CONTROL STANDARD
writer.interface(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod packet;
#[cfg(feature = "message-types")]
pub mod message;

pub use crate::class::{MidiClass, UsbMidiReadError};
pub use crate::class::{UsbMidiClass, UsbMidiReadError};
pub use crate::packet::cable_number::CableNumber;
pub use crate::packet::reader::UsbMidiPacketReader;
pub use crate::packet::{UsbMidiEventPacket, UsbMidiEventPacketError};
Expand Down

0 comments on commit f718a27

Please sign in to comment.