/[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 1008 by schoenebeck, Wed Jan 3 17:49:44 2007 UTC revision 1212 by schoenebeck, Tue May 29 23:59:36 2007 UTC
# 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 "engines/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 "drivers/midi/MidiInstrumentMapper.h"  #include "drivers/midi/MidiInstrumentMapper.h"
 #include "network/lscpserver.h"  
34    
35  namespace LinuxSampler {  namespace LinuxSampler {
36    
# Line 104  namespace LinuxSampler { Line 104  namespace LinuxSampler {
104          this->iMidiPort        = 0;          this->iMidiPort        = 0;
105    
106          pEngineChannel->StatusChanged(true);          pEngineChannel->StatusChanged(true);
107            fireEngineChanged();
108          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
109      }      }
110    
# Line 205  namespace LinuxSampler { Line 205  namespace LinuxSampler {
205          throw Exception("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
206      }      }
207    
208        void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
209            llEngineChangeListeners.AddListener(l);
210        }
211    
212        void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) {
213           llEngineChangeListeners.RemoveListener(l);
214        }
215    
216        void SamplerChannel::RemoveAllEngineChangeListeners() {
217           llEngineChangeListeners.RemoveAllListeners();
218        }
219    
220        void SamplerChannel::fireEngineChanged() {
221            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
222                llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
223            }
224        }
225    
226      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
227          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
228          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
# Line 219  namespace LinuxSampler { Line 237  namespace LinuxSampler {
237      // * Sampler      // * Sampler
238    
239      Sampler::Sampler() {      Sampler::Sampler() {
240            eventHandler.SetSampler(this);
241      }      }
242    
243      Sampler::~Sampler() {      Sampler::~Sampler() {
# Line 229  namespace LinuxSampler { Line 248  namespace LinuxSampler {
248          return mSamplerChannels.size();          return mSamplerChannels.size();
249      }      }
250    
251        void Sampler::AddChannelCountListener(ChannelCountListener* l) {
252            llChannelCountListeners.AddListener(l);
253        }
254    
255        void Sampler::RemoveChannelCountListener(ChannelCountListener* l) {
256           llChannelCountListeners.RemoveListener(l);
257        }
258    
259        void Sampler::fireChannelCountChanged(int NewCount) {
260            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
261                llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount);
262            }
263        }
264    
265        void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
266            llAudioDeviceCountListeners.AddListener(l);
267        }
268    
269        void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) {
270            llAudioDeviceCountListeners.RemoveListener(l);
271        }
272    
273        void Sampler::fireAudioDeviceCountChanged(int NewCount) {
274            for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) {
275                llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount);
276            }
277        }
278    
279        void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) {
280            llMidiDeviceCountListeners.AddListener(l);
281        }
282    
283        void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) {
284            llMidiDeviceCountListeners.RemoveListener(l);
285        }
286    
287        void Sampler::fireMidiDeviceCountChanged(int NewCount) {
288            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
289                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount);
290            }
291        }
292    
293        void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
294            llVoiceCountListeners.AddListener(l);
295        }
296    
297        void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) {
298            llVoiceCountListeners.RemoveListener(l);
299        }
300    
301        void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) {
302            for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) {
303                llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount);
304            }
305        }
306    
307        void Sampler::AddStreamCountListener(StreamCountListener* l) {
308            llStreamCountListeners.AddListener(l);
309        }
310    
311        void Sampler::RemoveStreamCountListener(StreamCountListener* l) {
312            llStreamCountListeners.RemoveListener(l);
313        }
314    
315        void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) {
316            for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) {
317                llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount);
318            }
319        }
320    
321        void Sampler::AddBufferFillListener(BufferFillListener* l) {
322            llBufferFillListeners.AddListener(l);
323        }
324    
325        void Sampler::RemoveBufferFillListener(BufferFillListener* l) {
326            llBufferFillListeners.RemoveListener(l);
327        }
328    
329        void Sampler::fireBufferFillChanged(int ChannelId, String FillData) {
330            for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) {
331                llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData);
332            }
333        }
334    
335        void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
336            llTotalVoiceCountListeners.AddListener(l);
337        }
338    
339        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
340            llTotalVoiceCountListeners.RemoveListener(l);
341        }
342    
343        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
344            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
345                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
346            }
347        }
348    
349        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
350            llFxSendCountListeners.AddListener(l);
351        }
352    
353        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
354            llFxSendCountListeners.RemoveListener(l);
355        }
356    
357        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
358            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
359                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
360            }
361        }
362    
363        void Sampler::EventHandler::EngineChanged(int ChannelId) {
364            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
365            if(engineChannel == NULL) return;
366            engineChannel->AddFxSendCountListener(this);
367        }
368    
369        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
370            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
371        }
372    
373    
374      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
375          // if there's no sampler channel yet          // if there's no sampler channel yet
376          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
377              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
378              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
379              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelCountChanged(1);
380                pChannel->AddEngineChangeListener(&eventHandler);
381              return pChannel;              return pChannel;
382          }          }
383    
# Line 249  namespace LinuxSampler { Line 392  namespace LinuxSampler {
392                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
393                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
394                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
395                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelCountChanged(SamplerChannels());
396                    pChannel->AddEngineChangeListener(&eventHandler);
397                  return pChannel;                  return pChannel;
398              }              }
399              throw Exception("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
# Line 258  namespace LinuxSampler { Line 402  namespace LinuxSampler {
402          // 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
403          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
404          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
405          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelCountChanged(SamplerChannels());
406            pChannel->AddEngineChangeListener(&eventHandler);
407          return pChannel;          return pChannel;
408      }      }
409    
# Line 274  namespace LinuxSampler { Line 419  namespace LinuxSampler {
419          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
420          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
421              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
422                    pSamplerChannel->RemoveAllEngineChangeListeners();
423                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
424                  delete pSamplerChannel;                  delete pSamplerChannel;
425                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
426                  return;                  return;
427              }              }
428          }          }
# Line 312  namespace LinuxSampler { Line 458  namespace LinuxSampler {
458              }              }
459          }          }
460    
461          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));          fireAudioDeviceCountChanged(AudioOutputDevices());
462          return pDevice;          return pDevice;
463      }      }
464    
# Line 349  namespace LinuxSampler { Line 495  namespace LinuxSampler {
495                  // destroy and free device from memory                  // destroy and free device from memory
496                  delete pDevice;                  delete pDevice;
497    
498                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));                  fireAudioDeviceCountChanged(AudioOutputDevices());
499                  break;                  break;
500              }              }
501          }          }
# Line 372  namespace LinuxSampler { Line 518  namespace LinuxSampler {
518                  // destroy and free device from memory                  // destroy and free device from memory
519                  delete pDevice;                  delete pDevice;
520    
521                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));                  fireMidiDeviceCountChanged(MidiInputDevices());
522                  break;                  break;
523              }              }
524          }          }
# Line 390  namespace LinuxSampler { Line 536  namespace LinuxSampler {
536                  }                  }
537          }          }
538    
539          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));          fireMidiDeviceCountChanged(MidiInputDevices());
540          return pDevice;          return pDevice;
541      }      }
542    
# Line 453  namespace LinuxSampler { Line 599  namespace LinuxSampler {
599              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
600              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
601          }          }
602    
603            // unload all instrument editor DLLs
604            InstrumentEditorFactory::ClosePlugins();
605      }      }
606    
607  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1008  
changed lines
  Added in v.1212

  ViewVC Help
Powered by ViewVC