objc2_avf_audio/generated/
AVMIDIPlayer.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Generic callback block.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmidiplayercompletionhandler?language=objc)
13#[cfg(feature = "block2")]
14pub type AVMIDIPlayerCompletionHandler = *mut block2::Block<dyn Fn()>;
15
16extern_class!(
17    /// A player for music file formats (MIDI, iMelody).
18    ///
19    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avmidiplayer?language=objc)
20    #[unsafe(super(NSObject))]
21    #[derive(Debug, PartialEq, Eq, Hash)]
22    pub struct AVMIDIPlayer;
23);
24
25unsafe impl NSObjectProtocol for AVMIDIPlayer {}
26
27impl AVMIDIPlayer {
28    extern_methods!(
29        /// Create a player with the contents of the file specified by the URL.
30        ///
31        /// 'bankURL' should contain the path to a SoundFont2 or DLS bank to be used
32        /// by the MIDI synthesizer.  For OSX it can be set to nil for the default,
33        /// but for iOS it must always refer to a valid bank file.
34        #[unsafe(method(initWithContentsOfURL:soundBankURL:error:_))]
35        #[unsafe(method_family = init)]
36        pub unsafe fn initWithContentsOfURL_soundBankURL_error(
37            this: Allocated<Self>,
38            in_url: &NSURL,
39            bank_url: Option<&NSURL>,
40        ) -> Result<Retained<Self>, Retained<NSError>>;
41
42        /// Create a player with the contents of the data object
43        ///
44        /// 'bankURL' should contain the path to a SoundFont2 or DLS bank to be used
45        /// by the MIDI synthesizer.  For OSX it can be set to nil for the default,
46        /// but for iOS it must always refer to a valid bank file.
47        #[unsafe(method(initWithData:soundBankURL:error:_))]
48        #[unsafe(method_family = init)]
49        pub unsafe fn initWithData_soundBankURL_error(
50            this: Allocated<Self>,
51            data: &NSData,
52            bank_url: Option<&NSURL>,
53        ) -> Result<Retained<Self>, Retained<NSError>>;
54
55        /// Get ready to play the sequence by prerolling all events
56        ///
57        /// Happens automatically on play if it has not already been called, but may produce a delay in startup.
58        #[unsafe(method(prepareToPlay))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn prepareToPlay(&self);
61
62        #[cfg(feature = "block2")]
63        /// Play the sequence.
64        #[unsafe(method(play:))]
65        #[unsafe(method_family = none)]
66        pub unsafe fn play(&self, completion_handler: AVMIDIPlayerCompletionHandler);
67
68        /// Stop playing the sequence.
69        #[unsafe(method(stop))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn stop(&self);
72
73        /// The length of the currently loaded file in seconds.
74        #[unsafe(method(duration))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn duration(&self) -> NSTimeInterval;
77
78        /// Indicates whether or not the player is playing
79        #[unsafe(method(isPlaying))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn isPlaying(&self) -> bool;
82
83        /// The playback rate of the player
84        ///
85        /// 1.0 is normal playback rate.  Rate must be > 0.0.
86        #[unsafe(method(rate))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn rate(&self) -> c_float;
89
90        /// Setter for [`rate`][Self::rate].
91        #[unsafe(method(setRate:))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn setRate(&self, rate: c_float);
94
95        /// The current playback position in seconds
96        ///
97        /// Setting this positions the player to the specified time.  No range checking on the time value is done.
98        /// This can be set while the player is playing, in which case playback will resume at the new time.
99        #[unsafe(method(currentPosition))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn currentPosition(&self) -> NSTimeInterval;
102
103        /// Setter for [`currentPosition`][Self::currentPosition].
104        #[unsafe(method(setCurrentPosition:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn setCurrentPosition(&self, current_position: NSTimeInterval);
107    );
108}
109
110/// Methods declared on superclass `NSObject`.
111impl AVMIDIPlayer {
112    extern_methods!(
113        #[unsafe(method(init))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
116
117        #[unsafe(method(new))]
118        #[unsafe(method_family = new)]
119        pub unsafe fn new() -> Retained<Self>;
120    );
121}