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
53
54
55
56
57
58
//! Audio formats for [`super::MixMusic`].

use crate::bind;

/// A type of audio format supported by [`MixMusic`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MusicType {
    /// A player from the command specified by [`MixMusic::with_cmd`].
    Command,
    /// A wave format.
    Wave,
    /// A mod format.
    Mod,
    /// A midi format.
    Midi,
    /// A ogg vorbis format.
    Ogg,
    /// A mpeg-1 audio layer-3 format.
    Mp3,
    /// A flac format.
    Flac,
    /// A opus format.
    Opus,
    /// An unknown format.
    Unknown,
}

impl MusicType {
    pub(super) fn from_raw(raw: bind::Mix_MusicType) -> Self {
        use MusicType::*;
        match raw {
            bind::MUS_CMD => Command,
            bind::MUS_WAV => Wave,
            bind::MUS_MOD => Mod,
            bind::MUS_MID => Midi,
            bind::MUS_OGG => Ogg,
            bind::MUS_MP3 => Mp3,
            bind::MUS_FLAC => Flac,
            bind::MUS_OPUS => Opus,
            _ => Unknown,
        }
    }

    pub(super) fn convert_pos(&self, pos: f64) -> f64 {
        match *self {
            MusicType::Mod => pos.floor(),
            MusicType::Ogg => pos,
            MusicType::Mp3 => {
                unsafe {
                    bind::Mix_RewindMusic();
                }
                pos
            }
            _ => 0.0,
        }
    }
}