fmod/core/sound/
music.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 std::ffi::{c_float, c_int};
8
9use fmod_sys::*;
10
11use crate::Sound;
12
13impl Sound {
14    /// Gets the number of music channels inside a MOD/S3M/XM/IT/MIDI file.
15    pub fn get_music_channel_count(&self) -> Result<i32> {
16        let mut num_channels = 0;
17        unsafe {
18            FMOD_Sound_GetMusicNumChannels(self.inner, &mut num_channels).to_result()?;
19        }
20        Ok(num_channels)
21    }
22
23    /// Sets the volume of a MOD/S3M/XM/IT/MIDI music channel volume.
24    pub fn set_music_channel_volume(&self, channel: c_int, volume: c_float) -> Result<()> {
25        unsafe {
26            FMOD_Sound_SetMusicChannelVolume(self.inner, channel, volume).to_result()?;
27        }
28        Ok(())
29    }
30
31    /// Retrieves the volume of a MOD/S3M/XM/IT/MIDI music channel volume.
32    pub fn get_music_channel_volume(&self, channel: c_int) -> Result<c_float> {
33        let mut volume = 0.0;
34        unsafe {
35            FMOD_Sound_GetMusicChannelVolume(self.inner, channel, &mut volume).to_result()?;
36        }
37        Ok(volume)
38    }
39
40    /// Sets the relative speed of MOD/S3M/XM/IT/MIDI music.
41    pub fn set_music_speed(&self, speed: c_float) -> Result<()> {
42        unsafe {
43            FMOD_Sound_SetMusicSpeed(self.inner, speed).to_result()?;
44        }
45        Ok(())
46    }
47
48    /// Gets the relative speed of MOD/S3M/XM/IT/MIDI music.
49    pub fn get_music_speed(&self) -> Result<c_float> {
50        let mut speed = 0.0;
51        unsafe {
52            FMOD_Sound_GetMusicSpeed(self.inner, &mut speed).to_result()?;
53        }
54        Ok(speed)
55    }
56}