Debian Codegraph @

third_party/rust/coremidi/examples/notifications.rs

raw
1 extern crate core_foundation;
2 extern crate coremidi;
3
4 use coremidi::{Client, Notification};
5
6 use core_foundation::runloop::{kCFRunLoopDefaultMode, CFRunLoopRunInMode};
7
8 fn main() {
9 println!("Logging MIDI Client Notifications");
10 println!("Will Quit Automatically After 10 Seconds");
11 println!();
12
13 let _client = Client::new_with_notifications("example-client", print_notification).unwrap();
14
15 // As the MIDIClientCreate docs say (https://developer.apple.com/documentation/coremidi/1495360-midiclientcreate),
16 // notifications will be delivered on the run loop that was current when
17 // Client was created.
18 //
19 // In order to actually receive the notifications, a run loop must be
20 // running. Since this sample app does not use an app framework like
21 // UIApplication or NSApplication, it does not have a run loop running yet.
22 // So we start one that lasts for 10 seconds with the following line.
23 //
24 // 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
25 // for information about when run loops are running automatically.
26 unsafe { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10.0, 0) };
27 }
28
29 fn print_notification(notification: &Notification) {
30 println!("Received Notification: {:?} \r", notification);
31 }