objc2-core-haptics 0.3.2

Bindings to the CoreHaptics framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_protocol!(
    /// A protocol which defines operations for starting, stopping, and sending parameters to a pattern player.
    ///
    /// Instances of these objects are created via the factory methods such as
    /// `CHHapticEngine(createPlayerWithPattern:error)`.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticpatternplayer?language=objc)
    pub unsafe trait CHHapticPatternPlayer: NSObjectProtocol {
        /// Start playing the pattern at the specified time (see `CHHapticEngine(currentTime)`).
        /// If 'time' is set to `CHHapticTimeImmediate`, the pattern is started as soon as possible.
        #[unsafe(method(startAtTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn startAtTime_error(&self, time: NSTimeInterval) -> Result<(), Retained<NSError>>;

        /// Stop playing the pattern at the specified time (see `CHHapticEngine(currentTime)`).
        /// If 'time' is set to `CHHapticTimeImmediate`, the pattern is stopped as soon as possible.
        #[unsafe(method(stopAtTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn stopAtTime_error(&self, time: NSTimeInterval) -> Result<(), Retained<NSError>>;

        #[cfg(feature = "CHHapticParameter")]
        /// Send an array of CHHapticDynamicParameters, starting at the specified time (see `CHHapticEngine(currentTime)`).
        /// If 'time' is set to `CHHapticTimeImmediate`, the parameters are sent as soon as possible.
        #[unsafe(method(sendParameters:atTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn sendParameters_atTime_error(
            &self,
            parameters: &NSArray<CHHapticDynamicParameter>,
            time: NSTimeInterval,
        ) -> Result<(), Retained<NSError>>;

        #[cfg(feature = "CHHapticParameter")]
        /// Schedule a CHHapticParameterCurve, starting at the specified time (see `CHHapticEngine(currentTime)`).
        /// If 'time' is set to `CHHapticTimeImmediate`, the parameter curve is scheduled as soon as possible.
        ///
        /// This method overrides the relativeTime property of the passed-in CHHapticParameterCurve,
        /// setting it to this method's 'time' argument. All the curve's control point times will then be
        /// calculated relative to that time.
        #[unsafe(method(scheduleParameterCurve:atTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn scheduleParameterCurve_atTime_error(
            &self,
            parameter_curve: &CHHapticParameterCurve,
            time: NSTimeInterval,
        ) -> Result<(), Retained<NSError>>;

        /// Removes all pending commands and stops the player as soon as possible.
        #[unsafe(method(cancelAndReturnError:_))]
        #[unsafe(method_family = none)]
        unsafe fn cancelAndReturnError(&self) -> Result<(), Retained<NSError>>;

        /// When set to YES, the player's audio and haptic output will be silenced.
        #[unsafe(method(isMuted))]
        #[unsafe(method_family = none)]
        unsafe fn isMuted(&self) -> bool;

        /// Setter for [`isMuted`][Self::isMuted].
        #[unsafe(method(setIsMuted:))]
        #[unsafe(method_family = none)]
        unsafe fn setIsMuted(&self, is_muted: bool);
    }
);

/// Block which is called asynchronously when a CHHapticAdvancedPatternPlayer finishes playing.
///
/// Parameter `error`: If the call to start the player fails, this is set to a valid NSError describing the error.
///
/// In general, callbacks arrive on a non-main thread and it is the client's responsibility to handle them
/// in a thread-safe manner.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticadvancedpatternplayercompletionhandler?language=objc)
#[cfg(feature = "block2")]
pub type CHHapticAdvancedPatternPlayerCompletionHandler =
    *mut block2::DynBlock<dyn Fn(*mut NSError)>;

extern_protocol!(
    /// A protocol which defines operations for pausing, resuming, seeking, and sending parameters to a pattern player.
    ///
    /// Instances of these objects are created via the factory methods such as `CHHapticEngine(createAdvancedPlayerWithPattern:error)`.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticadvancedpatternplayer?language=objc)
    pub unsafe trait CHHapticAdvancedPatternPlayer: CHHapticPatternPlayer {
        /// Pause playback of the pattern at the specified time (see `CHHapticEngine(currentTime)`).
        ///
        /// If 'time' is set to `CHHapticTimeImmediate`, the pattern will be paused immediately.
        #[unsafe(method(pauseAtTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn pauseAtTime_error(&self, time: NSTimeInterval) -> Result<(), Retained<NSError>>;

        /// Resume playback on a previously-paused player at the specified time (see `CHHapticEngine(currentTime)`).
        ///
        /// If 'time' is set to `CHHapticTimeImmediate`, the pattern is resumed as soon as possible.
        /// Playback will resume at the time offset in the pattern at which it was paused.
        #[unsafe(method(resumeAtTime:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn resumeAtTime_error(&self, time: NSTimeInterval) -> Result<(), Retained<NSError>>;

        /// Set the playback position on an active player to the specified offset time.
        ///
        /// If 'offsetTime' is set to 0.0, the pattern will start from the beginning.  If
        /// set to >= the duration of the pattern, playback will terminate as soon as possible
        /// unless the player is looped, in which case playback will start at the beginning of
        /// the loop.
        #[unsafe(method(seekToOffset:error:_))]
        #[unsafe(method_family = none)]
        unsafe fn seekToOffset_error(
            &self,
            offset_time: NSTimeInterval,
        ) -> Result<(), Retained<NSError>>;

        /// When set to YES, the player will loop back to the beginning of the pattern whenever playback
        /// reaches the `loopEnd` time.
        #[unsafe(method(loopEnabled))]
        #[unsafe(method_family = none)]
        unsafe fn loopEnabled(&self) -> bool;

        /// Setter for [`loopEnabled`][Self::loopEnabled].
        #[unsafe(method(setLoopEnabled:))]
        #[unsafe(method_family = none)]
        unsafe fn setLoopEnabled(&self, loop_enabled: bool);

        /// The time in seconds at which the pattern will loop back if looping is enabled.
        ///
        /// If set to 0.0, the loop length will be set to the end of the last event in the pattern.
        #[unsafe(method(loopEnd))]
        #[unsafe(method_family = none)]
        unsafe fn loopEnd(&self) -> NSTimeInterval;

        /// Setter for [`loopEnd`][Self::loopEnd].
        #[unsafe(method(setLoopEnd:))]
        #[unsafe(method_family = none)]
        unsafe fn setLoopEnd(&self, loop_end: NSTimeInterval);

        /// Allows a pattern to be played back at any multiple of its normal rate.  The rate can be adjusted
        /// at any point before or during pattern playback.
        ///
        /// This rate factor scales the relative times of all events and parameters as they are played, as well as the
        /// durations of Continuous events and the `loopEnd` time.  It does not affect the pitches of the events.
        /// Any value greater than 0.0 is valid; all others are ignored.
        #[unsafe(method(playbackRate))]
        #[unsafe(method_family = none)]
        unsafe fn playbackRate(&self) -> c_float;

        /// Setter for [`playbackRate`][Self::playbackRate].
        #[unsafe(method(setPlaybackRate:))]
        #[unsafe(method_family = none)]
        unsafe fn setPlaybackRate(&self, playback_rate: c_float);

        /// When set to YES, all audio and haptic output will be silenced.
        #[unsafe(method(isMuted))]
        #[unsafe(method_family = none)]
        unsafe fn isMuted(&self) -> bool;

        /// Setter for [`isMuted`][Self::isMuted].
        #[unsafe(method(setIsMuted:))]
        #[unsafe(method_family = none)]
        unsafe fn setIsMuted(&self, is_muted: bool);

        #[cfg(feature = "block2")]
        /// The block or enclosure that will be called when the player finishes.
        ///
        /// # Safety
        ///
        /// The returned block's argument must be a valid pointer or null.
        #[unsafe(method(completionHandler))]
        #[unsafe(method_family = none)]
        unsafe fn completionHandler(&self) -> CHHapticAdvancedPatternPlayerCompletionHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`completionHandler`][Self::completionHandler].
        ///
        /// # Safety
        ///
        /// `completion_handler` must be a valid pointer.
        #[unsafe(method(setCompletionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn setCompletionHandler(
            &self,
            completion_handler: CHHapticAdvancedPatternPlayerCompletionHandler,
        );
    }
);