linuxsampler 2.3.1
InstrumentEditorFactory.h
Go to the documentation of this file.
1/***************************************************************************
2 * *
3 * Copyright (C) 2007 - 2022 Christian Schoenebeck *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21#ifndef LS_INSTRUMENT_EDITOR_FACTORY_H
22#define LS_INSTRUMENT_EDITOR_FACTORY_H
23
24#include <map>
25#include <vector>
26#include <list>
27
28#include "../common/Exception.h"
29#include "InstrumentEditor.h"
30
31#if defined(WIN32)
32# define REGISTER_INSTRUMENT_EDITOR(PluginClass) \
33 extern "C" __declspec(dllexport) void* \
34 createInstrumentEditorInnerFactory() { \
35 return new LinuxSampler::InstrumentEditorFactory::InnerFactoryTemplate<PluginClass>(); \
36 }
37 //FIXME: missing a destruction function for Windows
38
39 //NOTE: using Windows' DllMain() API callback function is probably not a
40 // viable alternative, as that callback is too limited of what is allowed
41 // to do (e.g. Windows prohibits any thread synchronization mechanisms)
42#else
43# define REGISTER_INSTRUMENT_EDITOR(PluginClass) \
44 LinuxSampler::InstrumentEditorFactory::InnerFactoryRegistrator<PluginClass> \
45 __auto_register_instrument_editor__##PluginClass;
46#endif
47
48namespace LinuxSampler {
49
51 public:
53 public:
54 virtual ~InnerFactory() {}
55 virtual InstrumentEditor* Create() = 0;
56 virtual void Destroy(InstrumentEditor* pEditor) = 0;
57 };
58
59 template<class PluginClass_T>
61 public:
63 return new PluginClass_T();
64 }
65
67 delete pEditor;
68 }
69 };
70
71 template<class PluginClass_T>
73 public:
86
88 //FIXME: potential race with ClosePlugins()
89 // (see comments in the latter for details)
92 if (InnerFactories.count(pEditor->Name())) {
94 InnerFactories[pEditor->Name()];
95 InnerFactories.erase(pEditor->Name());
96 if (pZombie) delete pZombie;
97 }
98 innerFactory.Destroy(pEditor);
99 }
100 };
101
104 static std::vector<String> PluginDirs();
106 static std::vector<String> AvailableEditors();
108 static std::vector<String> MatchingEditors(String sTypeName, String sTypeVersion);
109 static void LoadPlugins();
110 static void ClosePlugins();
111
112 protected:
113 static std::map<String, InnerFactory*> InnerFactories;
114 static bool bPluginsLoaded;
115 static std::list<void*> LoadedDLLs;
116
117 private:
118 static bool LoadPlugins(String plugindir);
119 };
120
121} // namespace LinuxSampler
122
123#endif // LS_INSTRUMENT_EDITOR_FACTORY_H
Exception that will be thrown in NON REAL TIME PARTS of the LinuxSampler application.
Definition Exception.h:37
virtual void Destroy(InstrumentEditor *pEditor)=0
static std::vector< String > PluginDirs()
static std::map< String, InnerFactory * > InnerFactories
static InstrumentEditor * Create(String InstrumentEditorName)
static std::vector< String > AvailableEditors()
static std::vector< String > MatchingEditors(String sTypeName, String sTypeVersion)
static void Destroy(InstrumentEditor *pInstrumentEditor)
Instrument Editor Interface (external plugin)
Wraps as a kind of pointer class some data object shared with other threads, to protect / synchronize...
std::string String
Definition global.h:44