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::DynBlock<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
25extern_conformance!(
26 unsafe impl NSObjectProtocol for AVMIDIPlayer {}
27);
28
29impl AVMIDIPlayer {
30 extern_methods!(
31 /// Create a player with the contents of the file specified by the URL.
32 ///
33 /// 'bankURL' should contain the path to a SoundFont2 or DLS bank to be used
34 /// by the MIDI synthesizer. For OSX it can be set to nil for the default,
35 /// but for iOS it must always refer to a valid bank file.
36 #[unsafe(method(initWithContentsOfURL:soundBankURL:error:_))]
37 #[unsafe(method_family = init)]
38 pub unsafe fn initWithContentsOfURL_soundBankURL_error(
39 this: Allocated<Self>,
40 in_url: &NSURL,
41 bank_url: Option<&NSURL>,
42 ) -> Result<Retained<Self>, Retained<NSError>>;
43
44 /// Create a player with the contents of the data object
45 ///
46 /// 'bankURL' should contain the path to a SoundFont2 or DLS bank to be used
47 /// by the MIDI synthesizer. For OSX it can be set to nil for the default,
48 /// but for iOS it must always refer to a valid bank file.
49 #[unsafe(method(initWithData:soundBankURL:error:_))]
50 #[unsafe(method_family = init)]
51 pub unsafe fn initWithData_soundBankURL_error(
52 this: Allocated<Self>,
53 data: &NSData,
54 bank_url: Option<&NSURL>,
55 ) -> Result<Retained<Self>, Retained<NSError>>;
56
57 /// Get ready to play the sequence by prerolling all events
58 ///
59 /// Happens automatically on play if it has not already been called, but may produce a delay in startup.
60 #[unsafe(method(prepareToPlay))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn prepareToPlay(&self);
63
64 #[cfg(feature = "block2")]
65 /// Play the sequence.
66 ///
67 /// # Safety
68 ///
69 /// `completion_handler` must be a valid pointer or null.
70 #[unsafe(method(play:))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn play(&self, completion_handler: AVMIDIPlayerCompletionHandler);
73
74 /// Stop playing the sequence.
75 #[unsafe(method(stop))]
76 #[unsafe(method_family = none)]
77 pub unsafe fn stop(&self);
78
79 /// The length of the currently loaded file in seconds.
80 #[unsafe(method(duration))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn duration(&self) -> NSTimeInterval;
83
84 /// Indicates whether or not the player is playing
85 #[unsafe(method(isPlaying))]
86 #[unsafe(method_family = none)]
87 pub unsafe fn isPlaying(&self) -> bool;
88
89 /// The playback rate of the player
90 ///
91 /// 1.0 is normal playback rate. Rate must be > 0.0.
92 #[unsafe(method(rate))]
93 #[unsafe(method_family = none)]
94 pub unsafe fn rate(&self) -> c_float;
95
96 /// Setter for [`rate`][Self::rate].
97 #[unsafe(method(setRate:))]
98 #[unsafe(method_family = none)]
99 pub unsafe fn setRate(&self, rate: c_float);
100
101 /// The current playback position in seconds
102 ///
103 /// Setting this positions the player to the specified time. No range checking on the time value is done.
104 /// This can be set while the player is playing, in which case playback will resume at the new time.
105 #[unsafe(method(currentPosition))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn currentPosition(&self) -> NSTimeInterval;
108
109 /// Setter for [`currentPosition`][Self::currentPosition].
110 #[unsafe(method(setCurrentPosition:))]
111 #[unsafe(method_family = none)]
112 pub unsafe fn setCurrentPosition(&self, current_position: NSTimeInterval);
113 );
114}
115
116/// Methods declared on superclass `NSObject`.
117impl AVMIDIPlayer {
118 extern_methods!(
119 #[unsafe(method(init))]
120 #[unsafe(method_family = init)]
121 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
122
123 #[unsafe(method(new))]
124 #[unsafe(method_family = new)]
125 pub unsafe fn new() -> Retained<Self>;
126 );
127}