#[repr(C)]pub struct AVMusicTrack { /* private fields */ }AVAudioSequencer only.Expand description
A collection of music events which will be sent to a given destination, and which can be offset, muted, etc. independently of events in other tracks.
AVMusicTrack is not a container of AVMusicEvents - it will not hold references to AVMusicEvents that are added, so an application should maintain its own if it is desired.
See also Apple’s documentation
Implementations§
Source§impl AVMusicTrack
impl AVMusicTrack
Sourcepub unsafe fn destinationAudioUnit(&self) -> Option<Retained<AVAudioUnit>>
Available on crate features AVAudioNode and AVAudioUnit only.
pub unsafe fn destinationAudioUnit(&self) -> Option<Retained<AVAudioUnit>>
AVAudioNode and AVAudioUnit only.The AVAudioUnit which will receive the track’s events
This is mutually exclusive with setting a destination MIDIEndpoint. The AU must already be attached to an audio engine, and the track must be part of the AVAudioSequencer associated with that engine. When playing, the track will send its events to that AVAudioUnit. The destination AU cannot be changed while the track’s sequence is playing.
Sourcepub unsafe fn setDestinationAudioUnit(
&self,
destination_audio_unit: Option<&AVAudioUnit>,
)
Available on crate features AVAudioNode and AVAudioUnit only.
pub unsafe fn setDestinationAudioUnit( &self, destination_audio_unit: Option<&AVAudioUnit>, )
AVAudioNode and AVAudioUnit only.Setter for destinationAudioUnit.
pub unsafe fn destinationMIDIEndpoint(&self) -> MIDIEndpointRef
objc2-core-midi only.Sourcepub unsafe fn setDestinationMIDIEndpoint(
&self,
destination_midi_endpoint: MIDIEndpointRef,
)
Available on crate feature objc2-core-midi only.
pub unsafe fn setDestinationMIDIEndpoint( &self, destination_midi_endpoint: MIDIEndpointRef, )
objc2-core-midi only.Setter for destinationMIDIEndpoint.
Sourcepub unsafe fn loopRange(&self) -> AVBeatRange
Available on crate feature AVAudioTypes only.
pub unsafe fn loopRange(&self) -> AVBeatRange
AVAudioTypes only.The timestamp range in beats for the loop
The loop is set by specifying its beat range.
Sourcepub unsafe fn setLoopRange(&self, loop_range: AVBeatRange)
Available on crate feature AVAudioTypes only.
pub unsafe fn setLoopRange(&self, loop_range: AVBeatRange)
AVAudioTypes only.Setter for loopRange.
Sourcepub unsafe fn isLoopingEnabled(&self) -> bool
pub unsafe fn isLoopingEnabled(&self) -> bool
Determines whether or not the track is looped.
If loopRange has not been set, the full track will be looped.
Sourcepub unsafe fn setLoopingEnabled(&self, looping_enabled: bool)
pub unsafe fn setLoopingEnabled(&self, looping_enabled: bool)
Setter for isLoopingEnabled.
Sourcepub unsafe fn numberOfLoops(&self) -> NSInteger
pub unsafe fn numberOfLoops(&self) -> NSInteger
The number of times that the track’s loop will repeat
If set to AVMusicTrackLoopCountForever, the track will loop forever. Otherwise, legal values start with 1.
Sourcepub unsafe fn setNumberOfLoops(&self, number_of_loops: NSInteger)
pub unsafe fn setNumberOfLoops(&self, number_of_loops: NSInteger)
Setter for numberOfLoops.
Sourcepub unsafe fn offsetTime(&self) -> AVMusicTimeStamp
Available on crate feature AVAudioTypes only.
pub unsafe fn offsetTime(&self) -> AVMusicTimeStamp
AVAudioTypes only.Offset the track’s start time to the specified time in beats
By default this value is zero.
Sourcepub unsafe fn setOffsetTime(&self, offset_time: AVMusicTimeStamp)
Available on crate feature AVAudioTypes only.
pub unsafe fn setOffsetTime(&self, offset_time: AVMusicTimeStamp)
AVAudioTypes only.Setter for offsetTime.
Sourcepub unsafe fn lengthInBeats(&self) -> AVMusicTimeStamp
Available on crate feature AVAudioTypes only.
pub unsafe fn lengthInBeats(&self) -> AVMusicTimeStamp
AVAudioTypes only.The total duration of the track in beats
This will return the beat of the last event in the track plus any additional time that may be needed for fading out of ending notes or round a loop point to musical bar, etc. If this has not been set by the user, the track length will always be adjusted to the end of the last active event in a track and is adjusted dynamically as events are added or removed.
The property will return the maximum of the user-set track length, or the calculated length.
Sourcepub unsafe fn setLengthInBeats(&self, length_in_beats: AVMusicTimeStamp)
Available on crate feature AVAudioTypes only.
pub unsafe fn setLengthInBeats(&self, length_in_beats: AVMusicTimeStamp)
AVAudioTypes only.Setter for lengthInBeats.
Sourcepub unsafe fn lengthInSeconds(&self) -> NSTimeInterval
pub unsafe fn lengthInSeconds(&self) -> NSTimeInterval
The total duration of the track in seconds
This will return time of the last event in the track plus any additional time that may be needed for fading out of ending notes or round a loop point to musical bar, etc. If this has not been set by the user, the track length will always be adjusted to the end of the last active event in a track and is adjusted dynamically as events are added or removed.
The property will return the maximum of the user-set track length, or the calculated length.
Sourcepub unsafe fn setLengthInSeconds(&self, length_in_seconds: NSTimeInterval)
pub unsafe fn setLengthInSeconds(&self, length_in_seconds: NSTimeInterval)
Setter for lengthInSeconds.
Sourcepub unsafe fn timeResolution(&self) -> NSUInteger
pub unsafe fn timeResolution(&self) -> NSUInteger
The time resolution value for the sequence, in ticks (pulses) per quarter note (PPQN)
If a MIDI file was used to construct the containing sequence, the resolution will be what was in the file. If you want to keep a time resolution when writing a new file, you can retrieve this value and then specify it when calling -[AVAudioSequencer writeToFile:flags:withResolution]. It has no direct bearing on the rendering or notion of time of the sequence itself, just its representation in MIDI files. By default this is set to either 480 if the sequence was created manually, or a value based on what was in a MIDI file if the sequence was created from a MIDI file.
This can only be retrieved from the tempo track.
Source§impl AVMusicTrack
Methods declared on superclass NSObject.
impl AVMusicTrack
Methods declared on superclass NSObject.
Source§impl AVMusicTrack
AVMusicTrackEditor.
impl AVMusicTrack
AVMusicTrackEditor.
Sourcepub unsafe fn usesAutomatedParameters(&self) -> bool
pub unsafe fn usesAutomatedParameters(&self) -> bool
Indicates whether the track is an automation track.
If set to YES, this can be used to contain, parameter automation events, exclusively. Adding any other event types will generate exceptions.
If a track already contains non-parameter events, setting this to YES will generate an exception.
Sourcepub unsafe fn setUsesAutomatedParameters(&self, uses_automated_parameters: bool)
pub unsafe fn setUsesAutomatedParameters(&self, uses_automated_parameters: bool)
Setter for usesAutomatedParameters.
Sourcepub unsafe fn addEvent_atBeat(
&self,
event: &AVMusicEvent,
beat: AVMusicTimeStamp,
)
Available on crate features AVAudioTypes and AVMusicEvents only.
pub unsafe fn addEvent_atBeat( &self, event: &AVMusicEvent, beat: AVMusicTimeStamp, )
AVAudioTypes and AVMusicEvents only.Adds an AVMusicEvent’s contents to a track at the specified AVMusicTimeStamp.
Parameter event: the event to be added
Parameter beat: the AVMusicTimeStamp
Because event contents are copied into the track, the same event may be added multiple times at different timestamps.
There are restrictions on which AVMusicEvent subclasses may be added to different tracks:
-
Only AVExtendedTempoEvents and AVMIDIMetaEvents with certain AVMIDIMetaEventTypes can be added to an AVMusicSequence’s tempo track (see AVMIDIMetaEvent).
-
AVParameterEvents can only be added to automation tracks (see AVParameterEvent).
-
All other event subclasses cannot be added to tempo or automation tracks.
Sourcepub unsafe fn moveEventsInRange_byAmount(
&self,
range: AVBeatRange,
beat_amount: AVMusicTimeStamp,
)
Available on crate feature AVAudioTypes only.
pub unsafe fn moveEventsInRange_byAmount( &self, range: AVBeatRange, beat_amount: AVMusicTimeStamp, )
AVAudioTypes only.Shift the beat location of all events in the given beat range by the amount specified.
Parameter range: the range of beats. Must be a valid AVBeatRange.
Parameter beatAmount: the amount in beats to shift each event. The amount may be positive or negative.
Sourcepub unsafe fn clearEventsInRange(&self, range: AVBeatRange)
Available on crate feature AVAudioTypes only.
pub unsafe fn clearEventsInRange(&self, range: AVBeatRange)
AVAudioTypes only.Removes all events in the given beat range, erasing that portion of the AVMusicTrack.
Parameter range: the range of beats. Must be a valid AVBeatRange.
All events outside of the specified range left unmodified.
Sourcepub unsafe fn cutEventsInRange(&self, range: AVBeatRange)
Available on crate feature AVAudioTypes only.
pub unsafe fn cutEventsInRange(&self, range: AVBeatRange)
AVAudioTypes only.Removes all events in the given beat range, splicing out that portion of the AVMusicTrack.
Parameter range: the range of beats. Must be a valid AVBeatRange.
All events past the end of the specified range will be shifted backward by the duration of the range.
Sourcepub unsafe fn copyEventsInRange_fromTrack_insertAtBeat(
&self,
range: AVBeatRange,
source_track: &AVMusicTrack,
insert_start_beat: AVMusicTimeStamp,
)
Available on crate feature AVAudioTypes only.
pub unsafe fn copyEventsInRange_fromTrack_insertAtBeat( &self, range: AVBeatRange, source_track: &AVMusicTrack, insert_start_beat: AVMusicTimeStamp, )
AVAudioTypes only.Copies all events in the given beat range from the specified AVMusicTrack, splicing them into the current AVMusicTrack.
Parameter range: the range of beats. Must be a valid AVBeatRange.
Parameter sourceTrack: the AVMusicTrack to copy the events from.
Parameter insertStartBeat: the start beat at which the copied events should be spliced in.
All events originally at or past insertStartBeat will be shifted forward by the duration of the copied-in range.
Sourcepub unsafe fn copyAndMergeEventsInRange_fromTrack_mergeAtBeat(
&self,
range: AVBeatRange,
source_track: &AVMusicTrack,
merge_start_beat: AVMusicTimeStamp,
)
Available on crate feature AVAudioTypes only.
pub unsafe fn copyAndMergeEventsInRange_fromTrack_mergeAtBeat( &self, range: AVBeatRange, source_track: &AVMusicTrack, merge_start_beat: AVMusicTimeStamp, )
AVAudioTypes only.Copies all events in the given beat range from the specified AVMusicTrack, merging them into the current AVMusicTrack.
Parameter range: the range of beats. Must be a valid AVBeatRange.
Parameter sourceTrack: the AVMusicTrack to copy the events from.
Parameter insertStartBeat: the start beat at which the copied events should be merged.
All events originally at or past mergeStartBeat will be left unmodified.
Copying events from track to track follows the same type-exclusion rules as adding events: The operation will generate an exception.
Sourcepub unsafe fn enumerateEventsInRange_usingBlock(
&self,
range: AVBeatRange,
block: AVMusicEventEnumerationBlock,
)
Available on crate features AVAudioTypes and AVMusicEvents and block2 only.
pub unsafe fn enumerateEventsInRange_usingBlock( &self, range: AVBeatRange, block: AVMusicEventEnumerationBlock, )
AVAudioTypes and AVMusicEvents and block2 only.Iterates through the AVMusicEvents within the AVMusicTrack whose timestamps fit within the range, calling the block for each.
Parameter block: the AVMusicEventEnumerationBlock to call for each event.
Each event returned via the block should be examined using NSObject(isKindOfClass:)
to determine its subclass and then cast and accessed/edited accordingly.
The iteration may continue after removing an event.
The event objects returned via the block will not be the same instances which were added to the AVMusicTrack, though their contents will be identical.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AVMusicTrack> for AVMusicTrack
impl AsRef<AVMusicTrack> for AVMusicTrack
Source§impl AsRef<AnyObject> for AVMusicTrack
impl AsRef<AnyObject> for AVMusicTrack
Source§impl AsRef<NSObject> for AVMusicTrack
impl AsRef<NSObject> for AVMusicTrack
Source§impl Borrow<AnyObject> for AVMusicTrack
impl Borrow<AnyObject> for AVMusicTrack
Source§impl Borrow<NSObject> for AVMusicTrack
impl Borrow<NSObject> for AVMusicTrack
Source§impl ClassType for AVMusicTrack
impl ClassType for AVMusicTrack
Source§const NAME: &'static str = "AVMusicTrack"
const NAME: &'static str = "AVMusicTrack"
Source§type ThreadKind = <<AVMusicTrack as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<AVMusicTrack as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for AVMusicTrack
impl Debug for AVMusicTrack
Source§impl Deref for AVMusicTrack
impl Deref for AVMusicTrack
Source§impl Hash for AVMusicTrack
impl Hash for AVMusicTrack
Source§impl Message for AVMusicTrack
impl Message for AVMusicTrack
Source§impl NSObjectProtocol for AVMusicTrack
impl NSObjectProtocol for AVMusicTrack
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref