objc2_audio_toolbox/generated/
AudioUnitUtilities.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "dispatch2")]
8use dispatch2::*;
9use objc2::__framework_prelude::*;
10#[cfg(feature = "objc2-core-foundation")]
11use objc2_core_foundation::*;
12
13use crate::*;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kauparameterlistener_anyparameter?language=objc)
16#[cfg(feature = "AUComponent")]
17pub const kAUParameterListener_AnyParameter: AudioUnitParameterID = 0xFFFFFFFF;
18
19/// Types of Audio Unit Events.
20///
21///
22/// The event is a change to a parameter value
23///
24/// The event signifies a gesture (e.g. mouse-down) beginning a potential series of
25/// related parameter value change events.
26///
27/// The event signifies a gesture (e.g. mouse-up) ending a series of related
28/// parameter value change events.
29///
30/// The event is a change to a property value.
31///
32/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/audiouniteventtype?language=objc)
33// NS_ENUM
34#[repr(transparent)]
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
36pub struct AudioUnitEventType(pub u32);
37impl AudioUnitEventType {
38    #[doc(alias = "kAudioUnitEvent_ParameterValueChange")]
39    pub const ParameterValueChange: Self = Self(0);
40    #[doc(alias = "kAudioUnitEvent_BeginParameterChangeGesture")]
41    pub const BeginParameterChangeGesture: Self = Self(1);
42    #[doc(alias = "kAudioUnitEvent_EndParameterChangeGesture")]
43    pub const EndParameterChangeGesture: Self = Self(2);
44    #[doc(alias = "kAudioUnitEvent_PropertyChange")]
45    pub const PropertyChange: Self = Self(3);
46}
47
48unsafe impl Encode for AudioUnitEventType {
49    const ENCODING: Encoding = u32::ENCODING;
50}
51
52unsafe impl RefEncode for AudioUnitEventType {
53    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
54}
55
56/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aulistenerbase?language=objc)
57#[repr(C)]
58#[derive(Debug)]
59pub struct AUListenerBase {
60    inner: [u8; 0],
61    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
62}
63
64unsafe impl RefEncode for AUListenerBase {
65    const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("AUListenerBase", &[]));
66}
67
68/// An object which receives notifications of Audio Unit parameter value changes.
69///
70/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auparameterlistenerref?language=objc)
71pub type AUParameterListenerRef = *mut AUListenerBase;
72
73/// An object which receives Audio Unit events.
74///
75/// An AUEventListenerRef may be passed to API's taking an AUEventListenerRef
76/// as an argument.
77///
78/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/aueventlistenerref?language=objc)
79pub type AUEventListenerRef = AUParameterListenerRef;
80
81/// A block called when a parameter value changes.
82///
83/// Parameter `inObject`: The object which generated the parameter change.
84///
85/// Parameter `inParameter`: Signifies the parameter whose value changed.
86///
87/// Parameter `inValue`: The parameter's new value.
88///
89/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auparameterlistenerblock?language=objc)
90#[cfg(all(
91    feature = "AUComponent",
92    feature = "AudioComponent",
93    feature = "block2"
94))]
95pub type AUParameterListenerBlock = *mut block2::DynBlock<
96    dyn Fn(*mut c_void, NonNull<AudioUnitParameter>, AudioUnitParameterValue),
97>;
98
99/// A function called when a parameter value changes.
100///
101/// Parameter `inUserData`: The value passed to AUListenerCreate when the callback function was installed.
102///
103/// Parameter `inObject`: The object which generated the parameter change.
104///
105/// Parameter `inParameter`: Signifies the parameter whose value changed.
106///
107/// Parameter `inValue`: The parameter's new value.
108///
109/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/auparameterlistenerproc?language=objc)
110#[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
111pub type AUParameterListenerProc = Option<
112    unsafe extern "C-unwind" fn(
113        *mut c_void,
114        *mut c_void,
115        NonNull<AudioUnitParameter>,
116        AudioUnitParameterValue,
117    ),
118>;
119
120extern "C-unwind" {
121    /// Create an object for fielding notifications when AudioUnit parameter values change.
122    ///
123    /// Parameter `outListener`: On successful return, an AUParameterListenerRef.
124    ///
125    /// Parameter `inNotificationInterval`: The minimum time interval, in seconds, at which the callback will be called.
126    /// If multiple parameter value changes occur within this time interval, the
127    /// listener will only receive a notification for the last value change that
128    /// occurred before the callback.  If inNotificationInterval is 0, the inRunLoop
129    /// and inRunLoopMode arguments are ignored, and the callback will be issued
130    /// immediately, on the thread on which the parameter was changed.
131    ///
132    /// Parameter `inDispatchQueue`: Dispatch queue on which the callback is called.
133    ///
134    /// Parameter `inBlock`: Block called when the parameter's value changes.
135    ///
136    /// Note that only parameter changes issued through AUParameterSet will generate
137    /// notifications to listeners; thus, in most cases, AudioUnit clients should use
138    /// AUParameterSet in preference to AudioUnitSetParameterValue.
139    ///
140    /// # Safety
141    ///
142    /// - `out_listener` must be a valid pointer.
143    /// - `in_dispatch_queue` possibly has additional threading requirements.
144    /// - `in_block` must be a valid pointer.
145    #[cfg(all(
146        feature = "AUComponent",
147        feature = "AudioComponent",
148        feature = "block2",
149        feature = "dispatch2"
150    ))]
151    pub fn AUListenerCreateWithDispatchQueue(
152        out_listener: NonNull<AUParameterListenerRef>,
153        in_notification_interval: f32,
154        in_dispatch_queue: &DispatchQueue,
155        in_block: AUParameterListenerBlock,
156    ) -> OSStatus;
157}
158
159extern "C-unwind" {
160    /// Create an object for fielding notifications when AudioUnit parameter values change.
161    ///
162    /// Parameter `inProc`: Function called when the parameter's value changes.
163    ///
164    /// Parameter `inUserData`: A reference value for the use of the callback function.
165    ///
166    /// Parameter `inRunLoop`: The run loop on which the callback is called.  If NULL,
167    /// CFRunLoopGetCurrent() is used.
168    ///
169    /// Parameter `inRunLoopMode`: The run loop mode in which the callback's underlying run loop source will be
170    /// attached.  If NULL, kCFRunLoopDefaultMode is used.
171    ///
172    /// Parameter `inNotificationInterval`: The minimum time interval, in seconds, at which the callback will be called.
173    /// If multiple parameter value changes occur within this time interval, the
174    /// listener will only receive a notification for the last value change that
175    /// occurred before the callback.  If inNotificationInterval is 0, the inRunLoop
176    /// and inRunLoopMode arguments are ignored, and the callback will be issued
177    /// immediately, on the thread on which the parameter was changed.
178    ///
179    /// Parameter `outListener`: On successful return, an AUParameterListenerRef.
180    ///
181    /// Note that only parameter changes issued through AUParameterSet will generate
182    /// notifications to listeners; thus, in most cases, AudioUnit clients should use
183    /// AUParameterSet in preference to AudioUnitSetParameter.
184    ///
185    /// # Safety
186    ///
187    /// - `in_proc` must be implemented correctly.
188    /// - `in_user_data` must be a valid pointer.
189    /// - `in_run_loop` possibly has additional threading requirements.
190    /// - `out_listener` must be a valid pointer.
191    #[cfg(all(
192        feature = "AUComponent",
193        feature = "AudioComponent",
194        feature = "objc2-core-foundation"
195    ))]
196    pub fn AUListenerCreate(
197        in_proc: AUParameterListenerProc,
198        in_user_data: NonNull<c_void>,
199        in_run_loop: Option<&CFRunLoop>,
200        in_run_loop_mode: Option<&CFString>,
201        in_notification_interval: f32,
202        out_listener: NonNull<AUParameterListenerRef>,
203    ) -> OSStatus;
204}
205
206extern "C-unwind" {
207    /// Dispose a parameter listener object.
208    ///
209    /// Parameter `inListener`: The parameter listener to dispose.
210    ///
211    /// # Safety
212    ///
213    /// `in_listener` must be a valid pointer.
214    pub fn AUListenerDispose(in_listener: AUParameterListenerRef) -> OSStatus;
215}
216
217extern "C-unwind" {
218    /// Connect a parameter to a listener.
219    ///
220    /// Parameter `inListener`: The parameter listener which will receive the callback.
221    ///
222    /// Parameter `inObject`: The object which is interested in the value of the parameter.  This will be
223    /// passed as the inObject parameter to the listener callback function when the
224    /// parameter changes.
225    ///
226    /// Parameter `inParameter`: The parameter whose value changes are to generate callbacks.
227    ///
228    /// Associates an arbitrary object (often a user interface widget) with an
229    /// AudioUnitParameter, and delivers notifications to the specified listener, telling it
230    /// that the object needs to be informed of the parameter's value change.
231    ///
232    /// # Safety
233    ///
234    /// - `in_listener` must be a valid pointer.
235    /// - `in_object` must be a valid pointer or null.
236    /// - `in_parameter` must be a valid pointer.
237    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
238    pub fn AUListenerAddParameter(
239        in_listener: AUParameterListenerRef,
240        in_object: *mut c_void,
241        in_parameter: NonNull<AudioUnitParameter>,
242    ) -> OSStatus;
243}
244
245extern "C-unwind" {
246    /// Remove a parameter/listener connection.
247    ///
248    /// Parameter `inListener`: The parameter listener to stop receiving callbacks.
249    ///
250    /// Parameter `inObject`: The object which is no longer interested in the value of the parameter.
251    ///
252    /// Parameter `inParameter`: The parameter whose value changes are to stop generating callbacks.
253    ///
254    /// # Safety
255    ///
256    /// - `in_listener` must be a valid pointer.
257    /// - `in_object` must be a valid pointer or null.
258    /// - `in_parameter` must be a valid pointer.
259    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
260    pub fn AUListenerRemoveParameter(
261        in_listener: AUParameterListenerRef,
262        in_object: *mut c_void,
263        in_parameter: NonNull<AudioUnitParameter>,
264    ) -> OSStatus;
265}
266
267extern "C-unwind" {
268    /// Set an AudioUnit parameter value and notify listeners.
269    ///
270    /// Parameter `inSendingListener`: A parameter listener generating the change and which does not want to
271    /// receive a callback as a result of it. May be NULL.
272    ///
273    /// Parameter `inSendingObject`: The object generating the change and which does not want to receive a
274    /// callback as a result of it. NULL is treated specially when inListener is
275    /// non-null; it signifies that none of the specified listener's objects will
276    /// receive notifications.
277    ///
278    /// Parameter `inParameter`: The parameter being changed.
279    ///
280    /// Parameter `inValue`: The new value of the parameter.
281    ///
282    /// Parameter `inBufferOffsetInFrames`: The offset into the next rendered buffer at which the parameter change will take
283    /// effect.
284    ///
285    /// Calls AudioUnitSetParameter, and performs/schedules notification callbacks to all
286    /// parameter listeners, for that parameter -- except that no callback will be generated to
287    /// the inListener/inObject pair.
288    ///
289    /// # Safety
290    ///
291    /// - `in_sending_listener` must be a valid pointer or null.
292    /// - `in_sending_object` must be a valid pointer or null.
293    /// - `in_parameter` must be a valid pointer.
294    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
295    pub fn AUParameterSet(
296        in_sending_listener: AUParameterListenerRef,
297        in_sending_object: *mut c_void,
298        in_parameter: NonNull<AudioUnitParameter>,
299        in_value: AudioUnitParameterValue,
300        in_buffer_offset_in_frames: u32,
301    ) -> OSStatus;
302}
303
304extern "C-unwind" {
305    /// Notify listeners of a past parameter change.
306    ///
307    /// Parameter `inSendingListener`: A parameter listener generating the change and which does not want to
308    /// receive a callback as a result of it. May be NULL.
309    ///
310    /// Parameter `inSendingObject`: The object generating the change and which does not want to receive a
311    /// callback as a result of it. NULL is treated specially when inListener is
312    /// non-null; it signifies that none of the specified listener's objects will
313    /// receive notifications.
314    ///
315    /// Parameter `inParameter`: The parameter which was changed.
316    ///
317    /// Performs and schedules the notification callbacks of AUParameterSet, without
318    /// actually setting an AudioUnit parameter value.
319    ///
320    /// Clients scheduling ramped parameter changes to AudioUnits must make this call
321    /// dynamically during playback in order for AudioUnitViews to be updated.  When the view's
322    /// listener receives a notification, it will be passed the current value of the parameter.
323    ///
324    /// A special meaning is applied if the mParameterID value of inParameter is equal to
325    /// kAUParameterListener_AnyParameter. In this case, ANY listener for ANY parameter value
326    /// changes on the specified AudioUnit will be notified of the current value of that
327    /// parameter.
328    ///
329    /// # Safety
330    ///
331    /// - `in_sending_listener` must be a valid pointer or null.
332    /// - `in_sending_object` must be a valid pointer or null.
333    /// - `in_parameter` must be a valid pointer.
334    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
335    pub fn AUParameterListenerNotify(
336        in_sending_listener: AUParameterListenerRef,
337        in_sending_object: *mut c_void,
338        in_parameter: NonNull<AudioUnitParameter>,
339    ) -> OSStatus;
340}
341
342extern "C-unwind" {
343    /// Converts a linear value to a parameter value according to the parameter's units.
344    ///
345    ///
346    /// Parameter `inLinearValue`: The linear value (0.0-1.0) to convert.
347    ///
348    /// Parameter `inParameter`: The parameter, including its Audio Unit, that will define the conversion of
349    /// the supplied linear value to a value that is natural to that parameter.
350    ///
351    /// Returns: The converted parameter value, in the parameter's natural units.
352    ///
353    /// # Safety
354    ///
355    /// `in_parameter` must be a valid pointer.
356    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
357    pub fn AUParameterValueFromLinear(
358        in_linear_value: f32,
359        in_parameter: NonNull<AudioUnitParameter>,
360    ) -> AudioUnitParameterValue;
361}
362
363extern "C-unwind" {
364    /// Converts a parameter value to a linear value according to the parameter's units.
365    ///
366    ///
367    /// Parameter `inParameterValue`: The value in the natural units of the specified parameter.
368    ///
369    ///
370    /// Parameter `inParameter`: The parameter, including its Audio Unit, that will define the conversion of
371    /// the supplied parameter value to a corresponding linear value.
372    ///
373    /// Returns: A number 0.0-1.0.
374    ///
375    /// # Safety
376    ///
377    /// `in_parameter` must be a valid pointer.
378    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
379    pub fn AUParameterValueToLinear(
380        in_parameter_value: AudioUnitParameterValue,
381        in_parameter: NonNull<AudioUnitParameter>,
382    ) -> f32;
383}
384
385/// Format a parameter value into a string.
386///
387/// Parameter `inParameterValue`: The parameter value to be formatted.
388///
389/// Parameter `inParameter`: The Audio Unit, scope, element, and parameter whose value this is.
390///
391/// Parameter `inTextBuffer`: The character array to receive the formatted text.  Should be at least 32
392/// characters.
393///
394/// Parameter `inDigits`: The resolution of the string (see example above).
395///
396/// Returns: `inTextBuffer`
397///
398///
399/// Formats a floating point value into a string.  Computes a power of 10 to which the value
400/// will be rounded and displayed as follows:  if the the parameter is logarithmic (Hertz),
401/// the number of significant digits is inDigits - pow10(inParameterValue) + 1.  Otherwise,
402/// it is inDigits - pow10(maxValue - minValue) + 1.
403///
404/// Example for inDigits=3:
405///
406/// pow10 | range        |  digits after decimal place display
407/// ------|--------------|------------------------------------
408/// -2    | .0100-.0999  |  4
409/// -1    | .100-.999    |  3
410/// 0     | 1.00-9.99    |  2
411/// 1     | 10.0-99.9    |  1
412/// 2     | 100-999      |  0
413/// 3     | 1000-9990    |  -1
414/// 4     | 10000-99900  |  -2
415///
416/// # Safety
417///
418/// - `in_parameter` must be a valid pointer.
419/// - `in_text_buffer` must be a valid pointer.
420#[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
421#[inline]
422pub unsafe extern "C-unwind" fn AUParameterFormatValue(
423    in_parameter_value: f64,
424    in_parameter: NonNull<AudioUnitParameter>,
425    in_text_buffer: NonNull<c_char>,
426    in_digits: u32,
427) -> NonNull<c_char> {
428    extern "C-unwind" {
429        fn AUParameterFormatValue(
430            in_parameter_value: f64,
431            in_parameter: NonNull<AudioUnitParameter>,
432            in_text_buffer: NonNull<c_char>,
433            in_digits: u32,
434        ) -> Option<NonNull<c_char>>;
435    }
436    let ret = unsafe {
437        AUParameterFormatValue(in_parameter_value, in_parameter, in_text_buffer, in_digits)
438    };
439    ret.expect("function was marked as returning non-null, but actually returned NULL")
440}