Skip to content

Commit

Permalink
BSoftSynth: Select the soundfont from the settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
jackburton79 committed Sep 28, 2014
1 parent db5b5df commit 611ef14
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/kits/midi/SoftSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <MidiRoster.h>
#include <MidiConsumer.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <string.h>
Expand All @@ -25,8 +26,6 @@

using namespace BPrivate;

const static char* kSynthFileName = "synth/synth.sf2";

struct ReverbSettings {
double room, damp, width, level;
} gReverbSettings[] = {
Expand Down Expand Up @@ -101,34 +100,38 @@ BSoftSynth::IsLoaded(void) const
status_t
BSoftSynth::SetDefaultInstrumentsFile()
{
// We first search for a softsynth file (or symlink to it)
// We first search for a setting file (or symlink to it)
// in the user settings directory
char buffer[512];
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, false, NULL) == B_OK) {
path.Append(kSynthFileName);
if (BEntry(path.Path()).Exists())
return SetInstrumentsFile(path.Path());
}

// Then in the system settings directory
if (find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, false, NULL) == B_OK) {
path.Append(kSynthFileName);
if (BEntry(path.Path()).Exists())
return SetInstrumentsFile(path.Path());
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
path.Append("midi");
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK
&& file.Read(buffer, sizeof(buffer)) > 0) {
char soundFont[512];
sscanf(buffer, "# Midi Settings\n soundfont = %s\n",
soundFont);
return SetInstrumentsFile(soundFont);
}
}

// fall back to the old default
// softsynth (big_synth.sy)
// TODO: Remove this
if (find_directory(B_SYNTH_DIRECTORY, &path, false, NULL) == B_OK) {
path.Append(kSynthFileName);
if (BEntry(path.Path()).Exists())
return SetInstrumentsFile(path.Path());
path.Append(B_BIG_SYNTH_FILE);
return SetInstrumentsFile(path.Path());
}

// If no link is present, fall back to the default
// softsynth (big_synth.sy)
// TODO: Use the first soundfont found in the synth directory
// instead of hardcoding
if (find_directory(B_SYNTH_DIRECTORY, &path, false, NULL) == B_OK) {
path.Append(B_BIG_SYNTH_FILE);
path.Append("TimGM6mb.sf2");
return SetInstrumentsFile(path.Path());
}

// TODO: Write the settings file

return B_ERROR;
}
Expand Down

0 comments on commit 611ef14

Please sign in to comment.