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 #[unsafe(method(renderBlock))]
564 #[unsafe(method_family = none)]
565 pub unsafe fn renderBlock(&self) -> AURenderBlock;
566
567 #[cfg(all(
568 feature = "AUParameters",
569 feature = "AudioUnitProperties",
570 feature = "block2"
571 ))]
572 /// Block which hosts use to schedule parameters.
573 ///
574 /// As with renderBlock, a host should fetch and cache this block before calling
575 /// allocateRenderResources, if it intends to schedule parameters.
576 ///
577 /// The block is safe to call from any thread context, including realtime audio render
578 /// threads.
579 ///
580 /// Subclassers should not override this; it is implemented in the base class and will schedule
581 /// the events to be provided to the internalRenderBlock.
582 ///
583 /// Bridged to the v2 API AudioUnitScheduleParameters().
584 #[unsafe(method(scheduleParameterBlock))]
585 #[unsafe(method_family = none)]
586 pub unsafe fn scheduleParameterBlock(&self) -> AUScheduleParameterBlock;
587
588 #[cfg(all(
589 feature = "AUComponent",
590 feature = "block2",
591 feature = "objc2-core-audio-types"
592 ))]
593 /// Add a block to be called on each render cycle.
594 ///
595 /// The supplied block is called at the beginning and ending of each render cycle. It should
596 /// not make any blocking calls.
597 ///
598 /// This method is implemented in the base class AUAudioUnit, and should not be overridden.
599 ///
600 /// Bridged to the v2 API AudioUnitAddRenderNotify().
601 ///
602 /// Parameter `observer`: The block to call.
603 ///
604 /// Returns: A token to be used when removing the observer.
605 #[unsafe(method(tokenByAddingRenderObserver:))]
606 #[unsafe(method_family = none)]
607 pub unsafe fn tokenByAddingRenderObserver(&self, observer: AURenderObserver) -> NSInteger;
608
609 /// Remove an observer block added via tokenByAddingRenderObserver:
610 ///
611 /// Parameter `token`: The token previously returned by tokenByAddingRenderObserver:
612 ///
613 /// Bridged to the v2 API AudioUnitRemoveRenderNotify().
614 #[unsafe(method(removeRenderObserver:))]
615 #[unsafe(method_family = none)]
616 pub unsafe fn removeRenderObserver(&self, token: NSInteger);
617
618 /// The maximum number of frames which the audio unit can render at once.
619 ///
620 /// This must be set by the host before render resources are allocated. It cannot be changed
621 /// while render resources are allocated.
622 ///
623 /// Bridged to the v2 property kAudioUnitProperty_MaximumFramesPerSlice.
624 #[unsafe(method(maximumFramesToRender))]
625 #[unsafe(method_family = none)]
626 pub unsafe fn maximumFramesToRender(&self) -> AUAudioFrameCount;
627
628 /// Setter for [`maximumFramesToRender`][Self::maximumFramesToRender].
629 #[unsafe(method(setMaximumFramesToRender:))]
630 #[unsafe(method_family = none)]
631 pub unsafe fn setMaximumFramesToRender(&self, maximum_frames_to_render: AUAudioFrameCount);
632
633 #[cfg(feature = "AUParameters")]
634 /// An audio unit's parameters, organized in a hierarchy.
635 ///
636 /// Returns: A parameter tree object, or nil if the unit has no parameters.
637 ///
638 /// Audio unit hosts can fetch this property to discover a unit's parameters. KVO notifications
639 /// are issued on this member to notify the host of changes to the set of available parameters.
640 ///
641 /// AUAudioUnit has an additional pseudo-property, "allParameterValues", on which KVO
642 /// notifications are issued in response to certain events where potentially all parameter
643 /// values are invalidated. This includes changes to currentPreset, fullState, and
644 /// fullStateForDocument.
645 ///
646 /// Hosts should not attempt to set this property.
647 ///
648 /// Subclassers should implement the parameterTree getter to expose parameters to hosts. They
649 /// should cache as much as possible and send KVO notifications on "parameterTree" when altering
650 /// the structure of the tree or the static information (ranges, etc) of parameters.
651 ///
652 /// This is similar to the v2 properties kAudioUnitProperty_ParameterList and
653 /// kAudioUnitProperty_ParameterInfo.
654 ///
655 /// Note that it is not safe to modify this property in a real-time context.
656 #[unsafe(method(parameterTree))]
657 #[unsafe(method_family = none)]
658 pub unsafe fn parameterTree(&self) -> Option<Retained<AUParameterTree>>;
659
660 #[cfg(feature = "AUParameters")]
661 /// Setter for [`parameterTree`][Self::parameterTree].
662 #[unsafe(method(setParameterTree:))]
663 #[unsafe(method_family = none)]
664 pub unsafe fn setParameterTree(&self, parameter_tree: Option<&AUParameterTree>);
665
666 /// Returns the audio unit's `count` most important parameters.
667 ///
668 /// This property allows a host to query an audio unit for some small number of parameters which
669 /// are its "most important", to be displayed in a compact generic view.
670 ///
671 /// An audio unit subclass should return an array of NSNumbers representing the addresses
672 /// of the `count` most important parameters.
673 ///
674 /// The base class returns an empty array regardless of count.
675 ///
676 /// Partially bridged to kAudioUnitProperty_ParametersForOverview (v2 hosts can use that
677 /// property to access this v3 method of an audio unit).
678 #[unsafe(method(parametersForOverviewWithCount:))]
679 #[unsafe(method_family = none)]
680 pub unsafe fn parametersForOverviewWithCount(
681 &self,
682 count: NSInteger,
683 ) -> Retained<NSArray<NSNumber>>;
684
685 #[unsafe(method(allParameterValues))]
686 #[unsafe(method_family = none)]
687 pub unsafe fn allParameterValues(&self) -> bool;
688
689 /// Specifies whether an audio unit responds to MIDI events.
690 ///
691 /// This is implemented in the base class and returns YES if the component type is music
692 /// device or music effect.
693 #[unsafe(method(isMusicDeviceOrEffect))]
694 #[unsafe(method_family = none)]
695 pub unsafe fn isMusicDeviceOrEffect(&self) -> bool;
696
697 /// The number of virtual MIDI cables implemented by a music device or effect.
698 ///
699 /// A music device or MIDI effect can support up to 256 virtual MIDI cables of input; this
700 /// property expresses the number of cables supported by the audio unit.
701 #[unsafe(method(virtualMIDICableCount))]
702 #[unsafe(method_family = none)]
703 pub unsafe fn virtualMIDICableCount(&self) -> NSInteger;
704
705 #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
706 /// Block used to schedule MIDI events.
707 ///
708 /// As with renderBlock, a host should fetch and cache this block before calling
709 /// allocateRenderResources if it intends to schedule MIDI events.
710 ///
711 /// This is implemented in the base class. It is nil when musicDeviceOrEffect is NO.
712 ///
713 /// Subclasses should not override. When hosts schedule events via this block, they are
714 /// sent to the Audio Unit via the list of AURenderEvents delivered to
715 /// internalRenderBlock.
716 ///
717 /// All events sent via this block will be delivered to the internalRenderBlock in the MIDI
718 /// protocol returned by the AudioUnitMIDIProtocol property. For example, if AudioUnitMIDIProtocol
719 /// returns kMIDIProtocol_2_0, incoming events will be translated to MIDI 2.0 if necessary.
720 /// If AudioUnitMIDIProtocol is not set, events will be delivered as legacy MIDI.
721 ///
722 /// This bridged to the v2 API MusicDeviceMIDIEvent.
723 #[unsafe(method(scheduleMIDIEventBlock))]
724 #[unsafe(method_family = none)]
725 pub unsafe fn scheduleMIDIEventBlock(&self) -> AUScheduleMIDIEventBlock;
726
727 /// Count, and names of, a plug-in's MIDI outputs.
728 ///
729 /// A plug-in may override this method to inform hosts about its MIDI outputs. The size of the
730 /// array is the number of outputs the Audio Unit supports. Each item in the array is the name
731 /// of the MIDI output at that index.
732 ///
733 /// This is bridged to the v2 API property kAudioUnitProperty_MIDIOutputCallbackInfo.
734 #[unsafe(method(MIDIOutputNames))]
735 #[unsafe(method_family = none)]
736 pub unsafe fn MIDIOutputNames(&self) -> Retained<NSArray<NSString>>;
737
738 /// Specifies whether an audio unit provides UI (normally in the form of a view controller).
739 ///
740 /// Implemented in the framework and should not be overridden by implementators. The
741 /// framework detects whether any subclass has implemented
742 /// `requestViewControllerWithCompletionHandler:` or is implemented by an AU extension whose
743 /// extension point identifier is `com.apple.AudioUnit-UI`. See also
744 /// `requestViewControllerWithCompletionHandler:` in
745 /// <CoreAudioKit
746 /// /AUViewController.h>
747 #[unsafe(method(providesUserInterface))]
748 #[unsafe(method_family = none)]
749 pub unsafe fn providesUserInterface(&self) -> bool;
750
751 #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
752 /// Block used by the host to access the MIDI output generated by an Audio Unit.
753 ///
754 /// The host can set this block and the plug-in can call it in its renderBlock to provide to the
755 /// host the MIDI data associated with the current render cycle.
756 ///
757 /// All events sent via this block will be delivered to the host in the MIDI protocol returned by
758 /// the hostMIDIProtocol property. For example, if hostMIDIProtocol is set to
759 /// kMIDIProtocol_2_0, incoming events will be translated to MIDI 2.0. If hostMIDIProtocol
760 /// is not set, events will be delivered as legacy MIDI.
761 ///
762 /// Note: AUMIDIEventListBlock should be preferred over this block going forward.
763 ///
764 /// This is bridged to the v2 API property kAudioUnitProperty_MIDIOutputCallback.
765 #[unsafe(method(MIDIOutputEventBlock))]
766 #[unsafe(method_family = none)]
767 pub unsafe fn MIDIOutputEventBlock(&self) -> AUMIDIOutputEventBlock;
768
769 #[cfg(all(feature = "AudioUnitProperties", feature = "block2"))]
770 /// Setter for [`MIDIOutputEventBlock`][Self::MIDIOutputEventBlock].
771 #[unsafe(method(setMIDIOutputEventBlock:))]
772 #[unsafe(method_family = none)]
773 pub unsafe fn setMIDIOutputEventBlock(
774 &self,
775 midi_output_event_block: AUMIDIOutputEventBlock,
776 );
777
778 #[cfg(feature = "objc2-core-midi")]
779 /// The MIDI protocol used by the Audio Unit for receiving MIDIEventList data.
780 ///
781 /// Subclassers should override to return the desired protocol in which the Audio Unit wants
782 /// to receive input MIDI data, otherwise the Audio Unit will default to receiving legacy MIDI.
783 ///
784 /// All translatable messages will be converted (if necessary) to this protocol prior to delivery
785 /// to the Audio Unit.
786 ///
787 /// This is bridged to the v2 API property kAudioUnitProperty_AudioUnitMIDIProtocol.
788 #[unsafe(method(AudioUnitMIDIProtocol))]
789 #[unsafe(method_family = none)]
790 pub unsafe fn AudioUnitMIDIProtocol(&self) -> MIDIProtocolID;
791
792 #[cfg(feature = "objc2-core-midi")]
793 /// The MIDI protocol to be used by the host for receiving MIDIEventList data.
794 ///
795 /// Hosts should set this property to the protocol they wish to receive MIDIEventList data
796 /// from the Audio Unit. This should be set prior to initialization, all translatable messages
797 /// will be converted (if necessary) to this property's protocol prior to delivery to the host.
798 ///
799 /// Host should setup in the following order:
800 /// - Set hostMIDIProtocol
801 /// - Set MIDIOutputEventListBlock
802 /// - Call allocateRenderResourcesAndReturnError
803 ///
804 /// This is bridged to the v2 API property kAudioUnitProperty_HostMIDIProtocol.
805 ///
806 /// Notes:
807 /// - If overriding this property, subclassers must call [super setHostMIDIProtocol:]
808 /// - hostMIDIProtocol should be set before attempting to query AudioUnitMIDIProtocol
809 /// or calling allocateRenderResourcesAndReturnError to allow Audio Units to
810 /// optionally match their input MIDI protocol to the desired host protocol and prevent
811 /// protocol conversion.
812 #[unsafe(method(hostMIDIProtocol))]
813 #[unsafe(method_family = none)]
814 pub unsafe fn hostMIDIProtocol(&self) -> MIDIProtocolID;
815
816 #[cfg(feature = "objc2-core-midi")]
817 /// Setter for [`hostMIDIProtocol`][Self::hostMIDIProtocol].
818 #[unsafe(method(setHostMIDIProtocol:))]
819 #[unsafe(method_family = none)]
820 pub unsafe fn setHostMIDIProtocol(&self, host_midi_protocol: MIDIProtocolID);
821
822 /// A persistable snapshot of the Audio Unit's properties and parameters, suitable for
823 /// saving as a user preset.
824 ///
825 /// Hosts may use this property to save and restore the state of an Audio Unit being used in a
826 /// user preset or document. The Audio Unit should not persist transitory properties such as
827 /// stream formats, but should save and restore all parameters and custom properties.
828 ///
829 /// The base class implementation of this property saves the values of all parameters
830 /// currently in the parameter tree. A subclass which dynamically produces multiple variants
831 /// of the parameter tree needs to be aware that the serialization method does a depth-first
832 /// preorder traversal of the tree.
833 ///
834 /// Bridged to the v2 property kAudioUnitProperty_ClassInfo.
835 #[unsafe(method(fullState))]
836 #[unsafe(method_family = none)]
837 pub unsafe fn fullState(&self) -> Option<Retained<NSDictionary<NSString, AnyObject>>>;
838
839 /// Setter for [`fullState`][Self::fullState].
840 #[unsafe(method(setFullState:))]
841 #[unsafe(method_family = none)]
842 pub unsafe fn setFullState(&self, full_state: Option<&NSDictionary<NSString, AnyObject>>);
843
844 /// A persistable snapshot of the audio unit's properties and parameters, suitable for
845 /// saving in a user's document.
846 ///
847 /// This property is distinct from fullState in that some state is suitable for saving in user
848 /// presets, while other state is not. For example, a synthesizer's master tuning setting could
849 /// be considered global state, inappropriate for storing in reusable presets, but desirable
850 /// for storing in a document for a specific live performance.
851 ///
852 /// Hosts saving documents should use this property. If the audio unit does not implement it,
853 /// the base class simply sets/gets fullState.
854 ///
855 /// Bridged to the v2 property kAudioUnitProperty_ClassInfoFromDocument.
856 #[unsafe(method(fullStateForDocument))]
857 #[unsafe(method_family = none)]
858 pub unsafe fn fullStateForDocument(
859 &self,
860 ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>;
861
862 /// Setter for [`fullStateForDocument`][Self::fullStateForDocument].
863 #[unsafe(method(setFullStateForDocument:))]
864 #[unsafe(method_family = none)]
865 pub unsafe fn setFullStateForDocument(
866 &self,
867 full_state_for_document: Option<&NSDictionary<NSString, AnyObject>>,
868 );
869
870 /// A collection of presets provided by the audio unit's developer.
871 ///
872 /// A preset provides users of an audio unit with an easily-selectable, fine-tuned set of
873 /// parameters provided by the developer. This property returns all of the available factory presets.
874 ///
875 /// Bridged to the v2 property kAudioUnitProperty_FactoryPresets.
876 #[unsafe(method(factoryPresets))]
877 #[unsafe(method_family = none)]
878 pub unsafe fn factoryPresets(&self) -> Option<Retained<NSArray<AUAudioUnitPreset>>>;
879
880 /// A collection of presets saved by the user
881 ///
882 /// In addition to factory presets, provided by the audio unit vendor, users have the ability to
883 /// save the values of the parameters of an audio unit into a user preset. These users presets
884 /// can be accessed using this property.
885 ///
886 /// The default implementation of this method will load the user presets from an internal
887 /// location that might not be directly accessible to the audio unit host application or to the
888 /// audio unit. Instead of accessing this path directly, the audio unit should rely on the
889 /// superclass implementation of this method to retrieve the presets.
890 ///
891 /// Audio Units are free to override this method to load their user presets via different means
892 /// (e.g. from their iCloud container).
893 #[unsafe(method(userPresets))]
894 #[unsafe(method_family = none)]
895 pub unsafe fn userPresets(&self) -> Retained<NSArray<AUAudioUnitPreset>>;
896
897 /// Persistently save the current state of the audio unit into a userPreset
898 ///
899 /// The new preset will be added to userPresets and will become selectable by assigning it
900 /// to the currentPreset property.
901 /// If a preset with the provided name already exists then it will be overwritten.
902 ///
903 /// For user presets, the preset number is required to be negative.
904 /// If a positive number is passed, the sign will be changed to negative.
905 /// If zero is passed, the number will be set to -1.
906 /// These changes will be reflected on the userPreset argument.
907 ///
908 /// The default implementation of this method will save the user preset to an internal
909 /// location.
910 ///
911 /// Audio Units are free to override this method to operate on a different location (e.g. their
912 /// iCloud container).
913 ///
914 /// Parameter `userPreset`: The preset under which the current state will be saved.
915 ///
916 /// Parameter `outError`: In the event of a failure, the method will return NO and outError will be set to an
917 /// NSError, describing the problem.
918 /// Some possible errors:
919 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
920 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_InvalidFilePath
921 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_MissingKey
922 ///
923 /// Returns: YES for success. NO in the event of a failure, in which case the error is returned in
924 /// outError.
925 #[unsafe(method(saveUserPreset:error:_))]
926 #[unsafe(method_family = none)]
927 pub unsafe fn saveUserPreset_error(
928 &self,
929 user_preset: &AUAudioUnitPreset,
930 ) -> Result<(), Retained<NSError>>;
931
932 /// Remove a user preset.
933 ///
934 /// The user preset will be removed from userPresets and will be permanently deleted.
935 ///
936 /// The default implementation of this method will delete the user preset from an internal
937 /// location.
938 ///
939 /// Audio Units are free to override this method to operate on a different location (e.g. their
940 /// iCloud container).
941 ///
942 /// Parameter `userPreset`: The preset to be deleted.
943 ///
944 /// Parameter `outError`: In the event of a failure, the method will return NO and outError will be set to an
945 /// NSError, describing the problem.
946 /// Some possible errors:
947 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
948 /// - domain: NSPOSIXErrorDomain code: ENOENT
949 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_InvalidFilePath
950 ///
951 /// Returns: YES for success. NO in the event of a failure, in which case the error is returned in
952 /// outError.
953 #[unsafe(method(deleteUserPreset:error:_))]
954 #[unsafe(method_family = none)]
955 pub unsafe fn deleteUserPreset_error(
956 &self,
957 user_preset: &AUAudioUnitPreset,
958 ) -> Result<(), Retained<NSError>>;
959
960 /// Retrieve the state stored in a user preset
961 ///
962 /// This method allows access to the contents of a preset without having to set that preset as
963 /// current. The returned dictionary is assignable to the audio unit's fullState and/or
964 /// fullStateForDocument properties.
965 ///
966 /// Audio units can override this method in order to vend user presets from a different location
967 /// (e.g. their iCloud container).
968 ///
969 /// In order to restore the state from a user preset, the audio unit should override the setter
970 /// for the currentPreset property and check the preset number to determine the type of preset.
971 /// If the preset number is >= 0 then the preset is a factory preset.
972 /// If the preset number is
973 /// <
974 /// 0 then it is a user preset.
975 ///
976 /// This method can then be called to retrieve the state stored in a user preset and the audio
977 /// unit can assign this to fullState or fullStateForDocument.
978 ///
979 ///
980 /// Parameter `userPreset`: The preset to be selected.
981 ///
982 /// Parameter `outError`: In the event of a failure, the method will return nil and outError will be set to an
983 /// NSError, describing the problem.
984 /// Some possible errors:
985 /// - domain: NSOSStatusErrorDomain code: kAudioUnitErr_NoConnection
986 /// - domain: NSPOSIXErrorDomain code: ENOENT
987 /// - domain: NSCocoaErrorDomain code: NSCoderReadCorruptError
988 ///
989 /// Returns: Returns nil if there was an error, otherwise returns a dictionary containing the full state
990 /// of the audio unit saved in the preset.
991 /// For details on the possible keys present in the full state dictionary, please see the
992 /// documentation for kAudioUnitProperty_ClassInfo.
993 /// The minimal set of keys and their type is:
994 /// : NSNumber,
995 /// : NSNumber,
996 /// : NSNumber,
997 /// : NSNumber,
998 /// : NSString,
999 /// : NSNumber,
1000 /// : NSData
1001 #[unsafe(method(presetStateFor:error:_))]
1002 #[unsafe(method_family = none)]
1003 pub unsafe fn presetStateFor_error(
1004 &self,
1005 user_preset: &AUAudioUnitPreset,
1006 ) -> Result<Retained<NSDictionary<NSString, AnyObject>>, Retained<NSError>>;
1007
1008 /// Specifies whether an audio unit supports loading and saving user presets
1009 ///
1010 /// The audio unit should set this property to YES if a user preset can be assigned to
1011 /// currentPreset.
1012 ///
1013 /// Audio unit host applications should query this property to determine whether the audio unit
1014 /// supports user presets.
1015 ///
1016 /// Assigning a user preset to the currentPreset property of an audio unit that does not support
1017 /// restoring state from user presets may result in incorrect behavior.
1018 #[unsafe(method(supportsUserPresets))]
1019 #[unsafe(method_family = none)]
1020 pub unsafe fn supportsUserPresets(&self) -> bool;
1021
1022 /// Set to YES when an AUAudioUnit is loaded in-process
1023 ///
1024 /// If the AUAudioUnit is instantiated with kAudioComponentInstantiation_LoadInProcess, but the
1025 /// audio unit is not packaged properly to support loading in-process, the system will silently
1026 /// fall back to loading the audio unit out-of-process.
1027 ///
1028 /// This property can be used to determine whether the instantiation succeeded as intended and
1029 /// the audio unit is running in-process.
1030 ///
1031 /// The presence of an extension process is not sufficient indication that the audio unit failed
1032 /// to load in-process, since the framework might launch the audio unit extension process to
1033 /// fulfill auxiliary functionality. If the audio unit is loaded in-process then rendering is
1034 /// done in the host process. Other operations that are not essential to rendering audio, might
1035 /// be done in the audio unit's extension process.
1036 #[unsafe(method(isLoadedInProcess))]
1037 #[unsafe(method_family = none)]
1038 pub unsafe fn isLoadedInProcess(&self) -> bool;
1039
1040 /// The audio unit's last-selected preset.
1041 ///
1042 /// Hosts can let the user select a preset by setting this property. Note that when getting
1043 /// this property, it does not reflect whether parameters may have been modified since the
1044 /// preset was selected.
1045 ///
1046 /// Bridged to the v2 property kAudioUnitProperty_PresentPreset.
1047 #[unsafe(method(currentPreset))]
1048 #[unsafe(method_family = none)]
1049 pub unsafe fn currentPreset(&self) -> Option<Retained<AUAudioUnitPreset>>;
1050
1051 /// Setter for [`currentPreset`][Self::currentPreset].
1052 #[unsafe(method(setCurrentPreset:))]
1053 #[unsafe(method_family = none)]
1054 pub unsafe fn setCurrentPreset(&self, current_preset: Option<&AUAudioUnitPreset>);
1055
1056 /// The audio unit's processing latency, in seconds.
1057 ///
1058 /// This property reflects the delay between when an impulse in the unit's audio unit stream
1059 /// arrives in the input vs. output streams. This should reflect the delay due
1060 /// to signal processing (e.g. filters, FFT's, etc.), not delay or reverberation which is
1061 /// being applied as an effect.
1062 ///
1063 /// Note that a latency that varies with parameter settings, including bypass, is generally not
1064 /// useful to hosts. A host is usually only prepared to add delays before starting to render and
1065 /// those delays need to be fixed. A variable delay would introduce artifacts even if the host
1066 /// could track it. If an algorithm has a variable latency it should be adjusted upwards to some
1067 /// fixed latency within the audio unit. If for some reason this is not possible, then latency
1068 /// could be regarded as an unavoidable consequence of the algorithm and left unreported (i.e.
1069 /// with a value of 0).
1070 ///
1071 /// Bridged to the v2 property kAudioUnitProperty_Latency.
1072 #[unsafe(method(latency))]
1073 #[unsafe(method_family = none)]
1074 pub unsafe fn latency(&self) -> NSTimeInterval;
1075
1076 /// The audio unit's tail time, in seconds.
1077 ///
1078 /// This property reflects the time interval between when the input stream ends or otherwise
1079 /// transitions to silence, and when the output stream becomes silent. Unlike latency, this
1080 /// should reflect the duration of a delay or reverb effect.
1081 ///
1082 /// Bridged to the v2 property kAudioUnitProperty_TailTime.
1083 #[unsafe(method(tailTime))]
1084 #[unsafe(method_family = none)]
1085 pub unsafe fn tailTime(&self) -> NSTimeInterval;
1086
1087 /// Provides a trade-off between rendering quality and CPU load.
1088 ///
1089 /// The range of valid values is 0-127.
1090 ///
1091 /// Bridged to the v2 property kAudioUnitProperty_RenderQuality.
1092 #[unsafe(method(renderQuality))]
1093 #[unsafe(method_family = none)]
1094 pub unsafe fn renderQuality(&self) -> NSInteger;
1095
1096 /// Setter for [`renderQuality`][Self::renderQuality].
1097 #[unsafe(method(setRenderQuality:))]
1098 #[unsafe(method_family = none)]
1099 pub unsafe fn setRenderQuality(&self, render_quality: NSInteger);
1100
1101 /// Directs an effect to route input directly to output, without any processing.
1102 ///
1103 /// Bridged to the v2 property kAudioUnitProperty_BypassEffect.
1104 #[unsafe(method(shouldBypassEffect))]
1105 #[unsafe(method_family = none)]
1106 pub unsafe fn shouldBypassEffect(&self) -> bool;
1107
1108 /// Setter for [`shouldBypassEffect`][Self::shouldBypassEffect].
1109 #[unsafe(method(setShouldBypassEffect:))]
1110 #[unsafe(method_family = none)]
1111 pub unsafe fn setShouldBypassEffect(&self, should_bypass_effect: bool);
1112
1113 /// Expresses whether an audio unit can process in place.
1114 ///
1115 /// In-place processing is the ability for an audio unit to transform an input signal to an
1116 /// output signal in-place in the input buffer, without requiring a separate output buffer.
1117 ///
1118 /// A host can express its desire to process in place by using null mData pointers in the output
1119 /// buffer list. The audio unit may process in-place in the input buffers. See the discussion of
1120 /// renderBlock.
1121 ///
1122 /// Partially bridged to the v2 property kAudioUnitProperty_InPlaceProcessing; in v3 it is not
1123 /// settable.
1124 ///
1125 /// Defaults to NO. Subclassers can override to return YES.
1126 #[unsafe(method(canProcessInPlace))]
1127 #[unsafe(method_family = none)]
1128 pub unsafe fn canProcessInPlace(&self) -> bool;
1129
1130 /// Communicates to an audio unit that it is rendering offline.
1131 ///
1132 /// A host should set this property when using an audio unit in a context where there are no
1133 /// realtime deadlines, before asking the unit to allocate render resources. An audio unit may
1134 /// respond by using a more expensive signal processing algorithm, or allowing itself to block
1135 /// at render time if data being generated on secondary work threads is not ready in time.
1136 /// (Normally, in a realtime thread, this data would have to be dropped).
1137 ///
1138 /// Bridged to the v2 property kAudioUnitProperty_OfflineRender.
1139 #[unsafe(method(isRenderingOffline))]
1140 #[unsafe(method_family = none)]
1141 pub unsafe fn isRenderingOffline(&self) -> bool;
1142
1143 /// Setter for [`isRenderingOffline`][Self::isRenderingOffline].
1144 #[unsafe(method(setRenderingOffline:))]
1145 #[unsafe(method_family = none)]
1146 pub unsafe fn setRenderingOffline(&self, rendering_offline: bool);
1147
1148 /// Expresses valid combinations of input and output channel counts.
1149 ///
1150 /// Elements are NSNumber containing integers; [0]=input count, [1]=output count, [2]=2nd input
1151 /// count, [3]=2nd output count, etc.
1152 ///
1153 /// An input, output count of (2, 2) signifies that the audio unit can process 2 input channels
1154 /// to 2 output channels.
1155 ///
1156 /// Negative numbers (-1, -2) indicate *any* number of channels. (-1, -1) means any number
1157 /// of channels on input and output as long as they are the same. (-1, -2) means any number of
1158 /// channels on input or output, without the requirement that the counts are the same.
1159 ///
1160 /// A negative number less than -2 is used to indicate a total number of channels across every
1161 /// bus in that scope, regardless of how many channels are set on any particular bus. For
1162 /// example, (-16, 2) indicates that a unit can accept up to 16 channels of input across its
1163 /// input busses, but will only produce 2 channels of output.
1164 ///
1165 /// Zero on either side (though typically input) means "not applicable", because there are no
1166 /// elements on that side.
1167 ///
1168 /// Bridged to the v2 property kAudioUnitProperty_SupportedNumChannels.
1169 #[unsafe(method(channelCapabilities))]
1170 #[unsafe(method_family = none)]
1171 pub unsafe fn channelCapabilities(&self) -> Option<Retained<NSArray<NSNumber>>>;
1172
1173 #[cfg(feature = "block2")]
1174 /// A callback for the AU to call the host for musical context information.
1175 ///
1176 /// Note that an audio unit implementation accessing this property should cache it in
1177 /// realtime-safe storage before beginning to render.
1178 ///
1179 /// Bridged to the HostCallback_GetBeatAndTempo and HostCallback_GetMusicalTimeLocation
1180 /// callback members in kAudioUnitProperty_HostCallbacks.
1181 #[unsafe(method(musicalContextBlock))]
1182 #[unsafe(method_family = none)]
1183 pub unsafe fn musicalContextBlock(&self) -> AUHostMusicalContextBlock;
1184
1185 #[cfg(feature = "block2")]
1186 /// Setter for [`musicalContextBlock`][Self::musicalContextBlock].
1187 #[unsafe(method(setMusicalContextBlock:))]
1188 #[unsafe(method_family = none)]
1189 pub unsafe fn setMusicalContextBlock(
1190 &self,
1191 musical_context_block: AUHostMusicalContextBlock,
1192 );
1193
1194 #[cfg(feature = "block2")]
1195 /// A callback for the AU to call the host for transport state information.
1196 ///
1197 /// Note that an audio unit implementation accessing this property should cache it in
1198 /// realtime-safe storage before beginning to render.
1199 ///
1200 /// Bridged to the HostCallback_GetTransportState and HostCallback_GetTransportState2
1201 /// callback members in kAudioUnitProperty_HostCallbacks.
1202 #[unsafe(method(transportStateBlock))]
1203 #[unsafe(method_family = none)]
1204 pub unsafe fn transportStateBlock(&self) -> AUHostTransportStateBlock;
1205
1206 #[cfg(feature = "block2")]
1207 /// Setter for [`transportStateBlock`][Self::transportStateBlock].
1208 #[unsafe(method(setTransportStateBlock:))]
1209 #[unsafe(method_family = none)]
1210 pub unsafe fn setTransportStateBlock(
1211 &self,
1212 transport_state_block: AUHostTransportStateBlock,
1213 );
1214
1215 /// Information about the host context in which the audio unit is connected, for display
1216 /// in the audio unit's view.
1217 ///
1218 /// For example, a host could set "track 3" as the context, so that the audio unit's view could
1219 /// then display to the user "My audio unit on track 3".
1220 ///
1221 /// Bridged to the v2 property kAudioUnitProperty_ContextName.
1222 #[unsafe(method(contextName))]
1223 #[unsafe(method_family = none)]
1224 pub unsafe fn contextName(&self) -> Option<Retained<NSString>>;
1225
1226 /// Setter for [`contextName`][Self::contextName].
1227 #[unsafe(method(setContextName:))]
1228 #[unsafe(method_family = none)]
1229 pub unsafe fn setContextName(&self, context_name: Option<&NSString>);
1230
1231 /// Information for migrating data from other audio plug-ins to the v3 Audio Unit architecture.
1232 ///
1233 /// This can be used to migrate settings from an older Audio Unit; this allows manufacturers
1234 /// to deprecate older Audio Units and replace them with new ones. The data for the older Audio Unit is
1235 /// an array of NSData representing byte encoded AudioUnitOtherPluginDescs to migrate from.
1236 /// Can also be used to migrate from a v2 to a v3 Audio Unit.
1237 ///
1238 /// Bridged to the v2 property kAudioUnitMigrateProperty_FromPlugin.
1239 #[unsafe(method(migrateFromPlugin))]
1240 #[unsafe(method_family = none)]
1241 pub unsafe fn migrateFromPlugin(&self) -> Retained<NSArray>;
1242
1243 /// Specifies whether an audio unit supports Multi-dimensional Polyphonic Expression.
1244 ///
1245 /// Bridged to the v2 property kAudioUnitProperty_SupportsMPE.
1246 #[unsafe(method(supportsMPE))]
1247 #[unsafe(method_family = none)]
1248 pub unsafe fn supportsMPE(&self) -> bool;
1249
1250 /// Specify a mapping of input channels to output channels.
1251 ///
1252 /// Converter and input/output audio units may support re-ordering or splitting of input
1253 /// channels to output channels. The number of channels in the channel map is the number of
1254 /// channels of the destination (output format). The channel map entries contain a channel
1255 /// number of the source channel that should be mapped to that destination channel. If -1 is
1256 /// specified, then that destination channel will not contain any channel from the source (so it
1257 /// will be silent).
1258 ///
1259 /// If the property value is nil, then the audio unit does not support this property.
1260 ///
1261 /// Bridged to the v2 property kAudioOutputUnitProperty_ChannelMap.
1262 #[unsafe(method(channelMap))]
1263 #[unsafe(method_family = none)]
1264 pub unsafe fn channelMap(&self) -> Option<Retained<NSArray<NSNumber>>>;
1265
1266 /// Setter for [`channelMap`][Self::channelMap].
1267 #[unsafe(method(setChannelMap:))]
1268 #[unsafe(method_family = none)]
1269 pub unsafe fn setChannelMap(&self, channel_map: Option<&NSArray<NSNumber>>);
1270
1271 #[cfg(feature = "objc2-core-midi")]
1272 /// Given a MIDI cable and channel number, return the supported MIDI-CI Profiles.
1273 ///
1274 /// Parameter `cable`: The virtual MIDI cable for which the profiles are requested.
1275 ///
1276 /// Parameter `channel`: The MIDI channel for which the profiles are requested.
1277 ///
1278 /// Returns: A MIDICIProfileState object containing all the supported MIDI-CI profiles for this channel
1279 /// on this cable.
1280 #[unsafe(method(profileStateForCable:channel:))]
1281 #[unsafe(method_family = none)]
1282 pub unsafe fn profileStateForCable_channel(
1283 &self,
1284 cable: u8,
1285 channel: MIDIChannelNumber,
1286 ) -> Retained<MIDICIProfileState>;
1287
1288 #[cfg(feature = "objc2-core-midi")]
1289 /// Enable a MIDI-CI Profile on the specified cable/channel.
1290 ///
1291 /// Parameter `profile`: The MIDI-CI profile to be enabled.
1292 ///
1293 /// Parameter `cable`: The virtual MIDI cable.
1294 ///
1295 /// Parameter `channel`: The MIDI channel.
1296 ///
1297 /// Parameter `outError`: Returned in the event of failure.
1298 ///
1299 /// Returns: YES for success. NO in the event of a failure, in which case the error is returned
1300 /// in outError.
1301 #[unsafe(method(enableProfile:cable:onChannel:error:_))]
1302 #[unsafe(method_family = none)]
1303 pub unsafe fn enableProfile_cable_onChannel_error(
1304 &self,
1305 profile: &MIDICIProfile,
1306 cable: u8,
1307 channel: MIDIChannelNumber,
1308 ) -> Result<(), Retained<NSError>>;
1309
1310 #[cfg(feature = "objc2-core-midi")]
1311 /// Disable a MIDI-CI Profile on the specified cable/channel.
1312 ///
1313 /// Parameter `profile`: The MIDI-CI profile to be disabled.
1314 ///
1315 /// Parameter `cable`: The virtual MIDI cable.
1316 ///
1317 /// Parameter `channel`: The MIDI channel.
1318 ///
1319 /// Parameter `outError`: Returned in the event of failure.
1320 ///
1321 /// Returns: YES for success. NO in the event of a failure, in which case the error is returned
1322 /// in outError.
1323 #[unsafe(method(disableProfile:cable:onChannel:error:_))]
1324 #[unsafe(method_family = none)]
1325 pub unsafe fn disableProfile_cable_onChannel_error(
1326 &self,
1327 profile: &MIDICIProfile,
1328 cable: u8,
1329 channel: MIDIChannelNumber,
1330 ) -> Result<(), Retained<NSError>>;
1331
1332 #[cfg(all(feature = "block2", feature = "objc2-core-midi"))]
1333 /// A block called when a device notifies that a MIDI-CI profile has been enabled or
1334 /// disabled.
1335 ///
1336 /// Since enabling / disabling MIDI-CI profiles is an asynchronous operation, the host can set
1337 /// this block and the audio unit is expected to call it every time the state of a MIDI-CI
1338 /// profile has changed.
1339 #[unsafe(method(profileChangedBlock))]
1340 #[unsafe(method_family = none)]
1341 pub unsafe fn profileChangedBlock(&self) -> AUMIDICIProfileChangedBlock;
1342
1343 #[cfg(all(feature = "block2", feature = "objc2-core-midi"))]
1344 /// Setter for [`profileChangedBlock`][Self::profileChangedBlock].
1345 #[unsafe(method(setProfileChangedBlock:))]
1346 #[unsafe(method_family = none)]
1347 pub unsafe fn setProfileChangedBlock(
1348 &self,
1349 profile_changed_block: AUMIDICIProfileChangedBlock,
1350 );
1351
1352 /// Returns an object for bidirectional communication between an Audio Unit and its host.
1353 ///
1354 /// Message channels provide a flexible way for custom data exchange between an Audio Unit and its host.
1355 /// An Audio Unit can support multiple message channels which are identified by the `channelName`.
1356 /// The message channel object's lifetime is managed by the host. Message channel objects should be designed
1357 /// in such a way that they could outlive the AU that vended them.
1358 /// For further details see discussion for `AUMessageChannel`.
1359 ///
1360 /// Parameter `channelName`: The name of the message channel to be returned by the Audio Unit if supported.
1361 ///
1362 /// Returns: An object that conforms to the `AUMessageChannel` protocol.
1363 #[unsafe(method(messageChannelFor:))]
1364 #[unsafe(method_family = none)]
1365 pub unsafe fn messageChannelFor(
1366 &self,
1367 channel_name: &NSString,
1368 ) -> Retained<ProtocolObject<dyn AUMessageChannel>>;
1369 );
1370}
1371
1372/// Methods declared on superclass `NSObject`.
1373impl AUAudioUnit {
1374 extern_methods!(
1375 #[unsafe(method(new))]
1376 #[unsafe(method_family = new)]
1377 pub unsafe fn new() -> Retained<Self>;
1378 );
1379}
1380
1381/// Block to notify the client of an I/O unit that input is available.
1382///
1383/// Parameter `actionFlags`: Pointer to action flags.
1384///
1385/// Parameter `timestamp`: The HAL time at which the input data was captured. If there is a sample rate conversion
1386/// or time compression/expansion downstream, the sample time will not be valid.
1387///
1388/// Parameter `frameCount`: The number of sample frames of input available.
1389///
1390/// Parameter `inputBusNumber`: The index of the input bus from which input is available.
1391///
1392/// The input data is obtained by calling the render block of the audio unit.
1393/// The AUAudioUnit is not provided since it is not safe to message an Objective C
1394/// object in a real time context.
1395///
1396/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auinputhandler?language=objc)
1397#[cfg(all(
1398 feature = "AUComponent",
1399 feature = "block2",
1400 feature = "objc2-core-audio-types"
1401))]
1402pub type AUInputHandler = *mut block2::DynBlock<
1403 dyn Fn(
1404 NonNull<AudioUnitRenderActionFlags>,
1405 NonNull<AudioTimeStamp>,
1406 AUAudioFrameCount,
1407 NSInteger,
1408 ),
1409>;
1410
1411/// AUAudioInputOutputUnit.
1412/// Additional methods for audio units which can do input/output.
1413///
1414/// These methods will fail if the audio unit is not an input/output audio unit.
1415impl AUAudioUnit {
1416 extern_methods!(
1417 /// Whether the I/O device can perform input.
1418 #[unsafe(method(canPerformInput))]
1419 #[unsafe(method_family = none)]
1420 pub unsafe fn canPerformInput(&self) -> bool;
1421
1422 /// Whether the I/O device can perform output.
1423 #[unsafe(method(canPerformOutput))]
1424 #[unsafe(method_family = none)]
1425 pub unsafe fn canPerformOutput(&self) -> bool;
1426
1427 /// Flag enabling audio input from the unit.
1428 ///
1429 /// Input is disabled by default. This must be set to YES if input audio is desired.
1430 /// Setting to YES will have no effect if canPerformInput is false.
1431 #[unsafe(method(isInputEnabled))]
1432 #[unsafe(method_family = none)]
1433 pub unsafe fn isInputEnabled(&self) -> bool;
1434
1435 /// Setter for [`isInputEnabled`][Self::isInputEnabled].
1436 #[unsafe(method(setInputEnabled:))]
1437 #[unsafe(method_family = none)]
1438 pub unsafe fn setInputEnabled(&self, input_enabled: bool);
1439
1440 /// Flag enabling audio output from the unit.
1441 ///
1442 /// Output is enabled by default.
1443 /// Setting to YES will have no effect if canPerformOutput is false.
1444 #[unsafe(method(isOutputEnabled))]
1445 #[unsafe(method_family = none)]
1446 pub unsafe fn isOutputEnabled(&self) -> bool;
1447
1448 /// Setter for [`isOutputEnabled`][Self::isOutputEnabled].
1449 #[unsafe(method(setOutputEnabled:))]
1450 #[unsafe(method_family = none)]
1451 pub unsafe fn setOutputEnabled(&self, output_enabled: bool);
1452
1453 #[cfg(all(
1454 feature = "AUComponent",
1455 feature = "block2",
1456 feature = "objc2-core-audio-types"
1457 ))]
1458 /// The block that the output unit will call to get audio to send to the output.
1459 ///
1460 /// This block must be set if output is enabled.
1461 #[unsafe(method(outputProvider))]
1462 #[unsafe(method_family = none)]
1463 pub unsafe fn outputProvider(&self) -> AURenderPullInputBlock;
1464
1465 #[cfg(all(
1466 feature = "AUComponent",
1467 feature = "block2",
1468 feature = "objc2-core-audio-types"
1469 ))]
1470 /// Setter for [`outputProvider`][Self::outputProvider].
1471 #[unsafe(method(setOutputProvider:))]
1472 #[unsafe(method_family = none)]
1473 pub unsafe fn setOutputProvider(&self, output_provider: AURenderPullInputBlock);
1474
1475 #[cfg(all(
1476 feature = "AUComponent",
1477 feature = "block2",
1478 feature = "objc2-core-audio-types"
1479 ))]
1480 /// The block that the output unit will call to notify when input is available.
1481 ///
1482 /// See discussion for AUInputHandler.
1483 #[unsafe(method(inputHandler))]
1484 #[unsafe(method_family = none)]
1485 pub unsafe fn inputHandler(&self) -> AUInputHandler;
1486
1487 #[cfg(all(
1488 feature = "AUComponent",
1489 feature = "block2",
1490 feature = "objc2-core-audio-types"
1491 ))]
1492 /// Setter for [`inputHandler`][Self::inputHandler].
1493 #[unsafe(method(setInputHandler:))]
1494 #[unsafe(method_family = none)]
1495 pub unsafe fn setInputHandler(&self, input_handler: AUInputHandler);
1496
1497 /// Get the I/O hardware device.
1498 #[unsafe(method(deviceID))]
1499 #[unsafe(method_family = none)]
1500 pub unsafe fn deviceID(&self) -> AUAudioObjectID;
1501
1502 /// Set the I/O hardware device.
1503 ///
1504 /// Parameter `deviceID`: The device to select.
1505 ///
1506 /// Parameter `outError`: Returned in the event of failure.
1507 #[unsafe(method(setDeviceID:error:_))]
1508 #[unsafe(method_family = none)]
1509 pub unsafe fn setDeviceID_error(
1510 &self,
1511 device_id: AUAudioObjectID,
1512 ) -> Result<(), Retained<NSError>>;
1513
1514 /// The audio device's input latency, in seconds.
1515 ///
1516 /// Bridged to the HAL property kAudioDevicePropertyLatency, which is implemented
1517 /// by v2 input/output units.
1518 #[unsafe(method(deviceInputLatency))]
1519 #[unsafe(method_family = none)]
1520 pub unsafe fn deviceInputLatency(&self) -> NSTimeInterval;
1521
1522 /// The audio device's output latency, in seconds.
1523 ///
1524 /// Bridged to the HAL property kAudioDevicePropertyLatency, which is implemented
1525 /// by v2 input/output units.
1526 #[unsafe(method(deviceOutputLatency))]
1527 #[unsafe(method_family = none)]
1528 pub unsafe fn deviceOutputLatency(&self) -> NSTimeInterval;
1529
1530 /// The audio device's running state.
1531 #[unsafe(method(isRunning))]
1532 #[unsafe(method_family = none)]
1533 pub unsafe fn isRunning(&self) -> bool;
1534
1535 /// Starts the audio hardware.
1536 ///
1537 /// Parameter `outError`: Returned in the event of failure.
1538 #[unsafe(method(startHardwareAndReturnError:_))]
1539 #[unsafe(method_family = none)]
1540 pub unsafe fn startHardwareAndReturnError(&self) -> Result<(), Retained<NSError>>;
1541
1542 /// Stops the audio hardware.
1543 #[unsafe(method(stopHardware))]
1544 #[unsafe(method_family = none)]
1545 pub unsafe fn stopHardware(&self);
1546 );
1547}
1548
1549extern_class!(
1550 /// Container for an audio unit's input or output busses.
1551 ///
1552 /// Hosts can observe a bus property across all busses by using KVO on this object, without
1553 /// having to observe it on each individual bus. (One could add listeners to individual busses,
1554 /// but that means one has to observe bus count changes and add/remove listeners in response.
1555 /// Also, NSArray's addObserver:toObjectsAtIndexes:forKeyPath:options:context: is problematic;
1556 /// it does not let the individual objects override the observation request, and so a bus which
1557 /// is proxying a bus in an extension process does not get the message.)
1558 ///
1559 /// Some audio units (e.g. mixers) support variable numbers of busses, via subclassing. When the
1560 /// bus count changes, a KVO notification is sent on "inputBusses" or "outputBusses," as
1561 /// appropriate.
1562 ///
1563 /// Subclassers should see also the AUAudioUnitBusImplementation category.
1564 ///
1565 /// The bus array is bridged to the v2 property kAudioUnitProperty_ElementCount.
1566 ///
1567 /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitbusarray?language=objc)
1568 #[unsafe(super(NSObject))]
1569 #[derive(Debug, PartialEq, Eq, Hash)]
1570 pub struct AUAudioUnitBusArray;
1571);
1572
1573extern_conformance!(
1574 unsafe impl NSFastEnumeration for AUAudioUnitBusArray {}
1575);
1576
1577extern_conformance!(
1578 unsafe impl NSObjectProtocol for AUAudioUnitBusArray {}
1579);
1580
1581impl AUAudioUnitBusArray {
1582 extern_methods!(
1583 #[unsafe(method(init))]
1584 #[unsafe(method_family = init)]
1585 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1586
1587 /// Initializes by making a copy of the supplied bus array.
1588 #[unsafe(method(initWithAudioUnit:busType:busses:))]
1589 #[unsafe(method_family = init)]
1590 pub unsafe fn initWithAudioUnit_busType_busses(
1591 this: Allocated<Self>,
1592 owner: &AUAudioUnit,
1593 bus_type: AUAudioUnitBusType,
1594 bus_array: &NSArray<AUAudioUnitBus>,
1595 ) -> Retained<Self>;
1596
1597 /// Initializes an empty bus array.
1598 #[unsafe(method(initWithAudioUnit:busType:))]
1599 #[unsafe(method_family = init)]
1600 pub unsafe fn initWithAudioUnit_busType(
1601 this: Allocated<Self>,
1602 owner: &AUAudioUnit,
1603 bus_type: AUAudioUnitBusType,
1604 ) -> Retained<Self>;
1605
1606 #[unsafe(method(count))]
1607 #[unsafe(method_family = none)]
1608 pub unsafe fn count(&self) -> NSUInteger;
1609
1610 #[unsafe(method(objectAtIndexedSubscript:))]
1611 #[unsafe(method_family = none)]
1612 pub unsafe fn objectAtIndexedSubscript(
1613 &self,
1614 index: NSUInteger,
1615 ) -> Retained<AUAudioUnitBus>;
1616
1617 /// Whether the array can have a variable number of busses.
1618 ///
1619 /// The base implementation returns false.
1620 #[unsafe(method(isCountChangeable))]
1621 #[unsafe(method_family = none)]
1622 pub unsafe fn isCountChangeable(&self) -> bool;
1623
1624 /// Change the number of busses in the array.
1625 #[unsafe(method(setBusCount:error:_))]
1626 #[unsafe(method_family = none)]
1627 pub unsafe fn setBusCount_error(&self, count: NSUInteger) -> Result<(), Retained<NSError>>;
1628
1629 /// Add a KVO observer for a property on all busses in the array.
1630 #[unsafe(method(addObserverToAllBusses:forKeyPath:options:context:))]
1631 #[unsafe(method_family = none)]
1632 pub unsafe fn addObserverToAllBusses_forKeyPath_options_context(
1633 &self,
1634 observer: &NSObject,
1635 key_path: &NSString,
1636 options: NSKeyValueObservingOptions,
1637 context: *mut c_void,
1638 );
1639
1640 /// Remove a KVO observer for a property on all busses in the array.
1641 #[unsafe(method(removeObserverFromAllBusses:forKeyPath:context:))]
1642 #[unsafe(method_family = none)]
1643 pub unsafe fn removeObserverFromAllBusses_forKeyPath_context(
1644 &self,
1645 observer: &NSObject,
1646 key_path: &NSString,
1647 context: *mut c_void,
1648 );
1649
1650 /// The audio unit that owns the bus.
1651 #[unsafe(method(ownerAudioUnit))]
1652 #[unsafe(method_family = none)]
1653 pub unsafe fn ownerAudioUnit(&self) -> Retained<AUAudioUnit>;
1654
1655 /// Which bus array this is (input or output).
1656 #[unsafe(method(busType))]
1657 #[unsafe(method_family = none)]
1658 pub unsafe fn busType(&self) -> AUAudioUnitBusType;
1659 );
1660}
1661
1662/// Methods declared on superclass `NSObject`.
1663impl AUAudioUnitBusArray {
1664 extern_methods!(
1665 #[unsafe(method(new))]
1666 #[unsafe(method_family = new)]
1667 pub unsafe fn new() -> Retained<Self>;
1668 );
1669}
1670
1671extern_class!(
1672 /// An input or output connection point on an audio unit.
1673 ///
1674 /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitbus?language=objc)
1675 #[unsafe(super(NSObject))]
1676 #[derive(Debug, PartialEq, Eq, Hash)]
1677 pub struct AUAudioUnitBus;
1678);
1679
1680extern_conformance!(
1681 unsafe impl NSObjectProtocol for AUAudioUnitBus {}
1682);
1683
1684impl AUAudioUnitBus {
1685 extern_methods!(
1686 /// Controls the audio unit's allocation strategy for a bus.
1687 ///
1688 /// Hosts can set this flag to communicate whether an audio unit should allocate its own buffer.
1689 /// By default this flag is set to true.
1690 ///
1691 /// On the output side, shouldAllocateBuffer=false means the AU can assume that it will be
1692 /// called with non-null output buffers. If shouldAllocateBuffer=true (the default), the AU must
1693 /// be prepared to be called with null pointers and replace them with pointers to its internally
1694 /// allocated buffer.
1695 ///
1696 /// On the input side, shouldAllocateBuffer=false means the AU can pull for input using a buffer
1697 /// list with null buffer pointers, and assume that the pull input block will provide pointers.
1698 /// If shouldAllocateBuffer=true (the default), the AU must pull with non-null pointers while
1699 /// still being prepared for the source to replace them with pointers of its own.
1700 ///
1701 /// Bridged to the v2 property kAudioUnitProperty_ShouldAllocateBuffer.
1702 #[unsafe(method(shouldAllocateBuffer))]
1703 #[unsafe(method_family = none)]
1704 pub unsafe fn shouldAllocateBuffer(&self) -> bool;
1705
1706 /// Setter for [`shouldAllocateBuffer`][Self::shouldAllocateBuffer].
1707 #[unsafe(method(setShouldAllocateBuffer:))]
1708 #[unsafe(method_family = none)]
1709 pub unsafe fn setShouldAllocateBuffer(&self, should_allocate_buffer: bool);
1710
1711 /// Whether the bus is active.
1712 ///
1713 /// Hosts must enable input busses before using them. The reason for this is to allow a unit
1714 /// such as a mixer to be prepared to render a large number of inputs, but avoid the work
1715 /// of preparing to pull inputs which are not in use.
1716 ///
1717 /// Bridged to the v2 properties kAudioUnitProperty_MakeConnection and
1718 /// kAudioUnitProperty_SetRenderCallback.
1719 #[unsafe(method(isEnabled))]
1720 #[unsafe(method_family = none)]
1721 pub unsafe fn isEnabled(&self) -> bool;
1722
1723 /// Setter for [`isEnabled`][Self::isEnabled].
1724 #[unsafe(method(setEnabled:))]
1725 #[unsafe(method_family = none)]
1726 pub unsafe fn setEnabled(&self, enabled: bool);
1727
1728 /// A name for the bus. Can be set by host.
1729 #[unsafe(method(name))]
1730 #[unsafe(method_family = none)]
1731 pub unsafe fn name(&self) -> Option<Retained<NSString>>;
1732
1733 /// Setter for [`name`][Self::name].
1734 #[unsafe(method(setName:))]
1735 #[unsafe(method_family = none)]
1736 pub unsafe fn setName(&self, name: Option<&NSString>);
1737
1738 /// The index of this bus in the containing array.
1739 #[unsafe(method(index))]
1740 #[unsafe(method_family = none)]
1741 pub unsafe fn index(&self) -> NSUInteger;
1742
1743 /// The AUAudioUnitBusType.
1744 #[unsafe(method(busType))]
1745 #[unsafe(method_family = none)]
1746 pub unsafe fn busType(&self) -> AUAudioUnitBusType;
1747
1748 /// The audio unit that owns the bus.
1749 #[unsafe(method(ownerAudioUnit))]
1750 #[unsafe(method_family = none)]
1751 pub unsafe fn ownerAudioUnit(&self) -> Retained<AUAudioUnit>;
1752
1753 /// This is an array of NSNumbers representing AudioChannelLayoutTag.
1754 #[unsafe(method(supportedChannelLayoutTags))]
1755 #[unsafe(method_family = none)]
1756 pub unsafe fn supportedChannelLayoutTags(&self) -> Option<Retained<NSArray<NSNumber>>>;
1757
1758 /// Information about latency in the audio unit's processing context.
1759 ///
1760 /// This should not be confused with the audio unit's latency property, where the audio unit
1761 /// describes to the host any processing latency it introduces between its input and its output.
1762 ///
1763 /// A host may set this property to describe to the audio unit the presentation latency of its
1764 /// input and/or output audio data. Latency is described in seconds. A value of zero means
1765 /// either no latency or an unknown latency.
1766 ///
1767 /// A host should set this property on each active bus, since, for example, the audio routing
1768 /// path to each of multiple output busses may differ.
1769 ///
1770 /// For input busses:
1771 /// Describes how long ago the audio arriving on this bus was acquired. For instance, when
1772 /// reading from a file to the first audio unit in a chain, the input presentation latency
1773 /// is zero. For audio input from a device, this initial input latency is the presentation
1774 /// latency of the device itself, i.e. the device's safety offset and latency.
1775 ///
1776 /// A second chained audio unit's input presentation latency will be the input presentation
1777 /// latency of the first unit, plus the processing latency of the first unit.
1778 ///
1779 /// For output busses:
1780 /// Describes how long it will be before the output audio of an audio unit is presented. For
1781 /// instance, when writing to a file, the output presentation latency of the last audio unit
1782 /// in a chain is zero. When the audio from that audio unit is to be played to a device,
1783 /// then that initial presentation latency will be the presentation latency of the device
1784 /// itself, which is the I/O buffer size, plus the device's safety offset and latency
1785 ///
1786 /// A previous chained audio unit's output presentation latency is the last unit's
1787 /// presentation latency plus its processing latency.
1788 ///
1789 /// So, for a given audio unit anywhere within a mixing graph, the input and output presentation
1790 /// latencies describe to that unit how long from the moment of generation it has taken for its
1791 /// input to arrive, and how long it will take for its output to be presented.
1792 ///
1793 /// Bridged to the v2 property kAudioUnitProperty_PresentationLatency.
1794 #[unsafe(method(contextPresentationLatency))]
1795 #[unsafe(method_family = none)]
1796 pub unsafe fn contextPresentationLatency(&self) -> NSTimeInterval;
1797
1798 /// Setter for [`contextPresentationLatency`][Self::contextPresentationLatency].
1799 #[unsafe(method(setContextPresentationLatency:))]
1800 #[unsafe(method_family = none)]
1801 pub unsafe fn setContextPresentationLatency(
1802 &self,
1803 context_presentation_latency: NSTimeInterval,
1804 );
1805 );
1806}
1807
1808/// Methods declared on superclass `NSObject`.
1809impl AUAudioUnitBus {
1810 extern_methods!(
1811 #[unsafe(method(init))]
1812 #[unsafe(method_family = init)]
1813 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1814
1815 #[unsafe(method(new))]
1816 #[unsafe(method_family = new)]
1817 pub unsafe fn new() -> Retained<Self>;
1818 );
1819}
1820
1821extern_class!(
1822 /// A collection of parameter settings provided by the audio unit implementor, producing a
1823 /// useful sound or starting point.
1824 ///
1825 /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitpreset?language=objc)
1826 #[unsafe(super(NSObject))]
1827 #[derive(Debug, PartialEq, Eq, Hash)]
1828 pub struct AUAudioUnitPreset;
1829);
1830
1831extern_conformance!(
1832 unsafe impl NSCoding for AUAudioUnitPreset {}
1833);
1834
1835extern_conformance!(
1836 unsafe impl NSObjectProtocol for AUAudioUnitPreset {}
1837);
1838
1839extern_conformance!(
1840 unsafe impl NSSecureCoding for AUAudioUnitPreset {}
1841);
1842
1843impl AUAudioUnitPreset {
1844 extern_methods!(
1845 /// The preset's unique numeric identifier.
1846 #[unsafe(method(number))]
1847 #[unsafe(method_family = none)]
1848 pub unsafe fn number(&self) -> NSInteger;
1849
1850 /// Setter for [`number`][Self::number].
1851 #[unsafe(method(setNumber:))]
1852 #[unsafe(method_family = none)]
1853 pub unsafe fn setNumber(&self, number: NSInteger);
1854
1855 /// The preset's name.
1856 #[unsafe(method(name))]
1857 #[unsafe(method_family = none)]
1858 pub unsafe fn name(&self) -> Retained<NSString>;
1859
1860 /// Setter for [`name`][Self::name].
1861 #[unsafe(method(setName:))]
1862 #[unsafe(method_family = none)]
1863 pub unsafe fn setName(&self, name: &NSString);
1864 );
1865}
1866
1867/// Methods declared on superclass `NSObject`.
1868impl AUAudioUnitPreset {
1869 extern_methods!(
1870 #[unsafe(method(init))]
1871 #[unsafe(method_family = init)]
1872 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1873
1874 #[unsafe(method(new))]
1875 #[unsafe(method_family = new)]
1876 pub unsafe fn new() -> Retained<Self>;
1877 );
1878}
1879
1880/// Block that hosts provide to AU message channels to be called back by the AU.
1881///
1882/// Parameter `message`: An NSDictionary with custom data. The allowed classes for key and value types are
1883/// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
1884///
1885/// Returns: An NSDictionary with custom data. The allowed classes for key and value types are
1886/// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
1887///
1888/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/callhostblock?language=objc)
1889#[cfg(feature = "block2")]
1890pub type CallHostBlock =
1891 *mut block2::DynBlock<dyn Fn(NonNull<NSDictionary>) -> NonNull<NSDictionary>>;
1892
1893extern_protocol!(
1894 /// The protocol which objects returned from `[AUAudioUnit messageChannelFor:]` have to conform to.
1895 ///
1896 /// Audio Units and hosts that have special needs of communication, e.g. to exchange musical context required for better audio processing,
1897 /// can implement a communication object to exchange messages in form of NSDictionaries. An Audio Unit would need to implement
1898 /// a class conforming to the AUMessageChannel protocol and return an instance via `[AUAudioUnit messageChannelFor:]`. A host can query
1899 /// the instance via the channel name.
1900 /// The protocol offers a method to send messages to the AU and a block to send messages to the host.
1901 ///
1902 /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aumessagechannel?language=objc)
1903 pub unsafe trait AUMessageChannel {
1904 /// Calls the Audio Unit with custom data message.
1905 ///
1906 /// Parameter `message`: An NSDictionary with custom data. The allowed classes for key and value types are
1907 /// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
1908 ///
1909 /// Returns: An NSDictionary with custom data. The allowed classes for key and value types are
1910 /// NSArray, NSDictionary, NSOrderedSet, NSSet, NSString, NSData, NSNull, NSNumber, NSDate
1911 #[optional]
1912 #[unsafe(method(callAudioUnit:))]
1913 #[unsafe(method_family = none)]
1914 unsafe fn callAudioUnit(&self, message: &NSDictionary) -> Retained<NSDictionary>;
1915
1916 #[cfg(feature = "block2")]
1917 /// A callback for the AU to send a message to the host.
1918 ///
1919 /// The host has to set a block on this property.
1920 #[optional]
1921 #[unsafe(method(callHostBlock))]
1922 #[unsafe(method_family = none)]
1923 unsafe fn callHostBlock(&self) -> CallHostBlock;
1924
1925 #[cfg(feature = "block2")]
1926 /// Setter for [`callHostBlock`][Self::callHostBlock].
1927 #[optional]
1928 #[unsafe(method(setCallHostBlock:))]
1929 #[unsafe(method_family = none)]
1930 unsafe fn setCallHostBlock(&self, call_host_block: CallHostBlock);
1931 }
1932);