Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chris-zen/coremidi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.8.0
Choose a base ref
...
head repository: chris-zen/coremidi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 5 files changed
  • 2 contributors

Commits on Jun 30, 2024

  1. Copy the full SHA
    e7f9716 View commit details
  2. Copy the full SHA
    e15673a View commit details
  3. Copy the full SHA
    926e2cc View commit details

Commits on Jul 2, 2024

  1. Copy the full SHA
    8e45046 View commit details
Showing with 45 additions and 13 deletions.
  1. +4 −4 Cargo.toml
  2. +1 −1 README.md
  3. +13 −6 src/client.rs
  4. +26 −2 src/endpoints/sources.rs
  5. +1 −0 src/lib.rs
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coremidi"
version = "0.8.0"
version = "0.8.1"
authors = ["Christian Perez-Llamas"]
description = "CoreMIDI library for Rust"
license = "MIT"
@@ -14,6 +14,6 @@ edition = "2021"

[dependencies]
block = "0.1.6"
core-foundation-sys = "0.8.4"
core-foundation = "0.9.3"
coremidi-sys = "3.1.0"
core-foundation-sys = "0.8.6"
core-foundation = "0.9.4"
coremidi-sys = "3.1.1"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ The library is published into [crates.io](https://crates.io/crates/coremidi), so

```toml
[dependencies]
coremidi = "^0.8.0"
coremidi = "^0.8.1"
```

If you prefer to live in the edge ;-) you can use the master branch by including this instead:
19 changes: 13 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use std::cell::RefCell;
use std::{mem::MaybeUninit, ops::Deref, os::raw::c_void, ptr};

use coremidi_sys::{
MIDIClientCreate, MIDIClientCreateWithBlock, MIDIClientDispose, MIDIDestinationCreateWithBlock,
MIDIClientCreate, MIDIClientCreateWithBlock, MIDIDestinationCreateWithBlock,
MIDIDestinationCreateWithProtocol, MIDIEventList, MIDIInputPortCreateWithBlock,
MIDIInputPortCreateWithProtocol, MIDINotification, MIDINotifyBlock, MIDIOutputPortCreate,
MIDIPacketList, MIDIReadBlock, MIDIReceiveBlock, MIDISourceCreate,
@@ -330,8 +330,15 @@ impl Deref for Client {
}
}

impl Drop for Client {
fn drop(&mut self) {
unsafe { MIDIClientDispose(self.object.0) };
}
}
// According to Apple docs:
//
// > Don’t explicitly dispose of your client; the system automatically disposes all clients when an app terminates.
// > However, if you call this method to dispose the last or only client owned by an app, the MIDI server may exit
// > if there are no other clients remaining in the system. If this occurs, all subsequent calls by your app to
// > MIDIClientCreate and MIDIClientCreateWithBlock fail.
//
// impl Drop for Client {
// fn drop(&mut self) {
// unsafe { MIDIClientDispose(self.object.0) };
// }
// }
28 changes: 26 additions & 2 deletions src/endpoints/sources.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@ use core_foundation_sys::base::OSStatus;
use std::ops::Deref;

use coremidi_sys::{
ItemCount, MIDIEndpointDispose, MIDIEndpointRef, MIDIGetNumberOfSources, MIDIGetSource,
MIDIReceived, MIDIReceivedEventList,
kMIDIObjectType_Source, ItemCount, MIDIEndpointDispose, MIDIEndpointRef,
MIDIGetNumberOfSources, MIDIGetSource, MIDIObjectFindByUniqueID, MIDIObjectRef, MIDIObjectType,
MIDIReceived, MIDIReceivedEventList, MIDIUniqueID,
};

use crate::endpoints::endpoint::Endpoint;
@@ -48,6 +49,13 @@ impl Source {
.into_iter()
.find(|source| source.name().as_deref() == Some(name))
}

/// Create a source from it's unique id.
/// See [MIDIObjectFindByUniqueID](https://developer.apple.com/documentation/coremidi/1495191-midiobjectfindbyuniqueid).
///
pub fn from_unique_id(unique_id: u32) -> Option<Source> {
Sources::find_by_unique_id(unique_id)
}
}

impl Clone for Source {
@@ -101,6 +109,22 @@ impl Sources {
pub fn count() -> usize {
unsafe { MIDIGetNumberOfSources() as usize }
}

/// Find a source based on its unique id.
/// See [MIDIObjectFindByUniqueID](https://developer.apple.com/documentation/coremidi/1495191-midiobjectfindbyuniqueid).
///
fn find_by_unique_id(unique_id: u32) -> Option<Source> {
let mut obj_ref: MIDIObjectRef = 0;
let mut obj_type: MIDIObjectType = 0;
let status = unsafe {
MIDIObjectFindByUniqueID(unique_id as MIDIUniqueID, &mut obj_ref, &mut obj_type)
};
if status != 0 || obj_type != kMIDIObjectType_Source {
None
} else {
Some(Source::new(obj_ref as MIDIEndpointRef))
}
}
}

impl IntoIterator for Sources {
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ use core_foundation_sys::base::OSStatus;

use coremidi_sys::{MIDIFlushOutput, MIDIRestart};

pub use crate::any_object::AnyObject;
pub use crate::client::{Client, NotifyCallback};
pub use crate::device::Device;
pub use crate::endpoints::destinations::{Destination, Destinations, VirtualDestination};