objc2_avf_audio/generated/
AVAudioSequencer.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::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// Determines whether data on different MIDI channels is mapped to multiple tracks, or
13/// if the tracks are preserved as-is.
14///
15/// If AVMusicSequenceLoadSMF_ChannelsToTracks is set, the loaded MIDI Sequence will contain a
16/// tempo track, one track for each MIDI channel that is found in the SMF, and one track for
17/// SysEx and/or MetaEvents (this will be the last track in the sequence).
18///
19/// If AVMusicSequenceLoadSMF_ChannelsToTracks is not set, the loadad MIDI Sequence will
20/// contain one track for each track that is found in the SMF, plus a tempo track (if not found
21/// in the SMF).
22///
23/// API_AVAILABLE(macos(10.11), ios(9.0), watchos(2.0), tvos(9.0))
24///
25/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusicsequenceloadoptions?language=objc)
26// NS_OPTIONS
27#[repr(transparent)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29pub struct AVMusicSequenceLoadOptions(pub NSUInteger);
30bitflags::bitflags! {
31    impl AVMusicSequenceLoadOptions: NSUInteger {
32        #[doc(alias = "AVMusicSequenceLoadSMF_PreserveTracks")]
33        const SMF_PreserveTracks = 0;
34        #[doc(alias = "AVMusicSequenceLoadSMF_ChannelsToTracks")]
35        const SMF_ChannelsToTracks = 1<<0;
36    }
37}
38
39unsafe impl Encode for AVMusicSequenceLoadOptions {
40    const ENCODING: Encoding = NSUInteger::ENCODING;
41}
42
43unsafe impl RefEncode for AVMusicSequenceLoadOptions {
44    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
45}
46
47/// Used to describe a specific time range within an AVMusicTrack.
48///
49/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avbeatrange?language=objc)
50#[cfg(feature = "AVAudioTypes")]
51#[repr(C)]
52#[derive(Clone, Copy, Debug, PartialEq)]
53pub struct AVBeatRange {
54    pub start: AVMusicTimeStamp,
55    pub length: AVMusicTimeStamp,
56}
57
58#[cfg(feature = "AVAudioTypes")]
59unsafe impl Encode for AVBeatRange {
60    const ENCODING: Encoding = Encoding::Struct(
61        "_AVBeatRange",
62        &[<AVMusicTimeStamp>::ENCODING, <AVMusicTimeStamp>::ENCODING],
63    );
64}
65
66#[cfg(feature = "AVAudioTypes")]
67unsafe impl RefEncode for AVBeatRange {
68    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
69}
70
71// TODO: pub fn AVMakeBeatRange(start_beat: AVMusicTimeStamp,length_in_beats: AVMusicTimeStamp,) -> AVBeatRange;
72
73/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykey?language=objc)
74// NS_TYPED_ENUM
75pub type AVAudioSequencerInfoDictionaryKey = NSString;
76
77extern "C" {
78    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyalbum?language=objc)
79    pub static AVAudioSequencerInfoDictionaryKeyAlbum: &'static AVAudioSequencerInfoDictionaryKey;
80}
81
82extern "C" {
83    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyapproximatedurationinseconds?language=objc)
84    pub static AVAudioSequencerInfoDictionaryKeyApproximateDurationInSeconds:
85        &'static AVAudioSequencerInfoDictionaryKey;
86}
87
88extern "C" {
89    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyartist?language=objc)
90    pub static AVAudioSequencerInfoDictionaryKeyArtist: &'static AVAudioSequencerInfoDictionaryKey;
91}
92
93extern "C" {
94    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeychannellayout?language=objc)
95    pub static AVAudioSequencerInfoDictionaryKeyChannelLayout:
96        &'static AVAudioSequencerInfoDictionaryKey;
97}
98
99extern "C" {
100    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeycomments?language=objc)
101    pub static AVAudioSequencerInfoDictionaryKeyComments:
102        &'static AVAudioSequencerInfoDictionaryKey;
103}
104
105extern "C" {
106    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeycomposer?language=objc)
107    pub static AVAudioSequencerInfoDictionaryKeyComposer:
108        &'static AVAudioSequencerInfoDictionaryKey;
109}
110
111extern "C" {
112    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeycopyright?language=objc)
113    pub static AVAudioSequencerInfoDictionaryKeyCopyright:
114        &'static AVAudioSequencerInfoDictionaryKey;
115}
116
117extern "C" {
118    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyencodingapplication?language=objc)
119    pub static AVAudioSequencerInfoDictionaryKeyEncodingApplication:
120        &'static AVAudioSequencerInfoDictionaryKey;
121}
122
123extern "C" {
124    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeygenre?language=objc)
125    pub static AVAudioSequencerInfoDictionaryKeyGenre: &'static AVAudioSequencerInfoDictionaryKey;
126}
127
128extern "C" {
129    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyisrc?language=objc)
130    pub static AVAudioSequencerInfoDictionaryKeyISRC: &'static AVAudioSequencerInfoDictionaryKey;
131}
132
133extern "C" {
134    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeykeysignature?language=objc)
135    pub static AVAudioSequencerInfoDictionaryKeyKeySignature:
136        &'static AVAudioSequencerInfoDictionaryKey;
137}
138
139extern "C" {
140    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeylyricist?language=objc)
141    pub static AVAudioSequencerInfoDictionaryKeyLyricist:
142        &'static AVAudioSequencerInfoDictionaryKey;
143}
144
145extern "C" {
146    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeynominalbitrate?language=objc)
147    pub static AVAudioSequencerInfoDictionaryKeyNominalBitRate:
148        &'static AVAudioSequencerInfoDictionaryKey;
149}
150
151extern "C" {
152    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyrecordeddate?language=objc)
153    pub static AVAudioSequencerInfoDictionaryKeyRecordedDate:
154        &'static AVAudioSequencerInfoDictionaryKey;
155}
156
157extern "C" {
158    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeysourcebitdepth?language=objc)
159    pub static AVAudioSequencerInfoDictionaryKeySourceBitDepth:
160        &'static AVAudioSequencerInfoDictionaryKey;
161}
162
163extern "C" {
164    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeysourceencoder?language=objc)
165    pub static AVAudioSequencerInfoDictionaryKeySourceEncoder:
166        &'static AVAudioSequencerInfoDictionaryKey;
167}
168
169extern "C" {
170    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeysubtitle?language=objc)
171    pub static AVAudioSequencerInfoDictionaryKeySubTitle:
172        &'static AVAudioSequencerInfoDictionaryKey;
173}
174
175extern "C" {
176    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeytempo?language=objc)
177    pub static AVAudioSequencerInfoDictionaryKeyTempo: &'static AVAudioSequencerInfoDictionaryKey;
178}
179
180extern "C" {
181    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeytimesignature?language=objc)
182    pub static AVAudioSequencerInfoDictionaryKeyTimeSignature:
183        &'static AVAudioSequencerInfoDictionaryKey;
184}
185
186extern "C" {
187    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeytitle?language=objc)
188    pub static AVAudioSequencerInfoDictionaryKeyTitle: &'static AVAudioSequencerInfoDictionaryKey;
189}
190
191extern "C" {
192    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeytracknumber?language=objc)
193    pub static AVAudioSequencerInfoDictionaryKeyTrackNumber:
194        &'static AVAudioSequencerInfoDictionaryKey;
195}
196
197extern "C" {
198    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerinfodictionarykeyyear?language=objc)
199    pub static AVAudioSequencerInfoDictionaryKeyYear: &'static AVAudioSequencerInfoDictionaryKey;
200}
201
202/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencerusercallback?language=objc)
203#[cfg(all(feature = "AVAudioTypes", feature = "block2"))]
204pub type AVAudioSequencerUserCallback =
205    *mut block2::DynBlock<dyn Fn(NonNull<AVMusicTrack>, NonNull<NSData>, AVMusicTimeStamp)>;
206
207extern_class!(
208    /// A collection of MIDI events organized into AVMusicTracks, plus a player to play back the events.
209    ///
210    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosequencer?language=objc)
211    #[unsafe(super(NSObject))]
212    #[derive(Debug, PartialEq, Eq, Hash)]
213    pub struct AVAudioSequencer;
214);
215
216extern_conformance!(
217    unsafe impl NSObjectProtocol for AVAudioSequencer {}
218);
219
220impl AVAudioSequencer {
221    extern_methods!(
222        /// Initialize a new sequencer, which will not be connected to an audio engine.
223        ///
224        /// This is used to create a sequencer whose tracks will only send events to external MIDI endpoints.
225        #[unsafe(method(init))]
226        #[unsafe(method_family = init)]
227        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
228
229        #[cfg(feature = "AVAudioEngine")]
230        /// Initialize a new sequencer, handing it the audio engine.
231        #[unsafe(method(initWithAudioEngine:))]
232        #[unsafe(method_family = init)]
233        pub unsafe fn initWithAudioEngine(
234            this: Allocated<Self>,
235            engine: &AVAudioEngine,
236        ) -> Retained<Self>;
237
238        /// Load the file referenced by the URL and add the events to the sequence
239        ///
240        /// Parameter `fileURL`: the URL to the file
241        ///
242        /// Parameter `options`: determines how the file's contents are mapped to tracks inside the sequence
243        ///
244        /// Parameter `outError`: on exit, if an error occurs, a description of the error
245        #[unsafe(method(loadFromURL:options:error:_))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn loadFromURL_options_error(
248            &self,
249            file_url: &NSURL,
250            options: AVMusicSequenceLoadOptions,
251        ) -> Result<(), Retained<NSError>>;
252
253        /// Parse the data and add the its events to the sequence
254        ///
255        /// Parameter `data`: the data to load from
256        ///
257        /// Parameter `options`: determines how the contents are mapped to tracks inside the sequence
258        ///
259        /// Parameter `outError`: on exit, if an error occurs, a description of the error
260        #[unsafe(method(loadFromData:options:error:_))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn loadFromData_options_error(
263            &self,
264            data: &NSData,
265            options: AVMusicSequenceLoadOptions,
266        ) -> Result<(), Retained<NSError>>;
267
268        /// Create and write a MIDI file containing the events and complete state of the sequence
269        ///
270        /// Parameter `fileURL`: the path for the file to be created
271        ///
272        /// Parameter `resolution`: the relationship between "tick" and quarter note for saving to a Standard MIDI File - pass in
273        /// zero to use default - this will be the value that is currently set on the tempo track
274        ///
275        /// Parameter `replace`: if the file already exists, YES will cause it to be overwritten with the new data.
276        /// Otherwise the call will fail with a permission error.
277        ///
278        /// Parameter `outError`: on exit, if an error occurs, a description of the error
279        ///
280        /// A MIDI file saved via this method will contain not only the complete MIDI content of the sequence,
281        /// but also the state of all tracks, including muting, loop points and enablement, etc.  It will also
282        /// contain all non-MIDI AVMusicEvent types which had been added to the sequence's track.
283        ///
284        /// MIDI files are normally beat based, but can also have a SMPTE (or real-time rather than beat time) representation.
285        /// The relationship between "tick" and quarter note for saving to Standard MIDI File
286        /// - pass in zero to use default - this will be the value that is currently set on the tempo track
287        #[unsafe(method(writeToURL:SMPTEResolution:replaceExisting:error:_))]
288        #[unsafe(method_family = none)]
289        pub unsafe fn writeToURL_SMPTEResolution_replaceExisting_error(
290            &self,
291            file_url: &NSURL,
292            resolution: NSInteger,
293            replace: bool,
294        ) -> Result<(), Retained<NSError>>;
295
296        /// Return a data object containing the events from the sequence
297        ///
298        /// All details regarding the SMPTE resolution apply here as well.
299        /// The returned NSData lifetime is controlled by the client.
300        #[unsafe(method(dataWithSMPTEResolution:error:))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn dataWithSMPTEResolution_error(
303            &self,
304            smpte_resolution: NSInteger,
305            out_error: Option<&mut Option<Retained<NSError>>>,
306        ) -> Retained<NSData>;
307
308        #[cfg(feature = "AVAudioTypes")]
309        /// Get the time in seconds for the given beat position (timestamp) in the AVMusicTrack
310        #[unsafe(method(secondsForBeats:))]
311        #[unsafe(method_family = none)]
312        pub unsafe fn secondsForBeats(&self, beats: AVMusicTimeStamp) -> NSTimeInterval;
313
314        #[cfg(feature = "AVAudioTypes")]
315        /// Get the beat position (timestamp) for the given time in the AVMusicTrack
316        #[unsafe(method(beatsForSeconds:))]
317        #[unsafe(method_family = none)]
318        pub unsafe fn beatsForSeconds(&self, seconds: NSTimeInterval) -> AVMusicTimeStamp;
319
320        /// Reverse the order of all events in all AVMusicTracks, including the tempo track
321        #[unsafe(method(reverseEvents))]
322        #[unsafe(method_family = none)]
323        pub unsafe fn reverseEvents(&self);
324
325        /// Create a new AVMusicTrack and append it to the AVMusicSequencer's list
326        #[unsafe(method(createAndAppendTrack))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn createAndAppendTrack(&self) -> Retained<AVMusicTrack>;
329
330        /// Remove the given AVMusicTrack from the AVMusicSequencer.
331        ///
332        /// This does not destroy the AVMusicTrack because it may be re-used.
333        #[unsafe(method(removeTrack:))]
334        #[unsafe(method_family = none)]
335        pub unsafe fn removeTrack(&self, track: &AVMusicTrack) -> bool;
336
337        #[cfg(all(feature = "AVAudioTypes", feature = "block2"))]
338        /// Add a block which will be called each time the AVAudioSequencer encounters an AVMusicUserEvent during playback.
339        ///
340        /// The same callback is called for events which occur on any track in the sequencer.
341        ///
342        /// Set the block to nil to disable it.
343        ///
344        /// # Safety
345        ///
346        /// `user_callback` must be a valid pointer or null.
347        #[unsafe(method(setUserCallback:))]
348        #[unsafe(method_family = none)]
349        pub unsafe fn setUserCallback(&self, user_callback: AVAudioSequencerUserCallback);
350
351        /// An NSArray containing all the AVMusicTracks in the sequence
352        ///
353        /// This list will not include the tempo track.
354        #[unsafe(method(tracks))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn tracks(&self) -> Retained<NSArray<AVMusicTrack>>;
357
358        /// The tempo track
359        ///
360        /// Each AVMusicSequence has a single tempo track.
361        ///
362        /// All tempo events read from external MIDI files are placed into this track (as well as other
363        /// appropriate events (e.g., the time signature meta event from the file).
364        ///
365        /// The tempo track can be edited and iterated upon as any other track.
366        ///
367        /// Non-tempo-related events will generate exceptions if added.
368        #[unsafe(method(tempoTrack))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn tempoTrack(&self) -> Retained<AVMusicTrack>;
371
372        /// A dictionary containing meta-data derived from a sequence
373        ///
374        /// The dictionary can contain one or more of the values accessible via the AVAudioSequencerInfoDictionaryKeys.
375        #[unsafe(method(userInfo))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn userInfo(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
378    );
379}
380
381/// Methods declared on superclass `NSObject`.
382impl AVAudioSequencer {
383    extern_methods!(
384        #[unsafe(method(new))]
385        #[unsafe(method_family = new)]
386        pub unsafe fn new() -> Retained<Self>;
387    );
388}
389
390/// AVAudioSequencer_Player.
391impl AVAudioSequencer {
392    extern_methods!(
393        /// The current playback position in seconds
394        ///
395        /// Setting this positions the sequencer's player to the specified time.  This can be set while
396        /// the player is playing, in which case playback will resume at the new position.
397        #[unsafe(method(currentPositionInSeconds))]
398        #[unsafe(method_family = none)]
399        pub unsafe fn currentPositionInSeconds(&self) -> NSTimeInterval;
400
401        /// Setter for [`currentPositionInSeconds`][Self::currentPositionInSeconds].
402        #[unsafe(method(setCurrentPositionInSeconds:))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn setCurrentPositionInSeconds(
405            &self,
406            current_position_in_seconds: NSTimeInterval,
407        );
408
409        /// The current playback position in beats
410        ///
411        /// Setting this positions the sequencer's player to the specified beat.  This can be set while
412        /// the player is playing, in which case playback will resume at the new position.
413        #[unsafe(method(currentPositionInBeats))]
414        #[unsafe(method_family = none)]
415        pub unsafe fn currentPositionInBeats(&self) -> NSTimeInterval;
416
417        /// Setter for [`currentPositionInBeats`][Self::currentPositionInBeats].
418        #[unsafe(method(setCurrentPositionInBeats:))]
419        #[unsafe(method_family = none)]
420        pub unsafe fn setCurrentPositionInBeats(&self, current_position_in_beats: NSTimeInterval);
421
422        /// Indicates whether or not the sequencer's player is playing
423        ///
424        /// Returns TRUE if the sequencer's player has been started and not stopped. It may have
425        /// "played" past the end of the events in the sequence, but it is still considered to be
426        /// playing (and its time value increasing) until it is explicitly stopped.
427        #[unsafe(method(isPlaying))]
428        #[unsafe(method_family = none)]
429        pub unsafe fn isPlaying(&self) -> bool;
430
431        /// The playback rate of the sequencer's player
432        ///
433        /// 1.0 is normal playback rate.  Rate must be > 0.0.
434        #[unsafe(method(rate))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn rate(&self) -> c_float;
437
438        /// Setter for [`rate`][Self::rate].
439        #[unsafe(method(setRate:))]
440        #[unsafe(method_family = none)]
441        pub unsafe fn setRate(&self, rate: c_float);
442
443        /// Get ready to play the sequence by prerolling all events
444        ///
445        /// Happens automatically on play if it has not already been called, but may produce a delay in
446        /// startup.
447        #[unsafe(method(prepareToPlay))]
448        #[unsafe(method_family = none)]
449        pub unsafe fn prepareToPlay(&self);
450
451        /// Start the sequencer's player
452        ///
453        /// If the AVAudioSequencer has not been prerolled, it will pre-roll itself and then start.
454        /// When the sequencer is associated with an audio engine, the sequencer's player will only
455        /// play if the audio engine is running.
456        #[unsafe(method(startAndReturnError:_))]
457        #[unsafe(method_family = none)]
458        pub unsafe fn startAndReturnError(&self) -> Result<(), Retained<NSError>>;
459
460        /// Stop the sequencer's player
461        ///
462        /// Stopping the player leaves it in an un-prerolled state, but stores the playback position so
463        /// that a subsequent call to startAndReturnError will resume where it left off. This action
464        /// will not stop an associated audio engine.
465        #[unsafe(method(stop))]
466        #[unsafe(method_family = none)]
467        pub unsafe fn stop(&self);
468    );
469}
470
471/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusictrackloopcount?language=objc)
472// NS_ENUM
473#[repr(transparent)]
474#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
475pub struct AVMusicTrackLoopCount(pub NSInteger);
476impl AVMusicTrackLoopCount {
477    #[doc(alias = "AVMusicTrackLoopCountForever")]
478    pub const Forever: Self = Self(-1);
479}
480
481unsafe impl Encode for AVMusicTrackLoopCount {
482    const ENCODING: Encoding = NSInteger::ENCODING;
483}
484
485unsafe impl RefEncode for AVMusicTrackLoopCount {
486    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
487}
488
489extern_class!(
490    /// A collection of music events which will be sent to a given destination, and which can be
491    /// offset, muted, etc. independently of events in other tracks.
492    ///
493    /// AVMusicTrack is not a container of AVMusicEvents - it will not hold references to
494    /// AVMusicEvents that are added, so an application should maintain its own if it is
495    /// desired.
496    ///
497    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusictrack?language=objc)
498    #[unsafe(super(NSObject))]
499    #[derive(Debug, PartialEq, Eq, Hash)]
500    pub struct AVMusicTrack;
501);
502
503extern_conformance!(
504    unsafe impl NSObjectProtocol for AVMusicTrack {}
505);
506
507impl AVMusicTrack {
508    extern_methods!(
509        #[cfg(all(feature = "AVAudioNode", feature = "AVAudioUnit"))]
510        /// The AVAudioUnit which will receive the track's events
511        ///
512        /// This is mutually exclusive with setting a destination MIDIEndpoint.  The AU must already be
513        /// attached to an audio engine, and the track must be part of the AVAudioSequencer associated
514        /// with that engine. When playing, the track will send its events to that AVAudioUnit. The
515        /// destination AU cannot be changed while the track's sequence is playing.
516        #[unsafe(method(destinationAudioUnit))]
517        #[unsafe(method_family = none)]
518        pub unsafe fn destinationAudioUnit(&self) -> Option<Retained<AVAudioUnit>>;
519
520        #[cfg(all(feature = "AVAudioNode", feature = "AVAudioUnit"))]
521        /// Setter for [`destinationAudioUnit`][Self::destinationAudioUnit].
522        #[unsafe(method(setDestinationAudioUnit:))]
523        #[unsafe(method_family = none)]
524        pub unsafe fn setDestinationAudioUnit(&self, destination_audio_unit: Option<&AVAudioUnit>);
525
526        #[cfg(feature = "objc2-core-midi")]
527        #[unsafe(method(destinationMIDIEndpoint))]
528        #[unsafe(method_family = none)]
529        pub unsafe fn destinationMIDIEndpoint(&self) -> MIDIEndpointRef;
530
531        #[cfg(feature = "objc2-core-midi")]
532        /// Setter for [`destinationMIDIEndpoint`][Self::destinationMIDIEndpoint].
533        #[unsafe(method(setDestinationMIDIEndpoint:))]
534        #[unsafe(method_family = none)]
535        pub unsafe fn setDestinationMIDIEndpoint(&self, destination_midi_endpoint: MIDIEndpointRef);
536
537        #[cfg(feature = "AVAudioTypes")]
538        /// The timestamp range in beats for the loop
539        ///
540        /// The loop is set by specifying its beat range.
541        #[unsafe(method(loopRange))]
542        #[unsafe(method_family = none)]
543        pub unsafe fn loopRange(&self) -> AVBeatRange;
544
545        #[cfg(feature = "AVAudioTypes")]
546        /// Setter for [`loopRange`][Self::loopRange].
547        #[unsafe(method(setLoopRange:))]
548        #[unsafe(method_family = none)]
549        pub unsafe fn setLoopRange(&self, loop_range: AVBeatRange);
550
551        /// Determines whether or not the track is looped.
552        ///
553        /// If loopRange has not been set, the full track will be looped.
554        #[unsafe(method(isLoopingEnabled))]
555        #[unsafe(method_family = none)]
556        pub unsafe fn isLoopingEnabled(&self) -> bool;
557
558        /// Setter for [`isLoopingEnabled`][Self::isLoopingEnabled].
559        #[unsafe(method(setLoopingEnabled:))]
560        #[unsafe(method_family = none)]
561        pub unsafe fn setLoopingEnabled(&self, looping_enabled: bool);
562
563        /// The number of times that the track's loop will repeat
564        ///
565        /// If set to AVMusicTrackLoopCountForever, the track will loop forever.
566        /// Otherwise, legal values start with 1.
567        #[unsafe(method(numberOfLoops))]
568        #[unsafe(method_family = none)]
569        pub unsafe fn numberOfLoops(&self) -> NSInteger;
570
571        /// Setter for [`numberOfLoops`][Self::numberOfLoops].
572        #[unsafe(method(setNumberOfLoops:))]
573        #[unsafe(method_family = none)]
574        pub unsafe fn setNumberOfLoops(&self, number_of_loops: NSInteger);
575
576        #[cfg(feature = "AVAudioTypes")]
577        /// Offset the track's start time to the specified time in beats
578        ///
579        /// By default this value is zero.
580        #[unsafe(method(offsetTime))]
581        #[unsafe(method_family = none)]
582        pub unsafe fn offsetTime(&self) -> AVMusicTimeStamp;
583
584        #[cfg(feature = "AVAudioTypes")]
585        /// Setter for [`offsetTime`][Self::offsetTime].
586        #[unsafe(method(setOffsetTime:))]
587        #[unsafe(method_family = none)]
588        pub unsafe fn setOffsetTime(&self, offset_time: AVMusicTimeStamp);
589
590        /// Whether the track is muted
591        #[unsafe(method(isMuted))]
592        #[unsafe(method_family = none)]
593        pub unsafe fn isMuted(&self) -> bool;
594
595        /// Setter for [`isMuted`][Self::isMuted].
596        #[unsafe(method(setMuted:))]
597        #[unsafe(method_family = none)]
598        pub unsafe fn setMuted(&self, muted: bool);
599
600        /// Whether the track is soloed
601        #[unsafe(method(isSoloed))]
602        #[unsafe(method_family = none)]
603        pub unsafe fn isSoloed(&self) -> bool;
604
605        /// Setter for [`isSoloed`][Self::isSoloed].
606        #[unsafe(method(setSoloed:))]
607        #[unsafe(method_family = none)]
608        pub unsafe fn setSoloed(&self, soloed: bool);
609
610        #[cfg(feature = "AVAudioTypes")]
611        /// The total duration of the track in beats
612        ///
613        /// This will return the beat of the last event in the track plus any additional time that may
614        /// be needed for fading out of ending notes or round a loop point to musical bar, etc.  If this
615        /// has not been set by the user, the track length will always be adjusted to the end of the
616        /// last active event in a track and is adjusted dynamically as events are added or removed.
617        ///
618        /// The property will return the maximum of the user-set track length, or the calculated length.
619        #[unsafe(method(lengthInBeats))]
620        #[unsafe(method_family = none)]
621        pub unsafe fn lengthInBeats(&self) -> AVMusicTimeStamp;
622
623        #[cfg(feature = "AVAudioTypes")]
624        /// Setter for [`lengthInBeats`][Self::lengthInBeats].
625        #[unsafe(method(setLengthInBeats:))]
626        #[unsafe(method_family = none)]
627        pub unsafe fn setLengthInBeats(&self, length_in_beats: AVMusicTimeStamp);
628
629        /// The total duration of the track in seconds
630        ///
631        /// This will return time of the last event in the track plus any additional time that may be
632        /// needed for fading out of ending notes or round a loop point to musical bar, etc.  If this
633        /// has not been set by the user, the track length will always be adjusted to the end of the
634        /// last active event in a track and is adjusted dynamically as events are added or removed.
635        ///
636        /// The property will return the maximum of the user-set track length, or the calculated length.
637        #[unsafe(method(lengthInSeconds))]
638        #[unsafe(method_family = none)]
639        pub unsafe fn lengthInSeconds(&self) -> NSTimeInterval;
640
641        /// Setter for [`lengthInSeconds`][Self::lengthInSeconds].
642        #[unsafe(method(setLengthInSeconds:))]
643        #[unsafe(method_family = none)]
644        pub unsafe fn setLengthInSeconds(&self, length_in_seconds: NSTimeInterval);
645
646        /// The time resolution value for the sequence, in ticks (pulses) per quarter note (PPQN)
647        ///
648        /// If a MIDI file was used to construct the containing sequence, the resolution will be what
649        /// was in the file. If you want to keep a time resolution when writing a new file, you can
650        /// retrieve this value and then specify it when calling -[AVAudioSequencer
651        /// writeToFile:flags:withResolution]. It has no direct bearing on the rendering or notion of
652        /// time of the sequence itself, just its representation in MIDI files. By default this is set
653        /// to either 480 if the sequence was created manually, or a value based on what was in a MIDI
654        /// file if the sequence was created from a MIDI file.
655        ///
656        /// This can only be retrieved from the tempo track.
657        #[unsafe(method(timeResolution))]
658        #[unsafe(method_family = none)]
659        pub unsafe fn timeResolution(&self) -> NSUInteger;
660    );
661}
662
663/// Methods declared on superclass `NSObject`.
664impl AVMusicTrack {
665    extern_methods!(
666        #[unsafe(method(init))]
667        #[unsafe(method_family = init)]
668        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
669
670        #[unsafe(method(new))]
671        #[unsafe(method_family = new)]
672        pub unsafe fn new() -> Retained<Self>;
673    );
674}
675
676/// The block type used to enumerate and optionally remove AVMusicEvents when using
677/// `AVMusicTrack(enumerateEventsInRange:usingBlock:)`
678///
679/// Parameter `event`: the AVMusicEvent returned by this enumeration block call.  If this
680/// event is modified by the block, the corresponding track event will be changed.
681///
682/// Parameter `timeStamp`: the beat position of this event in the AVMusicTrack.  If the block
683/// sets *timeStamp to a new value, the corresponding event's beat position
684/// in the track will be updated.
685///
686/// Parameter `removeEvent`: If the block sets *removeEvent to YES, the current event will be
687/// removed from the track.
688///
689/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusiceventenumerationblock?language=objc)
690#[cfg(all(
691    feature = "AVAudioTypes",
692    feature = "AVMusicEvents",
693    feature = "block2"
694))]
695pub type AVMusicEventEnumerationBlock =
696    *mut block2::DynBlock<dyn Fn(NonNull<AVMusicEvent>, NonNull<AVMusicTimeStamp>, NonNull<Bool>)>;
697
698/// AVMusicTrackEditor.
699impl AVMusicTrack {
700    extern_methods!(
701        /// Indicates whether the track is an automation track.
702        ///
703        /// If set to YES, this can be used to contain, parameter automation events, exclusively.
704        /// Adding any other event types will generate exceptions.
705        ///
706        /// If a track already contains non-parameter events, setting this to YES will
707        /// generate an exception.
708        #[unsafe(method(usesAutomatedParameters))]
709        #[unsafe(method_family = none)]
710        pub unsafe fn usesAutomatedParameters(&self) -> bool;
711
712        /// Setter for [`usesAutomatedParameters`][Self::usesAutomatedParameters].
713        #[unsafe(method(setUsesAutomatedParameters:))]
714        #[unsafe(method_family = none)]
715        pub unsafe fn setUsesAutomatedParameters(&self, uses_automated_parameters: bool);
716
717        #[cfg(all(feature = "AVAudioTypes", feature = "AVMusicEvents"))]
718        /// Adds an AVMusicEvent's contents to a track at the specified AVMusicTimeStamp.
719        ///
720        /// Parameter `event`: the event to be added
721        ///
722        /// Parameter `beat`: the AVMusicTimeStamp
723        ///
724        /// Because event contents are copied into the track, the same event may be added multiple
725        /// times at different timestamps.
726        ///
727        /// There are restrictions on which AVMusicEvent subclasses may be added to different tracks:
728        ///
729        /// - Only AVExtendedTempoEvents and AVMIDIMetaEvents with certain AVMIDIMetaEventTypes
730        /// can be added to an AVMusicSequence's tempo track (see AVMIDIMetaEvent).
731        ///
732        /// - AVParameterEvents can only be added to automation tracks (see AVParameterEvent).
733        ///
734        /// - All other event subclasses cannot be added to tempo or automation tracks.
735        #[unsafe(method(addEvent:atBeat:))]
736        #[unsafe(method_family = none)]
737        pub unsafe fn addEvent_atBeat(&self, event: &AVMusicEvent, beat: AVMusicTimeStamp);
738
739        #[cfg(feature = "AVAudioTypes")]
740        /// Shift the beat location of all events in the given beat range by the amount specified.
741        ///
742        /// Parameter `range`: the range of beats.  Must be a valid AVBeatRange.
743        ///
744        /// Parameter `beatAmount`: the amount in beats to shift each event.  The amount may be positive or negative.
745        #[unsafe(method(moveEventsInRange:byAmount:))]
746        #[unsafe(method_family = none)]
747        pub unsafe fn moveEventsInRange_byAmount(
748            &self,
749            range: AVBeatRange,
750            beat_amount: AVMusicTimeStamp,
751        );
752
753        #[cfg(feature = "AVAudioTypes")]
754        /// Removes all events in the given beat range, erasing that portion of the AVMusicTrack.
755        ///
756        /// Parameter `range`: the range of beats.  Must be a valid AVBeatRange.
757        ///
758        /// All events outside of the specified range left unmodified.
759        #[unsafe(method(clearEventsInRange:))]
760        #[unsafe(method_family = none)]
761        pub unsafe fn clearEventsInRange(&self, range: AVBeatRange);
762
763        #[cfg(feature = "AVAudioTypes")]
764        /// Removes all events in the given beat range, splicing out that portion of the AVMusicTrack.
765        ///
766        /// Parameter `range`: the range of beats.  Must be a valid AVBeatRange.
767        ///
768        /// All events past the end of the specified range will be shifted backward by the duration of the range.
769        #[unsafe(method(cutEventsInRange:))]
770        #[unsafe(method_family = none)]
771        pub unsafe fn cutEventsInRange(&self, range: AVBeatRange);
772
773        #[cfg(feature = "AVAudioTypes")]
774        /// Copies all events in the given beat range from the specified AVMusicTrack,
775        /// splicing them into the current AVMusicTrack.
776        ///
777        /// Parameter `range`: the range of beats.  Must be a valid AVBeatRange.
778        ///
779        /// Parameter `sourceTrack`: the AVMusicTrack to copy the events from.
780        ///
781        /// Parameter `insertStartBeat`: the start beat at which the copied events should be spliced in.
782        ///
783        /// All events originally at or past insertStartBeat will be shifted forward by the duration
784        /// of the copied-in range.
785        #[unsafe(method(copyEventsInRange:fromTrack:insertAtBeat:))]
786        #[unsafe(method_family = none)]
787        pub unsafe fn copyEventsInRange_fromTrack_insertAtBeat(
788            &self,
789            range: AVBeatRange,
790            source_track: &AVMusicTrack,
791            insert_start_beat: AVMusicTimeStamp,
792        );
793
794        #[cfg(feature = "AVAudioTypes")]
795        /// Copies all events in the given beat range from the specified AVMusicTrack,
796        /// merging them into the current AVMusicTrack.
797        ///
798        /// Parameter `range`: the range of beats.  Must be a valid AVBeatRange.
799        ///
800        /// Parameter `sourceTrack`: the AVMusicTrack to copy the events from.
801        ///
802        /// Parameter `insertStartBeat`: the start beat at which the copied events should be merged.
803        ///
804        /// All events originally at or past mergeStartBeat will be left unmodified.
805        ///
806        /// Copying events from track to track follows the same type-exclusion rules as adding
807        /// events:  The operation will generate an exception.
808        #[unsafe(method(copyAndMergeEventsInRange:fromTrack:mergeAtBeat:))]
809        #[unsafe(method_family = none)]
810        pub unsafe fn copyAndMergeEventsInRange_fromTrack_mergeAtBeat(
811            &self,
812            range: AVBeatRange,
813            source_track: &AVMusicTrack,
814            merge_start_beat: AVMusicTimeStamp,
815        );
816
817        #[cfg(all(
818            feature = "AVAudioTypes",
819            feature = "AVMusicEvents",
820            feature = "block2"
821        ))]
822        /// Iterates through the AVMusicEvents within the AVMusicTrack whose timestamps fit within the range,
823        /// calling the block for each.
824        ///
825        /// Parameter `block`: the AVMusicEventEnumerationBlock to call for each event.
826        ///
827        /// Each event returned via the block should be examined using `NSObject(isKindOfClass:)`
828        /// to determine its subclass and then cast and accessed/edited accordingly.
829        ///
830        /// The iteration may continue after removing an event.
831        ///
832        /// The event objects returned via the block will not be the same instances
833        /// which were added to the AVMusicTrack, though their contents will be identical.
834        ///
835        /// # Safety
836        ///
837        /// `block` must be a valid pointer.
838        #[unsafe(method(enumerateEventsInRange:usingBlock:))]
839        #[unsafe(method_family = none)]
840        pub unsafe fn enumerateEventsInRange_usingBlock(
841            &self,
842            range: AVBeatRange,
843            block: AVMusicEventEnumerationBlock,
844        );
845    );
846}