21 #include <QPluginLoader>
22 #include <QCoreApplication>
23 #include <QLibraryInfo>
26 #if defined(LINUX_BACKEND)
27 Q_IMPORT_PLUGIN(ALSAMIDIInput)
28 Q_IMPORT_PLUGIN(ALSAMIDIOutput)
29 Q_IMPORT_PLUGIN(SynthController)
32 #if defined(MAC_BACKEND)
33 Q_IMPORT_PLUGIN(MacMIDIInput)
34 Q_IMPORT_PLUGIN(MacMIDIOutput)
35 Q_IMPORT_PLUGIN(MacSynthOutput)
38 #if defined(WIN_BACKEND)
39 Q_IMPORT_PLUGIN(WinMIDIInput)
40 Q_IMPORT_PLUGIN(WinMIDIOutput)
43 #if defined(NET_BACKEND)
44 Q_IMPORT_PLUGIN(NetMIDIInput)
45 Q_IMPORT_PLUGIN(NetMIDIOutput)
48 #if defined(DUMMY_BACKEND)
49 Q_IMPORT_PLUGIN(DummyInput)
50 Q_IMPORT_PLUGIN(DummyOutput)
53 #if defined(SYNTH_BACKEND)
54 Q_IMPORT_PLUGIN(SynthOutput)
57 #if defined(OSS_BACKEND)
58 Q_IMPORT_PLUGIN(OSSInput)
59 Q_IMPORT_PLUGIN(OSSOutput)
63 #define MKSTR(x) MKSTR_A(x)
90 class BackendManager::BackendManagerPrivate {
92 QList<MIDIInput*> m_inputsList;
93 QList<MIDIOutput*> m_outputsList;
94 ~BackendManagerPrivate()
100 m_inputsList.clear();
101 m_outputsList.clear();
103 void appendDir(
const QString& candidate, QStringList& result)
105 QDir checked(candidate);
106 if (checked.exists() && !result.contains(checked.absolutePath())) {
107 result << checked.absolutePath();
135 QString appPath = QCoreApplication::applicationDirPath() + QDir::separator();
136 #if defined(Q_OS_WIN)
137 d->appendDir( appPath + QSTR_DRUMSTICK, result );
138 d->appendDir( appPath +
"../lib/" + QSTR_DRUMSTICK, result );
140 #if defined(Q_OS_MAC)
141 d->appendDir( appPath + QStringLiteral(
"../PlugIns/") + QSTR_DRUMSTICK, result );
142 #endif // Linux, Unix...
145 #if defined(LIBSUFFIX)
146 libs << QString(
"../%1/").arg(MKSTR(LIBSUFFIX));
148 foreach(
const QString& lib, libs) {
149 d->appendDir( appPath + lib + QSTR_DRUMSTICK, result );
152 d->appendDir( appPath +
".." + QDir::separator() + QSTR_DRUMSTICK, result );
153 QByteArray envdir = qgetenv(QSTR_DRUMSTICKRT.toLatin1());
154 if(!envdir.isEmpty()) {
155 d->appendDir(QString(envdir), result );
157 d->appendDir( QDir::homePath() + QDir::separator() + QSTR_DRUMSTICK, result );
158 d->appendDir( QLibraryInfo::location(QLibraryInfo::PluginsPath) + QDir::separator() + QSTR_DRUMSTICK, result );
159 foreach(
const QString& path, QCoreApplication::libraryPaths()) {
160 d->appendDir( path + QDir::separator() + QSTR_DRUMSTICK, result );
177 if (settings !=
nullptr) {
178 settings->beginGroup(QSTR_DRUMSTICKRT_GROUP);
179 d->appendDir(settings->value(QSTR_DRUMSTICKRT_PATH).toString(), paths);
180 name_in = settings->value(QSTR_DRUMSTICKRT_PUBLICNAMEIN).toString();
181 name_out = settings->value(QSTR_DRUMSTICKRT_PUBLICNAMEOUT).toString();
182 names << settings->value(QSTR_DRUMSTICKRT_EXCLUDED).toStringList();
183 names << (name_in.isEmpty() ? QLatin1String(
"MIDI In") : name_in);
184 names << (name_out.isEmpty() ? QLatin1String(
"MIDI Out") : name_out);
185 settings->endGroup();
191 foreach(
const QString& dir, paths) {
192 QDir pluginsDir(dir);
193 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
194 if (QLibrary::isLibrary(fileName)) {
195 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
196 QObject *obj = loader.instance();
197 if (obj !=
nullptr) {
198 MIDIInput *input = qobject_cast<MIDIInput*>(obj);
199 if (input !=
nullptr && !d->m_inputsList.contains(input)) {
200 if (!name_in.isEmpty()) {
204 d->m_inputsList << input;
206 MIDIOutput *output = qobject_cast<MIDIOutput*>(obj);
207 if (output !=
nullptr && !d->m_outputsList.contains(output)) {
208 if (!name_out.isEmpty()) {
212 d->m_outputsList << output;
221 foreach(
QObject* obj, QPluginLoader::staticInstances()) {
222 if (obj !=
nullptr) {
223 MIDIInput *input = qobject_cast<MIDIInput*>(obj);
224 if (input !=
nullptr && !d->m_inputsList.contains(input)) {
227 d->m_inputsList << input;
229 MIDIOutput *output = qobject_cast<MIDIOutput*>(obj);
230 if (output !=
nullptr && !d->m_outputsList.contains(output)) {
233 d->m_outputsList << output;
242 return d->m_inputsList;
247 return d->m_outputsList;
252 foreach (
MIDIInput* i, d->m_inputsList) {