objc2_shazam_kit/generated/
SHSession.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-avf-audio")]
7use objc2_avf_audio::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_protocol!(
13    /// Methods that the session calls with the result of a match request.
14    ///
15    /// See also [Apple's documentation](https://developer.apple.com/documentation/shazamkit/shsessiondelegate?language=objc)
16    pub unsafe trait SHSessionDelegate: NSObjectProtocol {
17        #[cfg(feature = "SHMatch")]
18        /// Tells the delegate that the query signature matches an item in the catalog.
19        ///
20        /// - Parameters:
21        /// - session: The session object that performs the match.
22        /// - match: The matching items from the catalog.
23        #[optional]
24        #[unsafe(method(session:didFindMatch:))]
25        #[unsafe(method_family = none)]
26        unsafe fn session_didFindMatch(&self, session: &SHSession, r#match: &SHMatch);
27
28        #[cfg(feature = "SHSignature")]
29        /// Tells the delegate that the query signature doesn't match an item in the catalog, or that there's an error.
30        ///
31        /// You can retry the match if the error indicates an issue in communicating with the catalog server, such as ``SHError/Code/matchAttemptFailed``.
32        ///
33        /// - Parameters:
34        /// - session: The session object that performs the match.
35        /// - signature: The query signature to use for the match.
36        /// - error: The error that occurs; otherwise, `nil`, which indicates that there's no match.
37        #[optional]
38        #[unsafe(method(session:didNotFindMatchForSignature:error:))]
39        #[unsafe(method_family = none)]
40        unsafe fn session_didNotFindMatchForSignature_error(
41            &self,
42            session: &SHSession,
43            signature: &SHSignature,
44            error: Option<&NSError>,
45        );
46    }
47);
48
49extern_class!(
50    /// An object that matches a specific audio recording when a segment of that recording is part of captured sound in the Shazam catalog or your custom catalog.
51    ///
52    /// Prepare to make matches by:
53    ///
54    /// - Creating a session for the catalog that contains the reference signatures
55    /// - Adding your delegate that receives the match results
56    ///
57    /// Search for a match in one of two ways:
58    ///
59    /// - Generate a signature for the captured audio and call ``match(_:)``
60    /// - Call ``matchStreamingBuffer(_:at:)`` with a streaming audio buffer, and ShazamKit generates the signature for you
61    ///
62    /// Searching the catalog is asynchronous. The session calls your delegate methods with the result.
63    ///
64    /// Matching songs in Shazam music requires enabling your app to access the catalog. For more information on enabling your app, see [Enable ShazamKit for an App ID](https://developer.apple.com/help/account/configure-app-services/shazamkit).
65    ///
66    /// The code below shows searching for a match in the Shazam catalog using an existing audio buffer:
67    ///
68    /// ```swift
69    /// // Set up the session.
70    /// let session = SHSession()
71    ///
72    /// // Create a signature from the captured audio buffer.
73    /// let signatureGenerator = SHSignatureGenerator()
74    /// try signatureGenerator.append(buffer, at: audioTime)
75    /// let signature = signatureGenerator.signature()
76    ///
77    /// // Check for a match.
78    /// let result = await session.result(from: signature)
79    ///
80    /// // Use the result.
81    /// switch result {
82    /// case .match(let match):
83    /// // Match found.
84    /// case .noMatch(let signature):
85    /// // No match found.
86    /// case .error(let error, let signature):
87    /// // An error occurred.
88    /// }
89    /// ```
90    ///
91    /// See also [Apple's documentation](https://developer.apple.com/documentation/shazamkit/shsession?language=objc)
92    #[unsafe(super(NSObject))]
93    #[derive(Debug, PartialEq, Eq, Hash)]
94    pub struct SHSession;
95);
96
97extern_conformance!(
98    unsafe impl NSObjectProtocol for SHSession {}
99);
100
101impl SHSession {
102    extern_methods!(
103        #[cfg(feature = "SHCatalog")]
104        /// The catalog object containing the reference signatures and their associated metadata that the session uses to perform matches.
105        #[unsafe(method(catalog))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn catalog(&self) -> Retained<SHCatalog>;
108
109        /// The object that the session calls with the result of a match request.
110        #[unsafe(method(delegate))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn SHSessionDelegate>>>;
113
114        /// Setter for [`delegate`][Self::delegate].
115        ///
116        /// This is a [weak property][objc2::topics::weak_property].
117        #[unsafe(method(setDelegate:))]
118        #[unsafe(method_family = none)]
119        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn SHSessionDelegate>>);
120
121        /// Creates a new session object for matching songs in the Shazam Music catalog.
122        #[unsafe(method(init))]
123        #[unsafe(method_family = init)]
124        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
125
126        #[cfg(feature = "SHCatalog")]
127        /// Creates a new session object for matching audio in a custom catalog.
128        ///
129        /// - Parameters:
130        /// - catalog: The catalog that contains the reference audio signatures and their associated metadata.
131        #[unsafe(method(initWithCatalog:))]
132        #[unsafe(method_family = init)]
133        pub unsafe fn initWithCatalog(this: Allocated<Self>, catalog: &SHCatalog)
134            -> Retained<Self>;
135
136        #[cfg(feature = "objc2-avf-audio")]
137        /// Converts the audio in the buffer to a signature, and searches the reference signatures in the session catalog.
138        ///
139        /// This method continues to generate signatures and perform searches until the audio in the buffer stops, which may result in multiple calls to the ``SHSession/delegate``.
140        ///
141        /// The audio buffer must be in one of the supported formats. For the list of the supported audio formats, see ``SHSignatureGenerator/append(_:at:)``.
142        ///
143        /// To use the microphone as input for the buffer, see
144        /// <doc
145        /// :matching-audio-using-the-built-in-microphone>.
146        ///
147        /// > Note:
148        /// > You must use the audio format of the first call to this method in the current session in all subsequent calls for the session.
149        ///
150        /// - Parameters:
151        /// - buffer: An audio buffer.
152        /// - time: The start time of the audio to use for generating the signatures.
153        #[unsafe(method(matchStreamingBuffer:atTime:))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn matchStreamingBuffer_atTime(
156            &self,
157            buffer: &AVAudioPCMBuffer,
158            time: Option<&AVAudioTime>,
159        );
160
161        #[cfg(feature = "SHSignature")]
162        /// Searches for the query signature in the reference signatures that the session catalog contains.
163        ///
164        /// - Parameters:
165        /// - signature: The signature for searching the catalog of reference signatures.
166        #[unsafe(method(matchSignature:))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn matchSignature(&self, signature: &SHSignature);
169    );
170}
171
172/// Methods declared on superclass `NSObject`.
173impl SHSession {
174    extern_methods!(
175        #[unsafe(method(new))]
176        #[unsafe(method_family = new)]
177        pub unsafe fn new() -> Retained<Self>;
178    );
179}