1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2005-2007 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 |
#include "EngineFactory.h" |
22 |
|
23 |
#include <strings.h> |
24 |
|
25 |
#include "gig/Engine.h" |
26 |
|
27 |
#if HAVE_SF2 |
28 |
#include "sf2/Engine.h" |
29 |
#endif |
30 |
|
31 |
#include "sfz/Engine.h" |
32 |
|
33 |
#include "../common/global.h" |
34 |
|
35 |
namespace LinuxSampler { |
36 |
|
37 |
// all currently existing engine instances |
38 |
static std::set<LinuxSampler::Engine*> engines; |
39 |
|
40 |
std::vector<String> EngineFactory::AvailableEngineTypes() { |
41 |
std::vector<String> result; |
42 |
result.push_back("GIG"); |
43 |
#if HAVE_SF2 |
44 |
result.push_back("SF2"); |
45 |
#endif |
46 |
result.push_back("SFZ"); |
47 |
return result; |
48 |
} |
49 |
|
50 |
String EngineFactory::AvailableEngineTypesAsString() { |
51 |
std::vector<String> types = AvailableEngineTypes(); |
52 |
String result; |
53 |
std::vector<String>::iterator iter = types.begin(); |
54 |
for (; iter != types.end(); iter++) { |
55 |
if (result != "") result += ","; |
56 |
result += "'" + *iter + "'"; |
57 |
} |
58 |
return result; |
59 |
} |
60 |
|
61 |
LinuxSampler::Engine* EngineFactory::Create(String EngineType) throw (Exception) { |
62 |
if (!strcasecmp(EngineType.c_str(),"GigEngine") || !strcasecmp(EngineType.c_str(),"gig")) { |
63 |
Engine* pEngine = new gig::Engine; |
64 |
engines.insert(pEngine); |
65 |
return pEngine; |
66 |
} else if (!strcasecmp(EngineType.c_str(),"sf2")) { |
67 |
#if HAVE_SF2 |
68 |
Engine* pEngine = new sf2::Engine; |
69 |
engines.insert(pEngine); |
70 |
return pEngine; |
71 |
#else |
72 |
throw Exception("LinuxSampler is not compiled with SF2 support"); |
73 |
#endif |
74 |
} else if (!strcasecmp(EngineType.c_str(),"sfz")) { |
75 |
Engine* pEngine = new sfz::Engine; |
76 |
engines.insert(pEngine); |
77 |
return pEngine; |
78 |
} |
79 |
|
80 |
throw Exception("Unknown engine type"); |
81 |
} |
82 |
|
83 |
void EngineFactory::Erase(LinuxSampler::Engine* pEngine) { |
84 |
engines.erase(pEngine); |
85 |
} |
86 |
|
87 |
void EngineFactory::Destroy(LinuxSampler::Engine* pEngine) { |
88 |
delete pEngine; |
89 |
} |
90 |
|
91 |
const std::set<LinuxSampler::Engine*>& EngineFactory::EngineInstances() { |
92 |
return engines; |
93 |
} |
94 |
|
95 |
} // namespace LinuxSampler |