fmod/core/sound/
synchronization.rs1use std::ffi::{c_int, c_uint};
8
9use fmod_sys::*;
10use lanyard::{Utf8CStr, Utf8CString};
11
12use crate::{get_string, Sound, TimeUnit};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[repr(transparent)] pub struct SyncPoint {
17 pub(crate) inner: *mut FMOD_SYNCPOINT,
18}
19
20unsafe impl Send for SyncPoint {}
21unsafe impl Sync for SyncPoint {}
22
23impl From<*mut FMOD_SYNCPOINT> for SyncPoint {
24 fn from(value: *mut FMOD_SYNCPOINT) -> Self {
25 SyncPoint { inner: value }
26 }
27}
28
29impl From<SyncPoint> for *mut FMOD_SYNCPOINT {
30 fn from(value: SyncPoint) -> Self {
31 value.inner
32 }
33}
34
35impl Sound {
36 pub fn get_sync_point(&self, index: i32) -> Result<SyncPoint> {
40 let mut sync_point = std::ptr::null_mut();
41 unsafe {
42 FMOD_Sound_GetSyncPoint(self.inner, index, &mut sync_point).to_result()?;
43 }
44 Ok(sync_point.into())
45 }
46
47 pub fn get_sync_point_info(
51 &self,
52 point: SyncPoint,
53 offset_type: TimeUnit,
54 ) -> Result<(Utf8CString, c_uint)> {
55 let mut offset = 0;
56 let name = get_string(|name| unsafe {
57 FMOD_Sound_GetSyncPointInfo(
58 self.inner,
59 point.into(),
60 name.as_mut_ptr().cast(),
61 name.len() as c_int,
62 &mut offset,
63 offset_type.into(),
64 )
65 })?;
66 Ok((name, offset))
67 }
68
69 pub fn get_sync_point_count(&self) -> Result<i32> {
73 let mut count = 0;
74 unsafe {
75 FMOD_Sound_GetNumSyncPoints(self.inner, &mut count).to_result()?;
76 }
77 Ok(count)
78 }
79
80 pub fn add_sync_point(
84 &self,
85 offset: c_uint,
86 offset_type: TimeUnit,
87 name: &Utf8CStr,
88 ) -> Result<SyncPoint> {
89 let mut sync_point = std::ptr::null_mut();
90 unsafe {
91 FMOD_Sound_AddSyncPoint(
92 self.inner,
93 offset,
94 offset_type.into(),
95 name.as_ptr(),
96 &mut sync_point,
97 )
98 .to_result()?;
99 }
100 Ok(sync_point.into())
101 }
102
103 pub fn delete_sync_point(&self, point: SyncPoint) -> Result<()> {
107 unsafe {
108 FMOD_Sound_DeleteSyncPoint(self.inner, point.into()).to_result()?;
109 }
110 Ok(())
111 }
112}