1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7 See the AUTHORS file for more details.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #define RG_MODULE_STRING "[PluginFactory]"
17
18 #include "PluginFactory.h"
19 #include "PluginIdentifier.h"
20 #include "misc/Strings.h"
21 #include "misc/Debug.h"
22
23 #include "LADSPAPluginFactory.h"
24 #include "DSSIPluginFactory.h"
25
26 #include <locale.h>
27
28 namespace Rosegarden
29 {
30
31 int PluginFactory::m_sampleRate = 48000;
32
33 static LADSPAPluginFactory *ladspaInstance = nullptr;
34 static LADSPAPluginFactory *dssiInstance = nullptr;
35
36 PluginFactory *
instance(QString pluginType)37 PluginFactory::instance(QString pluginType)
38 {
39 if (pluginType == "ladspa") {
40 if (!ladspaInstance) {
41 RG_DEBUG << "PluginFactory::instance(" << pluginType << "): creating new LADSPAPluginFactory";
42 ladspaInstance = new LADSPAPluginFactory();
43 ladspaInstance->discoverPlugins();
44 }
45 return ladspaInstance;
46 } else if (pluginType == "dssi") {
47 if (!dssiInstance) {
48 RG_DEBUG << "PluginFactory::instance(" << pluginType << "): creating new DSSIPluginFactory";
49 dssiInstance = new DSSIPluginFactory();
50 dssiInstance->discoverPlugins();
51 }
52 return dssiInstance;
53 } else {
54 return nullptr;
55 }
56 }
57
58 PluginFactory *
instanceFor(QString identifier)59 PluginFactory::instanceFor(QString identifier)
60 {
61 QString type, soName, label;
62 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
63 return instance(type);
64 }
65
66 void
enumerateAllPlugins(MappedObjectPropertyList & list)67 PluginFactory::enumerateAllPlugins(MappedObjectPropertyList &list)
68 {
69 PluginFactory *factory;
70
71 // Plugins can change the locale, store it for reverting afterwards
72 char *loc = setlocale(LC_ALL, nullptr);
73
74 // Query DSSI plugins before LADSPA ones.
75 // This is to provide for the interesting possibility of plugins
76 // providing either DSSI or LADSPA versions of themselves,
77 // returning both versions if the LADSPA identifiers are queried
78 // first but only the DSSI version if the DSSI identifiers are
79 // queried first.
80
81 factory = instance("dssi");
82 if (factory)
83 factory->enumeratePlugins(list);
84
85 factory = instance("ladspa");
86 if (factory)
87 factory->enumeratePlugins(list);
88
89 setlocale(LC_ALL, loc);
90 }
91
~PluginFactory()92 PluginFactory::~PluginFactory()
93 {
94 }
95
96
97 }
98
99