Skip to content

Commit

Permalink
Replace menu music (fixes #105)
Browse files Browse the repository at this point in the history
Setting music volume to/from 0 pauses/resumes
Remove debugging printf
  • Loading branch information
cxong committed Jun 25, 2013
1 parent 5f1fd4b commit 3be3605
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
Binary file removed music/menu/ac-lol.it
Binary file not shown.
1 change: 0 additions & 1 deletion music/menu/ac-lol.it.txt

This file was deleted.

Binary file added music/menu/space_0.ogg
Binary file not shown.
4 changes: 4 additions & 0 deletions music/menu/space_0.ogg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Reencoded from Space by Alexandr Zhelanov
http://opengameart.org/content/space-1

http://creativecommons.org/licenses/by/3.0/
25 changes: 24 additions & 1 deletion src/cdogs/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

int MusicPlay(SoundDevice *device, const char *path)
{
if (!device->isInitialised || gConfig.Sound.MusicVolume == 0)
if (!device->isInitialised)
{
return 0;
}
Expand All @@ -65,6 +65,11 @@ int MusicPlay(SoundDevice *device, const char *path)
Mix_PlayMusic(device->music, -1);
device->musicStatus = MUSIC_PLAYING;

if (gConfig.Sound.MusicVolume == 0)
{
MusicPause(device);
}

return 0;
}

Expand All @@ -78,6 +83,24 @@ void MusicStop(SoundDevice *device)
}
}

void MusicPause(SoundDevice *device)
{
if (device->musicStatus == MUSIC_PLAYING)
{
Mix_PauseMusic();
device->musicStatus = MUSIC_PAUSED;
}
}

void MusicResume(SoundDevice *device)
{
if (device->musicStatus == MUSIC_PAUSED)
{
Mix_ResumeMusic();
device->musicStatus = MUSIC_PLAYING;
}
}

int MusicGetStatus(SoundDevice *device)
{
return device->musicStatus;
Expand Down
2 changes: 2 additions & 0 deletions src/cdogs/music.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

int MusicPlay(SoundDevice *device, const char *path);
void MusicStop(SoundDevice *device);
void MusicPause(SoundDevice *device);
void MusicResume(SoundDevice *device);
int MusicGetStatus(SoundDevice *device);
const char *MusicGetErrorMessage(SoundDevice *device);

Expand Down
10 changes: 8 additions & 2 deletions src/cdogs/sounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ void SoundReconfigure(SoundDevice *device, SoundConfig *config)

Mix_Volume(-1, config->SoundVolume);
Mix_VolumeMusic(config->MusicVolume);
if (config->MusicVolume > 0)
{
MusicResume(device);
}
else
{
MusicPause(device);
}

device->isInitialised = 1;
}
Expand Down Expand Up @@ -227,8 +235,6 @@ void SoundPlayAtPosition(

debug(D_VERBOSE, "sound: %d distance: %d bearing: %d\n",
sound, distance, bearing);
printf("sound: %d distance: %d bearing: %d\n",
sound, distance, bearing);

channel = Mix_PlayChannel(-1, device->sounds[sound].data , 0);
Mix_SetPosition(channel, (Sint16)bearing, (Uint8)distance);
Expand Down

0 comments on commit 3be3605

Please sign in to comment.