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