fmod/studio/event_description/
parameter.rs1use fmod_sys::*;
8use lanyard::{Utf8CStr, Utf8CString};
9use std::{ffi::c_int, mem::MaybeUninit};
10
11use crate::studio::{EventDescription, ParameterDescription, ParameterID};
12
13impl EventDescription {
14 pub fn get_parameter_description_by_name(
16 &self,
17 name: &Utf8CStr,
18 ) -> Result<ParameterDescription> {
19 let mut description = MaybeUninit::zeroed();
20 unsafe {
21 FMOD_Studio_EventDescription_GetParameterDescriptionByName(
22 self.inner,
23 name.as_ptr(),
24 description.as_mut_ptr(),
25 )
26 .to_result()?;
27
28 let description = ParameterDescription::from_ffi(description.assume_init());
29 Ok(description)
30 }
31 }
32
33 pub fn get_parameter_description_by_id(&self, id: ParameterID) -> Result<ParameterDescription> {
35 let mut description = MaybeUninit::zeroed();
36 unsafe {
37 FMOD_Studio_EventDescription_GetParameterDescriptionByID(
38 self.inner,
39 id.into(),
40 description.as_mut_ptr(),
41 )
42 .to_result()?;
43
44 let description = ParameterDescription::from_ffi(description.assume_init());
45 Ok(description)
46 }
47 }
48
49 pub fn get_parameter_description_by_index(&self, index: c_int) -> Result<ParameterDescription> {
55 let mut description = MaybeUninit::zeroed();
56 unsafe {
57 FMOD_Studio_EventDescription_GetParameterDescriptionByIndex(
58 self.inner,
59 index,
60 description.as_mut_ptr(),
61 )
62 .to_result()?;
63
64 let description = ParameterDescription::from_ffi(description.assume_init());
65 Ok(description)
66 }
67 }
68
69 pub fn parameter_description_count(&self) -> Result<c_int> {
73 let mut count = 0;
74 unsafe {
75 FMOD_Studio_EventDescription_GetParameterDescriptionCount(self.inner, &mut count)
76 .to_result()?;
77 }
78 Ok(count)
79 }
80
81 pub fn get_parameter_label_by_name(
86 &self,
87 name: &Utf8CStr,
88 label_index: c_int,
89 ) -> Result<Utf8CString> {
90 let mut string_len = 0;
91
92 unsafe {
95 let error = FMOD_Studio_EventDescription_GetParameterLabelByName(
96 self.inner,
97 name.as_ptr(),
98 label_index,
99 std::ptr::null_mut(),
100 0,
101 &mut string_len,
102 )
103 .to_error();
104
105 match error {
108 Some(error) if error != FMOD_RESULT::FMOD_ERR_TRUNCATED => return Err(error),
109 _ => {}
110 }
111 };
112
113 let mut path = vec![0u8; string_len as usize];
114 let mut expected_string_len = 0;
115
116 unsafe {
117 FMOD_Studio_EventDescription_GetParameterLabelByName(
118 self.inner,
119 name.as_ptr(),
120 label_index,
121 path.as_mut_ptr().cast(),
123 string_len,
124 &mut expected_string_len,
125 )
126 .to_result()?;
127
128 debug_assert_eq!(string_len, expected_string_len);
129
130 let path = Utf8CString::from_utf8_with_nul_unchecked(path);
133
134 Ok(path)
135 }
136 }
137
138 pub fn get_parameter_label_by_id(
140 &self,
141 id: ParameterID,
142 label_index: c_int,
143 ) -> Result<Utf8CString> {
144 let mut string_len = 0;
145
146 unsafe {
149 let error = FMOD_Studio_EventDescription_GetParameterLabelByID(
150 self.inner,
151 id.into(),
152 label_index,
153 std::ptr::null_mut(),
154 0,
155 &mut string_len,
156 )
157 .to_error();
158
159 match error {
162 Some(error) if error != FMOD_RESULT::FMOD_ERR_TRUNCATED => return Err(error),
163 _ => {}
164 }
165 };
166
167 let mut path = vec![0u8; string_len as usize];
168 let mut expected_string_len = 0;
169
170 unsafe {
171 FMOD_Studio_EventDescription_GetParameterLabelByID(
172 self.inner,
173 id.into(),
174 label_index,
175 path.as_mut_ptr().cast(),
177 string_len,
178 &mut expected_string_len,
179 )
180 .to_result()?;
181
182 debug_assert_eq!(string_len, expected_string_len);
183
184 let path = Utf8CString::from_utf8_with_nul_unchecked(path);
187
188 Ok(path)
189 }
190 }
191
192 pub fn get_parameter_label_by_index(
196 &self,
197 index: c_int,
198 label_index: c_int,
199 ) -> Result<Utf8CString> {
200 let mut string_len = 0;
201
202 unsafe {
205 let error = FMOD_Studio_EventDescription_GetParameterLabelByIndex(
206 self.inner,
207 index,
208 label_index,
209 std::ptr::null_mut(),
210 0,
211 &mut string_len,
212 )
213 .to_error();
214
215 match error {
218 Some(error) if error != FMOD_RESULT::FMOD_ERR_TRUNCATED => return Err(error),
219 _ => {}
220 }
221 };
222
223 let mut path = vec![0u8; string_len as usize];
224 let mut expected_string_len = 0;
225
226 unsafe {
227 FMOD_Studio_EventDescription_GetParameterLabelByIndex(
228 self.inner,
229 index,
230 label_index,
231 path.as_mut_ptr().cast(),
233 string_len,
234 &mut expected_string_len,
235 )
236 .to_result()?;
237
238 debug_assert_eq!(string_len, expected_string_len);
239
240 let path = Utf8CString::from_utf8_with_nul_unchecked(path);
243
244 Ok(path)
245 }
246 }
247}