fmod-oxide 0.2.1

Zero cost bindings to FMOD and FMOD Studio
Documentation
// Copyright (c) 2024 Melody Madeline Lyons
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use fmod_sys::*;
use lanyard::Utf8CStr;

use crate::studio::{CommandCaptureFlags, CommandReplay, CommandReplayFlags, System};
use crate::{FmodResultExt, Result};

impl System {
    /// Recording Studio commands to a file.
    ///
    /// The commands generated by the FMOD Studio API can be captured and later replayed for debug and profiling purposes.
    ///
    /// Unless the [`CommandCaptureFlags::SKIP_INITIAL_STATE`] flag is specified, the command capture will first record the set of all banks and event instances that currently exist.
    pub fn start_command_capture(
        &self,
        filename: &Utf8CStr,
        flags: CommandCaptureFlags,
    ) -> Result<()> {
        unsafe {
            FMOD_Studio_System_StartCommandCapture(
                self.inner.as_ptr(),
                filename.as_ptr(),
                flags.into(),
            )
            .to_result()
        }
    }

    /// Stop recording Studio commands.
    pub fn stop_command_capture(&self) -> Result<()> {
        unsafe { FMOD_Studio_System_StopCommandCapture(self.inner.as_ptr()).to_result() }
    }

    /// Load a command replay.
    pub fn load_command_replay(
        &self,
        filename: &Utf8CStr,
        flags: CommandReplayFlags,
    ) -> Result<CommandReplay> {
        let mut replay = std::ptr::null_mut();
        unsafe {
            FMOD_Studio_System_LoadCommandReplay(
                self.inner.as_ptr(),
                filename.as_ptr(),
                flags.into(),
                &raw mut replay,
            )
            .to_result()?;
            Ok(CommandReplay::from_ffi(replay))
        }
    }
}