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::*;

/// Types of haptic and audio events.
///
///
/// An event which generates a haptic with a fixed length, such as a tap.  Transient events will complete on their own.  If a duration longer than the
/// haptic is provided, the pattern containing the event will be "padded" out to the duration specified.
///
///
/// An event which generates a haptic of arbitrary length.  The event can behave as either Transient or Continuous depending on the value
/// of the CHHapticEventParameterIDSustained parameter.  These events also include an AR or ADR gain envelope that may be controlled via Event or
/// Dynamic parameters.
/// See `CHHapticEventParameterIDAttackTime`, `CHHapticEventParameterIDDecayTime`, and `CHHapticEventParameterIDReleaseTime`.
///
///
/// An event which generates an audio signal.  The event can behave as either Transient or Continuous depending on the value of the
/// CHHapticEventParameterIDSustained parameter.  These events also include an AR or ADR gain envelope that may be controlled via Event or
/// Dynamic parameters.
/// See `CHHapticEventParameterIDAttackTime`, `CHHapticEventParameterIDDecayTime`, and `CHHapticEventParameterIDReleaseTime`.
///
///
/// An event which generates an audio signal using a client-supplied waveform (see `CHHapticEngine(registerAudioResource:options:error)`).
/// Currently, these behave as Transient events (i.e., no looping or enveloping).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticeventtype?language=objc)
// NS_TYPED_ENUM
pub type CHHapticEventType = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticeventtypehaptictransient?language=objc)
    pub static CHHapticEventTypeHapticTransient: &'static CHHapticEventType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticeventtypehapticcontinuous?language=objc)
    pub static CHHapticEventTypeHapticContinuous: &'static CHHapticEventType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticeventtypeaudiocontinuous?language=objc)
    pub static CHHapticEventTypeAudioContinuous: &'static CHHapticEventType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticeventtypeaudiocustom?language=objc)
    pub static CHHapticEventTypeAudioCustom: &'static CHHapticEventType;
}

/// Identifier for registered, client-loaded audio data which can be used as custom event types
/// (see `CHHapticEngine(registerAudioResource:options:error)`).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticaudioresourceid?language=objc)
pub type CHHapticAudioResourceID = NSUInteger;

extern_class!(
    /// The description of a single haptic/audio event, plus optional Event parameters which modify the event.
    ///
    /// CHHapticEvents have a relative time property to allow specifying the time relationship between events in a pattern.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/corehaptics/chhapticevent?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CHHapticEvent;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for CHHapticEvent {}
);

impl CHHapticEvent {
    extern_methods!(
        /// The type of event.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> Retained<CHHapticEventType>;

        #[cfg(feature = "CHHapticParameter")]
        /// NSArray of Event parameters.  Can be empty.
        #[unsafe(method(eventParameters))]
        #[unsafe(method_family = none)]
        pub unsafe fn eventParameters(&self) -> Retained<NSArray<CHHapticEventParameter>>;

        /// The relative time for this event versus the start time of the pattern.  Units are seconds.
        #[unsafe(method(relativeTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn relativeTime(&self) -> NSTimeInterval;

        /// Setter for [`relativeTime`][Self::relativeTime].
        #[unsafe(method(setRelativeTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRelativeTime(&self, relative_time: NSTimeInterval);

        /// The duration for this event.  Units are seconds.  If unset (0.0), Continuous event types will have no fixed end.
        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> NSTimeInterval;

        /// Setter for [`duration`][Self::duration].
        #[unsafe(method(setDuration:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDuration(&self, duration: NSTimeInterval);

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Option<Retained<Self>>;

        #[cfg(feature = "CHHapticParameter")]
        /// Initialize a new CHHapticEvent.  This can only be used to create Transient event types (which do not require a duration).
        ///
        /// Parameter `type`: The type of event.
        ///
        /// Parameter `eventParams`: An NSArray of Event parameters.  Can be empty.
        ///
        /// Parameter `time`: The relative time for this event versus the other events in the CHHapticPattern.
        #[unsafe(method(initWithEventType:parameters:relativeTime:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithEventType_parameters_relativeTime(
            this: Allocated<Self>,
            r#type: &CHHapticEventType,
            event_params: &NSArray<CHHapticEventParameter>,
            time: NSTimeInterval,
        ) -> Retained<Self>;

        #[cfg(feature = "CHHapticParameter")]
        /// Initialize a new CHHapticEvent, providing a duration.
        ///
        /// Parameter `type`: The type of event.
        ///
        /// Parameter `eventParams`: An NSArray of Event parameters.  Can be empty.
        ///
        /// Parameter `time`: The relative time for this event versus the other events in the CHHapticPattern.
        ///
        /// Parameter `duration`: For Continuous event types, the length of time before the event playback begins its release.
        /// For Transient event types, the logical length of the event (used to determine pattern end and loop points).
        #[unsafe(method(initWithEventType:parameters:relativeTime:duration:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithEventType_parameters_relativeTime_duration(
            this: Allocated<Self>,
            r#type: &CHHapticEventType,
            event_params: &NSArray<CHHapticEventParameter>,
            time: NSTimeInterval,
            duration: NSTimeInterval,
        ) -> Retained<Self>;

        #[cfg(feature = "CHHapticParameter")]
        /// Initialize a new CHHapticEvent using a previously-loaded audio resource.
        ///
        /// Parameter `resID`: A previously-registered audio resource ID (see `CHHapticEngine(registerAudioResource:options:error)`).
        ///
        /// Parameter `eventParams`: An NSArray of Event parameters.  Can be empty.
        ///
        /// Parameter `time`: The relative time for this event versus the other events in the CHHapticPattern.
        #[unsafe(method(initWithAudioResourceID:parameters:relativeTime:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithAudioResourceID_parameters_relativeTime(
            this: Allocated<Self>,
            res_id: CHHapticAudioResourceID,
            event_params: &NSArray<CHHapticEventParameter>,
            time: NSTimeInterval,
        ) -> Retained<Self>;

        #[cfg(feature = "CHHapticParameter")]
        /// Initialize a new CHHapticEvent using a previously-loaded audio resource.
        ///
        /// Parameter `resID`: A previously-registered audio resource ID (see `CHHapticEngine(registerAudioResource:options:error)`).
        ///
        /// Parameter `eventParams`: An NSArray of Event parameters.  Can be empty.
        ///
        /// Parameter `time`: The relative time for this event versus the other events in the CHHapticPattern.
        ///
        /// Parameter `duration`: The duration of this event in seconds.
        ///
        /// If the specified duration is less than the duration of the audio resource, its playback will be truncated.  If it
        /// is greater, its playback will be padded with silence.  If zero, it will be ignored.
        #[unsafe(method(initWithAudioResourceID:parameters:relativeTime:duration:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithAudioResourceID_parameters_relativeTime_duration(
            this: Allocated<Self>,
            res_id: CHHapticAudioResourceID,
            event_params: &NSArray<CHHapticEventParameter>,
            time: NSTimeInterval,
            duration: NSTimeInterval,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl CHHapticEvent {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}