/[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 900 by schoenebeck, Wed Jul 5 17:53:22 2006 UTC revision 1375 by schoenebeck, Wed Oct 3 18:41:09 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 27  Line 27 
27    
28  #include "engines/EngineFactory.h"  #include "engines/EngineFactory.h"
29  #include "engines/EngineChannelFactory.h"  #include "engines/EngineChannelFactory.h"
30    #include "plugins/InstrumentEditorFactory.h"
31  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
32  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
33  #include "network/lscpserver.h"  #include "drivers/midi/MidiInstrumentMapper.h"
34    
35  namespace LinuxSampler {  namespace LinuxSampler {
36    
# Line 66  namespace LinuxSampler { Line 67  namespace LinuxSampler {
67    
68      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
69          dmsg(2,("SamplerChannel: Assigning engine type..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
70            
71            if (pEngineChannel) {
72                if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) {
73                    dmsg(2,("OK\n"));
74                    return;
75                }
76            }
77    
78          // create new engine channel          // create new engine channel
79          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
# Line 103  namespace LinuxSampler { Line 111  namespace LinuxSampler {
111          this->iMidiPort        = 0;          this->iMidiPort        = 0;
112    
113          pEngineChannel->StatusChanged(true);          pEngineChannel->StatusChanged(true);
114            fireEngineChanged();
115          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
116      }      }
117    
118      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
119            if(pAudioOutputDevice == pDevice) return;
120    
121          // disconnect old device          // disconnect old device
122          if (pAudioOutputDevice && pEngineChannel) {          if (pAudioOutputDevice && pEngineChannel) {
123              Engine* engine = pEngineChannel->GetEngine();              Engine* engine = pEngineChannel->GetEngine();
# Line 202  namespace LinuxSampler { Line 212  namespace LinuxSampler {
212          throw Exception("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
213      }      }
214    
215        void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
216            llEngineChangeListeners.AddListener(l);
217        }
218    
219        void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) {
220           llEngineChangeListeners.RemoveListener(l);
221        }
222    
223        void SamplerChannel::RemoveAllEngineChangeListeners() {
224           llEngineChangeListeners.RemoveAllListeners();
225        }
226    
227        void SamplerChannel::fireEngineChanged() {
228            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
229                llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
230            }
231        }
232    
233      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
234          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
235          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
# Line 216  namespace LinuxSampler { Line 244  namespace LinuxSampler {
244      // * Sampler      // * Sampler
245    
246      Sampler::Sampler() {      Sampler::Sampler() {
247            eventHandler.SetSampler(this);
248      }      }
249    
250      Sampler::~Sampler() {      Sampler::~Sampler() {
# Line 226  namespace LinuxSampler { Line 255  namespace LinuxSampler {
255          return mSamplerChannels.size();          return mSamplerChannels.size();
256      }      }
257    
258        void Sampler::AddChannelCountListener(ChannelCountListener* l) {
259            llChannelCountListeners.AddListener(l);
260        }
261    
262        void Sampler::RemoveChannelCountListener(ChannelCountListener* l) {
263           llChannelCountListeners.RemoveListener(l);
264        }
265    
266        void Sampler::fireChannelCountChanged(int NewCount) {
267            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
268                llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount);
269            }
270        }
271    
272        void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
273            llAudioDeviceCountListeners.AddListener(l);
274        }
275    
276        void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) {
277            llAudioDeviceCountListeners.RemoveListener(l);
278        }
279    
280        void Sampler::fireAudioDeviceCountChanged(int NewCount) {
281            for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) {
282                llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount);
283            }
284        }
285    
286        void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) {
287            llMidiDeviceCountListeners.AddListener(l);
288        }
289    
290        void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) {
291            llMidiDeviceCountListeners.RemoveListener(l);
292        }
293    
294        void Sampler::fireMidiDeviceCountChanged(int NewCount) {
295            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
296                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount);
297            }
298        }
299    
300        void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
301            llVoiceCountListeners.AddListener(l);
302        }
303    
304        void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) {
305            llVoiceCountListeners.RemoveListener(l);
306        }
307    
308        void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) {
309            for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) {
310                llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount);
311            }
312        }
313    
314        void Sampler::AddStreamCountListener(StreamCountListener* l) {
315            llStreamCountListeners.AddListener(l);
316        }
317    
318        void Sampler::RemoveStreamCountListener(StreamCountListener* l) {
319            llStreamCountListeners.RemoveListener(l);
320        }
321    
322        void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) {
323            for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) {
324                llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount);
325            }
326        }
327    
328        void Sampler::AddBufferFillListener(BufferFillListener* l) {
329            llBufferFillListeners.AddListener(l);
330        }
331    
332        void Sampler::RemoveBufferFillListener(BufferFillListener* l) {
333            llBufferFillListeners.RemoveListener(l);
334        }
335    
336        void Sampler::fireBufferFillChanged(int ChannelId, String FillData) {
337            for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) {
338                llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData);
339            }
340        }
341    
342        void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
343            llTotalVoiceCountListeners.AddListener(l);
344        }
345    
346        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
347            llTotalVoiceCountListeners.RemoveListener(l);
348        }
349    
350        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
351            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
352                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
353            }
354        }
355    
356        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
357            llFxSendCountListeners.AddListener(l);
358        }
359    
360        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
361            llFxSendCountListeners.RemoveListener(l);
362        }
363    
364        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
365            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
366                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
367            }
368        }
369    
370        void Sampler::EventHandler::EngineChanged(int ChannelId) {
371            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
372            if(engineChannel == NULL) return;
373            engineChannel->AddFxSendCountListener(this);
374        }
375    
376        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
377            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
378        }
379    
380    
381      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
382          // if there's no sampler channel yet          // if there's no sampler channel yet
383          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
384              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
385              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
386              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelCountChanged(1);
387                pChannel->AddEngineChangeListener(&eventHandler);
388              return pChannel;              return pChannel;
389          }          }
390    
# Line 246  namespace LinuxSampler { Line 399  namespace LinuxSampler {
399                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
400                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
401                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
402                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelCountChanged(SamplerChannels());
403                    pChannel->AddEngineChangeListener(&eventHandler);
404                  return pChannel;                  return pChannel;
405              }              }
406              throw Exception("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
# Line 255  namespace LinuxSampler { Line 409  namespace LinuxSampler {
409          // we have not reached the index limit so we just add the channel past the highest index          // we have not reached the index limit so we just add the channel past the highest index
410          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
411          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
412          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelCountChanged(SamplerChannels());
413            pChannel->AddEngineChangeListener(&eventHandler);
414          return pChannel;          return pChannel;
415      }      }
416    
# Line 271  namespace LinuxSampler { Line 426  namespace LinuxSampler {
426          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
427          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
428              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
429                    pSamplerChannel->RemoveAllEngineChangeListeners();
430                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
431                  delete pSamplerChannel;                  delete pSamplerChannel;
432                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
433                  return;                  return;
434              }              }
435          }          }
# Line 309  namespace LinuxSampler { Line 465  namespace LinuxSampler {
465              }              }
466          }          }
467    
468            fireAudioDeviceCountChanged(AudioOutputDevices());
469          return pDevice;          return pDevice;
470      }      }
471    
# Line 345  namespace LinuxSampler { Line 502  namespace LinuxSampler {
502                  // destroy and free device from memory                  // destroy and free device from memory
503                  delete pDevice;                  delete pDevice;
504    
505                    fireAudioDeviceCountChanged(AudioOutputDevices());
506                  break;                  break;
507              }              }
508          }          }
# Line 367  namespace LinuxSampler { Line 525  namespace LinuxSampler {
525                  // destroy and free device from memory                  // destroy and free device from memory
526                  delete pDevice;                  delete pDevice;
527    
528                    fireMidiDeviceCountChanged(MidiInputDevices());
529                  break;                  break;
530              }              }
531          }          }
# Line 384  namespace LinuxSampler { Line 543  namespace LinuxSampler {
543                  }                  }
544          }          }
545    
546            fireMidiDeviceCountChanged(MidiInputDevices());
547          return pDevice;          return pDevice;
548      }      }
549    
# Line 437  namespace LinuxSampler { Line 597  namespace LinuxSampler {
597              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;
598              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
599          }          }
600    
601            // delete MIDI instrument maps
602            try {
603                MidiInstrumentMapper::RemoveAllMaps();
604            }
605            catch(...) {
606                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
607                exit(EXIT_FAILURE);
608            }
609    
610            // unload all instrument editor DLLs
611            InstrumentEditorFactory::ClosePlugins();
612      }      }
613    
614  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.900  
changed lines
  Added in v.1375

  ViewVC Help
Powered by ViewVC