1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2024 Lily 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};

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, 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).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,
                filename.as_ptr(),
                flags.into(),
                &mut replay,
            )
            .to_result()?;
            Ok(CommandReplay::from(replay))
        }
    }
}