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