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::Block<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
216unsafe impl NSObjectProtocol for AVAudioSequencer {}
217
218impl AVAudioSequencer {
219 extern_methods!(
220 /// Initialize a new sequencer, which will not be connected to an audio engine.
221 ///
222 /// This is used to create a sequencer whose tracks will only send events to external MIDI endpoints.
223 #[unsafe(method(init))]
224 #[unsafe(method_family = init)]
225 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
226
227 #[cfg(feature = "AVAudioEngine")]
228 /// Initialize a new sequencer, handing it the audio engine.
229 #[unsafe(method(initWithAudioEngine:))]
230 #[unsafe(method_family = init)]
231 pub unsafe fn initWithAudioEngine(
232 this: Allocated<Self>,
233 engine: &AVAudioEngine,
234 ) -> Retained<Self>;
235
236 /// Load the file referenced by the URL and add the events to the sequence
237 ///
238 /// Parameter `fileURL`: the URL to the file
239 ///
240 /// Parameter `options`: determines how the file's contents are mapped to tracks inside the sequence
241 ///
242 /// Parameter `outError`: on exit, if an error occurs, a description of the error
243 #[unsafe(method(loadFromURL:options:error:_))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn loadFromURL_options_error(
246 &self,
247 file_url: &NSURL,
248 options: AVMusicSequenceLoadOptions,
249 ) -> Result<(), Retained<NSError>>;
250
251 /// Parse the data and add the its events to the sequence
252 ///
253 /// Parameter `data`: the data to load from
254 ///
255 /// Parameter `options`: determines how the contents are mapped to tracks inside the sequence
256 ///
257 /// Parameter `outError`: on exit, if an error occurs, a description of the error
258 #[unsafe(method(loadFromData:options:error:_))]
259 #[unsafe(method_family = none)]
260 pub unsafe fn loadFromData_options_error(
261 &self,
262 data: &NSData,
263 options: AVMusicSequenceLoadOptions,
264 ) -> Result<(), Retained<NSError>>;
265
266 /// Create and write a MIDI file containing the events and complete state of the sequence
267 ///
268 /// Parameter `fileURL`: the path for the file to be created
269 ///
270 /// Parameter `resolution`: the relationship between "tick" and quarter note for saving to a Standard MIDI File - pass in
271 /// zero to use default - this will be the value that is currently set on the tempo track
272 ///
273 /// Parameter `replace`: if the file already exists, YES will cause it to be overwritten with the new data.
274 /// Otherwise the call will fail with a permission error.
275 ///
276 /// Parameter `outError`: on exit, if an error occurs, a description of the error
277 ///
278 /// A MIDI file saved via this method will contain not only the complete MIDI content of the sequence,
279 /// but also the state of all tracks, including muting, loop points and enablement, etc. It will also
280 /// contain all non-MIDI AVMusicEvent types which had been added to the sequence's track.
281 ///
282 /// MIDI files are normally beat based, but can also have a SMPTE (or real-time rather than beat time) representation.
283 /// The relationship between "tick" and quarter note for saving to Standard MIDI File
284 /// - pass in zero to use default - this will be the value that is currently set on the tempo track
285 #[unsafe(method(writeToURL:SMPTEResolution:replaceExisting:error:_))]
286 #[unsafe(method_family = none)]
287 pub unsafe fn writeToURL_SMPTEResolution_replaceExisting_error(
288 &self,
289 file_url: &NSURL,
290 resolution: NSInteger,
291 replace: bool,
292 ) -> Result<(), Retained<NSError>>;
293
294 #[cfg(feature = "AVAudioTypes")]
295 /// Get the time in seconds for the given beat position (timestamp) in the AVMusicTrack
296 #[unsafe(method(secondsForBeats:))]
297 #[unsafe(method_family = none)]
298 pub unsafe fn secondsForBeats(&self, beats: AVMusicTimeStamp) -> NSTimeInterval;
299
300 #[cfg(feature = "AVAudioTypes")]
301 /// Get the beat position (timestamp) for the given time in the AVMusicTrack
302 #[unsafe(method(beatsForSeconds:))]
303 #[unsafe(method_family = none)]
304 pub unsafe fn beatsForSeconds(&self, seconds: NSTimeInterval) -> AVMusicTimeStamp;
305
306 /// Reverse the order of all events in all AVMusicTracks, including the tempo track
307 #[unsafe(method(reverseEvents))]
308 #[unsafe(method_family = none)]
309 pub unsafe fn reverseEvents(&self);
310
311 /// Create a new AVMusicTrack and append it to the AVMusicSequencer's list
312 #[unsafe(method(createAndAppendTrack))]
313 #[unsafe(method_family = none)]
314 pub unsafe fn createAndAppendTrack(&self) -> Retained<AVMusicTrack>;
315
316 /// Remove the given AVMusicTrack from the AVMusicSequencer.
317 ///
318 /// This does not destroy the AVMusicTrack because it may be re-used.
319 #[unsafe(method(removeTrack:))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn removeTrack(&self, track: &AVMusicTrack) -> bool;
322
323 #[cfg(all(feature = "AVAudioTypes", feature = "block2"))]
324 /// Add a block which will be called each time the AVAudioSequencer encounters an AVMusicUserEvent during playback.
325 ///
326 /// The same callback is called for events which occur on any track in the sequencer.
327 ///
328 /// Set the block to nil to disable it.
329 #[unsafe(method(setUserCallback:))]
330 #[unsafe(method_family = none)]
331 pub unsafe fn setUserCallback(&self, user_callback: AVAudioSequencerUserCallback);
332
333 /// An NSArray containing all the AVMusicTracks in the sequence
334 ///
335 /// This list will not include the tempo track.
336 #[unsafe(method(tracks))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn tracks(&self) -> Retained<NSArray<AVMusicTrack>>;
339
340 /// The tempo track
341 ///
342 /// Each AVMusicSequence has a single tempo track.
343 ///
344 /// All tempo events read from external MIDI files are placed into this track (as well as other
345 /// appropriate events (e.g., the time signature meta event from the file).
346 ///
347 /// The tempo track can be edited and iterated upon as any other track.
348 ///
349 /// Non-tempo-related events will generate exceptions if added.
350 #[unsafe(method(tempoTrack))]
351 #[unsafe(method_family = none)]
352 pub unsafe fn tempoTrack(&self) -> Retained<AVMusicTrack>;
353
354 /// A dictionary containing meta-data derived from a sequence
355 ///
356 /// The dictionary can contain one or more of the values accessible via the AVAudioSequencerInfoDictionaryKeys.
357 #[unsafe(method(userInfo))]
358 #[unsafe(method_family = none)]
359 pub unsafe fn userInfo(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
360 );
361}
362
363/// Methods declared on superclass `NSObject`.
364impl AVAudioSequencer {
365 extern_methods!(
366 #[unsafe(method(new))]
367 #[unsafe(method_family = new)]
368 pub unsafe fn new() -> Retained<Self>;
369 );
370}
371
372/// AVAudioSequencer_Player.
373impl AVAudioSequencer {
374 extern_methods!(
375 /// The current playback position in seconds
376 ///
377 /// Setting this positions the sequencer's player to the specified time. This can be set while
378 /// the player is playing, in which case playback will resume at the new position.
379 #[unsafe(method(currentPositionInSeconds))]
380 #[unsafe(method_family = none)]
381 pub unsafe fn currentPositionInSeconds(&self) -> NSTimeInterval;
382
383 /// Setter for [`currentPositionInSeconds`][Self::currentPositionInSeconds].
384 #[unsafe(method(setCurrentPositionInSeconds:))]
385 #[unsafe(method_family = none)]
386 pub unsafe fn setCurrentPositionInSeconds(
387 &self,
388 current_position_in_seconds: NSTimeInterval,
389 );
390
391 /// The current playback position in beats
392 ///
393 /// Setting this positions the sequencer's player to the specified beat. This can be set while
394 /// the player is playing, in which case playback will resume at the new position.
395 #[unsafe(method(currentPositionInBeats))]
396 #[unsafe(method_family = none)]
397 pub unsafe fn currentPositionInBeats(&self) -> NSTimeInterval;
398
399 /// Setter for [`currentPositionInBeats`][Self::currentPositionInBeats].
400 #[unsafe(method(setCurrentPositionInBeats:))]
401 #[unsafe(method_family = none)]
402 pub unsafe fn setCurrentPositionInBeats(&self, current_position_in_beats: NSTimeInterval);
403
404 /// Indicates whether or not the sequencer's player is playing
405 ///
406 /// Returns TRUE if the sequencer's player has been started and not stopped. It may have
407 /// "played" past the end of the events in the sequence, but it is still considered to be
408 /// playing (and its time value increasing) until it is explicitly stopped.
409 #[unsafe(method(isPlaying))]
410 #[unsafe(method_family = none)]
411 pub unsafe fn isPlaying(&self) -> bool;
412
413 /// The playback rate of the sequencer's player
414 ///
415 /// 1.0 is normal playback rate. Rate must be > 0.0.
416 #[unsafe(method(rate))]
417 #[unsafe(method_family = none)]
418 pub unsafe fn rate(&self) -> c_float;
419
420 /// Setter for [`rate`][Self::rate].
421 #[unsafe(method(setRate:))]
422 #[unsafe(method_family = none)]
423 pub unsafe fn setRate(&self, rate: c_float);
424
425 /// Get ready to play the sequence by prerolling all events
426 ///
427 /// Happens automatically on play if it has not already been called, but may produce a delay in
428 /// startup.
429 #[unsafe(method(prepareToPlay))]
430 #[unsafe(method_family = none)]
431 pub unsafe fn prepareToPlay(&self);
432
433 /// Start the sequencer's player
434 ///
435 /// If the AVAudioSequencer has not been prerolled, it will pre-roll itself and then start.
436 /// When the sequencer is associated with an audio engine, the sequencer's player will only
437 /// play if the audio engine is running.
438 #[unsafe(method(startAndReturnError:_))]
439 #[unsafe(method_family = none)]
440 pub unsafe fn startAndReturnError(&self) -> Result<(), Retained<NSError>>;
441
442 /// Stop the sequencer's player
443 ///
444 /// Stopping the player leaves it in an un-prerolled state, but stores the playback position so
445 /// that a subsequent call to startAndReturnError will resume where it left off. This action
446 /// will not stop an associated audio engine.
447 #[unsafe(method(stop))]
448 #[unsafe(method_family = none)]
449 pub unsafe fn stop(&self);
450 );
451}
452
453/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusictrackloopcount?language=objc)
454// NS_ENUM
455#[repr(transparent)]
456#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
457pub struct AVMusicTrackLoopCount(pub NSInteger);
458impl AVMusicTrackLoopCount {
459 #[doc(alias = "AVMusicTrackLoopCountForever")]
460 pub const Forever: Self = Self(-1);
461}
462
463unsafe impl Encode for AVMusicTrackLoopCount {
464 const ENCODING: Encoding = NSInteger::ENCODING;
465}
466
467unsafe impl RefEncode for AVMusicTrackLoopCount {
468 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
469}
470
471extern_class!(
472 /// A collection of music events which will be sent to a given destination, and which can be
473 /// offset, muted, etc. independently of events in other tracks.
474 ///
475 /// AVMusicTrack is not a container of AVMusicEvents - it will not hold references to
476 /// AVMusicEvents that are added, so an application should maintain its own if it is
477 /// desired.
478 ///
479 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusictrack?language=objc)
480 #[unsafe(super(NSObject))]
481 #[derive(Debug, PartialEq, Eq, Hash)]
482 pub struct AVMusicTrack;
483);
484
485unsafe impl NSObjectProtocol for AVMusicTrack {}
486
487impl AVMusicTrack {
488 extern_methods!(
489 #[cfg(all(feature = "AVAudioNode", feature = "AVAudioUnit"))]
490 /// The AVAudioUnit which will receive the track's events
491 ///
492 /// This is mutually exclusive with setting a destination MIDIEndpoint. The AU must already be
493 /// attached to an audio engine, and the track must be part of the AVAudioSequencer associated
494 /// with that engine. When playing, the track will send its events to that AVAudioUnit. The
495 /// destination AU cannot be changed while the track's sequence is playing.
496 #[unsafe(method(destinationAudioUnit))]
497 #[unsafe(method_family = none)]
498 pub unsafe fn destinationAudioUnit(&self) -> Option<Retained<AVAudioUnit>>;
499
500 #[cfg(all(feature = "AVAudioNode", feature = "AVAudioUnit"))]
501 /// Setter for [`destinationAudioUnit`][Self::destinationAudioUnit].
502 #[unsafe(method(setDestinationAudioUnit:))]
503 #[unsafe(method_family = none)]
504 pub unsafe fn setDestinationAudioUnit(&self, destination_audio_unit: Option<&AVAudioUnit>);
505
506 #[cfg(feature = "objc2-core-midi")]
507 #[unsafe(method(destinationMIDIEndpoint))]
508 #[unsafe(method_family = none)]
509 pub unsafe fn destinationMIDIEndpoint(&self) -> MIDIEndpointRef;
510
511 #[cfg(feature = "objc2-core-midi")]
512 /// Setter for [`destinationMIDIEndpoint`][Self::destinationMIDIEndpoint].
513 #[unsafe(method(setDestinationMIDIEndpoint:))]
514 #[unsafe(method_family = none)]
515 pub unsafe fn setDestinationMIDIEndpoint(&self, destination_midi_endpoint: MIDIEndpointRef);
516
517 #[cfg(feature = "AVAudioTypes")]
518 /// The timestamp range in beats for the loop
519 ///
520 /// The loop is set by specifying its beat range.
521 #[unsafe(method(loopRange))]
522 #[unsafe(method_family = none)]
523 pub unsafe fn loopRange(&self) -> AVBeatRange;
524
525 #[cfg(feature = "AVAudioTypes")]
526 /// Setter for [`loopRange`][Self::loopRange].
527 #[unsafe(method(setLoopRange:))]
528 #[unsafe(method_family = none)]
529 pub unsafe fn setLoopRange(&self, loop_range: AVBeatRange);
530
531 /// Determines whether or not the track is looped.
532 ///
533 /// If loopRange has not been set, the full track will be looped.
534 #[unsafe(method(isLoopingEnabled))]
535 #[unsafe(method_family = none)]
536 pub unsafe fn isLoopingEnabled(&self) -> bool;
537
538 /// Setter for [`isLoopingEnabled`][Self::isLoopingEnabled].
539 #[unsafe(method(setLoopingEnabled:))]
540 #[unsafe(method_family = none)]
541 pub unsafe fn setLoopingEnabled(&self, looping_enabled: bool);
542
543 /// The number of times that the track's loop will repeat
544 ///
545 /// If set to AVMusicTrackLoopCountForever, the track will loop forever.
546 /// Otherwise, legal values start with 1.
547 #[unsafe(method(numberOfLoops))]
548 #[unsafe(method_family = none)]
549 pub unsafe fn numberOfLoops(&self) -> NSInteger;
550
551 /// Setter for [`numberOfLoops`][Self::numberOfLoops].
552 #[unsafe(method(setNumberOfLoops:))]
553 #[unsafe(method_family = none)]
554 pub unsafe fn setNumberOfLoops(&self, number_of_loops: NSInteger);
555
556 #[cfg(feature = "AVAudioTypes")]
557 /// Offset the track's start time to the specified time in beats
558 ///
559 /// By default this value is zero.
560 #[unsafe(method(offsetTime))]
561 #[unsafe(method_family = none)]
562 pub unsafe fn offsetTime(&self) -> AVMusicTimeStamp;
563
564 #[cfg(feature = "AVAudioTypes")]
565 /// Setter for [`offsetTime`][Self::offsetTime].
566 #[unsafe(method(setOffsetTime:))]
567 #[unsafe(method_family = none)]
568 pub unsafe fn setOffsetTime(&self, offset_time: AVMusicTimeStamp);
569
570 /// Whether the track is muted
571 #[unsafe(method(isMuted))]
572 #[unsafe(method_family = none)]
573 pub unsafe fn isMuted(&self) -> bool;
574
575 /// Setter for [`isMuted`][Self::isMuted].
576 #[unsafe(method(setMuted:))]
577 #[unsafe(method_family = none)]
578 pub unsafe fn setMuted(&self, muted: bool);
579
580 /// Whether the track is soloed
581 #[unsafe(method(isSoloed))]
582 #[unsafe(method_family = none)]
583 pub unsafe fn isSoloed(&self) -> bool;
584
585 /// Setter for [`isSoloed`][Self::isSoloed].
586 #[unsafe(method(setSoloed:))]
587 #[unsafe(method_family = none)]
588 pub unsafe fn setSoloed(&self, soloed: bool);
589
590 #[cfg(feature = "AVAudioTypes")]
591 /// The total duration of the track in beats
592 ///
593 /// This will return the beat of the last event in the track plus any additional time that may
594 /// be needed for fading out of ending notes or round a loop point to musical bar, etc. If this
595 /// has not been set by the user, the track length will always be adjusted to the end of the
596 /// last active event in a track and is adjusted dynamically as events are added or removed.
597 ///
598 /// The property will return the maximum of the user-set track length, or the calculated length.
599 #[unsafe(method(lengthInBeats))]
600 #[unsafe(method_family = none)]
601 pub unsafe fn lengthInBeats(&self) -> AVMusicTimeStamp;
602
603 #[cfg(feature = "AVAudioTypes")]
604 /// Setter for [`lengthInBeats`][Self::lengthInBeats].
605 #[unsafe(method(setLengthInBeats:))]
606 #[unsafe(method_family = none)]
607 pub unsafe fn setLengthInBeats(&self, length_in_beats: AVMusicTimeStamp);
608
609 /// The total duration of the track in seconds
610 ///
611 /// This will return time of the last event in the track plus any additional time that may be
612 /// needed for fading out of ending notes or round a loop point to musical bar, etc. If this
613 /// has not been set by the user, the track length will always be adjusted to the end of the
614 /// last active event in a track and is adjusted dynamically as events are added or removed.
615 ///
616 /// The property will return the maximum of the user-set track length, or the calculated length.
617 #[unsafe(method(lengthInSeconds))]
618 #[unsafe(method_family = none)]
619 pub unsafe fn lengthInSeconds(&self) -> NSTimeInterval;
620
621 /// Setter for [`lengthInSeconds`][Self::lengthInSeconds].
622 #[unsafe(method(setLengthInSeconds:))]
623 #[unsafe(method_family = none)]
624 pub unsafe fn setLengthInSeconds(&self, length_in_seconds: NSTimeInterval);
625
626 /// The time resolution value for the sequence, in ticks (pulses) per quarter note (PPQN)
627 ///
628 /// If a MIDI file was used to construct the containing sequence, the resolution will be what
629 /// was in the file. If you want to keep a time resolution when writing a new file, you can
630 /// retrieve this value and then specify it when calling -[AVAudioSequencer
631 /// writeToFile:flags:withResolution]. It has no direct bearing on the rendering or notion of
632 /// time of the sequence itself, just its representation in MIDI files. By default this is set
633 /// to either 480 if the sequence was created manually, or a value based on what was in a MIDI
634 /// file if the sequence was created from a MIDI file.
635 ///
636 /// This can only be retrieved from the tempo track.
637 #[unsafe(method(timeResolution))]
638 #[unsafe(method_family = none)]
639 pub unsafe fn timeResolution(&self) -> NSUInteger;
640 );
641}
642
643/// Methods declared on superclass `NSObject`.
644impl AVMusicTrack {
645 extern_methods!(
646 #[unsafe(method(init))]
647 #[unsafe(method_family = init)]
648 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
649
650 #[unsafe(method(new))]
651 #[unsafe(method_family = new)]
652 pub unsafe fn new() -> Retained<Self>;
653 );
654}
655
656/// The block type used to enumerate and optionally remove AVMusicEvents when using
657/// `AVMusicTrack(enumerateEventsInRange:usingBlock:)`
658///
659/// Parameter `event`: the AVMusicEvent returned by this enumeration block call. If this
660/// event is modified by the block, the corresponding track event will be changed.
661///
662/// Parameter `timeStamp`: the beat position of this event in the AVMusicTrack. If the block
663/// sets *timeStamp to a new value, the corresponding event's beat position
664/// in the track will be updated.
665///
666/// Parameter `removeEvent`: If the block sets *removeEvent to YES, the current event will be
667/// removed from the track.
668///
669/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmusiceventenumerationblock?language=objc)
670#[cfg(all(
671 feature = "AVAudioTypes",
672 feature = "AVMusicEvents",
673 feature = "block2"
674))]
675pub type AVMusicEventEnumerationBlock =
676 *mut block2::Block<dyn Fn(NonNull<AVMusicEvent>, NonNull<AVMusicTimeStamp>, NonNull<Bool>)>;
677
678/// AVMusicTrackEditor.
679impl AVMusicTrack {
680 extern_methods!(
681 /// Indicates whether the track is an automation track.
682 ///
683 /// If set to YES, this can be used to contain, parameter automation events, exclusively.
684 /// Adding any other event types will generate exceptions.
685 ///
686 /// If a track already contains non-parameter events, setting this to YES will
687 /// generate an exception.
688 #[unsafe(method(usesAutomatedParameters))]
689 #[unsafe(method_family = none)]
690 pub unsafe fn usesAutomatedParameters(&self) -> bool;
691
692 /// Setter for [`usesAutomatedParameters`][Self::usesAutomatedParameters].
693 #[unsafe(method(setUsesAutomatedParameters:))]
694 #[unsafe(method_family = none)]
695 pub unsafe fn setUsesAutomatedParameters(&self, uses_automated_parameters: bool);
696
697 #[cfg(all(feature = "AVAudioTypes", feature = "AVMusicEvents"))]
698 /// Adds an AVMusicEvent's contents to a track at the specified AVMusicTimeStamp.
699 ///
700 /// Parameter `event`: the event to be added
701 ///
702 /// Parameter `beat`: the AVMusicTimeStamp
703 ///
704 /// Because event contents are copied into the track, the same event may be added multiple
705 /// times at different timestamps.
706 ///
707 /// There are restrictions on which AVMusicEvent subclasses may be added to different tracks:
708 ///
709 /// - Only AVExtendedTempoEvents and AVMIDIMetaEvents with certain AVMIDIMetaEventTypes
710 /// can be added to an AVMusicSequence's tempo track (see AVMIDIMetaEvent).
711 ///
712 /// - AVParameterEvents can only be added to automation tracks (see AVParameterEvent).
713 ///
714 /// - All other event subclasses cannot be added to tempo or automation tracks.
715 #[unsafe(method(addEvent:atBeat:))]
716 #[unsafe(method_family = none)]
717 pub unsafe fn addEvent_atBeat(&self, event: &AVMusicEvent, beat: AVMusicTimeStamp);
718
719 #[cfg(feature = "AVAudioTypes")]
720 /// Shift the beat location of all events in the given beat range by the amount specified.
721 ///
722 /// Parameter `range`: the range of beats. Must be a valid AVBeatRange.
723 ///
724 /// Parameter `beatAmount`: the amount in beats to shift each event. The amount may be positive or negative.
725 #[unsafe(method(moveEventsInRange:byAmount:))]
726 #[unsafe(method_family = none)]
727 pub unsafe fn moveEventsInRange_byAmount(
728 &self,
729 range: AVBeatRange,
730 beat_amount: AVMusicTimeStamp,
731 );
732
733 #[cfg(feature = "AVAudioTypes")]
734 /// Removes all events in the given beat range, erasing that portion of the AVMusicTrack.
735 ///
736 /// Parameter `range`: the range of beats. Must be a valid AVBeatRange.
737 ///
738 /// All events outside of the specified range left unmodified.
739 #[unsafe(method(clearEventsInRange:))]
740 #[unsafe(method_family = none)]
741 pub unsafe fn clearEventsInRange(&self, range: AVBeatRange);
742
743 #[cfg(feature = "AVAudioTypes")]
744 /// Removes all events in the given beat range, splicing out that portion of the AVMusicTrack.
745 ///
746 /// Parameter `range`: the range of beats. Must be a valid AVBeatRange.
747 ///
748 /// All events past the end of the specified range will be shifted backward by the duration of the range.
749 #[unsafe(method(cutEventsInRange:))]
750 #[unsafe(method_family = none)]
751 pub unsafe fn cutEventsInRange(&self, range: AVBeatRange);
752
753 #[cfg(feature = "AVAudioTypes")]
754 /// Copies all events in the given beat range from the specified AVMusicTrack,
755 /// splicing them into the current AVMusicTrack.
756 ///
757 /// Parameter `range`: the range of beats. Must be a valid AVBeatRange.
758 ///
759 /// Parameter `sourceTrack`: the AVMusicTrack to copy the events from.
760 ///
761 /// Parameter `insertStartBeat`: the start beat at which the copied events should be spliced in.
762 ///
763 /// All events originally at or past insertStartBeat will be shifted forward by the duration
764 /// of the copied-in range.
765 #[unsafe(method(copyEventsInRange:fromTrack:insertAtBeat:))]
766 #[unsafe(method_family = none)]
767 pub unsafe fn copyEventsInRange_fromTrack_insertAtBeat(
768 &self,
769 range: AVBeatRange,
770 source_track: &AVMusicTrack,
771 insert_start_beat: AVMusicTimeStamp,
772 );
773
774 #[cfg(feature = "AVAudioTypes")]
775 /// Copies all events in the given beat range from the specified AVMusicTrack,
776 /// merging them into the current AVMusicTrack.
777 ///
778 /// Parameter `range`: the range of beats. Must be a valid AVBeatRange.
779 ///
780 /// Parameter `sourceTrack`: the AVMusicTrack to copy the events from.
781 ///
782 /// Parameter `insertStartBeat`: the start beat at which the copied events should be merged.
783 ///
784 /// All events originally at or past mergeStartBeat will be left unmodified.
785 ///
786 /// Copying events from track to track follows the same type-exclusion rules as adding
787 /// events: The operation will generate an exception.
788 #[unsafe(method(copyAndMergeEventsInRange:fromTrack:mergeAtBeat:))]
789 #[unsafe(method_family = none)]
790 pub unsafe fn copyAndMergeEventsInRange_fromTrack_mergeAtBeat(
791 &self,
792 range: AVBeatRange,
793 source_track: &AVMusicTrack,
794 merge_start_beat: AVMusicTimeStamp,
795 );
796
797 #[cfg(all(
798 feature = "AVAudioTypes",
799 feature = "AVMusicEvents",
800 feature = "block2"
801 ))]
802 /// Iterates through the AVMusicEvents within the AVMusicTrack whose timestamps fit within the range,
803 /// calling the block for each.
804 ///
805 /// Parameter `block`: the AVMusicEventEnumerationBlock to call for each event.
806 ///
807 /// Each event returned via the block should be examined using `NSObject(isKindOfClass:)`
808 /// to determine its subclass and then cast and accessed/edited accordingly.
809 ///
810 /// The iteration may continue after removing an event.
811 ///
812 /// The event objects returned via the block will not be the same instances
813 /// which were added to the AVMusicTrack, though their contents will be identical.
814 #[unsafe(method(enumerateEventsInRange:usingBlock:))]
815 #[unsafe(method_family = none)]
816 pub unsafe fn enumerateEventsInRange_usingBlock(
817 &self,
818 range: AVBeatRange,
819 block: AVMusicEventEnumerationBlock,
820 );
821 );
822}