Skip to content

Commit

Permalink
Refactor|Audio: Soundfont config and querying play state in audiodriv…
Browse files Browse the repository at this point in the history
…er_music
  • Loading branch information
skyjake committed Jul 13, 2012
1 parent 45476e0 commit efdbd30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
21 changes: 14 additions & 7 deletions doomsday/engine/portable/include/audiodriver_music.h
Expand Up @@ -5,6 +5,9 @@
* The main purpose of this low-level thin layer is to group individual music
* interfaces together as an aggregate that can be treated as one interface.
*
* @todo Integrate the CD interface into this, too, as it is treated as an
* additional/alternative music interface.
*
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012 Daniel Swanson <danij@dengine.net>
*
Expand Down Expand Up @@ -33,20 +36,24 @@
extern "C" {
#endif

/**
* Tells the audio driver to choose a new name for the buffer filename, if a
* buffer file is needed.
*/
void AudioDriver_Music_SwitchBufferFilenames(void);

AutoStr* AudioDriver_Music_ComposeTempBufferFilename(const char* ext);
void AudioDriver_Music_SetSoundFont(const char* fileName);

int AudioDriver_Music_PlayNativeFile(const char* fileName, boolean looped);

int AudioDriver_Music_PlayLump(lumpnum_t lump, boolean looped);

int AudioDriver_Music_PlayFile(const char* virtualOrNativePath, boolean looped);

boolean AudioDriver_Music_IsPlaying(void);

/**
* Tells the audio driver to choose a new name for the buffer filename, if a
* buffer file is needed to play back a song.
*/
void AudioDriver_Music_SwitchBufferFilenames(void);

AutoStr* AudioDriver_Music_ComposeTempBufferFilename(const char* ext);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
13 changes: 13 additions & 0 deletions doomsday/engine/portable/src/audiodriver_music.c
Expand Up @@ -61,6 +61,13 @@ AutoStr* AudioDriver_Music_ComposeTempBufferFilename(const char* ext)
return composeBufferedMusicFilename(currentBufFile, ext);
}

void AudioDriver_Music_SetSoundFont(const char* fileName)
{
audiodriver_t* d = AudioDriver_Interface(AudioDriver_Music());
if(!d || !d->Set) return;
d->Set(AUDIOP_SOUNDFONT_FILENAME, fileName);
}

int AudioDriver_Music_PlayNativeFile(const char* fileName, boolean looped)
{
if(!AudioDriver_Music() || !AudioDriver_Music()->PlayFile)
Expand Down Expand Up @@ -141,3 +148,9 @@ int AudioDriver_Music_PlayFile(const char* virtualOrNativePath, boolean looped)
return AudioDriver_Music()->Play(looped);
}
}

boolean AudioDriver_Music_IsPlaying(void)
{
if(!AudioDriver_Music()) return false;
return AudioDriver_Music()->gen.Get(MUSIP_PLAYING, 0);
}
13 changes: 4 additions & 9 deletions doomsday/engine/portable/src/s_mus.c
Expand Up @@ -129,11 +129,8 @@ boolean Mus_Init(void)
return false;
}

if(AudioDriver_Music() && AudioDriver_Interface(AudioDriver_Music())->Set)
{
// Tell the audio driver about our soundfont config.
AudioDriver_Interface(AudioDriver_Music())->Set(AUDIOP_SOUNDFONT_FILENAME, soundFontPath);
}
// Tell the audio driver about our soundfont config.
AudioDriver_Music_SetSoundFont(soundFontPath);

musAvail = true;
return true;
Expand Down Expand Up @@ -367,7 +364,7 @@ int Mus_Start(ded_music_t* def, boolean looped)

// We will not restart the currently playing song.
if(songID == currentSong &&
((AudioDriver_Music() && AudioDriver_Music()->gen.Get(MUSIP_PLAYING, NULL)) ||
(AudioDriver_Music_IsPlaying() ||
(AudioDriver_CD() && AudioDriver_CD()->gen.Get(MUSIP_PLAYING, NULL))))
return false;

Expand Down Expand Up @@ -455,9 +452,7 @@ int Mus_Start(ded_music_t* def, boolean looped)

static void Mus_UpdateSoundFont(void)
{
audiodriver_t* d = AudioDriver_Interface(AudioDriver_Music());
if(!d || !d->Set) return;
d->Set(AUDIOP_SOUNDFONT_FILENAME, Con_GetString("music-soundfont"));
AudioDriver_Music_SetSoundFont(Con_GetString("music-soundfont"));
}

/**
Expand Down

0 comments on commit efdbd30

Please sign in to comment.