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 #[cfg(all(
140 feature = "AUComponent",
141 feature = "AudioComponent",
142 feature = "block2",
143 feature = "dispatch2"
144 ))]
145 pub fn AUListenerCreateWithDispatchQueue(
146 out_listener: NonNull<AUParameterListenerRef>,
147 in_notification_interval: f32,
148 in_dispatch_queue: &DispatchQueue,
149 in_block: AUParameterListenerBlock,
150 ) -> OSStatus;
151}
152
153extern "C-unwind" {
154 /// Create an object for fielding notifications when AudioUnit parameter values change.
155 ///
156 /// Parameter `inProc`: Function called when the parameter's value changes.
157 ///
158 /// Parameter `inUserData`: A reference value for the use of the callback function.
159 ///
160 /// Parameter `inRunLoop`: The run loop on which the callback is called. If NULL,
161 /// CFRunLoopGetCurrent() is used.
162 ///
163 /// Parameter `inRunLoopMode`: The run loop mode in which the callback's underlying run loop source will be
164 /// attached. If NULL, kCFRunLoopDefaultMode is used.
165 ///
166 /// Parameter `inNotificationInterval`: The minimum time interval, in seconds, at which the callback will be called.
167 /// If multiple parameter value changes occur within this time interval, the
168 /// listener will only receive a notification for the last value change that
169 /// occurred before the callback. If inNotificationInterval is 0, the inRunLoop
170 /// and inRunLoopMode arguments are ignored, and the callback will be issued
171 /// immediately, on the thread on which the parameter was changed.
172 ///
173 /// Parameter `outListener`: On successful return, an AUParameterListenerRef.
174 ///
175 /// Note that only parameter changes issued through AUParameterSet will generate
176 /// notifications to listeners; thus, in most cases, AudioUnit clients should use
177 /// AUParameterSet in preference to AudioUnitSetParameter.
178 #[cfg(all(
179 feature = "AUComponent",
180 feature = "AudioComponent",
181 feature = "objc2-core-foundation"
182 ))]
183 pub fn AUListenerCreate(
184 in_proc: AUParameterListenerProc,
185 in_user_data: NonNull<c_void>,
186 in_run_loop: Option<&CFRunLoop>,
187 in_run_loop_mode: Option<&CFString>,
188 in_notification_interval: f32,
189 out_listener: NonNull<AUParameterListenerRef>,
190 ) -> OSStatus;
191}
192
193extern "C-unwind" {
194 /// Dispose a parameter listener object.
195 ///
196 /// Parameter `inListener`: The parameter listener to dispose.
197 pub fn AUListenerDispose(in_listener: AUParameterListenerRef) -> OSStatus;
198}
199
200extern "C-unwind" {
201 /// Connect a parameter to a listener.
202 ///
203 /// Parameter `inListener`: The parameter listener which will receive the callback.
204 ///
205 /// Parameter `inObject`: The object which is interested in the value of the parameter. This will be
206 /// passed as the inObject parameter to the listener callback function when the
207 /// parameter changes.
208 ///
209 /// Parameter `inParameter`: The parameter whose value changes are to generate callbacks.
210 ///
211 /// Associates an arbitrary object (often a user interface widget) with an
212 /// AudioUnitParameter, and delivers notifications to the specified listener, telling it
213 /// that the object needs to be informed of the parameter's value change.
214 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
215 pub fn AUListenerAddParameter(
216 in_listener: AUParameterListenerRef,
217 in_object: *mut c_void,
218 in_parameter: NonNull<AudioUnitParameter>,
219 ) -> OSStatus;
220}
221
222extern "C-unwind" {
223 /// Remove a parameter/listener connection.
224 ///
225 /// Parameter `inListener`: The parameter listener to stop receiving callbacks.
226 ///
227 /// Parameter `inObject`: The object which is no longer interested in the value of the parameter.
228 ///
229 /// Parameter `inParameter`: The parameter whose value changes are to stop generating callbacks.
230 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
231 pub fn AUListenerRemoveParameter(
232 in_listener: AUParameterListenerRef,
233 in_object: *mut c_void,
234 in_parameter: NonNull<AudioUnitParameter>,
235 ) -> OSStatus;
236}
237
238extern "C-unwind" {
239 /// Set an AudioUnit parameter value and notify listeners.
240 ///
241 /// Parameter `inSendingListener`: A parameter listener generating the change and which does not want to
242 /// receive a callback as a result of it. May be NULL.
243 ///
244 /// Parameter `inSendingObject`: The object generating the change and which does not want to receive a
245 /// callback as a result of it. NULL is treated specially when inListener is
246 /// non-null; it signifies that none of the specified listener's objects will
247 /// receive notifications.
248 ///
249 /// Parameter `inParameter`: The parameter being changed.
250 ///
251 /// Parameter `inValue`: The new value of the parameter.
252 ///
253 /// Parameter `inBufferOffsetInFrames`: The offset into the next rendered buffer at which the parameter change will take
254 /// effect.
255 ///
256 /// Calls AudioUnitSetParameter, and performs/schedules notification callbacks to all
257 /// parameter listeners, for that parameter -- except that no callback will be generated to
258 /// the inListener/inObject pair.
259 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
260 pub fn AUParameterSet(
261 in_sending_listener: AUParameterListenerRef,
262 in_sending_object: *mut c_void,
263 in_parameter: NonNull<AudioUnitParameter>,
264 in_value: AudioUnitParameterValue,
265 in_buffer_offset_in_frames: u32,
266 ) -> OSStatus;
267}
268
269extern "C-unwind" {
270 /// Notify listeners of a past parameter change.
271 ///
272 /// Parameter `inSendingListener`: A parameter listener generating the change and which does not want to
273 /// receive a callback as a result of it. May be NULL.
274 ///
275 /// Parameter `inSendingObject`: The object generating the change and which does not want to receive a
276 /// callback as a result of it. NULL is treated specially when inListener is
277 /// non-null; it signifies that none of the specified listener's objects will
278 /// receive notifications.
279 ///
280 /// Parameter `inParameter`: The parameter which was changed.
281 ///
282 /// Performs and schedules the notification callbacks of AUParameterSet, without
283 /// actually setting an AudioUnit parameter value.
284 ///
285 /// Clients scheduling ramped parameter changes to AudioUnits must make this call
286 /// dynamically during playback in order for AudioUnitViews to be updated. When the view's
287 /// listener receives a notification, it will be passed the current value of the parameter.
288 ///
289 /// A special meaning is applied if the mParameterID value of inParameter is equal to
290 /// kAUParameterListener_AnyParameter. In this case, ANY listener for ANY parameter value
291 /// changes on the specified AudioUnit will be notified of the current value of that
292 /// parameter.
293 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
294 pub fn AUParameterListenerNotify(
295 in_sending_listener: AUParameterListenerRef,
296 in_sending_object: *mut c_void,
297 in_parameter: NonNull<AudioUnitParameter>,
298 ) -> OSStatus;
299}
300
301extern "C-unwind" {
302 /// Converts a linear value to a parameter value according to the parameter's units.
303 ///
304 ///
305 /// Parameter `inLinearValue`: The linear value (0.0-1.0) to convert.
306 ///
307 /// Parameter `inParameter`: The parameter, including its Audio Unit, that will define the conversion of
308 /// the supplied linear value to a value that is natural to that parameter.
309 ///
310 /// Returns: The converted parameter value, in the parameter's natural units.
311 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
312 pub fn AUParameterValueFromLinear(
313 in_linear_value: f32,
314 in_parameter: NonNull<AudioUnitParameter>,
315 ) -> AudioUnitParameterValue;
316}
317
318extern "C-unwind" {
319 /// Converts a parameter value to a linear value according to the parameter's units.
320 ///
321 ///
322 /// Parameter `inParameterValue`: The value in the natural units of the specified parameter.
323 ///
324 ///
325 /// Parameter `inParameter`: The parameter, including its Audio Unit, that will define the conversion of
326 /// the supplied parameter value to a corresponding linear value.
327 ///
328 /// Returns: A number 0.0-1.0.
329 #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
330 pub fn AUParameterValueToLinear(
331 in_parameter_value: AudioUnitParameterValue,
332 in_parameter: NonNull<AudioUnitParameter>,
333 ) -> f32;
334}
335
336/// Format a parameter value into a string.
337///
338/// Parameter `inParameterValue`: The parameter value to be formatted.
339///
340/// Parameter `inParameter`: The Audio Unit, scope, element, and parameter whose value this is.
341///
342/// Parameter `inTextBuffer`: The character array to receive the formatted text. Should be at least 32
343/// characters.
344///
345/// Parameter `inDigits`: The resolution of the string (see example above).
346///
347/// Returns: `inTextBuffer`
348///
349///
350/// Formats a floating point value into a string. Computes a power of 10 to which the value
351/// will be rounded and displayed as follows: if the the parameter is logarithmic (Hertz),
352/// the number of significant digits is inDigits - pow10(inParameterValue) + 1. Otherwise,
353/// it is inDigits - pow10(maxValue - minValue) + 1.
354///
355/// Example for inDigits=3:
356///
357/// pow10 | range | digits after decimal place display
358/// ------|--------------|------------------------------------
359/// -2 | .0100-.0999 | 4
360/// -1 | .100-.999 | 3
361/// 0 | 1.00-9.99 | 2
362/// 1 | 10.0-99.9 | 1
363/// 2 | 100-999 | 0
364/// 3 | 1000-9990 | -1
365/// 4 | 10000-99900 | -2
366#[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
367#[inline]
368pub unsafe extern "C-unwind" fn AUParameterFormatValue(
369 in_parameter_value: f64,
370 in_parameter: NonNull<AudioUnitParameter>,
371 in_text_buffer: NonNull<c_char>,
372 in_digits: u32,
373) -> NonNull<c_char> {
374 extern "C-unwind" {
375 fn AUParameterFormatValue(
376 in_parameter_value: f64,
377 in_parameter: NonNull<AudioUnitParameter>,
378 in_text_buffer: NonNull<c_char>,
379 in_digits: u32,
380 ) -> Option<NonNull<c_char>>;
381 }
382 let ret = unsafe {
383 AUParameterFormatValue(in_parameter_value, in_parameter, in_text_buffer, in_digits)
384 };
385 ret.expect("function was marked as returning non-null, but actually returned NULL")
386}