1use fmod_sys::*;
8use lanyard::Utf8CString;
9
10use std::ffi::{c_char, c_int};
11
12#[derive(PartialEq, Eq, Debug)]
13pub enum DebugMode {
14 TTY,
15 File(Utf8CString),
16 Callback(
17 unsafe extern "C" fn(
18 FMOD_DEBUG_FLAGS,
19 *const c_char,
20 c_int,
21 *const c_char,
22 *const c_char,
23 ) -> FMOD_RESULT,
24 ),
25}
26
27bitflags::bitflags! {
28 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
29 pub struct DebugFlags: FMOD_DEBUG_FLAGS {
30 const NONE = FMOD_DEBUG_LEVEL_NONE;
31 const ERROR = FMOD_DEBUG_LEVEL_ERROR;
32 const WARNING = FMOD_DEBUG_LEVEL_WARNING;
33 const LOG = FMOD_DEBUG_LEVEL_LOG;
34 const MEMORY = FMOD_DEBUG_TYPE_MEMORY;
35 const FILE = FMOD_DEBUG_TYPE_FILE;
36 const CODEC = FMOD_DEBUG_TYPE_CODEC;
37 const TRACE = FMOD_DEBUG_TYPE_TRACE;
38 const DISPLAY_TIMESTAMPS = FMOD_DEBUG_DISPLAY_TIMESTAMPS;
39 const DISPLAY_LINENUMBERS = FMOD_DEBUG_DISPLAY_LINENUMBERS;
40 const DISPLAY_THREAD = FMOD_DEBUG_DISPLAY_THREAD;
41 }
42}
43
44impl From<FMOD_DEBUG_FLAGS> for DebugFlags {
45 fn from(value: FMOD_DEBUG_FLAGS) -> Self {
46 DebugFlags::from_bits_truncate(value)
47 }
48}
49
50impl From<DebugFlags> for FMOD_DEBUG_FLAGS {
51 fn from(value: DebugFlags) -> Self {
52 value.bits()
53 }
54}
55
56pub fn initialize(flags: DebugFlags, mode: DebugMode) -> Result<()> {
69 match mode {
70 DebugMode::TTY => unsafe {
71 FMOD_Debug_Initialize(flags.into(), FMOD_DEBUG_MODE_TTY, None, std::ptr::null())
72 .to_result()
73 },
74 DebugMode::File(file) => unsafe {
75 FMOD_Debug_Initialize(flags.into(), FMOD_DEBUG_MODE_FILE, None, file.as_ptr())
76 .to_result()
77 },
78 DebugMode::Callback(c) => unsafe {
79 FMOD_Debug_Initialize(
80 flags.into(),
81 FMOD_DEBUG_MODE_CALLBACK,
82 Some(c),
83 std::ptr::null(),
84 )
85 .to_result()
86 },
87 }
88}