/[svn]/linuxsampler/trunk/src/engines/EngineChannelFactory.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/EngineChannelFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1825 by persson, Fri Jun 22 10:10:06 2007 UTC revision 1826 by iliev, Sat Jan 24 14:32:35 2009 UTC
# Line 25  Line 25 
25  #include "gig/EngineChannel.h"  #include "gig/EngineChannel.h"
26    
27  namespace LinuxSampler {  namespace LinuxSampler {
28        class LockedChannel {
29            public:
30                const EngineChannel* pChannel;
31                bool bDestroyed;
32    
33                LockedChannel(const EngineChannel* pChannel)  {
34                    this->pChannel = pChannel;
35                    bDestroyed = false;
36                }
37        };
38    
39        class LockedChannelList {
40            public:
41                void Add(const EngineChannel* pChannel) {
42                    vChannelList.push_back(LockedChannel(pChannel));
43                }
44    
45                bool IsDestroyed(const EngineChannel* pChannel) {
46                    LockedChannel* pLockedChannel = get(pChannel);
47                    if (pLockedChannel == NULL) return false;
48                    return pLockedChannel->bDestroyed;
49                }
50    
51                void SetDestroyed(const EngineChannel* pChannel, bool bDestroyed = true) {
52                    LockedChannel* pLockedChannel = get(pChannel);
53                    if (pLockedChannel == NULL) return;
54                    pLockedChannel->bDestroyed = bDestroyed;
55                }
56    
57                void Remove(const EngineChannel* pChannel) {
58                    std::vector<LockedChannel>::iterator it = vChannelList.begin();
59                    for (; it != vChannelList.end(); it++) {
60                        if ((*it).pChannel == pChannel) {
61                            vChannelList.erase(it);
62                            return;
63                        }
64                    }
65                }
66    
67                bool Contains(const EngineChannel* pChannel) {
68                    return get(pChannel) != NULL;
69                }
70    
71            private:
72                std::vector<LockedChannel> vChannelList;
73    
74                LockedChannel* get(const EngineChannel* pChannel) {
75                    for (int i = 0; i < vChannelList.size(); i++) {
76                        if (vChannelList[i].pChannel == pChannel) {
77                            return &vChannelList[i];
78                        }
79                    }
80    
81                    return NULL;
82                }
83        } lockedChannels;
84    
85        Mutex EngineChannelFactory::LockedChannelsMutex;
86    
87        void EngineChannelFactory::SetDeleteEnabled(const EngineChannel* pEngineChannel, bool enable) {
88            LockedChannelsMutex.Lock();
89            if (!enable) {
90                if (!lockedChannels.Contains(pEngineChannel)) lockedChannels.Add(pEngineChannel);
91                LockedChannelsMutex.Unlock();
92            } else {
93                bool b = lockedChannels.IsDestroyed(pEngineChannel);
94                lockedChannels.Remove(pEngineChannel);
95                LockedChannelsMutex.Unlock();
96    
97                if (b) delete pEngineChannel;
98            }
99        }
100    
101      // all currently existing engine channel instances      // all currently existing engine channel instances
102      static std::set<LinuxSampler::EngineChannel*> engineChannels;      static std::set<LinuxSampler::EngineChannel*> engineChannels;
# Line 41  namespace LinuxSampler { Line 113  namespace LinuxSampler {
113      void EngineChannelFactory::Destroy(LinuxSampler::EngineChannel* pEngineChannel) {      void EngineChannelFactory::Destroy(LinuxSampler::EngineChannel* pEngineChannel) {
114          pEngineChannel->RemoveAllFxSendCountListeners();          pEngineChannel->RemoveAllFxSendCountListeners();
115          engineChannels.erase(pEngineChannel);          engineChannels.erase(pEngineChannel);
116    
117            // Postpone the deletion of the specified EngineChannel if needed (bug #113)
118            LockedChannelsMutex.Lock();
119            if (lockedChannels.Contains(pEngineChannel)) {
120                lockedChannels.SetDestroyed(pEngineChannel);
121                pEngineChannel->SetSamplerChannel(NULL);
122                LockedChannelsMutex.Unlock();
123                return;
124            }
125            LockedChannelsMutex.Unlock();
126            ///////
127    
128          delete pEngineChannel;          delete pEngineChannel;
129      }      }
130    

Legend:
Removed from v.1825  
changed lines
  Added in v.1826

  ViewVC Help
Powered by ViewVC