objc2_core_midi/generated/
MIDIDriver.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7#[cfg(feature = "objc2-core-foundation")]
8use objc2_core_foundation::*;
9
10use crate::*;
11
12/// Points to a pointer to a MIDIDriverInterface, a CFPlugIn structure (defined in
13/// MIDIDriver.h) containing function pointers for the driver's methods.  Only the
14/// MIDIServer may call a driver's methods.
15///
16/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/mididriverref?language=objc)
17pub type MIDIDriverRef = *mut NonNull<MIDIDriverInterface>;
18
19/// A MIDIDeviceListRef is a list of MIDIDeviceRef's.  The devices are not owned by
20/// the list (i.e., disposing the list does not dispose the devices it references).
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/mididevicelistref?language=objc)
23#[cfg(feature = "MIDIServices")]
24pub type MIDIDeviceListRef = MIDIObjectRef;
25
26/// The COM-style interface to a MIDI driver.
27///
28///
29/// This is the function table interface to a MIDI driver.  Version 1 and 2 drivers use
30/// this same table of function pointers (except as noted).
31///
32/// Drivers which support multiple version interfaces can tell which version
33/// of the server is running by checking to see whether kMIDIDriverInterface2ID
34/// or kMIDIDriverInterfaceID is passed to the factory function. If the version 1 interface is
35/// requested, the driver should behave as if it is a version 1 driver.
36///
37/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/mididriverinterface?language=objc)
38#[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
39#[repr(C)]
40#[allow(unpredictable_function_pointer_comparisons)]
41#[derive(Clone, Copy, Debug, PartialEq)]
42pub struct MIDIDriverInterface {
43    pub(crate) _reserved: NonNull<c_void>,
44    pub QueryInterface:
45        unsafe extern "C-unwind" fn(NonNull<c_void>, REFIID, *mut LPVOID) -> HRESULT,
46    pub AddRef: unsafe extern "C-unwind" fn(NonNull<c_void>) -> ULONG,
47    pub Release: unsafe extern "C-unwind" fn(NonNull<c_void>) -> ULONG,
48    /// This is only called for version 1 drivers.  The server is requesting that the driver
49    /// detect the devices which are present.  For each device present, the driver should
50    /// create a MIDIDeviceRef with entities, using MIDIDeviceCreate and
51    /// MIDIDeviceAddEntity, and add the device to the supplied MIDIDeviceListRef, using
52    /// MIDIDeviceListAddDevice.
53    ///
54    /// The driver should not retain any references to the created devices and entities.
55    pub FindDevices: unsafe extern "C-unwind" fn(MIDIDriverRef, MIDIDeviceListRef) -> OSStatus,
56    /// The server is telling the driver to begin MIDI I/O.
57    ///
58    /// The provided device list contains the devices which were previously located by
59    /// FindDevices (in the case of a version 1 driver), or the devices which are owned by
60    /// this driver and are currently in the current MIDISetup (for version 2 drivers).
61    ///
62    /// The provided devices may or may not still be present.  A version 1 driver should
63    /// attempt to use as many of the devices as are actually present.
64    ///
65    /// A version 2 driver may make calls such as MIDISetupAddDevice, MIDIDeviceAddEntity,
66    /// MIDIDeviceRemoveEntity to dynamically modify the system's current state. For devices
67    /// in the provided device list which are not present, the driver should set their
68    /// kMIDIPropertyOffline property to 1.  A version 2 driver may also set up
69    /// notifications when the IORegistry changes, to detect connection and disconnection of
70    /// devices it wishes to control.  At these times also, the driver may change the
71    /// devices' kMIDIPropertyOffline, and dynamically modify the system's current state to
72    /// reflect the devices which are present.  When passing a CFRunLoopRef to IOKit for
73    /// notification purposes, the driver must use the server's main runloop, which is
74    /// obtained with CFRunLoopGetCurrent().
75    ///
76    /// The driver will probably want to iterate through the destination endpoints and
77    /// assign their driver refCons, so as to identify multiple destinations when Send() is
78    /// called.
79    ///
80    /// The provided device list remains owned by the system and can be assumed to contain
81    /// only devices owned by this driver.  The driver may retain references to the devices
82    /// in this list and any it creates while running.
83    pub Start: unsafe extern "C-unwind" fn(MIDIDriverRef, MIDIDeviceListRef) -> OSStatus,
84    /// The server is telling the driver to terminate MIDI I/O.  All I/O operations that
85    /// were begun in Start, or as a result of a subsequent IOKit notification, should be
86    /// terminated.
87    pub Stop: unsafe extern "C-unwind" fn(MIDIDriverRef) -> OSStatus,
88    /// not currently used
89    pub Configure: unsafe extern "C-unwind" fn(MIDIDriverRef, MIDIDeviceRef) -> OSStatus,
90    /// Send a MIDIPacketList to the destination endpoint whose refCons are being passed as
91    /// arguments.
92    pub Send: unsafe extern "C-unwind" fn(
93        MIDIDriverRef,
94        NonNull<MIDIPacketList>,
95        NonNull<c_void>,
96        NonNull<c_void>,
97    ) -> OSStatus,
98    /// A client has opened or closed a connection, and now the server is telling the driver
99    /// that input from a particular source either does or does not have any listeners in
100    /// the system.  The driver may use this information to decide whether to pass messages
101    /// from the source to the server, and it may even be able to tell the source hardware
102    /// not to generate incoming MIDI I/O for that source.
103    pub EnableSource:
104        unsafe extern "C-unwind" fn(MIDIDriverRef, MIDIEndpointRef, Boolean) -> OSStatus,
105    /// Only for version 2 drivers (new for CoreMIDI 1.1).
106    ///
107    /// Drivers which support schedule-ahead, when receiving this message, should unschedule
108    /// all pending output to the specified destination.  If the destination is null/0, the
109    /// driver should unschedule all pending output to all destinations.
110    pub Flush: unsafe extern "C-unwind" fn(
111        MIDIDriverRef,
112        MIDIEndpointRef,
113        *mut c_void,
114        *mut c_void,
115    ) -> OSStatus,
116    /// Only for version 2 drivers (new for CoreMIDI 1.1).
117    ///
118    /// Some specialized drivers (e.g. a MIDI monitor display) may wish to intercept and
119    /// look at all outgoing MIDI messages.  After a driver calls
120    /// MIDIDriverEnableMonitoring(true) on itself, this function is called with the
121    /// outgoing MIDI packets for all destinations in the system.  The Monitor function
122    /// cannot rely on the MIDI events arriving in order, due to MIDIServer's schedule-ahead
123    /// facilities.
124    pub Monitor: unsafe extern "C-unwind" fn(
125        MIDIDriverRef,
126        MIDIEndpointRef,
127        NonNull<MIDIPacketList>,
128    ) -> OSStatus,
129    /// Only for version 3 drivers (new for macOS 12.0).
130    ///
131    /// Send a MIDIEventList to the destination endpoint whose refCons are being passed as
132    /// arguments.
133    pub SendPackets: unsafe extern "C-unwind" fn(
134        MIDIDriverRef,
135        NonNull<MIDIEventList>,
136        NonNull<c_void>,
137        NonNull<c_void>,
138    ) -> OSStatus,
139    /// Only for version 3 drivers (new for macOS 12.0).
140    ///
141    /// Same as Monitor but uses MIDEventList, whose protocol may vary from MIDI 1.0.
142    pub MonitorEvents: unsafe extern "C-unwind" fn(
143        MIDIDriverRef,
144        MIDIEndpointRef,
145        NonNull<MIDIEventList>,
146    ) -> OSStatus,
147}
148
149#[cfg(all(
150    feature = "MIDIServices",
151    feature = "objc2",
152    feature = "objc2-core-foundation"
153))]
154unsafe impl Encode for MIDIDriverInterface {
155    const ENCODING: Encoding = Encoding::Struct("MIDIDriverInterface", &[
156        <NonNull<c_void>>::ENCODING,
157        <unsafe extern "C-unwind" fn(NonNull<c_void>,REFIID,*mut LPVOID,) -> HRESULT>::ENCODING,
158        <unsafe extern "C-unwind" fn(NonNull<c_void>,) -> ULONG>::ENCODING,
159        <unsafe extern "C-unwind" fn(NonNull<c_void>,) -> ULONG>::ENCODING,
160        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIDeviceListRef,) -> OSStatus>::ENCODING,
161        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIDeviceListRef,) -> OSStatus>::ENCODING,
162        <unsafe extern "C-unwind" fn(MIDIDriverRef,) -> OSStatus>::ENCODING,
163        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIDeviceRef,) -> OSStatus>::ENCODING,
164        <unsafe extern "C-unwind" fn(MIDIDriverRef,NonNull<MIDIPacketList>,NonNull<c_void>,NonNull<c_void>,) -> OSStatus>::ENCODING,
165        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIEndpointRef,Boolean,) -> OSStatus>::ENCODING,
166        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIEndpointRef,*mut c_void,*mut c_void,) -> OSStatus>::ENCODING,
167        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIEndpointRef,NonNull<MIDIPacketList>,) -> OSStatus>::ENCODING,
168        <unsafe extern "C-unwind" fn(MIDIDriverRef,NonNull<MIDIEventList>,NonNull<c_void>,NonNull<c_void>,) -> OSStatus>::ENCODING,
169        <unsafe extern "C-unwind" fn(MIDIDriverRef,MIDIEndpointRef,NonNull<MIDIEventList>,) -> OSStatus>::ENCODING,
170    ]);
171}
172
173#[cfg(all(
174    feature = "MIDIServices",
175    feature = "objc2",
176    feature = "objc2-core-foundation"
177))]
178unsafe impl RefEncode for MIDIDriverInterface {
179    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
180}
181
182extern "C" {
183    /// This constant, "MIDIDriverUsesSerial", when defined to "YES" in a driver's
184    /// bundle, tells MIDIServer that the driver uses serial ports and is eligible to
185    /// have serial ports assigned to it.
186    ///
187    /// When a serial driver's Start() method is called, it should use
188    /// MIDIGetSerialPortOwner to discover which serial ports it has
189    /// been assigned to use, and only use those ports.
190    ///
191    /// New for CoreMIDI 1.1.
192    ///
193    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/kmididriverpropertyusesserial?language=objc)
194    #[cfg(feature = "objc2-core-foundation")]
195    pub static kMIDIDriverPropertyUsesSerial: &'static CFString;
196}
197
198extern "C-unwind" {
199    /// Drivers call this function to create new MIDIDevice objects
200    /// corresponding to the hardware that is present.
201    ///
202    /// Non-drivers may call this function as of CoreMIDI 1.1, to
203    /// create external devices.
204    ///
205    ///
206    /// Parameter `owner`: The driver creating the device.  NULL if a non-driver.
207    ///
208    /// Parameter `name`: The name of the new device.
209    ///
210    /// Parameter `manufacturer`: The name of the device's manufacturer.
211    ///
212    /// Parameter `model`: The device's model name.
213    ///
214    /// Parameter `outDevice`: On successful return, points to the newly-created device.
215    ///
216    /// Returns: An OSStatus result code.
217    ///
218    /// # Safety
219    ///
220    /// - `owner` must be a valid pointer or null.
221    /// - `out_device` must be a valid pointer.
222    #[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
223    pub fn MIDIDeviceCreate(
224        owner: MIDIDriverRef,
225        name: &CFString,
226        manufacturer: &CFString,
227        model: &CFString,
228        out_device: NonNull<MIDIDeviceRef>,
229    ) -> OSStatus;
230}
231
232extern "C-unwind" {
233    /// Drivers may call this function to dispose MIDIDevice objects
234    /// which have not yet been added to the system via MIDISetupAddDevice.
235    /// Once a device has been added to the system with MIDISetupAddDevice,
236    /// the driver must not use this call to destroy it; it must
237    /// use MIDISetupRemoveDevice to do so.
238    ///
239    /// Non-drivers do not have access to this function; they must call
240    /// MIDISetupAddDevice and MIDISetupRemoveDevice.
241    ///
242    ///
243    /// Parameter `device`: The device to be disposed.
244    ///
245    /// Returns: An OSStatus result code.
246    #[cfg(feature = "MIDIServices")]
247    pub fn MIDIDeviceDispose(device: MIDIDeviceRef) -> OSStatus;
248}
249
250extern "C-unwind" {
251    /// Returns the number of devices in a device list.
252    ///
253    ///
254    /// Parameter `devList`: The device list.
255    ///
256    /// Returns: The number of devices in the list, or 0 if an error occurred.
257    #[cfg(feature = "MIDIServices")]
258    pub fn MIDIDeviceListGetNumberOfDevices(dev_list: MIDIDeviceListRef) -> ItemCount;
259}
260
261extern "C-unwind" {
262    /// Return one of the devices in a device list.
263    ///
264    ///
265    /// Parameter `devList`: The device list.
266    ///
267    /// Parameter `index0`: The index (0...MIDIDeviceListGetNumberOfDevices()-1) of the device
268    /// to return.
269    ///
270    /// Returns: A reference to a device, or NULL if an error occurred.
271    #[cfg(feature = "MIDIServices")]
272    pub fn MIDIDeviceListGetDevice(dev_list: MIDIDeviceListRef, index0: ItemCount)
273        -> MIDIDeviceRef;
274}
275
276extern "C-unwind" {
277    /// Add a device to a device list.
278    ///
279    ///
280    /// Parameter `devList`: The device list.
281    ///
282    /// Parameter `dev`: The device to add to the list.
283    ///
284    /// Returns: An OSStatus result code.
285    #[cfg(feature = "MIDIServices")]
286    pub fn MIDIDeviceListAddDevice(dev_list: MIDIDeviceListRef, dev: MIDIDeviceRef) -> OSStatus;
287}
288
289extern "C-unwind" {
290    /// Dispose a device list, but not the contained devices.
291    ///
292    ///
293    /// Parameter `devList`: The device list to be disposed.
294    ///
295    /// Returns: An OSStatus result code.
296    #[cfg(feature = "MIDIServices")]
297    pub fn MIDIDeviceListDispose(dev_list: MIDIDeviceListRef) -> OSStatus;
298}
299
300extern "C-unwind" {
301    /// Drivers need an efficient way to translate from a MIDIEndpoint (source or
302    /// destination) to their own internal data structures corresponding to
303    /// that endpoint.  This function provides a way for the driver to
304    /// assign its own refCons to endpoints.
305    ///
306    /// These refCons are passed back to the driver in its Send() and Flush()
307    /// methods.
308    ///
309    /// RefCons are not persistent (i.e. they are not saved as part of a
310    /// MIDISetup).  They need to be re-initialized in each call to Start().
311    ///
312    /// A typical use is to use one refCon to refer to a device, and a second
313    /// to refer to a port on the device.
314    ///
315    ///
316    /// Parameter `endpt`: The endpoint whose refCons are to be set
317    ///
318    /// Parameter `ref1`: The first refCon.
319    ///
320    /// Parameter `ref2`: The second refCon.
321    ///
322    /// Returns: An OSStatus result code.
323    ///
324    /// # Safety
325    ///
326    /// - `ref1` must be a valid pointer or null.
327    /// - `ref2` must be a valid pointer or null.
328    #[cfg(feature = "MIDIServices")]
329    pub fn MIDIEndpointSetRefCons(
330        endpt: MIDIEndpointRef,
331        ref1: *mut c_void,
332        ref2: *mut c_void,
333    ) -> OSStatus;
334}
335
336extern "C-unwind" {
337    /// Obtain the refCons assigned to the endpoints
338    ///
339    ///
340    /// Parameter `endpt`: The endpoint whose refCons are to be return
341    ///
342    /// Parameter `ref1`: On exit, the first refCon.
343    ///
344    /// Parameter `ref2`: On exit, the second refCon.
345    ///
346    /// Returns: An OSStatus result code.
347    ///
348    /// # Safety
349    ///
350    /// - `ref1` must be a valid pointer or null.
351    /// - `ref2` must be a valid pointer or null.
352    #[cfg(feature = "MIDIServices")]
353    pub fn MIDIEndpointGetRefCons(
354        endpt: MIDIEndpointRef,
355        ref1: *mut NonNull<c_void>,
356        ref2: *mut NonNull<c_void>,
357    ) -> OSStatus;
358}
359
360/// Drivers typically need to receive asynchronous I/O completion callbacks
361/// on a high-priority thread.  To save drivers from the trouble of
362/// creating their own threads for this purpose, and to make efficient
363/// use of system resources, the MIDIServer provides a thread which
364/// drivers may use.
365///
366/// Drivers should do as little work as possible in this thread; typically,
367/// just dequeueing and encoding output packets, and decoding input packets
368/// into MIDIPacketLists to be passed to MIDIReceived.
369///
370/// This is a realtime-priority thread and shouldn't be used for anything other
371/// than I/O.  For lower-priority tasks, drivers can use the runloop which
372/// was current when they were constructed.
373///
374///
375/// Returns: The CFRunLoopRef of the server's driver I/O thread.
376#[cfg(feature = "objc2-core-foundation")]
377#[inline]
378pub unsafe extern "C-unwind" fn MIDIGetDriverIORunLoop() -> CFRetained<CFRunLoop> {
379    extern "C-unwind" {
380        fn MIDIGetDriverIORunLoop() -> Option<NonNull<CFRunLoop>>;
381    }
382    let ret = unsafe { MIDIGetDriverIORunLoop() };
383    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
384    unsafe { CFRetained::retain(ret) }
385}
386
387extern "C-unwind" {
388    /// Returns the list of devices which are in the current MIDISetup
389    /// and which were created/owned by the specified driver.
390    ///
391    /// The returned device list should be disposed (using MIDIDeviceListDispose)
392    /// by the caller.
393    ///
394    ///
395    /// Parameter `driver`: The driver whose devices are to be returned.
396    ///
397    ///
398    /// Returns: The requested device list.
399    ///
400    /// # Safety
401    ///
402    /// `driver` must be a valid pointer.
403    #[cfg(feature = "MIDIServices")]
404    pub fn MIDIGetDriverDeviceList(driver: MIDIDriverRef) -> MIDIDeviceListRef;
405}
406
407/// A driver may make this call to have MIDIServer pass it every outgoing MIDI
408/// packet, to all destinations in the system (not just those controlled by
409/// itself).
410///
411///
412/// Parameter `driver`: The driver whose Monitor function is to be enabled.
413///
414/// Parameter `enabled`: true to enable monitoring, false to disable it.
415///
416///
417/// Returns: An OSStatus result code.
418///
419/// # Safety
420///
421/// `driver` must be a valid pointer.
422#[inline]
423pub unsafe extern "C-unwind" fn MIDIDriverEnableMonitoring(
424    driver: MIDIDriverRef,
425    enabled: bool,
426) -> OSStatus {
427    extern "C-unwind" {
428        fn MIDIDriverEnableMonitoring(driver: MIDIDriverRef, enabled: Boolean) -> OSStatus;
429    }
430    unsafe { MIDIDriverEnableMonitoring(driver, enabled as _) }
431}