objc2_audio_toolbox/generated/
AUAudioUnit.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-audio-types")]
7use objc2_core_audio_types::*;
8#[cfg(feature = "objc2-core-midi")]
9use objc2_core_midi::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudioobjectid?language=objc)
15pub type AUAudioObjectID = u32;
16
17/// A result code returned from an audio unit's render function.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitstatus?language=objc)
20pub type AUAudioUnitStatus = OSStatus;
21
22/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aueventsampletimeimmediate?language=objc)
23#[cfg(feature = "AudioUnitProperties")]
24pub const AUEventSampleTimeImmediate: AUEventSampleTime = -4294967296;
25
26/// A number of audio sample frames.
27///
28/// This is `uint32_t` for impedence-matching with the pervasive use of `UInt32` in AudioToolbox
29/// and C AudioUnit API's, as well as `AVAudioFrameCount`.
30///
31/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudioframecount?language=objc)
32pub type AUAudioFrameCount = u32;
33
34/// A number of audio channels.
35///
36/// This is `uint32_t` for impedence-matching with the pervasive use of `UInt32` in AudioToolbox
37/// and C AudioUnit API's, as well as `AVAudioChannelCount`.
38///
39/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiochannelcount?language=objc)
40pub type AUAudioChannelCount = u32;
41
42/// Describes whether a bus array is for input or output.
43///
44/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitbustype?language=objc)
45// NS_ENUM
46#[repr(transparent)]
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
48pub struct AUAudioUnitBusType(pub NSInteger);
49impl AUAudioUnitBusType {
50    #[doc(alias = "AUAudioUnitBusTypeInput")]
51    pub const Input: Self = Self(1);
52    #[doc(alias = "AUAudioUnitBusTypeOutput")]
53    pub const Output: Self = Self(2);
54}
55
56unsafe impl Encode for AUAudioUnitBusType {
57    const ENCODING: Encoding = NSInteger::ENCODING;
58}
59
60unsafe impl RefEncode for AUAudioUnitBusType {
61    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64/// Block to supply audio input to AURenderBlock.
65///
66/// Parameter `actionFlags`: Pointer to action flags.
67///
68/// Parameter `timestamp`: The HAL time at which the input data will be rendered. If there is a sample rate conversion
69/// or time compression/expansion downstream, the sample time will not be valid.
70///
71/// Parameter `frameCount`: The number of sample frames of input requested.
72///
73/// Parameter `inputBusNumber`: The index of the input bus being pulled.
74///
75/// Parameter `inputData`: The input audio data.
76///
77/// The caller must supply valid buffers in inputData's mBuffers' mData and mDataByteSize.
78/// mDataByteSize must be consistent with frameCount. This block may provide input in those
79/// specified buffers, or it may replace the mData pointers with pointers to memory which it
80/// owns and guarantees will remain valid until the next render cycle.
81///
82/// Returns: An AUAudioUnitStatus result code. If an error is returned, the input data should be assumed
83/// to be invalid.
84///
85/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aurenderpullinputblock?language=objc)
86#[cfg(all(
87    feature = "AUComponent",
88    feature = "block2",
89    feature = "objc2-core-audio-types"
90))]
91pub type AURenderPullInputBlock = *mut block2::DynBlock<
92    dyn Fn(
93        NonNull<AudioUnitRenderActionFlags>,
94        NonNull<AudioTimeStamp>,
95        AUAudioFrameCount,
96        NSInteger,
97        NonNull<AudioBufferList>,
98    ) -> AUAudioUnitStatus,
99>;
100
101/// Block to render the audio unit.
102///
103/// All realtime operations are implemented using blocks to avoid ObjC method dispatching and
104/// the possibility of blocking.
105///
106/// Parameter `actionFlags`: Pointer to action flags.
107///
108/// Parameter `timestamp`: The HAL time at which the output data will be rendered. If there is a sample rate conversion
109/// or time compression/expansion downstream, the sample time will not have a defined
110/// correlation with the AudioDevice sample time.
111///
112/// Parameter `frameCount`: The number of sample frames to render.
113///
114/// Parameter `outputBusNumber`: The index of the output bus to render.
115///
116/// Parameter `outputData`: The output bus's render buffers and flags.
117///
118/// The buffer pointers (outputData->mBuffers[x].mData) may be null on entry, in which case the
119/// block will render into memory it owns and modify the mData pointers to point to that memory.
120/// The block is responsible for preserving the validity of that memory until it is next called
121/// to render, or deallocateRenderResources is called.
122///
123/// If, on entry, the mData pointers are non-null, the block will render into those buffers.
124///
125/// Parameter `pullInputBlock`: A block which the AU will call in order to pull for input data. May be nil for instrument
126/// and generator audio units (which do not have input busses).
127///
128/// Returns: An `AUAudioUnitStatus` result code. If an error is returned, the output data should be assumed
129/// to be invalid.
130///
131/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aurenderblock?language=objc)
132#[cfg(all(
133    feature = "AUComponent",
134    feature = "block2",
135    feature = "objc2-core-audio-types"
136))]
137pub type AURenderBlock = *mut block2::DynBlock<
138    dyn Fn(
139        NonNull<AudioUnitRenderActionFlags>,
140        NonNull<AudioTimeStamp>,
141        AUAudioFrameCount,
142        NSInteger,
143        NonNull<AudioBufferList>,
144        AURenderPullInputBlock,
145    ) -> AUAudioUnitStatus,
146>;
147
148/// Block called when an audio unit renders.
149///
150/// This block is called by the base class's AURenderBlock before and after each render cycle.
151/// The observer can distinguish between before and after using the PreRender and PostRender
152/// flags.
153///
154/// The parameters are identical to those of AURenderBlock.
155///
156/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aurenderobserver?language=objc)
157#[cfg(all(
158    feature = "AUComponent",
159    feature = "block2",
160    feature = "objc2-core-audio-types"
161))]
162pub type AURenderObserver = *mut block2::DynBlock<
163    dyn Fn(AudioUnitRenderActionFlags, NonNull<AudioTimeStamp>, AUAudioFrameCount, NSInteger),
164>;
165
166/// Block to schedule parameter changes.
167///
168/// Not all parameters are rampable; check the parameter's flags.
169/// Note: If the parameter is not rampable, a rampDuration of zero will result in an immediate change to
170/// the target value, however, if rampDuration is non-zero, the parameter will not change.
171///
172///
173/// Parameter `eventSampleTime`: The sample time (timestamp->mSampleTime) at which the parameter is to begin changing. When
174/// scheduling parameters during the render cycle (e.g. via a render observer) this time can be
175/// AUEventSampleTimeImmediate plus an optional buffer offset, in which case the event is
176/// scheduled at that position in the current render cycle.
177///
178/// Parameter `rampDurationSampleFrames`: The number of sample frames over which the parameter's value is to ramp, or 0 if the
179/// parameter change should take effect immediately.
180///
181/// Parameter `parameterAddress`: The parameter's address.
182///
183/// Parameter `value`: The parameter's new value if the ramp duration is 0; otherwise, the value at the end
184/// of the scheduled ramp.
185///
186/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auscheduleparameterblock?language=objc)
187#[cfg(all(
188    feature = "AUParameters",
189    feature = "AudioUnitProperties",
190    feature = "block2"
191))]
192pub type AUScheduleParameterBlock = *mut block2::DynBlock<
193    dyn Fn(AUEventSampleTime, AUAudioFrameCount, AUParameterAddress, AUValue),
194>;
195
196/// Block to schedule MIDI events.
197///
198/// Parameter `eventSampleTime`: The sample time (timestamp->mSampleTime) at which the MIDI event is to occur. When
199/// scheduling events during the render cycle (e.g. via a render observer) this time can be
200/// AUEventSampleTimeImmediate plus an optional buffer offset, in which case the event is
201/// scheduled at that position in the current render cycle.
202///
203/// Parameter `cable`: The virtual cable number.
204///
205/// Parameter `length`: The number of bytes of MIDI data in the provided event(s).
206///
207/// Parameter `midiBytes`: One or more valid MIDI 1.0 events, except sysex which must always be sent as the only event
208/// in the chunk. Also, running status is not allowed.
209///
210/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auschedulemidieventblock?language=objc)
211#[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
212pub type AUScheduleMIDIEventBlock =
213    *mut block2::DynBlock<dyn Fn(AUEventSampleTime, u8, NSInteger, NonNull<u8>)>;
214
215/// Block to provide MIDI output events to the host.
216///
217/// Parameter `eventSampleTime`: The timestamp associated with the MIDI data in this chunk.
218///
219/// Parameter `cable`: The virtual cable number associated with this MIDI data.
220///
221/// Parameter `length`: The number of bytes of MIDI data in the provided event(s).
222///
223/// Parameter `midiBytes`: One or more valid MIDI 1.0 events, except sysex which must always be sent as the only event
224/// in the chunk.
225///
226/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aumidioutputeventblock?language=objc)
227#[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
228pub type AUMIDIOutputEventBlock =
229    *mut block2::DynBlock<dyn Fn(AUEventSampleTime, u8, NSInteger, NonNull<u8>) -> OSStatus>;
230
231/// Block by which hosts provide musical tempo, time signature, and beat position.
232///
233/// Parameter `currentTempo`: The current tempo in beats per minute.
234///
235/// Parameter `timeSignatureNumerator`: The numerator of the current time signature.
236///
237/// Parameter `timeSignatureDenominator`: The denominator of the current time signature.
238///
239/// Parameter `currentBeatPosition`: The precise beat position of the beginning of the current buffer being rendered.
240///
241/// Parameter `sampleOffsetToNextBeat`: The number of samples between the beginning of the buffer being rendered and the next beat
242/// (can be 0).
243///
244/// Parameter `currentMeasureDownbeatPosition`: The beat position corresponding to the beginning of the current measure.
245///
246/// Returns: YES for success.
247///
248/// If the host app provides this block to an AUAudioUnit (as its musicalContextBlock), then
249/// the block may be called at the beginning of each render cycle to obtain information about
250/// the current render cycle's musical context.
251///
252/// Any of the provided parameters may be null to indicate that the audio unit is not interested
253/// in that particular piece of information.
254///
255/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auhostmusicalcontextblock?language=objc)
256#[cfg(feature = "block2")]
257pub type AUHostMusicalContextBlock = *mut block2::DynBlock<
258    dyn Fn(
259        *mut c_double,
260        *mut c_double,
261        *mut NSInteger,
262        *mut c_double,
263        *mut NSInteger,
264        *mut c_double,
265    ) -> Bool,
266>;
267
268/// Block by which hosts are informed of an audio unit having enabled or disabled a
269/// MIDI-CI profile.
270///
271/// Parameter `cable`: The virtual MIDI cable on which the event occured.
272///
273/// Parameter `channel`: The MIDI channel on which the profile was enabled or disabled.
274///
275/// Parameter `profile`: The MIDI-CI profile.
276///
277/// Parameter `enabled`: YES if the profile was enabled, NO if the profile was disabled.
278///
279/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aumidiciprofilechangedblock?language=objc)
280#[cfg(all(feature = "block2", feature = "objc2-core-midi"))]
281pub type AUMIDICIProfileChangedBlock =
282    *mut block2::DynBlock<dyn Fn(u8, MIDIChannelNumber, NonNull<MIDICIProfile>, Bool)>;
283
284/// Flags describing the host's transport state.
285///
286/// True if, since the callback was last called, there was a change to the state of, or
287/// discontinuities in, the host's transport. Can indicate such state changes as
288/// start/stop, or seeking to another position in the timeline.
289///
290/// True if the transport is moving.
291///
292/// True if the host is recording, or prepared to record. Can be true with or without the
293/// transport moving.
294///
295/// True if the host is cycling or looping.
296///
297/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auhosttransportstateflags?language=objc)
298// NS_OPTIONS
299#[repr(transparent)]
300#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
301pub struct AUHostTransportStateFlags(pub NSUInteger);
302bitflags::bitflags! {
303    impl AUHostTransportStateFlags: NSUInteger {
304        #[doc(alias = "AUHostTransportStateChanged")]
305        const Changed = 1;
306        #[doc(alias = "AUHostTransportStateMoving")]
307        const Moving = 2;
308        #[doc(alias = "AUHostTransportStateRecording")]
309        const Recording = 4;
310        #[doc(alias = "AUHostTransportStateCycling")]
311        const Cycling = 8;
312    }
313}
314
315unsafe impl Encode for AUHostTransportStateFlags {
316    const ENCODING: Encoding = NSUInteger::ENCODING;
317}
318
319unsafe impl RefEncode for AUHostTransportStateFlags {
320    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
321}
322
323/// Block by which hosts provide information about their transport state.
324///
325/// Parameter `transportStateFlags`: The current state of the transport.
326///
327/// Parameter `currentSamplePosition`: The current position in the host's timeline, in samples at the audio unit's output sample
328/// rate.
329///
330/// Parameter `cycleStartBeatPosition`: If cycling, the starting beat position of the cycle.
331///
332/// Parameter `cycleEndBeatPosition`: If cycling, the ending beat position of the cycle.
333///
334/// If the host app provides this block to an AUAudioUnit (as its transportStateBlock), then
335/// the block may be called at the beginning of each render cycle to obtain information about
336/// the current transport state.
337///
338/// Any of the provided parameters may be null to indicate that the audio unit is not interested
339/// in that particular piece of information.
340///
341/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auhosttransportstateblock?language=objc)
342#[cfg(feature = "block2")]
343pub type AUHostTransportStateBlock = *mut block2::DynBlock<
344    dyn Fn(*mut AUHostTransportStateFlags, *mut c_double, *mut c_double, *mut c_double) -> Bool,
345>;
346
347extern_class!(
348    /// An audio unit instance.
349    ///
350    /// AUAudioUnit is a host interface to an audio unit. Hosts can instantiate either version 2 or
351    /// version 3 units with this class, and to some extent control whether an audio unit is
352    /// instantiated in-process or in a separate extension process.
353    ///
354    /// Implementors of version 3 audio units can and should subclass AUAudioUnit. To port an
355    /// existing version 2 audio unit easily, AUAudioUnitV2Bridge can be subclassed.
356    ///
357    /// These are the ways in which audio unit components can be registered:
358    ///
359    /// - (v2) Packaged into a component bundle containing an `AudioComponents` Info.plist entry,
360    /// referring to an `AudioComponentFactoryFunction`. See AudioComponent.h.
361    ///
362    /// - (v2) AudioComponentRegister(). Associates a component description with an
363    /// AudioComponentFactoryFunction. See AudioComponent.h.
364    ///
365    /// - (v3) Packaged into an app extension containing an AudioComponents Info.plist entry.
366    /// The principal class must conform to the AUAudioUnitFactory protocol, which will typically
367    /// instantiate an AUAudioUnit subclass.
368    ///
369    /// - (v3) `+[AUAudioUnit registerSubclass:asComponentDescription:name:version:]`. Associates
370    /// a component description with an AUAudioUnit subclass.
371    ///
372    /// A host need not be aware of the concrete subclass of AUAudioUnit that is being instantiated.
373    /// `initWithComponentDescription:options:error:` ensures that the proper subclass is used.
374    ///
375    /// When using AUAudioUnit with a v2 audio unit, or the C AudioComponent and AudioUnit API's
376    /// with a v3 audio unit, all major pieces of functionality are bridged between the
377    /// two API's. This header describes, for each v3 method or property, the v2 equivalent.
378    ///
379    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounit?language=objc)
380    #[unsafe(super(NSObject))]
381    #[derive(Debug, PartialEq, Eq, Hash)]
382    pub struct AUAudioUnit;
383);
384
385extern_conformance!(
386    unsafe impl NSObjectProtocol for AUAudioUnit {}
387);
388
389impl AUAudioUnit {
390    extern_methods!(
391        #[unsafe(method(init))]
392        #[unsafe(method_family = init)]
393        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
394
395        #[cfg(feature = "AudioComponent")]
396        /// Designated initializer.
397        ///
398        /// Parameter `componentDescription`: A single AUAudioUnit subclass may implement multiple audio units, for example, an effect
399        /// that can also function as a generator, or a cluster of related effects. The component
400        /// description specifies the component which was instantiated.
401        ///
402        /// Parameter `options`: Options for loading the unit in-process or out-of-process.
403        ///
404        /// Parameter `outError`: Returned in the event of failure.
405        #[unsafe(method(initWithComponentDescription:options:error:_))]
406        #[unsafe(method_family = init)]
407        pub unsafe fn initWithComponentDescription_options_error(
408            this: Allocated<Self>,
409            component_description: AudioComponentDescription,
410            options: AudioComponentInstantiationOptions,
411        ) -> Result<Retained<Self>, Retained<NSError>>;
412
413        #[cfg(feature = "AudioComponent")]
414        /// Convenience initializer (omits options).
415        #[unsafe(method(initWithComponentDescription:error:_))]
416        #[unsafe(method_family = init)]
417        pub unsafe fn initWithComponentDescription_error(
418            this: Allocated<Self>,
419            component_description: AudioComponentDescription,
420        ) -> Result<Retained<Self>, Retained<NSError>>;
421
422        #[cfg(all(feature = "AudioComponent", feature = "block2"))]
423        /// Asynchronously create an AUAudioUnit instance.
424        ///
425        /// Parameter `componentDescription`: The AudioComponentDescription of the audio unit to instantiate.
426        ///
427        /// Parameter `options`: See the discussion of AudioComponentInstantiationOptions in AudioToolbox/AudioComponent.h.
428        ///
429        /// Parameter `completionHandler`: Called in a thread/dispatch queue context internal to the implementation. The client should
430        /// retain the supplied AUAudioUnit.
431        ///
432        /// Certain types of AUAudioUnits must be instantiated asynchronously -- see
433        /// the discussion of kAudioComponentFlag_RequiresAsyncInstantiation in
434        /// AudioToolbox/AudioComponent.h.
435        ///
436        /// Note: Do not block the main thread while waiting for the completion handler to be called;
437        /// this can deadlock.
438        #[unsafe(method(instantiateWithComponentDescription:options:completionHandler:))]
439        #[unsafe(method_family = none)]
440        pub unsafe fn instantiateWithComponentDescription_options_completionHandler(
441            component_description: AudioComponentDescription,
442            options: AudioComponentInstantiationOptions,
443            completion_handler: &block2::DynBlock<dyn Fn(*mut AUAudioUnit, *mut NSError)>,
444        );
445
446        #[cfg(feature = "AudioComponent")]
447        /// The AudioComponentDescription with which the audio unit was created.
448        #[unsafe(method(componentDescription))]
449        #[unsafe(method_family = none)]
450        pub unsafe fn componentDescription(&self) -> AudioComponentDescription;
451
452        #[cfg(feature = "AudioComponent")]
453        /// The AudioComponent which was found based on componentDescription when the
454        /// audio unit was created.
455        #[unsafe(method(component))]
456        #[unsafe(method_family = none)]
457        pub unsafe fn component(&self) -> AudioComponent;
458
459        /// The unit's component's name.
460        ///
461        /// By convention, an audio unit's component name is its manufacturer's name, plus ": ",
462        /// plus the audio unit's name. The audioUnitName and manufacturerName properties are derived
463        /// from the component name.
464        #[unsafe(method(componentName))]
465        #[unsafe(method_family = none)]
466        pub unsafe fn componentName(&self) -> Option<Retained<NSString>>;
467
468        /// The audio unit's name.
469        #[unsafe(method(audioUnitName))]
470        #[unsafe(method_family = none)]
471        pub unsafe fn audioUnitName(&self) -> Option<Retained<NSString>>;
472
473        /// The manufacturer's name.
474        #[unsafe(method(manufacturerName))]
475        #[unsafe(method_family = none)]
476        pub unsafe fn manufacturerName(&self) -> Option<Retained<NSString>>;
477
478        /// A short name for the audio unit.
479        ///
480        /// Audio unit host applications can display this name in situations where the audioUnitName
481        /// might be too long. The recommended length is up to 16 characters. Host applications may
482        /// truncate it.
483        #[unsafe(method(audioUnitShortName))]
484        #[unsafe(method_family = none)]
485        pub unsafe fn audioUnitShortName(&self) -> Option<Retained<NSString>>;
486
487        /// The unit's component's version.
488        #[unsafe(method(componentVersion))]
489        #[unsafe(method_family = none)]
490        pub unsafe fn componentVersion(&self) -> u32;
491
492        /// Allocate resources required to render.
493        ///
494        /// Hosts must call this before beginning to render. Subclassers should call the superclass
495        /// implementation.
496        ///
497        /// Bridged to the v2 API AudioUnitInitialize().
498        #[unsafe(method(allocateRenderResourcesAndReturnError:_))]
499        #[unsafe(method_family = none)]
500        pub unsafe fn allocateRenderResourcesAndReturnError(&self)
501            -> Result<(), Retained<NSError>>;
502
503        /// Deallocate resources allocated by allocateRenderResourcesAndReturnError:
504        ///
505        /// Hosts should call this after finishing rendering. Subclassers should call the superclass
506        /// implementation.
507        ///
508        /// Bridged to the v2 API AudioUnitUninitialize().
509        #[unsafe(method(deallocateRenderResources))]
510        #[unsafe(method_family = none)]
511        pub unsafe fn deallocateRenderResources(&self);
512
513        /// returns YES if the unit has render resources allocated.
514        #[unsafe(method(renderResourcesAllocated))]
515        #[unsafe(method_family = none)]
516        pub unsafe fn renderResourcesAllocated(&self) -> bool;
517
518        /// Reset transitory rendering state to its initial state.
519        ///
520        /// Hosts should call this at the point of a discontinuity in the input stream being provided to
521        /// an audio unit, for example, when seeking forward or backward within a track. In response,
522        /// implementations should clear delay lines, filters, etc. Subclassers should call the
523        /// superclass implementation.
524        ///
525        /// Bridged to the v2 API AudioUnitReset(), in the global scope.
526        #[unsafe(method(reset))]
527        #[unsafe(method_family = none)]
528        pub unsafe fn reset(&self);
529
530        /// An audio unit's audio input connection points.
531        ///
532        /// Subclassers must override this property's getter. The implementation should return the same
533        /// object every time it is asked for it, since clients can install KVO observers on it.
534        #[unsafe(method(inputBusses))]
535        #[unsafe(method_family = none)]
536        pub unsafe fn inputBusses(&self) -> Retained<AUAudioUnitBusArray>;
537
538        /// An audio unit's audio output connection points.
539        ///
540        /// Subclassers must override this property's getter. The implementation should return the same
541        /// object every time it is asked for it, since clients can install KVO observers on it.
542        #[unsafe(method(outputBusses))]
543        #[unsafe(method_family = none)]
544        pub unsafe fn outputBusses(&self) -> Retained<AUAudioUnitBusArray>;
545
546        #[cfg(all(
547            feature = "AUComponent",
548            feature = "block2",
549            feature = "objc2-core-audio-types"
550        ))]
551        /// Block which hosts use to ask the unit to render.
552        ///
553        /// Before invoking an audio unit's rendering functionality, a host should fetch this block and
554        /// cache the result. The block can then be called from a realtime context without the
555        /// possibility of blocking and causing an overload at the Core Audio HAL level.
556        ///
557        /// This block will call a subclass' internalRenderBlock, providing all realtime events
558        /// scheduled for the current render time interval, bracketed by calls to any render observers.
559        ///
560        /// Subclassers should override internalRenderBlock, not this property.
561        ///
562        /// Bridged to the v2 API AudioUnitRender().
563        ///
564        /// # Safety
565        ///
566        /// - The returned block's argument 1 must be a valid pointer.
567        /// - The returned block's argument 2 must be a valid pointer.
568        /// - The returned block's argument 5 must be a valid pointer.
569        /// - The returned block's argument 6 must be a valid pointer or null.
570        #[unsafe(method(renderBlock))]
571        #[unsafe(method_family = none)]
572        pub unsafe fn renderBlock(&self) -> AURenderBlock;
573
574        #[cfg(all(
575            feature = "AUParameters",
576            feature = "AudioUnitProperties",
577            feature = "block2"
578        ))]
579        /// Block which hosts use to schedule parameters.
580        ///
581        /// As with renderBlock, a host should fetch and cache this block before calling
582        /// allocateRenderResources, if it intends to schedule parameters.
583        ///
584        /// The block is safe to call from any thread context, including realtime audio render
585        /// threads.
586        ///
587        /// Subclassers should not override this; it is implemented in the base class and will schedule
588        /// the events to be provided to the internalRenderBlock.
589        ///
590        /// Bridged to the v2 API AudioUnitScheduleParameters().
591        #[unsafe(method(scheduleParameterBlock))]
592        #[unsafe(method_family = none)]
593        pub unsafe fn scheduleParameterBlock(&self) -> AUScheduleParameterBlock;
594
595        #[cfg(all(
596            feature = "AUComponent",
597            feature = "block2",
598            feature = "objc2-core-audio-types"
599        ))]
600        /// Add a block to be called on each render cycle.
601        ///
602        /// The supplied block is called at the beginning and ending of each render cycle. It should
603        /// not make any blocking calls.
604        ///
605        /// This method is implemented in the base class AUAudioUnit, and should not be overridden.
606        ///
607        /// Bridged to the v2 API AudioUnitAddRenderNotify().
608        ///
609        /// Parameter `observer`: The block to call.
610        ///
611        /// Returns: A token to be used when removing the observer.
612        ///
613        /// # Safety
614        ///
615        /// `observer` must be a valid pointer.
616        #[unsafe(method(tokenByAddingRenderObserver:))]
617        #[unsafe(method_family = none)]
618        pub unsafe fn tokenByAddingRenderObserver(&self, observer: AURenderObserver) -> NSInteger;
619
620        /// Remove an observer block added via tokenByAddingRenderObserver:
621        ///
622        /// Parameter `token`: The token previously returned by tokenByAddingRenderObserver:
623        ///
624        /// Bridged to the v2 API AudioUnitRemoveRenderNotify().
625        #[unsafe(method(removeRenderObserver:))]
626        #[unsafe(method_family = none)]
627        pub unsafe fn removeRenderObserver(&self, token: NSInteger);
628
629        /// The maximum number of frames which the audio unit can render at once.
630        ///
631        /// This must be set by the host before render resources are allocated. It cannot be changed
632        /// while render resources are allocated.
633        ///
634        /// Bridged to the v2 property kAudioUnitProperty_MaximumFramesPerSlice.
635        #[unsafe(method(maximumFramesToRender))]
636        #[unsafe(method_family = none)]
637        pub unsafe fn maximumFramesToRender(&self) -> AUAudioFrameCount;
638
639        /// Setter for [`maximumFramesToRender`][Self::maximumFramesToRender].
640        #[unsafe(method(setMaximumFramesToRender:))]
641        #[unsafe(method_family = none)]
642        pub unsafe fn setMaximumFramesToRender(&self, maximum_frames_to_render: AUAudioFrameCount);
643
644        #[cfg(feature = "AUParameters")]
645        /// An audio unit's parameters, organized in a hierarchy.
646        ///
647        /// Returns: A parameter tree object, or nil if the unit has no parameters.
648        ///
649        /// Audio unit hosts can fetch this property to discover a unit's parameters. KVO notifications
650        /// are issued on this member to notify the host of changes to the set of available parameters.
651        ///
652        /// AUAudioUnit has an additional pseudo-property, "allParameterValues", on which KVO
653        /// notifications are issued in response to certain events where potentially all parameter
654        /// values are invalidated. This includes changes to currentPreset, fullState, and
655        /// fullStateForDocument.
656        ///
657        /// Hosts should not attempt to set this property.
658        ///
659        /// Subclassers should implement the parameterTree getter to expose parameters to hosts. They
660        /// should cache as much as possible and send KVO notifications on "parameterTree" when altering
661        /// the structure of the tree or the static information (ranges, etc) of parameters.
662        ///
663        /// This is similar to the v2 properties kAudioUnitProperty_ParameterList and
664        /// kAudioUnitProperty_ParameterInfo.
665        ///
666        /// Note that it is not safe to modify this property in a real-time context.
667        #[unsafe(method(parameterTree))]
668        #[unsafe(method_family = none)]
669        pub unsafe fn parameterTree(&self) -> Option<Retained<AUParameterTree>>;
670
671        #[cfg(feature = "AUParameters")]
672        /// Setter for [`parameterTree`][Self::parameterTree].
673        #[unsafe(method(setParameterTree:))]
674        #[unsafe(method_family = none)]
675        pub unsafe fn setParameterTree(&self, parameter_tree: Option<&AUParameterTree>);
676
677        /// Returns the audio unit's `count` most important parameters.
678        ///
679        /// This property allows a host to query an audio unit for some small number of parameters which
680        /// are its "most important", to be displayed in a compact generic view.
681        ///
682        /// An audio unit subclass should return an array of NSNumbers representing the addresses
683        /// of the `count` most important parameters.
684        ///
685        /// The base class returns an empty array regardless of count.
686        ///
687        /// Partially bridged to kAudioUnitProperty_ParametersForOverview (v2 hosts can use that
688        /// property to access this v3 method of an audio unit).
689        #[unsafe(method(parametersForOverviewWithCount:))]
690        #[unsafe(method_family = none)]
691        pub unsafe fn parametersForOverviewWithCount(
692            &self,
693            count: NSInteger,
694        ) -> Retained<NSArray<NSNumber>>;
695
696        #[unsafe(method(allParameterValues))]
697        #[unsafe(method_family = none)]
698        pub unsafe fn allParameterValues(&self) -> bool;
699
700        /// Specifies whether an audio unit responds to MIDI events.
701        ///
702        /// This is implemented in the base class and returns YES if the component type is music
703        /// device or music effect.
704        #[unsafe(method(isMusicDeviceOrEffect))]
705        #[unsafe(method_family = none)]
706        pub unsafe fn isMusicDeviceOrEffect(&self) -> bool;
707
708        /// The number of virtual MIDI cables implemented by a music device or effect.
709        ///
710        /// A music device or MIDI effect can support up to 256 virtual MIDI cables of input; this
711        /// property expresses the number of cables supported by the audio unit.
712        #[unsafe(method(virtualMIDICableCount))]
713        #[unsafe(method_family = none)]
714        pub unsafe fn virtualMIDICableCount(&self) -> NSInteger;
715
716        #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
717        /// Block used to schedule MIDI events.
718        ///
719        /// As with renderBlock, a host should fetch and cache this block before calling
720        /// allocateRenderResources if it intends to schedule MIDI events.
721        ///
722        /// This is implemented in the base class. It is nil when musicDeviceOrEffect is NO.
723        ///
724        /// Subclasses should not override. When hosts schedule events via this block, they are
725        /// sent to the Audio Unit via the list of AURenderEvents delivered to
726        /// internalRenderBlock.
727        ///
728        /// All events sent via this block will be delivered to the internalRenderBlock in the MIDI
729        /// protocol returned by the AudioUnitMIDIProtocol property. For example, if AudioUnitMIDIProtocol
730        /// returns kMIDIProtocol_2_0, incoming events will be translated to MIDI 2.0 if necessary.
731        /// If AudioUnitMIDIProtocol is not set, events will be delivered as legacy MIDI.
732        ///
733        /// This bridged to the v2 API MusicDeviceMIDIEvent.
734        ///
735        /// # Safety
736        ///
737        /// The returned block's argument 4 must be a valid pointer.
738        #[unsafe(method(scheduleMIDIEventBlock))]
739        #[unsafe(method_family = none)]
740        pub unsafe fn scheduleMIDIEventBlock(&self) -> AUScheduleMIDIEventBlock;
741
742        /// Count, and names of, a plug-in's MIDI outputs.
743        ///
744        /// A plug-in may override this method to inform hosts about its MIDI outputs. The size of the
745        /// array is the number of outputs the Audio Unit supports. Each item in the array is the name
746        /// of the MIDI output at that index.
747        ///
748        /// This is bridged to the v2 API property kAudioUnitProperty_MIDIOutputCallbackInfo.
749        #[unsafe(method(MIDIOutputNames))]
750        #[unsafe(method_family = none)]
751        pub unsafe fn MIDIOutputNames(&self) -> Retained<NSArray<NSString>>;
752
753        /// Specifies whether an audio unit provides UI (normally in the form of a view controller).
754        ///
755        /// Implemented in the framework and should not be overridden by implementators. The
756        /// framework detects whether any subclass has implemented
757        /// `requestViewControllerWithCompletionHandler:` or is implemented by an AU extension whose
758        /// extension point identifier is `com.apple.AudioUnit-UI`. See also
759        /// `requestViewControllerWithCompletionHandler:` in
760        /// <CoreAudioKit
761        /// /AUViewController.h>
762        #[unsafe(method(providesUserInterface))]
763        #[unsafe(method_family = none)]
764        pub unsafe fn providesUserInterface(&self) -> bool;
765
766        #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
767        /// Block used by the host to access the MIDI output generated by an Audio Unit.
768        ///
769        /// The host can set this block and the plug-in can call it in its renderBlock to provide to the
770        /// host the MIDI data associated with the current render cycle.
771        ///
772        /// All events sent via this block will be delivered to the host in the MIDI protocol returned by
773        /// the hostMIDIProtocol property. For example, if hostMIDIProtocol is set to
774        /// kMIDIProtocol_2_0, incoming events will be translated to MIDI 2.0. If hostMIDIProtocol
775        /// is not set, events will be delivered as legacy MIDI.
776        ///
777        /// Note: AUMIDIEventListBlock should be preferred over this block going forward.
778        ///
779        /// This is bridged to the v2 API property kAudioUnitProperty_MIDIOutputCallback.
780        ///
781        /// # Safety
782        ///
783        /// The returned block's argument 4 must be a valid pointer.
784        #[unsafe(method(MIDIOutputEventBlock))]
785        #[unsafe(method_family = none)]
786        pub unsafe fn MIDIOutputEventBlock(&self) -> AUMIDIOutputEventBlock;
787
788        #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
789        /// Setter for [`MIDIOutputEventBlock`][Self::MIDIOutputEventBlock].
790        ///
791        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
792        ///
793        /// # Safety
794        ///
795        /// `midi_output_event_block` must be a valid pointer or null.
796        #[unsafe(method(setMIDIOutputEventBlock:))]
797        #[unsafe(method_family = none)]
798        pub unsafe fn setMIDIOutputEventBlock(
799            &self,
800            midi_output_event_block: AUMIDIOutputEventBlock,
801        );
802
803        #[cfg(feature = "objc2-core-midi")]
804        /// The MIDI protocol used by the Audio Unit for receiving MIDIEventList data.
805        ///
806        /// Subclassers should override to return the desired protocol in which the Audio Unit wants
807        /// to receive input MIDI data, otherwise the Audio Unit will default to receiving legacy MIDI.
808        ///
809        /// All translatable messages will be converted (if necessary) to this protocol prior to delivery
810        /// to the Audio Unit.
811        ///
812        /// This is bridged to the v2 API property kAudioUnitProperty_AudioUnitMIDIProtocol.
813        #[unsafe(method(AudioUnitMIDIProtocol))]
814        #[unsafe(method_family = none)]
815        pub unsafe fn AudioUnitMIDIProtocol(&self) -> MIDIProtocolID;
816
817        #[cfg(feature = "objc2-core-midi")]
818        /// The MIDI protocol to be used by the host for receiving MIDIEventList data.
819        ///
820        /// Hosts should set this property to the protocol they wish to receive MIDIEventList data
821        /// from the Audio Unit. This should be set prior to initialization, all translatable messages
822        /// will be converted  (if necessary) to this property's protocol prior to delivery to the host.
823        ///
824        /// Host should setup in the following order:
825        /// - Set hostMIDIProtocol
826        /// - Set MIDIOutputEventListBlock
827        /// - Call allocateRenderResourcesAndReturnError
828        ///
829        /// This is bridged to the v2 API property kAudioUnitProperty_HostMIDIProtocol.
830        ///
831        /// Notes:
832        /// - If overriding this property, subclassers must call [super setHostMIDIProtocol:]
833        /// - hostMIDIProtocol should be set before attempting to query AudioUnitMIDIProtocol
834        /// or calling allocateRenderResourcesAndReturnError to allow Audio Units to
835        /// optionally match their input MIDI protocol to the desired host protocol and prevent
836        /// protocol conversion.
837        #[unsafe(method(hostMIDIProtocol))]
838        #[unsafe(method_family = none)]
839        pub unsafe fn hostMIDIProtocol(&self) -> MIDIProtocolID;
840
841        #[cfg(feature = "objc2-core-midi")]
842        /// Setter for [`hostMIDIProtocol`][Self::hostMIDIProtocol].
843        #[unsafe(method(setHostMIDIProtocol:))]
844        #[unsafe(method_family = none)]
845        pub unsafe fn setHostMIDIProtocol(&self, host_midi_protocol: MIDIProtocolID);
846
847        /// A persistable snapshot of the Audio Unit's properties and parameters, suitable for
848        /// saving as a user preset.
849        ///
850        /// Hosts may use this property to save and restore the state of an Audio Unit being used in a
851        /// user preset or document. The Audio Unit should not persist transitory properties such as
852        /// stream formats, but should save and restore all parameters and custom properties.
853        ///
854        /// The base class implementation of this property saves the values of all parameters
855        /// currently in the parameter tree. A subclass which dynamically produces multiple variants
856        /// of the parameter tree needs to be aware that the serialization method does a depth-first
857        /// preorder traversal of the tree.
858        ///
859        /// Bridged to the v2 property kAudioUnitProperty_ClassInfo.
860        #[unsafe(method(fullState))]
861        #[unsafe(method_family = none)]
862        pub unsafe fn fullState(&self) -> Option<Retained<NSDictionary<NSString, AnyObject>>>;
863
864        /// Setter for [`fullState`][Self::fullState].
865        ///
866        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
867        ///
868        /// # Safety
869        ///
870        /// `full_state` generic should be of the correct type.
871        #[unsafe(method(setFullState:))]
872        #[unsafe(method_family = none)]
873        pub unsafe fn setFullState(&self, full_state: Option<&NSDictionary<NSString, AnyObject>>);
874
875        /// A persistable snapshot of the audio unit's properties and parameters, suitable for
876        /// saving in a user's document.
877        ///
878        /// This property is distinct from fullState in that some state is suitable for saving in user
879        /// presets, while other state is not. For example, a synthesizer's master tuning setting could
880        /// be considered global state, inappropriate for storing in reusable presets, but desirable
881        /// for storing in a document for a specific live performance.
882        ///
883        /// Hosts saving documents should use this property. If the audio unit does not implement it,
884        /// the base class simply sets/gets fullState.
885        ///
886        /// Bridged to the v2 property kAudioUnitProperty_ClassInfoFromDocument.
887        #[unsafe(method(fullStateForDocument))]
888        #[unsafe(method_family = none)]
889        pub unsafe fn fullStateForDocument(
890            &self,
891        ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>;
892
893        /// Setter for [`fullStateForDocument`][Self::fullStateForDocument].
894        ///
895        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
896        ///
897        /// # Safety
898        ///
899        /// `full_state_for_document` generic should be of the correct type.
900        #[unsafe(method(setFullStateForDocument:))]
901        #[unsafe(method_family = none)]
902        pub unsafe fn setFullStateForDocument(
903            &self,
904            full_state_for_document: Option<&NSDictionary<NSString, AnyObject>>,
905        );
906
907        /// A collection of presets provided by the audio unit's developer.
908        ///
909        /// A preset provides users of an audio unit with an easily-selectable, fine-tuned set of
910        /// parameters provided by the developer. This property returns all of the available factory presets.
911        ///
912        /// Bridged to the v2 property kAudioUnitProperty_FactoryPresets.
913        #[unsafe(method(factoryPresets))]
914        #[unsafe(method_family = none)]
915        pub unsafe fn factoryPresets(&self) -> Option<Retained<NSArray<AUAudioUnitPreset>>>;
916
917        /// A collection of presets saved by the user
918        ///
919        /// In addition to factory presets, provided by the audio unit vendor, users have the ability to
920        /// save the values of the parameters of an audio unit into a user preset. These users presets
921        /// can be accessed using this property.
922        ///
923        /// The default implementation of this method will load the user presets from an internal
924        /// location that might not be directly accessible to the audio unit host application or to the
925        /// audio unit. Instead of accessing this path directly, the audio unit should rely on the
926        /// superclass implementation of this method to retrieve the presets.
927        ///
928        /// Audio Units are free to override this method to load their user presets via different means
929        /// (e.g. from their iCloud container).
930        #[unsafe(method(userPresets))]
931        #[unsafe(method_family = none)]
932        pub unsafe fn userPresets(&self) -> Retained<NSArray<AUAudioUnitPreset>>;
933
934        /// Persistently save the current state of the audio unit into a userPreset
935        ///
936        /// The new preset will be added to userPresets and will become selectable by assigning it
937        /// to the currentPreset property.
938        /// If a preset with the provided name already exists then it will be overwritten.
939        ///
940        /// For user presets, the preset number is required to be negative.
941        /// If a positive number is passed, the sign will be changed to negative.
942        /// If zero is passed, the number will be set to -1.
943        /// These changes will be reflected on the userPreset argument.
944        ///
945        /// The default implementation of this method will save the user preset to an internal
946        /// location.
947        ///
948        /// Audio Units are free to override this method to operate on a different location (e.g. their
949        /// iCloud container).
950        ///
951        /// Parameter `userPreset`: The preset under which the current state will be saved.
952        ///
953        /// Parameter `outError`: In the event of a failure, the method will return NO and outError will be set to an
954        /// NSError, describing the problem.
955        /// Some possible errors:
956        /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
957        /// - domain: NSOSStatusErrorDomain    code: kAudioUnitErr_InvalidFilePath
958        /// - domain: NSOSStatusErrorDomain    code: kAudioUnitErr_MissingKey
959        ///
960        /// Returns: YES for success. NO in the event of a failure, in which case the error is returned in
961        /// outError.
962        #[unsafe(method(saveUserPreset:error:_))]
963        #[unsafe(method_family = none)]
964        pub unsafe fn saveUserPreset_error(
965            &self,
966            user_preset: &AUAudioUnitPreset,
967        ) -> Result<(), Retained<NSError>>;
968
969        /// Remove a user preset.
970        ///
971        /// The user preset will be removed from userPresets and will be permanently deleted.
972        ///
973        /// The default implementation of this method will delete the user preset from an internal
974        /// location.
975        ///
976        /// Audio Units are free to override this method to operate on a different location (e.g. their
977        /// iCloud container).
978        ///
979        /// Parameter `userPreset`: The preset to be deleted.
980        ///
981        /// Parameter `outError`: In the event of a failure, the method will return NO and outError will be set to an
982        /// NSError, describing the problem.
983        /// Some possible errors:
984        /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
985        /// - domain: NSPOSIXErrorDomain    code: ENOENT
986        /// - domain: NSOSStatusErrorDomain    code: kAudioUnitErr_InvalidFilePath
987        ///
988        /// Returns: YES for success. NO in the event of a failure, in which case the error is returned in
989        /// outError.
990        #[unsafe(method(deleteUserPreset:error:_))]
991        #[unsafe(method_family = none)]
992        pub unsafe fn deleteUserPreset_error(
993            &self,
994            user_preset: &AUAudioUnitPreset,
995        ) -> Result<(), Retained<NSError>>;
996
997        /// Retrieve the state stored in a user preset
998        ///
999        /// This method allows access to the contents of a preset without having to set that preset as
1000        /// current. The returned dictionary is assignable to the audio unit's fullState and/or
1001        /// fullStateForDocument properties.
1002        ///
1003        /// Audio units can override this method in order to vend user presets from a different location
1004        /// (e.g. their iCloud container).
1005        ///
1006        /// In order to restore the state from a user preset, the audio unit should override the setter
1007        /// for the currentPreset property and check the preset number to determine the type of preset.
1008        /// If the preset number is >= 0 then the preset is a factory preset.
1009        /// If the preset number is
1010        /// <
1011        /// 0 then it is a user preset.
1012        ///
1013        /// This method can then be called to retrieve the state stored in a user preset and the audio
1014        /// unit can assign this to fullState or fullStateForDocument.
1015        ///
1016        ///
1017        /// Parameter `userPreset`: The preset to be selected.
1018        ///
1019        /// Parameter `outError`: In the event of a failure, the method will return nil and outError will be set to an
1020        /// NSError, describing the problem.
1021        /// Some possible errors:
1022        /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
1023        /// - domain: NSPOSIXErrorDomain    code: ENOENT
1024        /// - domain: NSCocoaErrorDomain    code: NSCoderReadCorruptError
1025        ///
1026        /// Returns: Returns nil if there was an error, otherwise returns a dictionary containing the full state
1027        /// of the audio unit saved in the preset.
1028        /// For details on the possible keys present in the full state dictionary, please see the
1029        /// documentation for kAudioUnitProperty_ClassInfo.
1030        /// The minimal set of keys and their type is:
1031        /// : NSNumber,
1032        /// : NSNumber,
1033        /// : NSNumber,
1034        /// : NSNumber,
1035        /// : NSString,
1036        /// : NSNumber,
1037        /// : NSData
1038        #[unsafe(method(presetStateFor:error:_))]
1039        #[unsafe(method_family = none)]
1040        pub unsafe fn presetStateFor_error(
1041            &self,
1042            user_preset: &AUAudioUnitPreset,
1043        ) -> Result<Retained<NSDictionary<NSString, AnyObject>>, Retained<NSError>>;
1044
1045        /// Specifies whether an audio unit supports loading and saving user presets
1046        ///
1047        /// The audio unit should set this property to YES if a user preset can be assigned to
1048        /// currentPreset.
1049        ///
1050        /// Audio unit host applications should query this property to determine whether the audio unit
1051        /// supports user presets.
1052        ///
1053        /// Assigning a user preset to the currentPreset property of an audio unit that does not support
1054        /// restoring state from user presets may result in incorrect behavior.
1055        #[unsafe(method(supportsUserPresets))]
1056        #[unsafe(method_family = none)]
1057        pub unsafe fn supportsUserPresets(&self) -> bool;
1058
1059        /// Set to YES when an AUAudioUnit is loaded in-process
1060        ///
1061        /// If the AUAudioUnit is instantiated with kAudioComponentInstantiation_LoadInProcess, but the
1062        /// audio unit is not packaged properly to support loading in-process, the system will silently
1063        /// fall back to loading the audio unit out-of-process.
1064        ///
1065        /// This property can be used to determine whether the instantiation succeeded as intended and
1066        /// the audio unit is running in-process.
1067        ///
1068        /// The presence of an extension process is not sufficient indication that the audio unit failed
1069        /// to load in-process, since the framework might launch the audio unit extension process to
1070        /// fulfill auxiliary functionality. If the audio unit is loaded in-process then rendering is
1071        /// done in the host process. Other operations that are not essential to rendering audio, might
1072        /// be done in the audio unit's extension process.
1073        #[unsafe(method(isLoadedInProcess))]
1074        #[unsafe(method_family = none)]
1075        pub unsafe fn isLoadedInProcess(&self) -> bool;
1076
1077        /// The audio unit's last-selected preset.
1078        ///
1079        /// Hosts can let the user select a preset by setting this property. Note that when getting
1080        /// this property, it does not reflect whether parameters may have been modified since the
1081        /// preset was selected.
1082        ///
1083        /// Bridged to the v2 property kAudioUnitProperty_PresentPreset.
1084        #[unsafe(method(currentPreset))]
1085        #[unsafe(method_family = none)]
1086        pub unsafe fn currentPreset(&self) -> Option<Retained<AUAudioUnitPreset>>;
1087
1088        /// Setter for [`currentPreset`][Self::currentPreset].
1089        #[unsafe(method(setCurrentPreset:))]
1090        #[unsafe(method_family = none)]
1091        pub unsafe fn setCurrentPreset(&self, current_preset: Option<&AUAudioUnitPreset>);
1092
1093        /// The audio unit's processing latency, in seconds.
1094        ///
1095        /// This property reflects the delay between when an impulse in the unit's audio unit stream
1096        /// arrives in the input vs. output streams. This should reflect the delay due
1097        /// to signal processing (e.g. filters, FFT's, etc.), not delay or reverberation which is
1098        /// being applied as an effect.
1099        ///
1100        /// Note that a latency that varies with parameter settings, including bypass, is generally not
1101        /// useful to hosts. A host is usually only prepared to add delays before starting to render and
1102        /// those delays need to be fixed. A variable delay would introduce artifacts even if the host
1103        /// could track it. If an algorithm has a variable latency it should be adjusted upwards to some
1104        /// fixed latency within the audio unit. If for some reason this is not possible, then latency
1105        /// could be regarded as an unavoidable consequence of the algorithm and left unreported (i.e.
1106        /// with a value of 0).
1107        ///
1108        /// Bridged to the v2 property kAudioUnitProperty_Latency.
1109        #[unsafe(method(latency))]
1110        #[unsafe(method_family = none)]
1111        pub unsafe fn latency(&self) -> NSTimeInterval;
1112
1113        /// The audio unit's tail time, in seconds.
1114        ///
1115        /// This property reflects the time interval between when the input stream ends or otherwise
1116        /// transitions to silence, and when the output stream becomes silent. Unlike latency, this
1117        /// should reflect the duration of a delay or reverb effect.
1118        ///
1119        /// Bridged to the v2 property kAudioUnitProperty_TailTime.
1120        #[unsafe(method(tailTime))]
1121        #[unsafe(method_family = none)]
1122        pub unsafe fn tailTime(&self) -> NSTimeInterval;
1123
1124        /// Provides a trade-off between rendering quality and CPU load.
1125        ///
1126        /// The range of valid values is 0-127.
1127        ///
1128        /// Bridged to the v2 property kAudioUnitProperty_RenderQuality.
1129        #[unsafe(method(renderQuality))]
1130        #[unsafe(method_family = none)]
1131        pub unsafe fn renderQuality(&self) -> NSInteger;
1132
1133        /// Setter for [`renderQuality`][Self::renderQuality].
1134        #[unsafe(method(setRenderQuality:))]
1135        #[unsafe(method_family = none)]
1136        pub unsafe fn setRenderQuality(&self, render_quality: NSInteger);
1137
1138        /// Directs an effect to route input directly to output, without any processing.
1139        ///
1140        /// Bridged to the v2 property kAudioUnitProperty_BypassEffect.
1141        #[unsafe(method(shouldBypassEffect))]
1142        #[unsafe(method_family = none)]
1143        pub unsafe fn shouldBypassEffect(&self) -> bool;
1144
1145        /// Setter for [`shouldBypassEffect`][Self::shouldBypassEffect].
1146        #[unsafe(method(setShouldBypassEffect:))]
1147        #[unsafe(method_family = none)]
1148        pub unsafe fn setShouldBypassEffect(&self, should_bypass_effect: bool);
1149
1150        /// Expresses whether an audio unit can process in place.
1151        ///
1152        /// In-place processing is the ability for an audio unit to transform an input signal to an
1153        /// output signal in-place in the input buffer, without requiring a separate output buffer.
1154        ///
1155        /// A host can express its desire to process in place by using null mData pointers in the output
1156        /// buffer list. The audio unit may process in-place in the input buffers. See the discussion of
1157        /// renderBlock.
1158        ///
1159        /// Partially bridged to the v2 property kAudioUnitProperty_InPlaceProcessing; in v3 it is not
1160        /// settable.
1161        ///
1162        /// Defaults to NO. Subclassers can override to return YES.
1163        #[unsafe(method(canProcessInPlace))]
1164        #[unsafe(method_family = none)]
1165        pub unsafe fn canProcessInPlace(&self) -> bool;
1166
1167        /// Communicates to an audio unit that it is rendering offline.
1168        ///
1169        /// A host should set this property when using an audio unit in a context where there are no
1170        /// realtime deadlines, before asking the unit to allocate render resources. An audio unit may
1171        /// respond by using a more expensive signal processing algorithm, or allowing itself to block
1172        /// at render time if data being generated on secondary work threads is not ready in time.
1173        /// (Normally, in a realtime thread, this data would have to be dropped).
1174        ///
1175        /// Bridged to the v2 property kAudioUnitProperty_OfflineRender.
1176        #[unsafe(method(isRenderingOffline))]
1177        #[unsafe(method_family = none)]
1178        pub unsafe fn isRenderingOffline(&self) -> bool;
1179
1180        /// Setter for [`isRenderingOffline`][Self::isRenderingOffline].
1181        #[unsafe(method(setRenderingOffline:))]
1182        #[unsafe(method_family = none)]
1183        pub unsafe fn setRenderingOffline(&self, rendering_offline: bool);
1184
1185        /// Expresses valid combinations of input and output channel counts.
1186        ///
1187        /// Elements are NSNumber containing integers; [0]=input count, [1]=output count, [2]=2nd input
1188        /// count, [3]=2nd output count, etc.
1189        ///
1190        /// An input, output count of (2, 2) signifies that the audio unit can process 2 input channels
1191        /// to 2 output channels.
1192        ///
1193        /// Negative numbers (-1, -2) indicate *any* number of channels. (-1, -1) means any number
1194        /// of channels on input and output as long as they are the same. (-1, -2) means any number of
1195        /// channels on input or output, without the requirement that the counts are the same.
1196        ///
1197        /// A negative number less than -2 is used to indicate a total number of channels across every
1198        /// bus in that scope, regardless of how many channels are set on any particular bus. For
1199        /// example, (-16, 2) indicates that a unit can accept up to 16 channels of input across its
1200        /// input busses, but will only produce 2 channels of output.
1201        ///
1202        /// Zero on either side (though typically input) means "not applicable", because there are no
1203        /// elements on that side.
1204        ///
1205        /// Bridged to the v2 property kAudioUnitProperty_SupportedNumChannels.
1206        #[unsafe(method(channelCapabilities))]
1207        #[unsafe(method_family = none)]
1208        pub unsafe fn channelCapabilities(&self) -> Option<Retained<NSArray<NSNumber>>>;
1209
1210        #[cfg(feature = "block2")]
1211        /// A callback for the AU to call the host for musical context information.
1212        ///
1213        /// Note that an audio unit implementation accessing this property should cache it in
1214        /// realtime-safe storage before beginning to render.
1215        ///
1216        /// Bridged to the HostCallback_GetBeatAndTempo and HostCallback_GetMusicalTimeLocation
1217        /// callback members in kAudioUnitProperty_HostCallbacks.
1218        ///
1219        /// # Safety
1220        ///
1221        /// - The returned block's argument 1 must be a valid pointer or null.
1222        /// - The returned block's argument 2 must be a valid pointer or null.
1223        /// - The returned block's argument 3 must be a valid pointer or null.
1224        /// - The returned block's argument 4 must be a valid pointer or null.
1225        /// - The returned block's argument 5 must be a valid pointer or null.
1226        /// - The returned block's argument 6 must be a valid pointer or null.
1227        #[unsafe(method(musicalContextBlock))]
1228        #[unsafe(method_family = none)]
1229        pub unsafe fn musicalContextBlock(&self) -> AUHostMusicalContextBlock;
1230
1231        #[cfg(feature = "block2")]
1232        /// Setter for [`musicalContextBlock`][Self::musicalContextBlock].
1233        ///
1234        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1235        ///
1236        /// # Safety
1237        ///
1238        /// `musical_context_block` must be a valid pointer or null.
1239        #[unsafe(method(setMusicalContextBlock:))]
1240        #[unsafe(method_family = none)]
1241        pub unsafe fn setMusicalContextBlock(
1242            &self,
1243            musical_context_block: AUHostMusicalContextBlock,
1244        );
1245
1246        #[cfg(feature = "block2")]
1247        /// A callback for the AU to call the host for transport state information.
1248        ///
1249        /// Note that an audio unit implementation accessing this property should cache it in
1250        /// realtime-safe storage before beginning to render.
1251        ///
1252        /// Bridged to the HostCallback_GetTransportState and HostCallback_GetTransportState2
1253        /// callback members in kAudioUnitProperty_HostCallbacks.
1254        ///
1255        /// # Safety
1256        ///
1257        /// - The returned block's argument 1 must be a valid pointer or null.
1258        /// - The returned block's argument 2 must be a valid pointer or null.
1259        /// - The returned block's argument 3 must be a valid pointer or null.
1260        /// - The returned block's argument 4 must be a valid pointer or null.
1261        #[unsafe(method(transportStateBlock))]
1262        #[unsafe(method_family = none)]
1263        pub unsafe fn transportStateBlock(&self) -> AUHostTransportStateBlock;
1264
1265        #[cfg(feature = "block2")]
1266        /// Setter for [`transportStateBlock`][Self::transportStateBlock].
1267        ///
1268        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1269        ///
1270        /// # Safety
1271        ///
1272        /// `transport_state_block` must be a valid pointer or null.
1273        #[unsafe(method(setTransportStateBlock:))]
1274        #[unsafe(method_family = none)]
1275        pub unsafe fn setTransportStateBlock(
1276            &self,
1277            transport_state_block: AUHostTransportStateBlock,
1278        );
1279
1280        /// Information about the host context in which the audio unit is connected, for display
1281        /// in the audio unit's view.
1282        ///
1283        /// For example, a host could set "track 3" as the context, so that the audio unit's view could
1284        /// then display to the user "My audio unit on track 3".
1285        ///
1286        /// Bridged to the v2 property kAudioUnitProperty_ContextName.
1287        #[unsafe(method(contextName))]
1288        #[unsafe(method_family = none)]
1289        pub unsafe fn contextName(&self) -> Option<Retained<NSString>>;
1290
1291        /// Setter for [`contextName`][Self::contextName].
1292        ///
1293        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1294        #[unsafe(method(setContextName:))]
1295        #[unsafe(method_family = none)]
1296        pub unsafe fn setContextName(&self, context_name: Option<&NSString>);
1297
1298        /// Information for migrating data from other audio plug-ins to the v3 Audio Unit architecture.
1299        ///
1300        /// This can be used to migrate settings from an older Audio Unit; this allows manufacturers
1301        /// to deprecate older Audio Units and replace them with new ones. The data for the older Audio Unit is
1302        /// an array of NSData representing byte encoded AudioUnitOtherPluginDescs to migrate from.
1303        /// Can also be used to migrate from a v2 to a v3 Audio Unit.
1304        ///
1305        /// Bridged to the v2 property kAudioUnitMigrateProperty_FromPlugin.
1306        #[unsafe(method(migrateFromPlugin))]
1307        #[unsafe(method_family = none)]
1308        pub unsafe fn migrateFromPlugin(&self) -> Retained<NSArray>;
1309
1310        /// Specifies whether an audio unit supports Multi-dimensional Polyphonic Expression.
1311        ///
1312        /// Bridged to the v2 property kAudioUnitProperty_SupportsMPE.
1313        #[unsafe(method(supportsMPE))]
1314        #[unsafe(method_family = none)]
1315        pub unsafe fn supportsMPE(&self) -> bool;
1316
1317        /// Specify a mapping of input channels to output channels.
1318        ///
1319        /// Converter and input/output audio units may support re-ordering or splitting of input
1320        /// channels to output channels. The number of channels in the channel map is the number of
1321        /// channels of the destination (output format). The channel map entries contain a channel
1322        /// number of the source channel that should be mapped to that destination channel. If -1 is
1323        /// specified, then that destination channel will not contain any channel from the source (so it
1324        /// will be silent).
1325        ///
1326        /// If the property value is nil, then the audio unit does not support this property.
1327        ///
1328        /// Bridged to the v2 property kAudioOutputUnitProperty_ChannelMap.
1329        #[unsafe(method(channelMap))]
1330        #[unsafe(method_family = none)]
1331        pub unsafe fn channelMap(&self) -> Option<Retained<NSArray<NSNumber>>>;
1332
1333        /// Setter for [`channelMap`][Self::channelMap].
1334        ///
1335        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1336        #[unsafe(method(setChannelMap:))]
1337        #[unsafe(method_family = none)]
1338        pub unsafe fn setChannelMap(&self, channel_map: Option<&NSArray<NSNumber>>);
1339
1340        #[cfg(feature = "objc2-core-midi")]
1341        /// Given a MIDI cable and channel number, return the supported MIDI-CI Profiles.
1342        ///
1343        /// Parameter `cable`: The virtual MIDI cable for which the profiles are requested.
1344        ///
1345        /// Parameter `channel`: The MIDI channel for which the profiles are requested.
1346        ///
1347        /// Returns: A MIDICIProfileState object containing all the supported MIDI-CI profiles for this channel
1348        /// on this cable.
1349        #[unsafe(method(profileStateForCable:channel:))]
1350        #[unsafe(method_family = none)]
1351        pub unsafe fn profileStateForCable_channel(
1352            &self,
1353            cable: u8,
1354            channel: MIDIChannelNumber,
1355        ) -> Retained<MIDICIProfileState>;
1356
1357        #[cfg(feature = "objc2-core-midi")]
1358        /// Enable a MIDI-CI Profile on the specified cable/channel.
1359        ///
1360        /// Parameter `profile`: The MIDI-CI profile to be enabled.
1361        ///
1362        /// Parameter `cable`: The virtual MIDI cable.
1363        ///
1364        /// Parameter `channel`: The MIDI channel.
1365        ///
1366        /// Parameter `outError`: Returned in the event of failure.
1367        ///
1368        /// Returns: YES for success. NO in the event of a failure, in which case the error is returned
1369        /// in outError.
1370        #[unsafe(method(enableProfile:cable:onChannel:error:_))]
1371        #[unsafe(method_family = none)]
1372        pub unsafe fn enableProfile_cable_onChannel_error(
1373            &self,
1374            profile: &MIDICIProfile,
1375            cable: u8,
1376            channel: MIDIChannelNumber,
1377        ) -> Result<(), Retained<NSError>>;
1378
1379        #[cfg(feature = "objc2-core-midi")]
1380        /// Disable a MIDI-CI Profile on the specified cable/channel.
1381        ///
1382        /// Parameter `profile`: The MIDI-CI profile to be disabled.
1383        ///
1384        /// Parameter `cable`: The virtual MIDI cable.
1385        ///
1386        /// Parameter `channel`: The MIDI channel.
1387        ///
1388        /// Parameter `outError`: Returned in the event of failure.
1389        ///
1390        /// Returns: YES for success. NO in the event of a failure, in which case the error is returned
1391        /// in outError.
1392        #[unsafe(method(disableProfile:cable:onChannel:error:_))]
1393        #[unsafe(method_family = none)]
1394        pub unsafe fn disableProfile_cable_onChannel_error(
1395            &self,
1396            profile: &MIDICIProfile,
1397            cable: u8,
1398            channel: MIDIChannelNumber,
1399        ) -> Result<(), Retained<NSError>>;
1400
1401        #[cfg(all(feature = "block2", feature = "objc2-core-midi"))]
1402        /// A block called when a device notifies that a MIDI-CI profile has been enabled or
1403        /// disabled.
1404        ///
1405        /// Since enabling / disabling MIDI-CI profiles is an asynchronous operation, the host can set
1406        /// this block and the audio unit is expected to call it every time the state of a MIDI-CI
1407        /// profile has changed.
1408        ///
1409        /// # Safety
1410        ///
1411        /// The returned block's argument 3 must be a valid pointer.
1412        #[unsafe(method(profileChangedBlock))]
1413        #[unsafe(method_family = none)]
1414        pub unsafe fn profileChangedBlock(&self) -> AUMIDICIProfileChangedBlock;
1415
1416        #[cfg(all(feature = "block2", feature = "objc2-core-midi"))]
1417        /// Setter for [`profileChangedBlock`][Self::profileChangedBlock].
1418        ///
1419        /// # Safety
1420        ///
1421        /// `profile_changed_block` must be a valid pointer or null.
1422        #[unsafe(method(setProfileChangedBlock:))]
1423        #[unsafe(method_family = none)]
1424        pub unsafe fn setProfileChangedBlock(
1425            &self,
1426            profile_changed_block: AUMIDICIProfileChangedBlock,
1427        );
1428
1429        /// Returns an object for bidirectional communication between an Audio Unit and its host.
1430        ///
1431        /// Message channels provide a flexible way for custom data exchange between an Audio Unit and its host.
1432        /// An Audio Unit can support multiple message channels which are identified by the `channelName`.
1433        /// The message channel object's lifetime is managed by the host. Message channel objects should be designed
1434        /// in such a way that they could outlive the AU that vended them.
1435        /// For further details see discussion for `AUMessageChannel`.
1436        ///
1437        /// Parameter `channelName`: The name of the message channel to be returned by the Audio Unit if supported.
1438        ///
1439        /// Returns: An object that conforms to the `AUMessageChannel` protocol.
1440        #[unsafe(method(messageChannelFor:))]
1441        #[unsafe(method_family = none)]
1442        pub unsafe fn messageChannelFor(
1443            &self,
1444            channel_name: &NSString,
1445        ) -> Retained<ProtocolObject<dyn AUMessageChannel>>;
1446    );
1447}
1448
1449/// Methods declared on superclass `NSObject`.
1450impl AUAudioUnit {
1451    extern_methods!(
1452        #[unsafe(method(new))]
1453        #[unsafe(method_family = new)]
1454        pub unsafe fn new() -> Retained<Self>;
1455    );
1456}
1457
1458/// Block to notify the client of an I/O unit that input is available.
1459///
1460/// Parameter `actionFlags`: Pointer to action flags.
1461///
1462/// Parameter `timestamp`: The HAL time at which the input data was captured. If there is a sample rate conversion
1463/// or time compression/expansion downstream, the sample time will not be valid.
1464///
1465/// Parameter `frameCount`: The number of sample frames of input available.
1466///
1467/// Parameter `inputBusNumber`: The index of the input bus from which input is available.
1468///
1469/// The input data is obtained by calling the render block of the audio unit.
1470/// The AUAudioUnit is not provided since it is not safe to message an Objective C
1471/// object in a real time context.
1472///
1473/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auinputhandler?language=objc)
1474#[cfg(all(
1475    feature = "AUComponent",
1476    feature = "block2",
1477    feature = "objc2-core-audio-types"
1478))]
1479pub type AUInputHandler = *mut block2::DynBlock<
1480    dyn Fn(
1481        NonNull<AudioUnitRenderActionFlags>,
1482        NonNull<AudioTimeStamp>,
1483        AUAudioFrameCount,
1484        NSInteger,
1485    ),
1486>;
1487
1488/// AUAudioInputOutputUnit.
1489///
1490/// Additional methods for audio units which can do input/output.
1491///
1492/// These methods will fail if the audio unit is not an input/output audio unit.
1493impl AUAudioUnit {
1494    extern_methods!(
1495        /// Whether the I/O device can perform input.
1496        #[unsafe(method(canPerformInput))]
1497        #[unsafe(method_family = none)]
1498        pub unsafe fn canPerformInput(&self) -> bool;
1499
1500        /// Whether the I/O device can perform output.
1501        #[unsafe(method(canPerformOutput))]
1502        #[unsafe(method_family = none)]
1503        pub unsafe fn canPerformOutput(&self) -> bool;
1504
1505        /// Flag enabling audio input from the unit.
1506        ///
1507        /// Input is disabled by default. This must be set to YES if input audio is desired.
1508        /// Setting to YES will have no effect if canPerformInput is false.
1509        #[unsafe(method(isInputEnabled))]
1510        #[unsafe(method_family = none)]
1511        pub unsafe fn isInputEnabled(&self) -> bool;
1512
1513        /// Setter for [`isInputEnabled`][Self::isInputEnabled].
1514        #[unsafe(method(setInputEnabled:))]
1515        #[unsafe(method_family = none)]
1516        pub unsafe fn setInputEnabled(&self, input_enabled: bool);
1517
1518        /// Flag enabling audio output from the unit.
1519        ///
1520        /// Output is enabled by default.
1521        /// Setting to YES will have no effect if canPerformOutput is false.
1522        #[unsafe(method(isOutputEnabled))]
1523        #[unsafe(method_family = none)]
1524        pub unsafe fn isOutputEnabled(&self) -> bool;
1525
1526        /// Setter for [`isOutputEnabled`][Self::isOutputEnabled].
1527        #[unsafe(method(setOutputEnabled:))]
1528        #[unsafe(method_family = none)]
1529        pub unsafe fn setOutputEnabled(&self, output_enabled: bool);
1530
1531        #[cfg(all(
1532            feature = "AUComponent",
1533            feature = "block2",
1534            feature = "objc2-core-audio-types"
1535        ))]
1536        /// The block that the output unit will call to get audio to send to the output.
1537        ///
1538        /// This block must be set if output is enabled.
1539        ///
1540        /// # Safety
1541        ///
1542        /// - The returned block's argument 1 must be a valid pointer.
1543        /// - The returned block's argument 2 must be a valid pointer.
1544        /// - The returned block's argument 5 must be a valid pointer.
1545        #[unsafe(method(outputProvider))]
1546        #[unsafe(method_family = none)]
1547        pub unsafe fn outputProvider(&self) -> AURenderPullInputBlock;
1548
1549        #[cfg(all(
1550            feature = "AUComponent",
1551            feature = "block2",
1552            feature = "objc2-core-audio-types"
1553        ))]
1554        /// Setter for [`outputProvider`][Self::outputProvider].
1555        ///
1556        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1557        ///
1558        /// # Safety
1559        ///
1560        /// `output_provider` must be a valid pointer or null.
1561        #[unsafe(method(setOutputProvider:))]
1562        #[unsafe(method_family = none)]
1563        pub unsafe fn setOutputProvider(&self, output_provider: AURenderPullInputBlock);
1564
1565        #[cfg(all(
1566            feature = "AUComponent",
1567            feature = "block2",
1568            feature = "objc2-core-audio-types"
1569        ))]
1570        /// The block that the output unit will call to notify when input is available.
1571        ///
1572        /// See discussion for AUInputHandler.
1573        ///
1574        /// # Safety
1575        ///
1576        /// - The returned block's argument 1 must be a valid pointer.
1577        /// - The returned block's argument 2 must be a valid pointer.
1578        #[unsafe(method(inputHandler))]
1579        #[unsafe(method_family = none)]
1580        pub unsafe fn inputHandler(&self) -> AUInputHandler;
1581
1582        #[cfg(all(
1583            feature = "AUComponent",
1584            feature = "block2",
1585            feature = "objc2-core-audio-types"
1586        ))]
1587        /// Setter for [`inputHandler`][Self::inputHandler].
1588        ///
1589        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1590        ///
1591        /// # Safety
1592        ///
1593        /// `input_handler` must be a valid pointer or null.
1594        #[unsafe(method(setInputHandler:))]
1595        #[unsafe(method_family = none)]
1596        pub unsafe fn setInputHandler(&self, input_handler: AUInputHandler);
1597
1598        /// Get the I/O hardware device.
1599        #[unsafe(method(deviceID))]
1600        #[unsafe(method_family = none)]
1601        pub unsafe fn deviceID(&self) -> AUAudioObjectID;
1602
1603        /// Set the I/O hardware device.
1604        ///
1605        /// Parameter `deviceID`: The device to select.
1606        ///
1607        /// Parameter `outError`: Returned in the event of failure.
1608        #[unsafe(method(setDeviceID:error:_))]
1609        #[unsafe(method_family = none)]
1610        pub unsafe fn setDeviceID_error(
1611            &self,
1612            device_id: AUAudioObjectID,
1613        ) -> Result<(), Retained<NSError>>;
1614
1615        /// The audio device's input latency, in seconds.
1616        ///
1617        /// Bridged to the HAL property kAudioDevicePropertyLatency, which is implemented
1618        /// by v2 input/output units.
1619        #[unsafe(method(deviceInputLatency))]
1620        #[unsafe(method_family = none)]
1621        pub unsafe fn deviceInputLatency(&self) -> NSTimeInterval;
1622
1623        /// The audio device's output latency, in seconds.
1624        ///
1625        /// Bridged to the HAL property kAudioDevicePropertyLatency, which is implemented
1626        /// by v2 input/output units.
1627        #[unsafe(method(deviceOutputLatency))]
1628        #[unsafe(method_family = none)]
1629        pub unsafe fn deviceOutputLatency(&self) -> NSTimeInterval;
1630
1631        /// The audio device's running state.
1632        #[unsafe(method(isRunning))]
1633        #[unsafe(method_family = none)]
1634        pub unsafe fn isRunning(&self) -> bool;
1635
1636        /// Starts the audio hardware.
1637        ///
1638        /// Parameter `outError`: Returned in the event of failure.
1639        #[unsafe(method(startHardwareAndReturnError:_))]
1640        #[unsafe(method_family = none)]
1641        pub unsafe fn startHardwareAndReturnError(&self) -> Result<(), Retained<NSError>>;
1642
1643        /// Stops the audio hardware.
1644        #[unsafe(method(stopHardware))]
1645        #[unsafe(method_family = none)]
1646        pub unsafe fn stopHardware(&self);
1647    );
1648}
1649
1650extern_class!(
1651    /// Container for an audio unit's input or output busses.
1652    ///
1653    /// Hosts can observe a bus property across all busses by using KVO on this object, without
1654    /// having to observe it on each individual bus. (One could add listeners to individual busses,
1655    /// but that means one has to observe bus count changes and add/remove listeners in response.
1656    /// Also, NSArray's addObserver:toObjectsAtIndexes:forKeyPath:options:context: is problematic;
1657    /// it does not let the individual objects override the observation request, and so a bus which
1658    /// is proxying a bus in an extension process does not get the message.)
1659    ///
1660    /// Some audio units (e.g. mixers) support variable numbers of busses, via subclassing. When the
1661    /// bus count changes, a KVO notification is sent on "inputBusses" or "outputBusses," as
1662    /// appropriate.
1663    ///
1664    /// Subclassers should see also the AUAudioUnitBusImplementation category.
1665    ///
1666    /// The bus array is bridged to the v2 property kAudioUnitProperty_ElementCount.
1667    ///
1668    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitbusarray?language=objc)
1669    #[unsafe(super(NSObject))]
1670    #[derive(Debug, PartialEq, Eq, Hash)]
1671    pub struct AUAudioUnitBusArray;
1672);
1673
1674extern_conformance!(
1675    unsafe impl NSFastEnumeration for AUAudioUnitBusArray {}
1676);
1677
1678extern_conformance!(
1679    unsafe impl NSObjectProtocol for AUAudioUnitBusArray {}
1680);
1681
1682impl AUAudioUnitBusArray {
1683    extern_methods!(
1684        #[unsafe(method(init))]
1685        #[unsafe(method_family = init)]
1686        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1687
1688        /// Initializes by making a copy of the supplied bus array.
1689        #[unsafe(method(initWithAudioUnit:busType:busses:))]
1690        #[unsafe(method_family = init)]
1691        pub unsafe fn initWithAudioUnit_busType_busses(
1692            this: Allocated<Self>,
1693            owner: &AUAudioUnit,
1694            bus_type: AUAudioUnitBusType,
1695            bus_array: &NSArray<AUAudioUnitBus>,
1696        ) -> Retained<Self>;
1697
1698        /// Initializes an empty bus array.
1699        #[unsafe(method(initWithAudioUnit:busType:))]
1700        #[unsafe(method_family = init)]
1701        pub unsafe fn initWithAudioUnit_busType(
1702            this: Allocated<Self>,
1703            owner: &AUAudioUnit,
1704            bus_type: AUAudioUnitBusType,
1705        ) -> Retained<Self>;
1706
1707        #[unsafe(method(count))]
1708        #[unsafe(method_family = none)]
1709        pub unsafe fn count(&self) -> NSUInteger;
1710
1711        #[unsafe(method(objectAtIndexedSubscript:))]
1712        #[unsafe(method_family = none)]
1713        pub unsafe fn objectAtIndexedSubscript(
1714            &self,
1715            index: NSUInteger,
1716        ) -> Retained<AUAudioUnitBus>;
1717
1718        /// Whether the array can have a variable number of busses.
1719        ///
1720        /// The base implementation returns false.
1721        #[unsafe(method(isCountChangeable))]
1722        #[unsafe(method_family = none)]
1723        pub unsafe fn isCountChangeable(&self) -> bool;
1724
1725        /// Change the number of busses in the array.
1726        #[unsafe(method(setBusCount:error:_))]
1727        #[unsafe(method_family = none)]
1728        pub unsafe fn setBusCount_error(&self, count: NSUInteger) -> Result<(), Retained<NSError>>;
1729
1730        /// Add a KVO observer for a property on all busses in the array.
1731        ///
1732        /// # Safety
1733        ///
1734        /// - `observer` should be of the correct type.
1735        /// - `context` must be a valid pointer or null.
1736        #[unsafe(method(addObserverToAllBusses:forKeyPath:options:context:))]
1737        #[unsafe(method_family = none)]
1738        pub unsafe fn addObserverToAllBusses_forKeyPath_options_context(
1739            &self,
1740            observer: &NSObject,
1741            key_path: &NSString,
1742            options: NSKeyValueObservingOptions,
1743            context: *mut c_void,
1744        );
1745
1746        /// Remove a KVO observer for a property on all busses in the array.
1747        ///
1748        /// # Safety
1749        ///
1750        /// - `observer` should be of the correct type.
1751        /// - `context` must be a valid pointer or null.
1752        #[unsafe(method(removeObserverFromAllBusses:forKeyPath:context:))]
1753        #[unsafe(method_family = none)]
1754        pub unsafe fn removeObserverFromAllBusses_forKeyPath_context(
1755            &self,
1756            observer: &NSObject,
1757            key_path: &NSString,
1758            context: *mut c_void,
1759        );
1760
1761        /// The audio unit that owns the bus.
1762        ///
1763        /// # Safety
1764        ///
1765        /// This is not retained internally, you must ensure the object is still alive.
1766        #[unsafe(method(ownerAudioUnit))]
1767        #[unsafe(method_family = none)]
1768        pub unsafe fn ownerAudioUnit(&self) -> Retained<AUAudioUnit>;
1769
1770        /// Which bus array this is (input or output).
1771        #[unsafe(method(busType))]
1772        #[unsafe(method_family = none)]
1773        pub unsafe fn busType(&self) -> AUAudioUnitBusType;
1774    );
1775}
1776
1777/// Methods declared on superclass `NSObject`.
1778impl AUAudioUnitBusArray {
1779    extern_methods!(
1780        #[unsafe(method(new))]
1781        #[unsafe(method_family = new)]
1782        pub unsafe fn new() -> Retained<Self>;
1783    );
1784}
1785
1786extern_class!(
1787    /// An input or output connection point on an audio unit.
1788    ///
1789    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitbus?language=objc)
1790    #[unsafe(super(NSObject))]
1791    #[derive(Debug, PartialEq, Eq, Hash)]
1792    pub struct AUAudioUnitBus;
1793);
1794
1795extern_conformance!(
1796    unsafe impl NSObjectProtocol for AUAudioUnitBus {}
1797);
1798
1799impl AUAudioUnitBus {
1800    extern_methods!(
1801        /// Controls the audio unit's allocation strategy for a bus.
1802        ///
1803        /// Hosts can set this flag to communicate whether an audio unit should allocate its own buffer.
1804        /// By default this flag is set to true.
1805        ///
1806        /// On the output side, shouldAllocateBuffer=false means the AU can assume that it will be
1807        /// called with non-null output buffers. If shouldAllocateBuffer=true (the default), the AU must
1808        /// be prepared to be called with null pointers and replace them with pointers to its internally
1809        /// allocated buffer.
1810        ///
1811        /// On the input side, shouldAllocateBuffer=false means the AU can pull for input using a buffer
1812        /// list with null buffer pointers, and assume that the pull input block will provide pointers.
1813        /// If shouldAllocateBuffer=true (the default), the AU must pull with non-null pointers while
1814        /// still being prepared for the source to replace them with pointers of its own.
1815        ///
1816        /// Bridged to the v2 property kAudioUnitProperty_ShouldAllocateBuffer.
1817        #[unsafe(method(shouldAllocateBuffer))]
1818        #[unsafe(method_family = none)]
1819        pub unsafe fn shouldAllocateBuffer(&self) -> bool;
1820
1821        /// Setter for [`shouldAllocateBuffer`][Self::shouldAllocateBuffer].
1822        #[unsafe(method(setShouldAllocateBuffer:))]
1823        #[unsafe(method_family = none)]
1824        pub unsafe fn setShouldAllocateBuffer(&self, should_allocate_buffer: bool);
1825
1826        /// Whether the bus is active.
1827        ///
1828        /// Hosts must enable input busses before using them. The reason for this is to allow a unit
1829        /// such as a mixer to be prepared to render a large number of inputs, but avoid the work
1830        /// of preparing to pull inputs which are not in use.
1831        ///
1832        /// Bridged to the v2 properties kAudioUnitProperty_MakeConnection and
1833        /// kAudioUnitProperty_SetRenderCallback.
1834        #[unsafe(method(isEnabled))]
1835        #[unsafe(method_family = none)]
1836        pub unsafe fn isEnabled(&self) -> bool;
1837
1838        /// Setter for [`isEnabled`][Self::isEnabled].
1839        #[unsafe(method(setEnabled:))]
1840        #[unsafe(method_family = none)]
1841        pub unsafe fn setEnabled(&self, enabled: bool);
1842
1843        /// A name for the bus. Can be set by host.
1844        #[unsafe(method(name))]
1845        #[unsafe(method_family = none)]
1846        pub unsafe fn name(&self) -> Option<Retained<NSString>>;
1847
1848        /// Setter for [`name`][Self::name].
1849        ///
1850        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1851        #[unsafe(method(setName:))]
1852        #[unsafe(method_family = none)]
1853        pub unsafe fn setName(&self, name: Option<&NSString>);
1854
1855        /// The index of this bus in the containing array.
1856        #[unsafe(method(index))]
1857        #[unsafe(method_family = none)]
1858        pub unsafe fn index(&self) -> NSUInteger;
1859
1860        /// The AUAudioUnitBusType.
1861        #[unsafe(method(busType))]
1862        #[unsafe(method_family = none)]
1863        pub unsafe fn busType(&self) -> AUAudioUnitBusType;
1864
1865        /// The audio unit that owns the bus.
1866        ///
1867        /// # Safety
1868        ///
1869        /// This is not retained internally, you must ensure the object is still alive.
1870        #[unsafe(method(ownerAudioUnit))]
1871        #[unsafe(method_family = none)]
1872        pub unsafe fn ownerAudioUnit(&self) -> Retained<AUAudioUnit>;
1873
1874        /// This is an array of NSNumbers representing AudioChannelLayoutTag.
1875        #[unsafe(method(supportedChannelLayoutTags))]
1876        #[unsafe(method_family = none)]
1877        pub unsafe fn supportedChannelLayoutTags(&self) -> Option<Retained<NSArray<NSNumber>>>;
1878
1879        /// Information about latency in the audio unit's processing context.
1880        ///
1881        /// This should not be confused with the audio unit's latency property, where the audio unit
1882        /// describes to the host any processing latency it introduces between its input and its output.
1883        ///
1884        /// A host may set this property to describe to the audio unit the presentation latency of its
1885        /// input and/or output audio data. Latency is described in seconds. A value of zero means
1886        /// either no latency or an unknown latency.
1887        ///
1888        /// A host should set this property on each active bus, since, for example, the audio routing
1889        /// path to each of multiple output busses may differ.
1890        ///
1891        /// For input busses:
1892        /// Describes how long ago the audio arriving on this bus was acquired. For instance, when
1893        /// reading from a file to the first audio unit in a chain, the input presentation latency
1894        /// is zero. For audio input from a device, this initial input latency is the presentation
1895        /// latency of the device itself, i.e. the device's safety offset and latency.
1896        ///
1897        /// A second chained audio unit's input presentation latency will be the input presentation
1898        /// latency of the first unit, plus the processing latency of the first unit.
1899        ///
1900        /// For output busses:
1901        /// Describes how long it will be before the output audio of an audio unit is presented. For
1902        /// instance, when writing to a file, the output presentation latency of the last audio unit
1903        /// in a chain is zero. When the audio from that audio unit is to be played to a device,
1904        /// then that initial presentation latency will be the presentation latency of the device
1905        /// itself, which is the I/O buffer size, plus the device's safety offset and latency
1906        ///
1907        /// A previous chained audio unit's output presentation latency is the last unit's
1908        /// presentation latency plus its processing latency.
1909        ///
1910        /// So, for a given audio unit anywhere within a mixing graph, the input and output presentation
1911        /// latencies describe to that unit how long from the moment of generation it has taken for its
1912        /// input to arrive, and how long it will take for its output to be presented.
1913        ///
1914        /// Bridged to the v2 property kAudioUnitProperty_PresentationLatency.
1915        #[unsafe(method(contextPresentationLatency))]
1916        #[unsafe(method_family = none)]
1917        pub unsafe fn contextPresentationLatency(&self) -> NSTimeInterval;
1918
1919        /// Setter for [`contextPresentationLatency`][Self::contextPresentationLatency].
1920        #[unsafe(method(setContextPresentationLatency:))]
1921        #[unsafe(method_family = none)]
1922        pub unsafe fn setContextPresentationLatency(
1923            &self,
1924            context_presentation_latency: NSTimeInterval,
1925        );
1926    );
1927}
1928
1929/// Methods declared on superclass `NSObject`.
1930impl AUAudioUnitBus {
1931    extern_methods!(
1932        #[unsafe(method(init))]
1933        #[unsafe(method_family = init)]
1934        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1935
1936        #[unsafe(method(new))]
1937        #[unsafe(method_family = new)]
1938        pub unsafe fn new() -> Retained<Self>;
1939    );
1940}
1941
1942extern_class!(
1943    /// A collection of parameter settings provided by the audio unit implementor, producing a
1944    /// useful sound or starting point.
1945    ///
1946    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitpreset?language=objc)
1947    #[unsafe(super(NSObject))]
1948    #[derive(Debug, PartialEq, Eq, Hash)]
1949    pub struct AUAudioUnitPreset;
1950);
1951
1952extern_conformance!(
1953    unsafe impl NSCoding for AUAudioUnitPreset {}
1954);
1955
1956extern_conformance!(
1957    unsafe impl NSObjectProtocol for AUAudioUnitPreset {}
1958);
1959
1960extern_conformance!(
1961    unsafe impl NSSecureCoding for AUAudioUnitPreset {}
1962);
1963
1964impl AUAudioUnitPreset {
1965    extern_methods!(
1966        /// The preset's unique numeric identifier.
1967        #[unsafe(method(number))]
1968        #[unsafe(method_family = none)]
1969        pub unsafe fn number(&self) -> NSInteger;
1970
1971        /// Setter for [`number`][Self::number].
1972        #[unsafe(method(setNumber:))]
1973        #[unsafe(method_family = none)]
1974        pub unsafe fn setNumber(&self, number: NSInteger);
1975
1976        /// The preset's name.
1977        #[unsafe(method(name))]
1978        #[unsafe(method_family = none)]
1979        pub unsafe fn name(&self) -> Retained<NSString>;
1980
1981        /// Setter for [`name`][Self::name].
1982        ///
1983        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
1984        #[unsafe(method(setName:))]
1985        #[unsafe(method_family = none)]
1986        pub unsafe fn setName(&self, name: &NSString);
1987    );
1988}
1989
1990/// Methods declared on superclass `NSObject`.
1991impl AUAudioUnitPreset {
1992    extern_methods!(
1993        #[unsafe(method(init))]
1994        #[unsafe(method_family = init)]
1995        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1996
1997        #[unsafe(method(new))]
1998        #[unsafe(method_family = new)]
1999        pub unsafe fn new() -> Retained<Self>;
2000    );
2001}
2002
2003/// Block that hosts provide to AU message channels to be called back by the AU.
2004///
2005/// Parameter `message`: An NSDictionary with custom data. The allowed classes for key and value types are
2006/// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
2007///
2008/// Returns: An NSDictionary with custom data. The allowed classes for key and value types are
2009/// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
2010///
2011/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/callhostblock?language=objc)
2012#[cfg(feature = "block2")]
2013pub type CallHostBlock =
2014    *mut block2::DynBlock<dyn Fn(NonNull<NSDictionary>) -> NonNull<NSDictionary>>;
2015
2016extern_protocol!(
2017    /// The protocol which objects returned from `[AUAudioUnit messageChannelFor:]` have to conform to.
2018    ///
2019    /// Audio Units and hosts that have special needs of communication, e.g. to exchange musical context required for better audio processing,
2020    /// can implement a communication object to exchange messages in form of NSDictionaries. An Audio Unit would need to implement
2021    /// a class conforming to the AUMessageChannel protocol and return an instance via `[AUAudioUnit messageChannelFor:]`. A host can query
2022    /// the instance via the channel name.
2023    /// The protocol offers a method to send messages to the AU and a block to send messages to the host.
2024    ///
2025    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aumessagechannel?language=objc)
2026    pub unsafe trait AUMessageChannel {
2027        /// Calls the Audio Unit with custom data message.
2028        ///
2029        /// Parameter `message`: An NSDictionary with custom data. The allowed classes for key and value types are
2030        /// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
2031        ///
2032        /// Returns: An NSDictionary with custom data. The allowed classes for key and value types are
2033        /// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
2034        ///
2035        /// # Safety
2036        ///
2037        /// `message` generic should be of the correct type.
2038        #[optional]
2039        #[unsafe(method(callAudioUnit:))]
2040        #[unsafe(method_family = none)]
2041        unsafe fn callAudioUnit(&self, message: &NSDictionary) -> Retained<NSDictionary>;
2042
2043        #[cfg(feature = "block2")]
2044        /// A callback for the AU to send a message to the host.
2045        ///
2046        /// The host has to set a block on this property.
2047        ///
2048        /// # Safety
2049        ///
2050        /// The returned block's argument must be a valid pointer.
2051        #[optional]
2052        #[unsafe(method(callHostBlock))]
2053        #[unsafe(method_family = none)]
2054        unsafe fn callHostBlock(&self) -> CallHostBlock;
2055
2056        #[cfg(feature = "block2")]
2057        /// Setter for [`callHostBlock`][Self::callHostBlock].
2058        ///
2059        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
2060        ///
2061        /// # Safety
2062        ///
2063        /// `call_host_block` must be a valid pointer or null.
2064        #[optional]
2065        #[unsafe(method(setCallHostBlock:))]
2066        #[unsafe(method_family = none)]
2067        unsafe fn setCallHostBlock(&self, call_host_block: CallHostBlock);
2068    }
2069);
2070
2071/// IntendedSpatialExperience.
2072impl AUAudioUnit {
2073    extern_methods!();
2074}