* Loads the specified music file format. * @param fmt Format of the music. * @param file Filename of the music. * @param track Track number of the music, if stored in a CAT. * @param volume Volume modifier of the music, if stored in a CAT. * @param adlibcat Pointer to ADLIB.CAT if available. * @param aintrocat Pointer to AINTRO.CAT if available. * @param gmcat Pointer to GM.CAT if available
| 951 | * @return Pointer to the music file, or NULL if it couldn't be loaded. |
| 952 | */ |
| 953 | Music *XcomResourcePack::loadMusic(MusicFormat fmt, const std::string &file, int track, float volume, CatFile *adlibcat, CatFile *aintrocat, GMCatFile *gmcat) |
| 954 | { |
| 955 | /* MUSIC_AUTO, MUSIC_FLAC, MUSIC_OGG, MUSIC_MP3, MUSIC_MOD, MUSIC_WAV, MUSIC_ADLIB, MUSIC_MIDI */ |
| 956 | static const std::string exts[] = {"", "flac", "ogg", "mp3", "mod", "wav", "", "mid"}; |
| 957 | Music *music = 0; |
| 958 | try |
| 959 | { |
| 960 | // Try Adlib music |
| 961 | if (fmt == MUSIC_ADLIB) |
| 962 | { |
| 963 | if (adlibcat && Options::audioBitDepth == 16) |
| 964 | { |
| 965 | music = new AdlibMusic(volume); |
| 966 | if (track < adlibcat->getAmount()) |
| 967 | { |
| 968 | music->load(adlibcat->load(track, true), adlibcat->getObjectSize(track)); |
| 969 | } |
| 970 | // separate intro music |
| 971 | else if (aintrocat) |
| 972 | { |
| 973 | track -= adlibcat->getAmount(); |
| 974 | music->load(aintrocat->load(track, true), aintrocat->getObjectSize(track)); |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | // Try MIDI music |
| 979 | else if (fmt == MUSIC_MIDI) |
| 980 | { |
| 981 | // DOS MIDI |
| 982 | if (gmcat) |
| 983 | { |
| 984 | music = gmcat->loadMIDI(track); |
| 985 | } |
| 986 | // Windows MIDI |
| 987 | else |
| 988 | { |
| 989 | std::ostringstream s; |
| 990 | s << "SOUND/" << file << "." << exts[fmt]; |
| 991 | if (CrossPlatform::fileExists(CrossPlatform::getDataFile(s.str()))) |
| 992 | { |
| 993 | music = new Music(); |
| 994 | music->load(CrossPlatform::getDataFile(s.str())); |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | // Try digital tracks |
| 999 | else |
| 1000 | { |
| 1001 | std::ostringstream s; |
| 1002 | s << "SOUND/" << file << "." << exts[fmt]; |
| 1003 | if (CrossPlatform::fileExists(CrossPlatform::getDataFile(s.str()))) |
| 1004 | { |
| 1005 | music = new Music(); |
| 1006 | music->load(CrossPlatform::getDataFile(s.str())); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | catch (Exception &e) |
nothing calls this directly
no test coverage detected