]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/CAudio.cpp
Update copyright statements.
[quix0rs-blobwars.git] / src / CAudio.cpp
index 1a39fbf75707b1bba187b812e0b3981b1f8a8f29..98d1a86babce839a9c57e859081d8c7d0061497d 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -34,7 +35,11 @@ Audio::Audio()
        music = NULL;
        quickSound = NULL;
        
-       strcpy(levelMusicName, "");
+       levelMusicName[0] = 0;
+       songtitle[0] = 0;
+       songalbum[0] = 0;
+       songartist[0] = 0;
+       songlicense = -1;
 }
 
 void Audio::setSoundVolume(int soundVolume)
@@ -97,7 +102,7 @@ bool Audio::loadMusic(const char *filename)
 {
        char tempPath[PATH_MAX];
        
-       sprintf(tempPath, "%smusic.mod", engine->userHomeDirectory);
+       snprintf(tempPath, sizeof tempPath, "%smusic.mod", engine->userHomeDirectory);
        
        if (!engine->useAudio)
        {
@@ -106,8 +111,6 @@ bool Audio::loadMusic(const char *filename)
 
        remove(tempPath);
        
-       SDL_Delay(250); // wait a bit, just to be sure!
-
        if (music != NULL)
        {
                Mix_HaltMusic();
@@ -123,13 +126,54 @@ bool Audio::loadMusic(const char *filename)
                music = Mix_LoadMUS(filename);
        #endif
 
+       songtitle[0] = 0;
+       songalbum[0] = 0;
+       songartist[0] = 0;
+       songlicense = -1;
+
        if (!music)
        {
                debug(("WARNING - Failed to load %s\n", filename));
                return false;
        }
-               
-       strcpy(levelMusicName, filename);
+
+       #if USEPAK
+               snprintf(tempPath, sizeof tempPath, "%smusic.tags", engine->userHomeDirectory);
+               remove(tempPath);
+               char tagfilename[PATH_MAX];
+               snprintf(tagfilename, sizeof tagfilename, "%s.tags", filename);
+               engine->unpack(tagfilename, PAK_TAGS);
+       #else
+               snprintf(tempPath, sizeof tempPath, "%s.tags", filename);
+       #endif
+       FILE *fp = fopen(tempPath, "r");
+       char line[1024];
+       
+       while(fp && fgets(line, sizeof line, fp))
+       {
+               int l = strlen(line);
+               if(line[l - 1] == '\n')
+                       line[l - 1] = 0;
+
+               if(!strncasecmp(line, "title=", 6))
+                        strlcpy(songtitle, line + 6, sizeof songtitle);
+               else if(!strncasecmp(line, "album=", 6))
+                        strlcpy(songalbum, line + 6, sizeof songalbum);
+               else if(!strncasecmp(line, "artist=", 7))
+                        strlcpy(songartist, line + 7, sizeof songartist);
+               else if(!strncasecmp(line, "license=", 8))
+               {
+                       if(!strncasecmp(line + 8, "CC-BY ", 6))
+                               songlicense = 0;
+                       else if(!strncasecmp(line + 8, "CC-BY-SA ", 9))
+                               songlicense = 1;
+               }
+       }
+
+       if(fp)
+               fclose(fp);
+       
+       strlcpy(levelMusicName, filename, sizeof levelMusicName);
 
        return true;
 }
@@ -183,7 +227,7 @@ bool Audio::loadGameOverMusic()
 {
        char tempPath[PATH_MAX];
        
-       sprintf(tempPath, "%smusic.mod", engine->userHomeDirectory);
+       snprintf(tempPath, sizeof tempPath, "%smusic.mod", engine->userHomeDirectory);
        
        if (!engine->useAudio)
        {
@@ -202,10 +246,10 @@ bool Audio::loadGameOverMusic()
        }
 
        #if USEPAK
-               engine->unpack("music/friendDied.mod", PAK_MUSIC);
+               engine->unpack("music/gameover", PAK_MUSIC);
                music = Mix_LoadMUS(tempPath);
        #else
-               music = Mix_LoadMUS("music/friendDied.mod");
+               music = Mix_LoadMUS("music/gameover");
        #endif
 
        if (!music)