From 611ef1414fc9147beb82e1a3dfbc8e80d6b6a8a4 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Sun, 28 Sep 2014 18:22:02 +0200 Subject: [PATCH] BSoftSynth: Select the soundfont from the settings file --- src/kits/midi/SoftSynth.cpp | 45 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/kits/midi/SoftSynth.cpp b/src/kits/midi/SoftSynth.cpp index bc9340bfa3..1e65509e39 100644 --- a/src/kits/midi/SoftSynth.cpp +++ b/src/kits/midi/SoftSynth.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -25,8 +26,6 @@ using namespace BPrivate; -const static char* kSynthFileName = "synth/synth.sf2"; - struct ReverbSettings { double room, damp, width, level; } gReverbSettings[] = { @@ -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()); + 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); + } } - // 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_SYNTH_DIRECTORY, &path, false, NULL) == B_OK) { - path.Append(kSynthFileName); - if (BEntry(path.Path()).Exists()) - return SetInstrumentsFile(path.Path()); - } - - // If no link is present, fall back to the default + // 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(B_BIG_SYNTH_FILE); return SetInstrumentsFile(path.Path()); } + + // 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("TimGM6mb.sf2"); + return SetInstrumentsFile(path.Path()); + } + + // TODO: Write the settings file return B_ERROR; }