/[svn]/linuxsampler/trunk/src/Sampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/Sampler.cpp

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

revision 203 by schoenebeck, Tue Jul 13 22:44:13 2004 UTC revision 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC
# Line 142  namespace LinuxSampler { Line 142  namespace LinuxSampler {
142      uint SamplerChannel::Index() {      uint SamplerChannel::Index() {
143          if (iIndex >= 0) return iIndex;          if (iIndex >= 0) return iIndex;
144    
145          std::vector<SamplerChannel*>::iterator iter = pSampler->vSamplerChannels.begin();          Sampler::SamplerChannelMap::iterator iter = pSampler->mSamplerChannels.begin();
146          for (int i = 0; iter != pSampler->vSamplerChannels.end(); i++, iter++) {          for (; iter != pSampler->mSamplerChannels.end(); iter++) {
147              if (*iter == this) {              if (iter->second == this) {
148                  iIndex = i;                  iIndex = iter->first;
149                  return i;                  return iIndex;
150              }              }
151          }          }
152    
153          throw LinuxSamplerException("SamplerChannel index not found");          throw LinuxSamplerException("Internal error: SamplerChannel index not found");
154      }      }
155    
156      MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) {      MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) {
# Line 169  namespace LinuxSampler { Line 169  namespace LinuxSampler {
169      Sampler::~Sampler() {      Sampler::~Sampler() {
170          // delete sampler channels          // delete sampler channels
171          {          {
172              std::vector<SamplerChannel*>::iterator iter = vSamplerChannels.begin();              SamplerChannelMap::iterator iter = mSamplerChannels.begin();
173              for (; iter != vSamplerChannels.end(); iter++) delete *iter;              for (; iter != mSamplerChannels.end(); iter++) delete iter->second;
174          }          }
175    
176          // delete midi input devices          // delete midi input devices
# Line 195  namespace LinuxSampler { Line 195  namespace LinuxSampler {
195      }      }
196    
197      uint Sampler::SamplerChannels() {      uint Sampler::SamplerChannels() {
198          return vSamplerChannels.size();          return mSamplerChannels.size();
199      }      }
200    
201      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
202            // if there's no sampler channel yet
203            if (!mSamplerChannels.size()) {
204                SamplerChannel* pChannel = new SamplerChannel(this);
205                mSamplerChannels[0] = pChannel;
206                return pChannel;
207            }
208    
209            // get the highest used sampler channel index
210            uint lastIndex = (--(mSamplerChannels.end()))->first;
211    
212            // check if we reached the index limit
213            if (lastIndex + 1 < lastIndex) {
214                // search for an unoccupied sampler channel index starting from 0
215                for (uint i = 0; i < lastIndex; i++) {
216                    if (mSamplerChannels.find(i) != mSamplerChannels.end()) continue;
217                    // we found an unused index, so insert the new channel there
218                    SamplerChannel* pChannel = new SamplerChannel(this);
219                    mSamplerChannels[i] = pChannel;
220                    return pChannel;
221                }
222                throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");
223            }
224    
225            // we have not reached the index limit so we just add the channel past the highest index
226          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
227          vSamplerChannels.push_back(pChannel);          mSamplerChannels[lastIndex + 1] = pChannel;
228          return pChannel;          return pChannel;
229      }      }
230    
231      SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) {      SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) {
232          if (uiSamplerChannel >= SamplerChannels()) return NULL;          return (mSamplerChannels.find(uiSamplerChannel) != mSamplerChannels.end()) ? mSamplerChannels[uiSamplerChannel] : NULL;
233          return vSamplerChannels[uiSamplerChannel];      }
234    
235        std::map<uint, SamplerChannel*> Sampler::GetSamplerChannels() {
236            return mSamplerChannels;
237      }      }
238    
239      void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) {      void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) {
240          std::vector<SamplerChannel*>::iterator iterChan = vSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
241          for (; iterChan != vSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
242              if (*iterChan == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
243                  vSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
244                  delete pSamplerChannel;                  delete pSamplerChannel;
245                  return;                  return;
246              }              }

Legend:
Removed from v.203  
changed lines
  Added in v.209

  ViewVC Help
Powered by ViewVC