Skip to content

Commit

Permalink
dsFluidSynth: Use libdeng2 for printing log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 14, 2012
1 parent f9fe6a0 commit 56aa7db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
5 changes: 4 additions & 1 deletion doomsday/engine/portable/include/fs_util.h
Expand Up @@ -44,9 +44,12 @@ void F_ExtractFileBase2(char* dest, const char* path, size_t len, int ignore);
void F_ExtractFileBase(char* dest, const char* path, size_t len);

/**
* Checks if a file exists in the native file system.
*
* @param file File to check existence of. Relative path directives are expanded
* automatically: '>' '}' (plus '~' on Unix-based platforms).
* @return @c 0 if the path points to a readable file on the local file system.
*
* @return @c 0 if the path points to a readable file on the local file system.
*/
int F_FileExists(const char* path);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/config_plugin.pri
Expand Up @@ -15,7 +15,7 @@ win32 {
INCLUDEPATH += $$DENG_API_DIR

# The libdeng2 C wrapper can be used from all plugins.
DEFINES += DENG_NO_QT
DEFINES += DENG_NO_QT DENG2_C_API_ONLY
include(../dep_deng2_cwrapper.pri)

include(../dep_deng.pri)
43 changes: 29 additions & 14 deletions doomsday/plugins/fluidsynth/src/fluidsynth_music.cpp
Expand Up @@ -23,6 +23,7 @@
#include "doomsday.h"
#include <string.h>
#include <de/concurrency.h>
#include <de/c_wrapper.h>
#include <vector>

static int sfontId = -1;
Expand Down Expand Up @@ -242,6 +243,7 @@ static void startPlayer()

// Create a sound buffer for playing the music.
sfxBuf = DMFluid_Sfx()->Create(SFXBF_STREAM, 16, 44100);

DSFLUIDSYNTH_TRACE("startPlayer: Created SFX buffer " << sfxBuf);

// As a streaming buffer, the data will be read from here.
Expand All @@ -252,6 +254,7 @@ static void startPlayer()
streamSample.bytesPer = 2;
streamSample.numSamples = MAX_BLOCKS * BLOCK_SAMPLES;
streamSample.rate = 44100;

DMFluid_Sfx()->Load(sfxBuf, &streamSample);

workerShouldStop = false;
Expand All @@ -270,6 +273,7 @@ static void stopPlayer()
// Destroy the sfx buffer.
DENG_ASSERT(sfxBuf != 0);
DSFLUIDSYNTH_TRACE("stopPlayer: Destroying SFX buffer " << sfxBuf);

DMFluid_Sfx()->Destroy(sfxBuf);
sfxBuf = 0;

Expand All @@ -285,6 +289,7 @@ static void stopPlayer()
}

DSFLUIDSYNTH_TRACE("stopPlayer: " << fsPlayer);

delete_fluid_player(fsPlayer);
fsPlayer = 0;

Expand All @@ -293,15 +298,17 @@ static void stopPlayer()

int DM_Music_Init(void)
{
if(blockBuffer) return true;

musicVolume = 1.f;
blockBuffer = new RingBuffer(MAX_BLOCKS * BLOCK_SIZE);

//soundFontFileName = 0; // empty for the default
return true; //fmodSystem != 0;
return true;
}

void DMFluid_Shutdown(void)
{
if(!blockBuffer) return;

stopPlayer();

delete blockBuffer; blockBuffer = 0;
Expand All @@ -326,6 +333,7 @@ void DMFluid_SetSoundFont(const char* fileName)
{
// First unload the previous font.
fluid_synth_sfunload(DMFluid_Synth(), sfontId, false);
sfontId = -1;
}

if(!fileName) return;
Expand All @@ -334,11 +342,13 @@ void DMFluid_SetSoundFont(const char* fileName)
sfontId = fluid_synth_sfload(DMFluid_Synth(), fileName, true);
if(sfontId >= 0)
{
Con_Message("Loaded soundfont \"%s\" with id:%i.\n", fileName, sfontId);
LegacyCore_PrintfLogFragmentAtLevel(DE2_LOG_VERBOSE,
"FluidSynth: Loaded SF2 soundfont \"%s\" with id:%i\n", fileName, sfontId);
}
else
{
Con_Message("Failed to load soundfont \"%s\".\n", fileName);
LegacyCore_PrintfLogFragmentAtLevel(DE2_LOG_VERBOSE,
"FluidSynth: Failed to load soundfont \"%s\" (not SF2 or not found)\n", fileName);
}
}

Expand Down Expand Up @@ -461,9 +471,20 @@ void DM_Music_Pause(int setPause)

int DM_Music_PlayFile(const char *filename, int looped)
{
if(!filename) return false;

if(!fluid_is_midifile(filename))
{
// It doesn't look like MIDI.
LegacyCore_PrintfLogFragmentAtLevel(DE2_LOG_VERBOSE,
"FluidSynth: Cannot play \"%s\": not a MIDI file.\n", filename);
return false;
}

if(sfontId < 0)
{
Con_Message("Cannot play \"%s\" without a soundfont. Define one with the cvar 'music-soundfont'.\n", filename);
LegacyCore_PrintfLogFragmentAtLevel(DE2_LOG_VERBOSE,
"FluidSynth: Cannot play \"%s\" without an SF2 soundfont.\n", filename);
return false;
}

Expand All @@ -472,13 +493,6 @@ int DM_Music_PlayFile(const char *filename, int looped)

DENG_ASSERT(fsPlayer == NULL);

if(!fluid_is_midifile(filename))
{
// It doesn't look like MIDI.
Con_Message("Cannot play \"%s\": not a MIDI file.\n", filename);
return false;
}

// Create a new player.
fsPlayer = new_fluid_player(DMFluid_Synth());
fluid_player_add(fsPlayer, filename);
Expand All @@ -487,6 +501,7 @@ int DM_Music_PlayFile(const char *filename, int looped)

startPlayer();

DSFLUIDSYNTH_TRACE("PlayFile: playing '" << filename << "' using player " << fsPlayer << " looped:" << looped);
DSFLUIDSYNTH_TRACE("PlayFile: playing '" << filename << "' using player "
<< fsPlayer << " looped:" << looped << " sfont:" << sfontId);
return true;
}

0 comments on commit 56aa7db

Please sign in to comment.