19#include <QCoreApplication>
21#include <QLibraryInfo>
22#include <QPluginLoader>
50 class BackendManager::BackendManagerPrivate {
52 QList<MIDIInput*> m_inputsList;
53 QList<MIDIOutput*> m_outputsList;
55 QString m_inputBackend{QLatin1String(
"Network")};
56 #if defined(Q_OS_LINUX)
57 QStringList m_outputBackends{QLatin1String(
"SonivoxEAS"),QLatin1String(
"FluidSynth"),QLatin1String(
"ALSA")};
58 #elif defined(Q_OS_DARWIN)
59 QStringList m_outputBackends{QLatin1String(
"DLS Synth"),QLatin1String(
"FluidSynth"),QLatin1String(
"CoreMIDI")};
60 #elif defined(Q_OS_WINDOWS)
61 QStringList m_outputBackends{QLatin1String(
"Windows MM"),QLatin1String(
"FluidSynth")};
62 #elif defined(Q_OS_UNIX)
63 QStringList m_outputBackends{QLatin1String(
"FluidSynth"),QLatin1String(
"OSS")};
65 QStringList m_outputBackends{m_inputBackend};
68 ~BackendManagerPrivate()
75 m_outputsList.clear();
77 void appendDir(
const QString& candidate, QStringList& result)
79 QDir checked(candidate.trimmed());
81 if (checked.exists() && !result.contains(checked.absolutePath())) {
82 result << checked.absolutePath();
92 QVariantMap defaultSettings {
93 { QSTR_DRUMSTICKRT_PUBLICNAMEIN, QStringLiteral(
"MIDI In")},
94 { QSTR_DRUMSTICKRT_PUBLICNAMEOUT, QStringLiteral(
"MIDI Out")}
112 QString appPath = QCoreApplication::applicationDirPath() + QDir::separator();
113 #if defined(Q_OS_WIN)
114 d->appendDir( appPath + QSTR_DRUMSTICK, result );
115 d->appendDir( appPath +
"../lib/" + QSTR_DRUMSTICK, result );
117 #if defined(Q_OS_MAC)
118 d->appendDir( appPath + QStringLiteral(
"../PlugIns/") + QSTR_DRUMSTICK, result );
122 #if defined(LIBSUFFIX)
123 QString libextra(QT_STRINGIFY(LIBSUFFIX));
124 if (QDir::isAbsolutePath(libextra)) {
125 d->appendDir( libextra + QDir::separator() + QSTR_DRUMSTICK, result );
127 libs << QString(
"../%1/").arg(libextra);
130 foreach(
const QString& lib, libs) {
131 d->appendDir( appPath + lib + QSTR_DRUMSTICK, result );
134 d->appendDir( appPath +
".." + QDir::separator() + QSTR_DRUMSTICK, result );
135 QByteArray envdir = qgetenv(QSTR_DRUMSTICKRT.toLatin1());
137 if(!envdir.isEmpty()) {
138 d->appendDir(QString(envdir), result );
140 d->appendDir( QDir::homePath() + QDir::separator() + QSTR_DRUMSTICK, result );
141#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
142 d->appendDir( QLibraryInfo::location(QLibraryInfo::PluginsPath) + QDir::separator() + QSTR_DRUMSTICK, result );
144 d->appendDir( QLibraryInfo::path(QLibraryInfo::PluginsPath) + QDir::separator() + QSTR_DRUMSTICK, result );
146 foreach(
const QString& path, QCoreApplication::libraryPaths()) {
147 d->appendDir( path + QDir::separator() + QSTR_DRUMSTICK, result );
159 settings->beginGroup(QSTR_DRUMSTICKRT_GROUP);
160 const QStringList allKeys = settings->allKeys();
162 for(
const auto &k : allKeys) {
163 tmpMap.insert(k, settings->value(k));
165 settings->endGroup();
181 d->appendDir(map.value(QSTR_DRUMSTICKRT_PATH).toString(), paths);
182 name_in = map.value(QSTR_DRUMSTICKRT_PUBLICNAMEIN).toString();
183 name_out = map.value(QSTR_DRUMSTICKRT_PUBLICNAMEOUT).toString();
184 names << map.value(QSTR_DRUMSTICKRT_EXCLUDED).toStringList();
185 names << (name_in.isEmpty() ? QStringLiteral(
"MIDI In") : name_in);
186 names << (name_out.isEmpty() ? QStringLiteral(
"MIDI Out") : name_out);
194 foreach(
const QString& dir, paths) {
195 QDir pluginsDir(dir);
196 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
197 if (QLibrary::isLibrary(fileName)) {
198 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
199 QObject *obj = loader.instance();
200 if (obj !=
nullptr) {
201 MIDIInput *input = qobject_cast<MIDIInput*>(obj);
202 if (input !=
nullptr && !d->m_inputsList.contains(input)) {
203 if (!name_in.isEmpty()) {
207 d->m_inputsList << input;
209 MIDIOutput *output = qobject_cast<MIDIOutput*>(obj);
210 if (output !=
nullptr && !d->m_outputsList.contains(output)) {
211 if (!name_out.isEmpty()) {
215 d->m_outputsList << output;
224 foreach(
QObject* obj, QPluginLoader::staticInstances()) {
225 if (obj !=
nullptr) {
226 MIDIInput *input = qobject_cast<MIDIInput*>(obj);
227 if (input !=
nullptr && !d->m_inputsList.contains(input)) {
228 if (!name_in.isEmpty()) {
232 d->m_inputsList << input;
234 MIDIOutput *output = qobject_cast<MIDIOutput*>(obj);
235 if (output !=
nullptr && !d->m_outputsList.contains(output)) {
236 if (!name_out.isEmpty()) {
240 d->m_outputsList << output;
249 return d->m_inputsList;
254 return d->m_outputsList;
259 foreach (
MIDIInput* i, d->m_inputsList) {
279 QStringList names{name};
280 names << d->m_inputBackend;
281 names.removeDuplicates();
282 if (!names.isEmpty()) {
283 foreach(
const QString& n, names) {
284 foreach(
MIDIInput* input, d->m_inputsList) {
296 QStringList names{name};
297 names << d->m_outputBackends;
298 names.removeDuplicates();
299 if (!names.isEmpty()) {
300 foreach(
const QString& n, names) {
301 foreach(
MIDIOutput* output, d->m_outputsList) {
311 const QString BackendManager::QSTR_DRUMSTICK = QStringLiteral(
"drumstick2");
312 const QString BackendManager::QSTR_DRUMSTICK_VERSION = QStringLiteral(QT_STRINGIFY(VERSION));
313 const QString BackendManager::QSTR_DRUMSTICKRT = QStringLiteral(
"DRUMSTICKRT");
314 const QString BackendManager::QSTR_DRUMSTICKRT_GROUP = QStringLiteral(
"DrumstickRT");
315 const QString BackendManager::QSTR_DRUMSTICKRT_PUBLICNAMEIN = QStringLiteral(
"PublicNameIN");
316 const QString BackendManager::QSTR_DRUMSTICKRT_PUBLICNAMEOUT = QStringLiteral(
"PublicNameOUT");
317 const QString BackendManager::QSTR_DRUMSTICKRT_EXCLUDED = QStringLiteral(
"ExcludedNames");
318 const QString BackendManager::QSTR_DRUMSTICKRT_PATH = QStringLiteral(
"BackendsPath");
326 return BackendManager::QSTR_DRUMSTICK_VERSION;
BackendManager class declaration.
The QObject class is the base class of all Qt objects.
The QSettings class provides persistent platform-independent application settings.
QList< MIDIInput * > availableInputs()
availableInputs
virtual ~BackendManager()
~BackendManager destructor
BackendManager()
BackendManager constructor.
MIDIOutput * outputBackendByName(const QString name)
outputBackendByName
void refresh(QSettings *settings=nullptr)
refresh the list of backends
QList< MIDIOutput * > availableOutputs()
availableOutputs
MIDIOutput * findOutput(QString name)
findOutput returns the backend corresponding to the provided name, or a suitable output instead.
MIDIInput * findInput(QString name)
findInput returns the backend corresponding to the provided name, or a suitable input instead.
QStringList defaultPaths()
defaultPaths
MIDIInput * inputBackendByName(const QString name)
inputBackendByName
virtual void setExcludedConnections(QStringList conns)=0
setExcludedConnections
virtual QString backendName()=0
backendName
virtual void setPublicName(QString name)=0
setPublicName
QString DRUMSTICK_RT_EXPORT drumstickLibraryVersion()
drumstickLibraryVersion provides the Drumstick version as an edited QString