diff --git a/src/plugins/fluidsynthsoundcontroller/fluidsynthsoundcontroller.cpp b/src/plugins/fluidsynthsoundcontroller/fluidsynthsoundcontroller.cpp --- a/src/plugins/fluidsynthsoundcontroller/fluidsynthsoundcontroller.cpp +++ b/src/plugins/fluidsynthsoundcontroller/fluidsynthsoundcontroller.cpp @@ -22,6 +22,8 @@ #include "fluidsynthsoundcontroller.h" +#include +#include #include #include #include @@ -50,11 +52,32 @@ #ifdef Q_OS_WIN const QString sf_path = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("minuet/soundfonts/GeneralUser-v1.47.sf2")); #else - const QString sf_path = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("soundfonts/GeneralUser-v1.47.sf2")); + QString sf_path = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("soundfonts/GeneralUser-v1.47.sf2")); +#ifdef Q_OS_MACOS + // Qt does not check XDG_DATA_DIRS for MACOS but KDE prefix.sh script sets it. + // If AppDataLocation fail, we should give a shot and check XDG env variable + if (sf_path.isEmpty()) { + const QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); + if (!xdgDataDirsEnv.isEmpty()) { + const auto parts = xdgDataDirsEnv.splitRef(QLatin1Char(':'), QString::SkipEmptyParts); + // Normalize paths, skip relative paths + for (const QStringRef &dir : parts) { + if (dir.startsWith(QLatin1Char('/'))) { + const QFile testFile(QDir(dir.toString()).absoluteFilePath(QStringLiteral("minuet/soundfonts/GeneralUser-v1.47.sf2"))); + if (testFile.exists()) { + sf_path = testFile.fileName(); + break; + } + } + } + } + } +#endif #endif + int fluid_res = fluid_synth_sfload(m_synth, sf_path.toLatin1(), 1); if (fluid_res == FLUID_FAILED) - qCritical() << "Error when loading soundfont!"; + qCritical() << "Error when loading soundfont in:" << sf_path; m_unregisteringEvent = new_fluid_event(); fluid_event_set_source(m_unregisteringEvent, -1);