objc2_audio_toolbox/generated/
AUAudioUnitImplementation.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Describes the type of a render event.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aurendereventtype?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct AURenderEventType(pub u8);
17impl AURenderEventType {
18    #[doc(alias = "AURenderEventParameter")]
19    pub const Parameter: Self = Self(1);
20    #[doc(alias = "AURenderEventParameterRamp")]
21    pub const ParameterRamp: Self = Self(2);
22    #[doc(alias = "AURenderEventMIDI")]
23    pub const MIDI: Self = Self(8);
24    #[doc(alias = "AURenderEventMIDISysEx")]
25    pub const MIDISysEx: Self = Self(9);
26    #[doc(alias = "AURenderEventMIDIEventList")]
27    pub const MIDIEventList: Self = Self(10);
28}
29
30unsafe impl Encode for AURenderEventType {
31    const ENCODING: Encoding = u8::ENCODING;
32}
33
34unsafe impl RefEncode for AURenderEventType {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38/// AUAudioUnitImplementation.
39///
40/// Aspects of AUAudioUnit of interest only to subclassers.
41#[cfg(feature = "AUAudioUnit")]
42impl AUAudioUnit {
43    extern_methods!(
44        #[cfg(feature = "AudioComponent")]
45        /// Register an audio unit component implemented as an AUAudioUnit subclass.
46        ///
47        /// This method dynamically registers the supplied AUAudioUnit subclass with the Audio Component
48        /// system, in the context of the current process (only). After registering the subclass, it can
49        /// be instantiated via AudioComponentInstanceNew,
50        /// -[AUAudioUnit initWithComponentDescription:options:error:], and via any other API's which
51        /// instantiate audio units via their component descriptions (e.g.
52        /// <AudioToolbox
53        /// /AUGraph.h>, or
54        /// <AVFoundation
55        /// /AVAudioUnitEffect.h>).
56        ///
57        /// # Safety
58        ///
59        /// `cls` probably has further requirements.
60        #[unsafe(method(registerSubclass:asComponentDescription:name:version:))]
61        #[unsafe(method_family = none)]
62        pub unsafe fn registerSubclass_asComponentDescription_name_version(
63            cls: &AnyClass,
64            component_description: AudioComponentDescription,
65            name: &NSString,
66            version: u32,
67        );
68
69        /// Hint to control the size of the allocated buffer for outgoing MIDI events.
70        ///
71        /// This property allows the plug-in to provide a hint to the framework regarding the size of
72        /// its outgoing MIDI data buffer.
73        ///
74        /// If the plug-in produces more MIDI output data than the default size of the allocated buffer,
75        /// then the plug-in can provide this property to increase the size of this buffer.
76        ///
77        /// The value represents the number of 3-byte Legacy MIDI messages that fit into the buffer or
78        /// a single MIDIEventList containing 1 MIDIEventPacket of 2 words when using MIDI 2.0 (MIDIEventList based API's).
79        ///
80        /// This property is set to the default value by the framework.
81        ///
82        /// In case of kAudioUnitErr_MIDIOutputBufferFull errors caused by producing too much MIDI
83        /// output in one render call, set this property to increase the buffer.
84        ///
85        /// This only provides a recommendation to the framework.
86        ///
87        /// Bridged to kAudioUnitProperty_MIDIOutputBufferSizeHint.
88        #[unsafe(method(MIDIOutputBufferSizeHint))]
89        #[unsafe(method_family = none)]
90        pub unsafe fn MIDIOutputBufferSizeHint(&self) -> NSInteger;
91
92        /// Setter for [`MIDIOutputBufferSizeHint`][Self::MIDIOutputBufferSizeHint].
93        #[unsafe(method(setMIDIOutputBufferSizeHint:))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn setMIDIOutputBufferSizeHint(&self, midi_output_buffer_size_hint: NSInteger);
96
97        /// Parameter `flag`: In the base class implementation of allocateRenderResourcesAndReturnError:, the property renderResourcesAllocated is set to YES.
98        /// If allocateRenderResourcesAndReturnError: should fail in a subclass, subclassers must use this method to set renderResourcesAllocated to NO.
99        #[unsafe(method(setRenderResourcesAllocated:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn setRenderResourcesAllocated(&self, flag: bool);
102    );
103}
104
105/// AUAudioUnitImplementation.
106///
107/// Aspects of AUAudioUnitBus of interest only to the implementation of v3 AUs.
108#[cfg(feature = "AUAudioUnit")]
109impl AUAudioUnitBus {
110    extern_methods!(
111        /// An array of numbers giving the supported numbers of channels for this bus.
112        ///
113        /// If supportedChannelCounts is nil, then any number less than or equal to maximumChannelCount
114        /// is supported. If setting supportedChannelCounts makes the current format unsupported, then
115        /// format will be set to nil. The default value is nil.
116        #[unsafe(method(supportedChannelCounts))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn supportedChannelCounts(&self) -> Option<Retained<NSArray<NSNumber>>>;
119
120        /// Setter for [`supportedChannelCounts`][Self::supportedChannelCounts].
121        #[unsafe(method(setSupportedChannelCounts:))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn setSupportedChannelCounts(
124            &self,
125            supported_channel_counts: Option<&NSArray<NSNumber>>,
126        );
127
128        /// The maximum numbers of channels supported for this bus.
129        ///
130        /// If supportedChannelCounts is set, then this value is derived from supportedChannelCounts. If
131        /// setting maximumChannelCount makes the current format unsupported, then format will be set to
132        /// nil. The default value is UINT_MAX.
133        #[unsafe(method(maximumChannelCount))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn maximumChannelCount(&self) -> AUAudioChannelCount;
136
137        /// Setter for [`maximumChannelCount`][Self::maximumChannelCount].
138        #[unsafe(method(setMaximumChannelCount:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn setMaximumChannelCount(&self, maximum_channel_count: AUAudioChannelCount);
141    );
142}
143
144/// AUAudioUnitBusImplementation.
145///
146/// Aspects of AUAudioUnitBusArray of interest only to subclassers.
147#[cfg(feature = "AUAudioUnit")]
148impl AUAudioUnitBusArray {
149    extern_methods!(
150        /// Sets the bus array to be a copy of the supplied array. The base class issues KVO notifications.
151        #[unsafe(method(replaceBusses:))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn replaceBusses(&self, bus_array: &NSArray<AUAudioUnitBus>);
154    );
155}
156
157/// Factory.
158///
159/// Factory methods for building parameters, parameter groups, and parameter trees.
160///
161///
162/// Note: In non-ARC code, "create" methods return unretained objects (unlike "create"
163/// C functions); the caller should generally retain them.
164#[cfg(feature = "AUParameters")]
165impl AUParameterTree {
166    extern_methods!(
167        #[cfg(feature = "AudioUnitProperties")]
168        /// Create an AUParameter.
169        /// See AUParameter's properties for descriptions of the arguments.
170        #[unsafe(method(createParameterWithIdentifier:name:address:min:max:unit:unitName:flags:valueStrings:dependentParameters:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn createParameterWithIdentifier_name_address_min_max_unit_unitName_flags_valueStrings_dependentParameters(
173            identifier: &NSString,
174            name: &NSString,
175            address: AUParameterAddress,
176            min: AUValue,
177            max: AUValue,
178            unit: AudioUnitParameterUnit,
179            unit_name: Option<&NSString>,
180            flags: AudioUnitParameterOptions,
181            value_strings: Option<&NSArray<NSString>>,
182            dependent_parameters: Option<&NSArray<NSNumber>>,
183        ) -> Retained<AUParameter>;
184
185        /// Create an AUParameterGroup.
186        ///
187        /// Parameter `identifier`: An identifier for the group (non-localized, persistent).
188        ///
189        /// Parameter `name`: The group's human-readable name (localized).
190        ///
191        /// Parameter `children`: The group's child nodes.
192        #[unsafe(method(createGroupWithIdentifier:name:children:))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn createGroupWithIdentifier_name_children(
195            identifier: &NSString,
196            name: &NSString,
197            children: &NSArray<AUParameterNode>,
198        ) -> Retained<AUParameterGroup>;
199
200        /// Create a template group which may be used as a prototype for further group instances.
201        ///
202        ///
203        /// Template groups provide a way to construct multiple instances of identical parameter
204        /// groups, sharing certain immutable state between the instances.
205        ///
206        /// Template groups may not appear in trees except at the root.
207        #[unsafe(method(createGroupTemplate:))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn createGroupTemplate(
210            children: &NSArray<AUParameterNode>,
211        ) -> Retained<AUParameterGroup>;
212
213        /// Initialize a group as a copied instance of a template group.
214        ///
215        /// Parameter `templateGroup`: A group to be used as a template and largely copied.
216        ///
217        /// Parameter `identifier`: An identifier for the new group (non-localized, persistent).
218        ///
219        /// Parameter `name`: The new group's human-readable name (localized).
220        ///
221        /// Parameter `addressOffset`: The new group's parameters' addresses will be offset from those in
222        /// the template by this value.
223        #[unsafe(method(createGroupFromTemplate:identifier:name:addressOffset:))]
224        #[unsafe(method_family = none)]
225        pub unsafe fn createGroupFromTemplate_identifier_name_addressOffset(
226            template_group: &AUParameterGroup,
227            identifier: &NSString,
228            name: &NSString,
229            address_offset: AUParameterAddress,
230        ) -> Retained<AUParameterGroup>;
231
232        /// Create an AUParameterTree.
233        ///
234        /// Parameter `children`: The tree's top-level child nodes.
235        #[unsafe(method(createTreeWithChildren:))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn createTreeWithChildren(
238            children: &NSArray<AUParameterNode>,
239        ) -> Retained<AUParameterTree>;
240    );
241}
242
243/// A block called to notify the AUAudioUnit implementation of changes to AUParameter values.
244///
245/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auimplementorvalueobserver?language=objc)
246#[cfg(all(feature = "AUParameters", feature = "block2"))]
247pub type AUImplementorValueObserver = *mut block2::DynBlock<dyn Fn(NonNull<AUParameter>, AUValue)>;
248
249/// A block called to fetch an AUParameter's current value from the AUAudioUnit implementation.
250///
251/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auimplementorvalueprovider?language=objc)
252#[cfg(all(feature = "AUParameters", feature = "block2"))]
253pub type AUImplementorValueProvider =
254    *mut block2::DynBlock<dyn Fn(NonNull<AUParameter>) -> AUValue>;
255
256/// A block called to convert an AUParameter's value to a string.
257///
258/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auimplementorstringfromvaluecallback?language=objc)
259#[cfg(all(feature = "AUParameters", feature = "block2"))]
260pub type AUImplementorStringFromValueCallback =
261    *mut block2::DynBlock<dyn Fn(NonNull<AUParameter>, *const AUValue) -> NonNull<NSString>>;
262
263/// A block called to convert a string to an AUParameter's value.
264///
265/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auimplementorvaluefromstringcallback?language=objc)
266#[cfg(all(feature = "AUParameters", feature = "block2"))]
267pub type AUImplementorValueFromStringCallback =
268    *mut block2::DynBlock<dyn Fn(NonNull<AUParameter>, NonNull<NSString>) -> AUValue>;
269
270/// A block called to return a group or parameter's localized display name, abbreviated to the requested length.
271///
272/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auimplementordisplaynamewithlengthcallback?language=objc)
273#[cfg(all(feature = "AUParameters", feature = "block2"))]
274pub type AUImplementorDisplayNameWithLengthCallback =
275    *mut block2::DynBlock<dyn Fn(NonNull<AUParameterNode>, NSInteger) -> NonNull<NSString>>;
276
277/// AUParameterNodeImplementation.
278///
279/// Aspects of AUParameterNode of interest only to AUAudioUnit subclassers.
280#[cfg(feature = "AUParameters")]
281impl AUParameterNode {
282    extern_methods!(
283        #[cfg(feature = "block2")]
284        /// Called when a parameter changes value.
285        ///
286        /// This block, used only in an audio unit implementation, receives all externally-generated
287        /// changes to parameter values. It should store the new value in its audio signal processing
288        /// state (assuming that that state is separate from the AUParameter object).
289        ///
290        /// # Safety
291        ///
292        /// The returned block's argument 1 must be a valid pointer.
293        #[unsafe(method(implementorValueObserver))]
294        #[unsafe(method_family = none)]
295        pub unsafe fn implementorValueObserver(&self) -> AUImplementorValueObserver;
296
297        #[cfg(feature = "block2")]
298        /// Setter for [`implementorValueObserver`][Self::implementorValueObserver].
299        ///
300        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
301        ///
302        /// # Safety
303        ///
304        /// `implementor_value_observer` must be a valid pointer.
305        #[unsafe(method(setImplementorValueObserver:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn setImplementorValueObserver(
308            &self,
309            implementor_value_observer: AUImplementorValueObserver,
310        );
311
312        #[cfg(feature = "block2")]
313        /// Called when a value of a parameter in the tree is known to have a stale value
314        /// needing to be refreshed.
315        ///
316        /// The audio unit should return the current value for this parameter; the AUParameterNode will
317        /// store the value.
318        ///
319        /// # Safety
320        ///
321        /// The returned block's argument must be a valid pointer.
322        #[unsafe(method(implementorValueProvider))]
323        #[unsafe(method_family = none)]
324        pub unsafe fn implementorValueProvider(&self) -> AUImplementorValueProvider;
325
326        #[cfg(feature = "block2")]
327        /// Setter for [`implementorValueProvider`][Self::implementorValueProvider].
328        ///
329        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
330        ///
331        /// # Safety
332        ///
333        /// `implementor_value_provider` must be a valid pointer.
334        #[unsafe(method(setImplementorValueProvider:))]
335        #[unsafe(method_family = none)]
336        pub unsafe fn setImplementorValueProvider(
337            &self,
338            implementor_value_provider: AUImplementorValueProvider,
339        );
340
341        #[cfg(feature = "block2")]
342        /// Called to provide string representations of parameter values.
343        /// If value is nil, the callback uses the current value of the parameter.
344        ///
345        /// # Safety
346        ///
347        /// - The returned block's argument 1 must be a valid pointer.
348        /// - The returned block's argument 2 must be a valid pointer or null.
349        #[unsafe(method(implementorStringFromValueCallback))]
350        #[unsafe(method_family = none)]
351        pub unsafe fn implementorStringFromValueCallback(
352            &self,
353        ) -> AUImplementorStringFromValueCallback;
354
355        #[cfg(feature = "block2")]
356        /// Setter for [`implementorStringFromValueCallback`][Self::implementorStringFromValueCallback].
357        ///
358        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
359        ///
360        /// # Safety
361        ///
362        /// `implementor_string_from_value_callback` must be a valid pointer.
363        #[unsafe(method(setImplementorStringFromValueCallback:))]
364        #[unsafe(method_family = none)]
365        pub unsafe fn setImplementorStringFromValueCallback(
366            &self,
367            implementor_string_from_value_callback: AUImplementorStringFromValueCallback,
368        );
369
370        #[cfg(feature = "block2")]
371        /// Called to convert string to numeric representations of parameter values.
372        ///
373        /// # Safety
374        ///
375        /// - The returned block's argument 1 must be a valid pointer.
376        /// - The returned block's argument 2 must be a valid pointer.
377        #[unsafe(method(implementorValueFromStringCallback))]
378        #[unsafe(method_family = none)]
379        pub unsafe fn implementorValueFromStringCallback(
380            &self,
381        ) -> AUImplementorValueFromStringCallback;
382
383        #[cfg(feature = "block2")]
384        /// Setter for [`implementorValueFromStringCallback`][Self::implementorValueFromStringCallback].
385        ///
386        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
387        ///
388        /// # Safety
389        ///
390        /// `implementor_value_from_string_callback` must be a valid pointer.
391        #[unsafe(method(setImplementorValueFromStringCallback:))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn setImplementorValueFromStringCallback(
394            &self,
395            implementor_value_from_string_callback: AUImplementorValueFromStringCallback,
396        );
397
398        #[cfg(feature = "block2")]
399        /// Called to obtain an abbreviated version of a parameter or group name.
400        ///
401        /// # Safety
402        ///
403        /// The returned block's argument 1 must be a valid pointer.
404        #[unsafe(method(implementorDisplayNameWithLengthCallback))]
405        #[unsafe(method_family = none)]
406        pub unsafe fn implementorDisplayNameWithLengthCallback(
407            &self,
408        ) -> AUImplementorDisplayNameWithLengthCallback;
409
410        #[cfg(feature = "block2")]
411        /// Setter for [`implementorDisplayNameWithLengthCallback`][Self::implementorDisplayNameWithLengthCallback].
412        ///
413        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
414        ///
415        /// # Safety
416        ///
417        /// `implementor_display_name_with_length_callback` must be a valid pointer.
418        #[unsafe(method(setImplementorDisplayNameWithLengthCallback:))]
419        #[unsafe(method_family = none)]
420        pub unsafe fn setImplementorDisplayNameWithLengthCallback(
421            &self,
422            implementor_display_name_with_length_callback: AUImplementorDisplayNameWithLengthCallback,
423        );
424    );
425}
426
427extern_class!(
428    /// Wraps a v2 audio unit in an AUAudioUnit subclass.
429    ///
430    /// Implementors of version 3 audio units may derive their implementations from
431    /// AUAudioUnitV2Bridge. It expects the component description with which it is initialized to
432    /// refer to a registered component with a v2 implementation using an
433    /// AudioComponentFactoryFunction. The bridge will instantiate the v2 audio unit via the factory
434    /// function and communicate it with it using the v2 AudioUnit API's (AudioUnitSetProperty,
435    /// etc.)
436    ///
437    /// Hosts should not access this class; it will be instantiated when needed when creating an
438    /// AUAudioUnit.
439    ///
440    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitv2bridge?language=objc)
441    #[unsafe(super(AUAudioUnit, NSObject))]
442    #[derive(Debug, PartialEq, Eq, Hash)]
443    #[cfg(feature = "AUAudioUnit")]
444    pub struct AUAudioUnitV2Bridge;
445);
446
447#[cfg(feature = "AUAudioUnit")]
448extern_conformance!(
449    unsafe impl NSObjectProtocol for AUAudioUnitV2Bridge {}
450);
451
452#[cfg(feature = "AUAudioUnit")]
453impl AUAudioUnitV2Bridge {
454    extern_methods!(
455        #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
456        /// The underlying v2 AudioUnit
457        ///
458        /// We generally discourage interacting with the underlying v2 AudioUnit directly and
459        /// recommend using the v3 equivalent methods and properties from AUAudioUnitV2Bridge.
460        ///
461        /// In some rare cases it may be desirable to interact with the v2 AudioUnit.
462        /// For example, a v2 plugin may define custom properties that are not bridged to v3.
463        /// Implementors can sublcass AUAudioUnitV2Bridge and call the v2 API methods
464        /// AudioUnitGetProperty / AudioUnitSetProperty with the v2 AudioUnit.
465        #[unsafe(method(audioUnit))]
466        #[unsafe(method_family = none)]
467        pub unsafe fn audioUnit(&self) -> AudioUnit;
468    );
469}
470
471/// Methods declared on superclass `AUAudioUnit`.
472#[cfg(feature = "AUAudioUnit")]
473impl AUAudioUnitV2Bridge {
474    extern_methods!(
475        #[unsafe(method(init))]
476        #[unsafe(method_family = init)]
477        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
478
479        #[cfg(feature = "AudioComponent")]
480        /// Designated initializer.
481        ///
482        /// Parameter `componentDescription`: A single AUAudioUnit subclass may implement multiple audio units, for example, an effect
483        /// that can also function as a generator, or a cluster of related effects. The component
484        /// description specifies the component which was instantiated.
485        ///
486        /// Parameter `options`: Options for loading the unit in-process or out-of-process.
487        ///
488        /// Parameter `outError`: Returned in the event of failure.
489        #[unsafe(method(initWithComponentDescription:options:error:_))]
490        #[unsafe(method_family = init)]
491        pub unsafe fn initWithComponentDescription_options_error(
492            this: Allocated<Self>,
493            component_description: AudioComponentDescription,
494            options: AudioComponentInstantiationOptions,
495        ) -> Result<Retained<Self>, Retained<NSError>>;
496
497        #[cfg(feature = "AudioComponent")]
498        /// Convenience initializer (omits options).
499        #[unsafe(method(initWithComponentDescription:error:_))]
500        #[unsafe(method_family = init)]
501        pub unsafe fn initWithComponentDescription_error(
502            this: Allocated<Self>,
503            component_description: AudioComponentDescription,
504        ) -> Result<Retained<Self>, Retained<NSError>>;
505    );
506}
507
508/// Methods declared on superclass `NSObject`.
509#[cfg(feature = "AUAudioUnit")]
510impl AUAudioUnitV2Bridge {
511    extern_methods!(
512        #[unsafe(method(new))]
513        #[unsafe(method_family = new)]
514        pub unsafe fn new() -> Retained<Self>;
515    );
516}
517
518extern_protocol!(
519    /// Protocol to which principal classes of v3 audio units (extensions) must conform.
520    ///
521    /// The principal class of a non-UI v3 audio unit extension will generally derive from NSObject
522    /// and implement this protocol.
523    ///
524    /// The principal class of a UI v3 audio unit extension must derive from AUViewController and
525    /// implement this protocol.
526    ///
527    /// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auaudiounitfactory?language=objc)
528    pub unsafe trait AUAudioUnitFactory: NSExtensionRequestHandling {
529        #[cfg(all(feature = "AUAudioUnit", feature = "AudioComponent"))]
530        /// Create an instance of an extension's AUAudioUnit.
531        ///
532        /// This method should create and return an instance of its audio unit.
533        ///
534        /// This method will be called only once per instance of the factory.
535        ///
536        /// Note that in non-ARC code, "create" methods return unretained objects (unlike "create"
537        /// C functions); the implementor should return an object with reference count 1 but
538        /// autoreleased.
539        #[unsafe(method(createAudioUnitWithComponentDescription:error:_))]
540        #[unsafe(method_family = none)]
541        unsafe fn createAudioUnitWithComponentDescription_error(
542            &self,
543            desc: AudioComponentDescription,
544        ) -> Result<Retained<AUAudioUnit>, Retained<NSError>>;
545    }
546);