/[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 2126 - (hide annotations) (download)
Tue Sep 21 06:00:25 2010 UTC (13 years, 8 months ago) by persson
File size: 2552 byte(s)
* fixed memory leak in the new internal effects code

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 persson 2126 namespace {
11 schoenebeck 2124
12 persson 2126 class EffectInfos {
13     public:
14     EffectInfos();
15     ~EffectInfos();
16     void Update();
17     uint Count();
18     EffectInfo* GetEffectInfo(uint index);
19     private:
20     std::vector<EffectInfo*> infos;
21     bool bInitialized;
22     };
23 schoenebeck 2124
24 persson 2126 EffectInfos::EffectInfos() : bInitialized(false) {
25     }
26 schoenebeck 2124
27 persson 2126 EffectInfos::~EffectInfos() {
28     for (int i = 0; i < infos.size(); i++) delete infos[i];
29     }
30    
31     void EffectInfos::Update() {
32     // clear out all old effect infos
33     for (int i = 0; i < infos.size(); i++) delete infos[i];
34    
35     // scan for LADSPA effects
36     infos = LadspaEffect::AvailableEffects();
37     }
38    
39     uint EffectInfos::Count() {
40     if (!bInitialized) {
41     Update();
42     bInitialized = true;
43     }
44     return infos.size();
45     }
46    
47     EffectInfo* EffectInfos::GetEffectInfo(uint index) {
48     if (index >= infos.size()) return NULL;
49     return infos[index];
50     }
51    
52    
53     EffectInfos effectInfos;
54    
55     std::vector<Effect*> vEffectInstances;
56    
57     }
58    
59    
60 schoenebeck 2124 ////////////////////////////////////////////////////////////////////////////
61     // class 'EffectFactory'
62    
63     String EffectFactory::AvailableEffectSystemsAsString() {
64     return "LADSPA";
65     }
66    
67     uint EffectFactory::AvailableEffectsCount() {
68 persson 2126 return effectInfos.Count();
69 schoenebeck 2124 }
70    
71     EffectInfo* EffectFactory::GetEffectInfo(uint index) {
72 persson 2126 return effectInfos.GetEffectInfo(index);
73 schoenebeck 2124 }
74    
75     Effect* EffectFactory::Create(EffectInfo* pEffectInfo) throw (Exception) {
76     Effect* pEffect = NULL;
77     try {
78     if (pEffectInfo->EffectSystem() == "LADSPA") {
79     pEffect = new LadspaEffect(pEffectInfo);
80     } else {
81     throw Exception(
82     "Effect system '" + pEffectInfo->EffectSystem() +
83     "' not supported"
84     );
85     }
86     } catch (Exception e) {
87     throw Exception("Could not create effect: " + e.Message());
88     } catch (...) {
89     throw Exception("Could not create effect: unknown exception");
90     }
91     if (!pEffect) {
92     // should never happen
93     throw Exception("Oops, EffectFactory bug: !pEffect");
94     }
95     vEffectInstances.push_back(pEffect);
96     return pEffect;
97     }
98    
99     void EffectFactory::Destroy(Effect* pEffect) {
100     for (int i = 0; i < vEffectInstances.size(); i++) {
101     if (vEffectInstances[i] == pEffect) {
102     vEffectInstances.erase(vEffectInstances.begin() + i);
103     delete pEffect;
104     }
105     }
106     }
107    
108     void EffectFactory::UpdateAvailableEffects() {
109 persson 2126 effectInfos.Update();
110 schoenebeck 2124 }
111    
112     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC