-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documented How to Receive Client Notifications (#28)
- Loading branch information
1 parent
c1bee2f
commit 14eff2e
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extern crate coremidi; | ||
extern crate core_foundation; | ||
|
||
use coremidi::{ | ||
Client, | ||
Notification, | ||
}; | ||
|
||
use core_foundation::runloop::{ | ||
CFRunLoopRunInMode, | ||
kCFRunLoopDefaultMode, | ||
}; | ||
|
||
fn main() { | ||
println!("Logging MIDI Client Notifications"); | ||
println!("Will Quit Automatically After 10 Seconds"); | ||
println!(""); | ||
|
||
let _client = Client::new_with_notifications("example-client", print_notification).unwrap(); | ||
|
||
// As the MIDIClientCreate docs say (https://developer.apple.com/documentation/coremidi/1495360-midiclientcreate), | ||
// notifications will be delivered on the run loop that was current when | ||
// Client was created. | ||
// | ||
// In order to actually receive the notifications, a run loop must be | ||
// running. Since this sample app does not use an app framework like | ||
// UIApplication or NSApplication, it does not have a run loop running yet. | ||
// So we start one that lasts for 10 seconds with the following line. | ||
// | ||
// You may not have to do this in your app - see https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW24 | ||
// for information about when run loops are running automatically. | ||
unsafe { | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10.0, 0) | ||
}; | ||
} | ||
|
||
fn print_notification(notification: &Notification) { | ||
println!("Received Notification: {:?} \r", notification); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters