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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2126 - (show annotations) (download)
Tue Sep 21 06:00:25 2010 UTC (13 years, 6 months ago) by persson
File size: 2552 byte(s)
* fixed memory leak in the new internal effects code

1 /*
2 Copyright (C) 2010 Christian Schoenebeck
3 */
4
5 #include "EffectFactory.h"
6 #include "LadspaEffect.h"
7
8 namespace LinuxSampler {
9
10 namespace {
11
12 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
24 EffectInfos::EffectInfos() : bInitialized(false) {
25 }
26
27 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 ////////////////////////////////////////////////////////////////////////////
61 // class 'EffectFactory'
62
63 String EffectFactory::AvailableEffectSystemsAsString() {
64 return "LADSPA";
65 }
66
67 uint EffectFactory::AvailableEffectsCount() {
68 return effectInfos.Count();
69 }
70
71 EffectInfo* EffectFactory::GetEffectInfo(uint index) {
72 return effectInfos.GetEffectInfo(index);
73 }
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 effectInfos.Update();
110 }
111
112 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC