objc2_audio_toolbox/generated/
MusicDevice.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-midi")]
7use objc2_core_midi::*;
8
9use crate::*;
10
11/// type for instrument identifiers
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdeviceinstrumentid?language=objc)
14pub type MusicDeviceInstrumentID = u32;
15
16/// convenience struct for specifying a note and velocity
17///
18///
19/// This struct is the common usage for MusicDeviceStartNote, as most synths that implement this functionality
20/// will only allow for the specification of a note number and velocity when starting a new note.
21///
22///
23/// Should be set to 2
24///
25/// The pitch of the new note, typically specified using a MIDI note number (and a fractional pitch) within the
26/// range of 0
27/// <
28/// 128. So 60 is middle C, 60.5 is middle C + 50 cents.
29///
30/// The velocity of the new note - this can be a fractional value - specified as MIDI (within the range of 0
31/// <
32/// 128)
33///
34/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicestdnoteparams?language=objc)
35#[repr(C)]
36#[derive(Clone, Copy, Debug, PartialEq)]
37pub struct MusicDeviceStdNoteParams {
38    pub argCount: u32,
39    pub mPitch: f32,
40    pub mVelocity: f32,
41}
42
43unsafe impl Encode for MusicDeviceStdNoteParams {
44    const ENCODING: Encoding = Encoding::Struct(
45        "MusicDeviceStdNoteParams",
46        &[<u32>::ENCODING, <f32>::ENCODING, <f32>::ENCODING],
47    );
48}
49
50unsafe impl RefEncode for MusicDeviceStdNoteParams {
51    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
52}
53
54/// used to describe a control and value
55///
56///
57/// This struct is used to describe a parameterID (a control in MIDI terminology, though it is not limited to
58/// MIDI CC specifications) and the value of this parameter.
59///
60///
61/// The parameter ID
62///
63/// The value of that parameter
64///
65/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/noteparamscontrolvalue?language=objc)
66#[cfg(feature = "AUComponent")]
67#[repr(C)]
68#[derive(Clone, Copy, Debug, PartialEq)]
69pub struct NoteParamsControlValue {
70    pub mID: AudioUnitParameterID,
71    pub mValue: AudioUnitParameterValue,
72}
73
74#[cfg(feature = "AUComponent")]
75unsafe impl Encode for NoteParamsControlValue {
76    const ENCODING: Encoding = Encoding::Struct(
77        "NoteParamsControlValue",
78        &[
79            <AudioUnitParameterID>::ENCODING,
80            <AudioUnitParameterValue>::ENCODING,
81        ],
82    );
83}
84
85#[cfg(feature = "AUComponent")]
86unsafe impl RefEncode for NoteParamsControlValue {
87    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
88}
89
90/// Used to hold the value of the inParams parameter for the MusicDeviceStartNote function.
91///
92///
93/// The generic version of this structure describes an arg count (which is the number of mControls values
94/// + 1 for mPitch and 1 for mVelocity). So, argCount should at least be two. See MusicDeviceStdNoteParams
95/// for the common use case, as many audio unit instruments will not respond to control values provided
96/// in the start note function
97///
98///
99/// The number of controls + 2 (for mPitch and mVelocity)
100///
101/// The pitch of the new note, typically specified using a MIDI note number (and a fractional pitch) within the
102/// range of 0
103/// <
104/// 128. So 60 is middle C, 60.5 is middle C + 50 cents.
105///
106/// The velocity of the new note - this can be a fractional value - specified as MIDI (within the range of 0
107/// <
108/// 128)
109///
110/// A variable length array with the number of elements: argCount - 2.
111///
112/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicenoteparams?language=objc)
113#[cfg(feature = "AUComponent")]
114#[repr(C)]
115#[derive(Clone, Copy, Debug, PartialEq)]
116pub struct MusicDeviceNoteParams {
117    pub argCount: u32,
118    pub mPitch: f32,
119    pub mVelocity: f32,
120    pub mControls: [NoteParamsControlValue; 1],
121}
122
123#[cfg(feature = "AUComponent")]
124unsafe impl Encode for MusicDeviceNoteParams {
125    const ENCODING: Encoding = Encoding::Struct(
126        "MusicDeviceNoteParams",
127        &[
128            <u32>::ENCODING,
129            <f32>::ENCODING,
130            <f32>::ENCODING,
131            <[NoteParamsControlValue; 1]>::ENCODING,
132        ],
133    );
134}
135
136#[cfg(feature = "AUComponent")]
137unsafe impl RefEncode for MusicDeviceNoteParams {
138    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
139}
140
141/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicnoteevent_usegroupinstrument?language=objc)
142pub const kMusicNoteEvent_UseGroupInstrument: c_uint = 0xFFFFFFFF;
143/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicnoteevent_unused?language=objc)
144pub const kMusicNoteEvent_Unused: c_uint = 0xFFFFFFFF;
145
146/// The type used to specify which group (channel number in MIDI) is used with a given command (new note,
147/// control or parameter value change)
148///
149/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicegroupid?language=objc)
150pub type MusicDeviceGroupID = u32;
151
152/// The type used to hold an unique identifier returned by MusicDeviceStartNote that is used to then address
153/// that note (typically to turn the note off). An ID must be used for notes, because notes can be specified
154/// by fractional pitches, and so using the MIDI note number is not sufficient to identify the note to turn
155/// it off (or to apply polyphonic after touch).
156///
157/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/noteinstanceid?language=objc)
158pub type NoteInstanceID = u32;
159
160/// The unique type of a MusicDevice audio unit (which is an AudioComponentInstance)
161///
162/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicecomponent?language=objc)
163#[cfg(feature = "AudioComponent")]
164pub type MusicDeviceComponent = AudioComponentInstance;
165
166extern "C-unwind" {
167    /// Used to sent MIDI channel messages to an audio unit
168    ///
169    ///
170    /// This is the API used to send MIDI channel messages to an audio unit. The status and data parameters
171    /// are used exactly as described by the MIDI specification, including the combination of channel and
172    /// command in the status byte. All events sent via MusicDeviceMIDIEventList will be delivered to the
173    /// audio unit in the MIDI protocol returned by kAudioUnitProperty_AudioUnitMIDIProtocol.
174    ///
175    ///
176    /// Parameter `inUnit`: The audio unit
177    ///
178    /// Parameter `inStatus`: The MIDI status byte
179    ///
180    /// Parameter `inData1`: The first MIDI data byte (value is in the range 0
181    /// <
182    /// 128)
183    ///
184    /// Parameter `inData2`: The second MIDI data byte (value is in the range 0
185    /// <
186    /// 128). If the MIDI status byte only has one
187    /// data byte, this should be set to zero.
188    ///
189    /// Parameter `inOffsetSampleFrame`: If you are scheduling the MIDI Event from the audio unit's render thread, then you can supply a
190    /// sample offset that the audio unit may apply when applying that event in its next audio unit render.
191    /// This allows you to schedule to the sample, the time when a MIDI command is applied and is particularly
192    /// important when starting new notes. If you are not scheduling in the audio unit's render thread,
193    /// then you should set this value to 0
194    ///
195    ///
196    /// Returns: noErr, or an audio unit error code
197    ///
198    /// # Safety
199    ///
200    /// `in_unit` must be a valid pointer.
201    #[cfg(feature = "AudioComponent")]
202    pub fn MusicDeviceMIDIEvent(
203        in_unit: MusicDeviceComponent,
204        in_status: u32,
205        in_data1: u32,
206        in_data2: u32,
207        in_offset_sample_frame: u32,
208    ) -> OSStatus;
209}
210
211extern "C-unwind" {
212    /// used to send any non-channel MIDI event to an audio unit
213    ///
214    ///
215    /// This is used to send any non-channel MIDI event to an audio unit. In practise this is a System Exclusive
216    /// (SysEx) MIDI message
217    ///
218    ///
219    /// Parameter `inUnit`: The audio unit
220    ///
221    /// Parameter `inData`: The complete MIDI SysEx message including the F0 and F7 start and termination bytes
222    ///
223    /// Parameter `inLength`: The size, in bytes, of the data
224    ///
225    ///
226    /// Returns: noErr, or an audio unit error code
227    ///
228    /// # Safety
229    ///
230    /// - `in_unit` must be a valid pointer.
231    /// - `in_data` must be a valid pointer.
232    #[cfg(feature = "AudioComponent")]
233    pub fn MusicDeviceSysEx(
234        in_unit: MusicDeviceComponent,
235        in_data: NonNull<u8>,
236        in_length: u32,
237    ) -> OSStatus;
238}
239
240extern "C-unwind" {
241    /// Used to send MIDI messages to an audio unit
242    ///
243    ///
244    /// This API is suitable for sending Universal MIDI Packet (UMP) MIDI messages to an audio unit. The message must be
245    /// a full non-SysEx event, a partial SysEx event, or a complete SysEx event. Running status is not allowed. MIDI 1.0 in
246    /// universal packets (MIDI-1UP) and MIDI 2.0 messages are allowed. All events sent via MusicDeviceMIDIEventList will
247    /// be delivered to the audio unit in the MIDI protocol returned by kAudioUnitProperty_AudioUnitMIDIProtocol.
248    ///
249    /// This is bridged to the v2 API property kAudioUnitProperty_MIDIOutputCallback.
250    ///
251    ///
252    /// Parameter `inUnit`: The audio unit
253    ///
254    /// Parameter `inOffsetSampleFrame`: If you are scheduling the MIDIEventList from the audio unit's render thread, then you can supply a
255    /// sample offset that the audio unit may apply within its next audio unit render.
256    /// This allows you to schedule to the sample, the time when a MIDI command is applied and is particularly
257    /// important when starting new notes. If you are not scheduling in the audio unit's render thread,
258    /// then you should set this value to 0
259    ///
260    /// inOffsetSampleFrame should serve as the base offset for each packet's timestamp i.e.
261    /// sampleOffset = inOffsetSampleFrame + evtList.packet[0].timeStamp
262    ///
263    ///
264    /// Parameter `evtList`: The MIDIEventList to be sent
265    ///
266    ///
267    /// Returns: noErr, or an audio unit error code
268    ///
269    /// # Safety
270    ///
271    /// - `in_unit` must be a valid pointer.
272    /// - `evt_list` must be a valid pointer.
273    #[cfg(all(feature = "AudioComponent", feature = "objc2-core-midi"))]
274    pub fn MusicDeviceMIDIEventList(
275        in_unit: MusicDeviceComponent,
276        in_offset_sample_frame: u32,
277        evt_list: NonNull<MIDIEventList>,
278    ) -> OSStatus;
279}
280
281extern "C-unwind" {
282    /// used to start a note
283    ///
284    ///
285    /// This function is used to start a note.  The caller must provide a NoteInstanceID to receive a
286    /// token that is then used to stop the note. The MusicDeviceStopNote call should be used to stop
287    /// notes started with this API. The token can also be used to address individual notes on the
288    /// kAudioUnitScope_Note if the audio unit supports it. The instrumentID is no longer used and the
289    /// kMusicNoteEvent_Unused constant should be specified (this takes the current patch for the
290    /// specifed group as the sound to use for the note).
291    ///
292    /// The Audio unit must provide an unique ID for the note instance ID. This ID must be non-zero and not
293    /// 0xFFFFFFFF (any other UInt32 value is valid).
294    ///
295    /// Not all Music Device audio units implement the semantics of this API (though it is strongly recommended
296    /// that they do). A host application shoudl query the kMusicDeviceProperty_SupportsStartStopNote to
297    /// check that this is supported.
298    ///
299    ///
300    /// Parameter `inUnit`: The audio unit
301    ///
302    /// Parameter `inInstrument`: The instrumentID is no longer used and the kMusicNoteEvent_Unused constant should be specified (this takes
303    /// the current patch for the specifed group as the sound to use for the note)
304    ///
305    /// Parameter `inGroupID`: The group ID that this note will be attached too. As with MIDI, all notes sounding on a groupID can be
306    /// controlled through the various parameters (such as pitch bend, etc) that can be specified on the Group
307    /// Scope
308    ///
309    /// Parameter `outNoteInstanceID`: A pointer to receive the token that is used to identify the note. This parameter must be specified
310    ///
311    /// Parameter `inOffsetSampleFrame`: If you are scheduling the MIDI Event from the audio unit's render thread, then you can supply a sample offset
312    /// that the audio unit may apply when starting the note in its next audio unit render. This allows you to
313    /// schedule to the sample and is particularly important when starting new notes. If you are not scheduling
314    /// in the audio unit's render thread, then you should set this value to 0
315    ///
316    /// Parameter `inParams`: The parameters to be used when starting the note - pitch and velocity must be specified
317    ///
318    ///
319    /// Returns: noErr, or an audio unit error code
320    ///
321    /// # Safety
322    ///
323    /// - `in_unit` must be a valid pointer.
324    /// - `out_note_instance_id` must be a valid pointer.
325    /// - `in_params` must be a valid pointer.
326    #[cfg(all(feature = "AUComponent", feature = "AudioComponent"))]
327    pub fn MusicDeviceStartNote(
328        in_unit: MusicDeviceComponent,
329        in_instrument: MusicDeviceInstrumentID,
330        in_group_id: MusicDeviceGroupID,
331        out_note_instance_id: NonNull<NoteInstanceID>,
332        in_offset_sample_frame: u32,
333        in_params: NonNull<MusicDeviceNoteParams>,
334    ) -> OSStatus;
335}
336
337extern "C-unwind" {
338    /// used to stop notes started with the MusicDeviceStartNote call
339    ///
340    ///
341    /// This call is used to stop notes that have been started with the MusicDeviceStartNote call; both the group ID
342    /// that the note was started on and the noteInstanceID should be specified.
343    ///
344    ///
345    /// Parameter `inUnit`: The audio unit
346    ///
347    /// Parameter `inGroupID`: the group ID
348    ///
349    /// Parameter `inNoteInstanceID`: the note instance ID
350    ///
351    /// Parameter `inOffsetSampleFrame`: the sample offset within the next buffer rendered that the note should be turned off at
352    ///
353    ///
354    /// Returns: noErr, or an audio unit error code
355    ///
356    /// # Safety
357    ///
358    /// `in_unit` must be a valid pointer.
359    #[cfg(feature = "AudioComponent")]
360    pub fn MusicDeviceStopNote(
361        in_unit: MusicDeviceComponent,
362        in_group_id: MusicDeviceGroupID,
363        in_note_instance_id: NoteInstanceID,
364        in_offset_sample_frame: u32,
365    ) -> OSStatus;
366}
367
368/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicerange?language=objc)
369pub const kMusicDeviceRange: c_uint = 0x0100;
370/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicemidieventselect?language=objc)
371pub const kMusicDeviceMIDIEventSelect: c_uint = 0x0101;
372/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicesysexselect?language=objc)
373pub const kMusicDeviceSysExSelect: c_uint = 0x0102;
374/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdeviceprepareinstrumentselect?language=objc)
375pub const kMusicDevicePrepareInstrumentSelect: c_uint = 0x0103;
376/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicereleaseinstrumentselect?language=objc)
377pub const kMusicDeviceReleaseInstrumentSelect: c_uint = 0x0104;
378/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicestartnoteselect?language=objc)
379pub const kMusicDeviceStartNoteSelect: c_uint = 0x0105;
380/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicestopnoteselect?language=objc)
381pub const kMusicDeviceStopNoteSelect: c_uint = 0x0106;
382/// [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/kmusicdevicemidieventlistselect?language=objc)
383pub const kMusicDeviceMIDIEventListSelect: c_uint = 0x0107;
384
385/// This proc can be exported through the FastDispatch property or is used as the prototype for
386/// an audio component dispatch for this selector.
387///
388/// The arguments are the same as are provided to the corresponding API call
389///
390///
391/// Parameter `self`: For a component manager component, this is the component instance storage pointer
392///
393///
394/// Returns: noErr, or an audio unit error code
395///
396/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicemidieventproc?language=objc)
397pub type MusicDeviceMIDIEventProc =
398    Option<unsafe extern "C-unwind" fn(NonNull<c_void>, u32, u32, u32, u32) -> OSStatus>;
399
400/// This proc can be exported through the FastDispatch property or is used as the prototype for
401/// an audio component dispatch for this selector.
402///
403/// The arguments are the same as are provided to the corresponding API call
404///
405///
406/// Parameter `self`: For a component manager component, this is the component instance storage pointer
407///
408///
409/// Returns: noErr, or an audio unit error code
410///
411/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicesysexproc?language=objc)
412pub type MusicDeviceSysExProc =
413    Option<unsafe extern "C-unwind" fn(NonNull<c_void>, NonNull<u8>, u32) -> OSStatus>;
414
415/// This proc can be exported through the FastDispatch property or is used as the prototype for
416/// an audio component dispatch for this selector.
417///
418/// The arguments are the same as are provided to the corresponding API call
419///
420///
421/// Parameter `self`: For a component manager component, this is the component instance storage pointer
422///
423///
424/// Returns: noErr, or an audio unit error code
425///
426/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicestartnoteproc?language=objc)
427#[cfg(feature = "AUComponent")]
428pub type MusicDeviceStartNoteProc = Option<
429    unsafe extern "C-unwind" fn(
430        NonNull<c_void>,
431        MusicDeviceInstrumentID,
432        MusicDeviceGroupID,
433        NonNull<NoteInstanceID>,
434        u32,
435        NonNull<MusicDeviceNoteParams>,
436    ) -> OSStatus,
437>;
438
439/// This proc can be exported through the FastDispatch property or is used as the prototype for
440/// an audio component dispatch for this selector.
441///
442/// The arguments are the same as are provided to the corresponding API call
443///
444///
445/// Parameter `self`: For a component manager component, this is the component instance storage pointer
446///
447///
448/// Returns: noErr, or an audio unit error code
449///
450/// See also [Apple's documentation](https://developer.apple.com/documentation/audiotoolbox/musicdevicestopnoteproc?language=objc)
451pub type MusicDeviceStopNoteProc = Option<
452    unsafe extern "C-unwind" fn(
453        NonNull<c_void>,
454        MusicDeviceGroupID,
455        NoteInstanceID,
456        u32,
457    ) -> OSStatus,
458>;
459
460extern "C-unwind" {
461    /// # Safety
462    ///
463    /// `in_unit` must be a valid pointer.
464    #[cfg(feature = "AudioComponent")]
465    #[deprecated = "no longer supported"]
466    pub fn MusicDevicePrepareInstrument(
467        in_unit: MusicDeviceComponent,
468        in_instrument: MusicDeviceInstrumentID,
469    ) -> OSStatus;
470}
471
472extern "C-unwind" {
473    /// # Safety
474    ///
475    /// `in_unit` must be a valid pointer.
476    #[cfg(feature = "AudioComponent")]
477    #[deprecated = "no longer supported"]
478    pub fn MusicDeviceReleaseInstrument(
479        in_unit: MusicDeviceComponent,
480        in_instrument: MusicDeviceInstrumentID,
481    ) -> OSStatus;
482}