objc2-core-midi 0.3.2

Bindings to the CoreMIDI framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

/// Derives from MIDIObjectRef, does not have an owner object.
///
/// This represents the global state of the MIDI system,
/// containing lists of the MIDI devices and serial port
/// owners.
///
/// Generally, only MIDI drivers and specialized configuration
/// editors will need to manipulate MIDISetup objects, not the
/// average MIDI client application.  As of CoreMIDI 1.1, the
/// MIDIServer maintains a single global MIDISetupRef, stored
/// persistently in a preference file.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coremidi/midisetupref?language=objc)
#[cfg(feature = "MIDIServices")]
pub type MIDISetupRef = MIDIObjectRef;

extern "C-unwind" {
    /// Interrogates drivers, to discover what hardware is present.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `outSetup`: On successful return, points to a newly-created MIDISetup
    /// object.  The caller is responsible for disposing it,
    /// or transferring ownership of the object back to the
    /// system, with MIDISetupInstall.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_setup` must be a valid pointer.
    #[cfg(feature = "MIDIServices")]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupCreate(out_setup: NonNull<MIDISetupRef>) -> OSStatus;
}

extern "C-unwind" {
    /// Dispose a MIDISetup object.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `setup`: The MIDISetup to be disposed.
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "MIDIServices")]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupDispose(setup: MIDISetupRef) -> OSStatus;
}

extern "C-unwind" {
    /// Install a MIDISetup as the system's current state.
    ///
    /// A client can create a MIDISetup object using
    /// MIDISetupCreate, or MIDISetupFromData.  This function will
    /// install this state as the current state of the system,
    /// possibly changing the devices visible to clients.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `setup`: The MIDISetup object to install.  Ownership of this
    /// object is transferred from the client to the system; the
    /// client must
    /// <b>
    /// not
    /// </b>
    /// dispose of this MIDISetup.
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "MIDIServices")]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupInstall(setup: MIDISetupRef) -> OSStatus;
}

extern "C-unwind" {
    /// Return the system's current MIDISetup.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `outSetup`: On successful return, points to the system's most
    /// recently installed MIDISetup.  The system retains
    /// ownership of the object; the client must
    /// <b>
    /// not
    /// </b>
    /// dispose of this MIDISetup.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_setup` must be a valid pointer.
    #[cfg(feature = "MIDIServices")]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupGetCurrent(out_setup: NonNull<MIDISetupRef>) -> OSStatus;
}

extern "C-unwind" {
    /// Create an XML representation of a MIDISetup object.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `setup`: The MIDISetup object whose XML representation is to be
    /// returned.
    ///
    /// Parameter `outData`: On successful return, points to a newly-created CFDataRef
    /// containing the XML text.  The client is responsible for
    /// releasing this CFData object when done with it.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_data` must be a valid pointer.
    #[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupToData(setup: MIDISetupRef, out_data: NonNull<*const CFData>) -> OSStatus;
}

extern "C-unwind" {
    /// Create a MIDISetup object from an XML stream.
    ///
    /// As of CoreMIDI 1.1, it is usually not necessary to call
    /// this function, as CoreMIDI manages a single persistent
    /// MIDISetup itself.
    ///
    ///
    /// Parameter `data`: The XML text from which a MIDISetup object is to be built.
    ///
    /// Parameter `outSetup`: On successful return, points to a newly-created MIDISetup
    /// object.  The caller is responsible for disposing it, or
    /// transferring ownership of the object back to the system,
    /// with MIDISetupInstall.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_setup` must be a valid pointer.
    #[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
    #[deprecated = "No longer supported"]
    pub fn MIDISetupFromData(data: &CFData, out_setup: NonNull<MIDISetupRef>) -> OSStatus;
}

/// Drivers call this function to specify one of the entities that
/// comprise a device.
///
/// Non-drivers may call this function as of macOS 11.0
/// &
/// iOS 14 to
/// add entities to external devices.
///
///
/// Parameter `device`: The device to which an entity is to be added.
///
/// Parameter `name`: The name of the new entity.
///
/// Parameter `protocol`: The MIDI protocol variant used by the sources and
/// destinations that comprise this entity.
///
/// Parameter `embedded`: True if this entity is inside the device, false if the
/// entity simply consists of external connectors to which
/// other devices can be attached.
///
/// Parameter `numSourceEndpoints`: The number of source endpoints the entity has.
///
/// Parameter `numDestinationEndpoints`: The number of destination endpoints the entity has.
///
/// Parameter `newEntity`: On successful return, points to the newly-created entity.
///
/// Returns: An OSStatus result code.
///
/// # Safety
///
/// `new_entity` must be a valid pointer.
#[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
#[inline]
pub unsafe extern "C-unwind" fn MIDIDeviceNewEntity(
    device: MIDIDeviceRef,
    name: &CFString,
    protocol: MIDIProtocolID,
    embedded: bool,
    num_source_endpoints: ItemCount,
    num_destination_endpoints: ItemCount,
    new_entity: NonNull<MIDIEntityRef>,
) -> OSStatus {
    extern "C-unwind" {
        fn MIDIDeviceNewEntity(
            device: MIDIDeviceRef,
            name: &CFString,
            protocol: MIDIProtocolID,
            embedded: Boolean,
            num_source_endpoints: ItemCount,
            num_destination_endpoints: ItemCount,
            new_entity: NonNull<MIDIEntityRef>,
        ) -> OSStatus;
    }
    unsafe {
        MIDIDeviceNewEntity(
            device,
            name,
            protocol,
            embedded as _,
            num_source_endpoints,
            num_destination_endpoints,
            new_entity,
        )
    }
}

/// Drivers call this function to specify one of the entities that
/// comprise a device.
///
/// Non-drivers may call this function as of CoreMIDI 1.1 to
/// add entities to external devices.
///
///
/// Parameter `device`: The device to which an entity is to be added.
///
/// Parameter `name`: The name of the new entity.
///
/// Parameter `embedded`: True if this entity is inside the device, false if the
/// entity simply consists of external connectors to which
/// other devices can be attached.
///
/// Parameter `numSourceEndpoints`: The number of source endpoints the entity has.
///
/// Parameter `numDestinationEndpoints`: The number of destination endpoints the entity has.
///
/// Parameter `newEntity`: On successful return, points to the newly-created entity.
///
/// Returns: An OSStatus result code.
///
/// # Safety
///
/// `new_entity` must be a valid pointer.
#[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
#[deprecated]
#[inline]
pub unsafe extern "C-unwind" fn MIDIDeviceAddEntity(
    device: MIDIDeviceRef,
    name: &CFString,
    embedded: bool,
    num_source_endpoints: ItemCount,
    num_destination_endpoints: ItemCount,
    new_entity: NonNull<MIDIEntityRef>,
) -> OSStatus {
    extern "C-unwind" {
        fn MIDIDeviceAddEntity(
            device: MIDIDeviceRef,
            name: &CFString,
            embedded: Boolean,
            num_source_endpoints: ItemCount,
            num_destination_endpoints: ItemCount,
            new_entity: NonNull<MIDIEntityRef>,
        ) -> OSStatus;
    }
    unsafe {
        MIDIDeviceAddEntity(
            device,
            name,
            embedded as _,
            num_source_endpoints,
            num_destination_endpoints,
            new_entity,
        )
    }
}

extern "C-unwind" {
    /// Drivers may call this function to remove one of a device's
    /// entities.
    ///
    /// New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `device`: The device from which an entity is to be removed.
    ///
    /// Parameter `entity`: The entity to be removed.
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDIDeviceRemoveEntity(device: MIDIDeviceRef, entity: MIDIEntityRef) -> OSStatus;
}

extern "C-unwind" {
    /// Drivers and configuration editors may call this function to add to
    /// or remove an entity's endpoints.
    ///
    /// New for CoreMIDI 1.3.
    ///
    /// The MIDIProtocolID of new endpoints is initially the same as that of
    /// the entity.
    ///
    ///
    /// Parameter `entity`: The entity whose endpoints are to be manipulated.
    ///
    /// Parameter `numSourceEndpoints`: The desired new number of source endpoints.
    ///
    /// Parameter `numDestinationEndpoints`: The desired new number of destination endpoints.
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDIEntityAddOrRemoveEndpoints(
        entity: MIDIEntityRef,
        num_source_endpoints: ItemCount,
        num_destination_endpoints: ItemCount,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Adds a driver-owner MIDI device to the current MIDISetup
    ///
    ///
    /// Only MIDI drivers may make this call; it is in this header
    /// file only for consistency with MIDISetupRemoveDevice.
    ///
    /// New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `device`: The device to be added.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDISetupAddDevice(device: MIDIDeviceRef) -> OSStatus;
}

extern "C-unwind" {
    /// Removes a driver-owned MIDI device from the current MIDISetup
    ///
    ///
    /// Generally this should only be called from a studio configuration
    /// editor, to remove a device which is offline and which the user
    /// has specified as being permanently missing.
    ///
    /// Instead of removing devices from the setup, drivers should
    /// set the device's kMIDIPropertyOffline to 1 so that if the
    /// device reappears later, none of its properties are lost.
    ///
    /// New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `device`: The device to be added.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDISetupRemoveDevice(device: MIDIDeviceRef) -> OSStatus;
}

extern "C-unwind" {
    /// Adds an external MIDI device to the current MIDISetup
    ///
    ///
    /// Useful for a studio configuration editor.  New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `device`: The device to be added.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDISetupAddExternalDevice(device: MIDIDeviceRef) -> OSStatus;
}

extern "C-unwind" {
    /// Removes an external MIDI device from the current MIDISetup
    ///
    ///
    /// Useful for a studio configuration editor.  New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `device`: The device to be removed.
    #[cfg(feature = "MIDIServices")]
    pub fn MIDISetupRemoveExternalDevice(device: MIDIDeviceRef) -> OSStatus;
}

extern "C-unwind" {
    /// Returns the MIDI driver that owns a serial port.
    ///
    ///
    /// The current MIDISetup tracks ownership of serial ports
    /// to one of the MIDI drivers installed in the system.
    ///
    /// Serial ports can be enumerated using IOServiceMatching(
    /// kIOSerialBSDServiceValue).  The port's unique name is
    /// the IOService's kIOTTYDeviceKey property.
    ///
    /// New for CoreMIDI 1.1.
    ///
    /// A previous version of this documentation specified an incorrect
    /// key for obtaining the port's unique name (IOTTYBaseName).
    ///
    ///
    /// Parameter `portName`: The name of a serial port.
    ///
    /// Parameter `outDriverName`: On exit, the name of the driver owning the port,
    /// or NULL if no driver owns it.
    ///
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_driver_name` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "No longer supported"]
    pub fn MIDIGetSerialPortOwner(
        port_name: &CFString,
        out_driver_name: NonNull<*const CFString>,
    ) -> OSStatus;
}

extern "C-unwind" {
    /// Specifies the MIDI driver that owns a serial port.
    ///
    ///
    /// Use this to assign ownership of a serial port
    /// to one of the MIDI drivers installed in the system.
    ///
    /// New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `portName`: The name of a serial port.
    ///
    /// Parameter `driverName`: The name of the driver that owns the serial port,
    /// or NULL to specify that no driver owns it.
    ///
    ///
    /// Returns: An OSStatus result code.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "No longer supported"]
    pub fn MIDISetSerialPortOwner(port_name: &CFString, driver_name: &CFString) -> OSStatus;
}

extern "C-unwind" {
    /// Returns a list of installed MIDI drivers for serial port
    /// MIDI devices.
    ///
    ///
    /// Use this to determine which of the installed MIDI drivers
    /// are for devices which may attach to serial ports.
    ///
    /// New for CoreMIDI 1.1.
    ///
    ///
    /// Parameter `outDriverNames`: On exit, a CFArrayRef containing a list of CFStringRef's
    /// which are the names of the serial port MIDI drivers.
    /// The array should be released by the caller.
    ///
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_driver_names` must be a valid pointer.
    #[cfg(feature = "objc2-core-foundation")]
    #[deprecated = "No longer supported"]
    pub fn MIDIGetSerialPortDrivers(out_driver_names: NonNull<*const CFArray>) -> OSStatus;
}

extern "C-unwind" {
    /// Create a new external MIDI device.
    ///
    ///
    /// Non-drivers may call this function as of CoreMIDI 1.1, to
    /// create external devices.
    ///
    /// The new device is not added to the current MIDISetupRef;
    /// to do this, use MIDISetupAddExternalDevice.
    ///
    ///
    /// Parameter `name`: The name of the new device.
    ///
    /// Parameter `manufacturer`: The name of the device's manufacturer.
    ///
    /// Parameter `model`: The device's model name.
    ///
    /// Parameter `outDevice`: On successful return, points to the newly-created device.
    ///
    /// Returns: An OSStatus result code.
    ///
    /// # Safety
    ///
    /// `out_device` must be a valid pointer.
    #[cfg(all(feature = "MIDIServices", feature = "objc2-core-foundation"))]
    pub fn MIDIExternalDeviceCreate(
        name: &CFString,
        manufacturer: &CFString,
        model: &CFString,
        out_device: NonNull<MIDIDeviceRef>,
    ) -> OSStatus;
}