fmod/studio/event_instance/general.rs
1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use fmod_sys::*;
8
9use crate::studio::{EventDescription, EventInstance};
10
11impl EventInstance {
12 /// Retrieves the event description.
13 pub fn get_description(&self) -> Result<EventDescription> {
14 let mut description = std::ptr::null_mut();
15 unsafe {
16 FMOD_Studio_EventInstance_GetDescription(self.inner, &mut description).to_result()?;
17 Ok(EventDescription::from(description))
18 }
19 }
20
21 /// Marks the event instance for release.
22 ///
23 /// This function marks the event instance to be released.
24 /// Event instances marked for release are destroyed by the asynchronous update when they are in the stopped state ([`PlaybackState::Stopped`]).
25 ///
26 /// Generally it is a best practice to release event instances immediately after calling [`EventInstance::start`],
27 /// unless you want to play the event instance multiple times or explicitly stop it and start it again later.
28 /// It is possible to interact with the instance after falling [`EventInstance::release`], however if the sound has stopped [`FMOD_RESULT::FMOD_ERR_INVALID_HANDLE`] will be returned.
29 pub fn release(self) -> Result<()> {
30 // we don't actually release userdata here because there is a callback, and the user might interact with the instance while it's being released
31 unsafe { FMOD_Studio_EventInstance_Release(self.inner).to_result() }
32 }
33
34 /// Checks that the [`EventInstance`] reference is valid.
35 pub fn is_valid(&self) -> bool {
36 unsafe { FMOD_Studio_EventInstance_IsValid(self.inner).into() }
37 }
38}