/[svn]/linuxsampler/trunk/src/effects/EffectFactory.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/effects/EffectFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2124 - (hide annotations) (download)
Sat Sep 18 09:24:41 2010 UTC (13 years, 7 months ago) by schoenebeck
File size: 2073 byte(s)
* implemented support for internal LADSPA effects (work in progress)

1 schoenebeck 2124 /*
2     Copyright (C) 2010 Christian Schoenebeck
3     */
4    
5     #include "EffectFactory.h"
6     #include "LadspaEffect.h"
7    
8     namespace LinuxSampler {
9    
10     static bool bInitialized = false;
11    
12     static std::vector<EffectInfo*> vEffectInfos;
13    
14     static std::vector<Effect*> vEffectInstances;
15    
16     ////////////////////////////////////////////////////////////////////////////
17     // class 'EffectFactory'
18    
19     String EffectFactory::AvailableEffectSystemsAsString() {
20     return "LADSPA";
21     }
22    
23     uint EffectFactory::AvailableEffectsCount() {
24     if (!bInitialized) UpdateAvailableEffects();
25     bInitialized = true;
26     return vEffectInfos.size();
27     }
28    
29     EffectInfo* EffectFactory::GetEffectInfo(uint index) {
30     if (index >= vEffectInfos.size()) return NULL;
31     return vEffectInfos[index];
32     }
33    
34     Effect* EffectFactory::Create(EffectInfo* pEffectInfo) throw (Exception) {
35     Effect* pEffect = NULL;
36     try {
37     if (pEffectInfo->EffectSystem() == "LADSPA") {
38     pEffect = new LadspaEffect(pEffectInfo);
39     } else {
40     throw Exception(
41     "Effect system '" + pEffectInfo->EffectSystem() +
42     "' not supported"
43     );
44     }
45     } catch (Exception e) {
46     throw Exception("Could not create effect: " + e.Message());
47     } catch (...) {
48     throw Exception("Could not create effect: unknown exception");
49     }
50     if (!pEffect) {
51     // should never happen
52     throw Exception("Oops, EffectFactory bug: !pEffect");
53     }
54     vEffectInstances.push_back(pEffect);
55     return pEffect;
56     }
57    
58     void EffectFactory::Destroy(Effect* pEffect) {
59     for (int i = 0; i < vEffectInstances.size(); i++) {
60     if (vEffectInstances[i] == pEffect) {
61     vEffectInstances.erase(vEffectInstances.begin() + i);
62     delete pEffect;
63     }
64     }
65     }
66    
67     void EffectFactory::UpdateAvailableEffects() {
68     // clear out all old effect infos
69     for (int i = 0; i < vEffectInfos.size(); i++) delete vEffectInfos[i];
70     vEffectInfos.clear();
71    
72     // scan for LADSPA effects
73     vEffectInfos = LadspaEffect::AvailableEffects();
74     }
75    
76     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC