fmod/studio/command_replay/
query.rs1use fmod_sys::*;
8use lanyard::{Utf8CStr, Utf8CString};
9use std::{
10 ffi::{c_float, c_int},
11 mem::MaybeUninit,
12};
13
14use crate::{
15 get_string,
16 studio::{CommandInfo, CommandReplay, System},
17};
18
19impl CommandReplay {
20 pub fn set_bank_path(&self, path: &Utf8CStr) -> Result<()> {
24 unsafe { FMOD_Studio_CommandReplay_SetBankPath(self.inner, path.as_ptr()).to_result() }
25 }
26
27 pub fn command_at_time(&self, time: c_float) -> Result<c_int> {
32 let mut index = 0;
33 unsafe {
34 FMOD_Studio_CommandReplay_GetCommandAtTime(self.inner, time, &mut index).to_result()?;
35 }
36 Ok(index)
37 }
38
39 pub fn get_command_count(&self) -> Result<c_int> {
41 let mut count = 0;
42 unsafe {
43 FMOD_Studio_CommandReplay_GetCommandCount(self.inner, &mut count).to_result()?;
44 }
45 Ok(count)
46 }
47
48 pub fn get_command_info(&self, index: c_int) -> Result<CommandInfo> {
50 let mut info = MaybeUninit::zeroed();
51
52 unsafe {
53 FMOD_Studio_CommandReplay_GetCommandInfo(self.inner, index, info.as_mut_ptr())
54 .to_result()?;
55
56 let info = CommandInfo::from_ffi(info.assume_init());
57 Ok(info)
58 }
59 }
60
61 pub fn get_command_string(&self, index: c_int) -> Result<Utf8CString> {
63 let string = get_string(|buffer| unsafe {
64 FMOD_Studio_CommandReplay_GetCommandString(
65 self.inner,
66 index,
67 buffer.as_mut_ptr().cast::<i8>(),
68 buffer.len() as c_int,
69 )
70 })?;
71
72 Ok(string)
73 }
74
75 pub fn get_length(&self) -> Result<c_float> {
77 let mut length = 0.0;
78 unsafe {
79 FMOD_Studio_CommandReplay_GetLength(self.inner, &mut length).to_result()?;
80 }
81 Ok(length)
82 }
83
84 pub fn get_system(&self) -> Result<System> {
86 let mut system = std::ptr::null_mut();
87 unsafe {
88 FMOD_Studio_CommandReplay_GetSystem(self.inner, &mut system).to_result()?;
89 Ok(System::from(system))
90 }
91 }
92
93 pub fn is_valid(&self) -> bool {
95 unsafe { FMOD_Studio_CommandReplay_IsValid(self.inner).into() }
96 }
97}