From 65b4405eccf4d9cf1800e1ad327d0635ce044a26 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 24 Aug 2015 10:04:17 +0200 Subject: [PATCH] BSoftSynth: Fixed auto selection of soundfont. When no midi settings file was available, BSoftSynth should use the well known TimGM6mb.sf2 soundfont. This wasn't working, since the code looked in the wrong path (we have to append "synth" to the path returned by find_directory). In case this SF is not present, now we try harder not to fail, and look for any soundfont available in the system and user directories. Fixes ticket #12325 although the selected soundfont is not written to the user settings file. --- src/kits/midi/SoftSynth.cpp | 48 ++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/kits/midi/SoftSynth.cpp b/src/kits/midi/SoftSynth.cpp index 905aa3dd2f..baacf9944f 100644 --- a/src/kits/midi/SoftSynth.cpp +++ b/src/kits/midi/SoftSynth.cpp @@ -14,9 +14,13 @@ #include #include +#include #include #include +#include +#include #include +#include #include #include @@ -100,6 +104,8 @@ BSoftSynth::IsLoaded(void) const status_t BSoftSynth::SetDefaultInstrumentsFile() { + // TODO: Duplicated code, check MidiSettingsView::_LoadSettings() and + // MidiSettingsView::_RetrieveSoftSynthList() // We first search for a setting file (or symlink to it) // in the user settings directory char buffer[512]; @@ -112,18 +118,48 @@ BSoftSynth::SetDefaultInstrumentsFile() char soundFont[512]; sscanf(buffer, "# Midi Settings\n soundfont = %s\n", soundFont); - return SetInstrumentsFile(soundFont); + if (SetInstrumentsFile(soundFont) == B_OK) + return B_OK; } } - // TODO: Use the first soundfont found in the synth directory - // instead of hardcoding + // Try a well-known (and usually present on a default install) soft synth if (find_directory(B_SYNTH_DIRECTORY, &path, false, NULL) == B_OK) { - path.Append("TimGM6mb.sf2"); - return SetInstrumentsFile(path.Path()); + path.Append("synth/TimGM6mb.sf2"); + if (SetInstrumentsFile(path.Path()) == B_OK) + return B_OK; } - // TODO: Write the settings file + // Just use the first soundfont we find + BStringList paths; + status_t status = BPathFinder::FindPaths(B_FIND_PATH_DATA_DIRECTORY, + "synth", paths); + + if (status != B_OK) + return B_ERROR; + + for (int32 i = 0; i < paths.CountStrings(); i++) { + BDirectory directory(paths.StringAt(i).String()); + BEntry entry; + if (directory.InitCheck() != B_OK) + continue; + while (directory.GetNextEntry(&entry) == B_OK) { + BNode node(&entry); + BNodeInfo nodeInfo(&node); + char mimeType[B_MIME_TYPE_LENGTH]; + // TODO: For some reason the mimetype check fails. + // maybe because the file hasn't yet been sniffed and recognized? + if (nodeInfo.GetType(mimeType) == B_OK + /*&& !strcmp(mimeType, "audio/x-soundfont")*/) { + BPath fullPath = paths.StringAt(i).String(); + fullPath.Append(entry.Name()); + if (SetInstrumentsFile(fullPath.Path()) == B_OK) + return B_OK; + } + } + } + + // TODO: Write the settings file ? return B_ERROR; }