linuxsampler 1.0.0
|
00001 /*************************************************************************** 00002 * * 00003 * LinuxSampler - modular, streaming capable sampler * 00004 * * 00005 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * 00006 * Copyright (C) 2005 - 2009 Christian Schoenebeck * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00021 * MA 02111-1307 USA * 00022 ***************************************************************************/ 00023 00024 #ifndef __LS_SAMPLER_H__ 00025 #define __LS_SAMPLER_H__ 00026 00027 #include <vector> 00028 #include <map> 00029 #include "EventListeners.h" 00030 #include "common/global.h" 00031 #include "common/Exception.h" 00032 #include "engines/EngineChannel.h" 00033 #include "drivers/midi/MidiInputDevice.h" 00034 #include "drivers/audio/AudioOutputDevice.h" 00035 00036 namespace LinuxSampler { 00037 00038 // just symbol prototyping 00039 class Sampler; 00040 00049 class SamplerChannel { 00050 public: 00058 void SetEngineType(String EngineType) throw (Exception); 00059 00072 void SetAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception); 00073 00084 void SetMidiInputDevice(MidiInputDevice *pDevice) throw (Exception); 00085 00095 void SetMidiInputPort(int MidiPort) throw (Exception); 00096 00105 void SetMidiInputChannel(midi_chan_t MidiChannel); 00106 00120 void SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel = midi_chan_all) throw (Exception); 00121 00128 EngineChannel* GetEngineChannel(); 00129 00137 midi_chan_t GetMidiInputChannel(); 00138 00145 int GetMidiInputPort(); 00146 00154 AudioOutputDevice* GetAudioOutputDevice(); 00155 00163 MidiInputDevice* GetMidiInputDevice(); 00164 00169 uint Index(); 00170 00172 Sampler* GetSampler(); 00173 00175 // Event Listener methods 00176 00181 void AddEngineChangeListener(EngineChangeListener* l); 00182 00186 void RemoveEngineChangeListener(EngineChangeListener* l); 00187 00191 void RemoveAllEngineChangeListeners(); 00192 00197 void fireEngineToBeChanged(); 00198 00203 void fireEngineChanged(); 00204 00205 00206 protected: 00207 SamplerChannel(Sampler* pS); 00208 virtual ~SamplerChannel(); 00209 00211 MidiInputPort* __GetMidiInputDevicePort(int iMidiPort); 00212 00213 Sampler* pSampler; 00214 EngineChannel* pEngineChannel; 00215 AudioOutputDevice* pAudioOutputDevice; 00216 MidiInputDevice* pMidiInputDevice; 00217 int iIndex; 00218 00219 friend class Sampler; 00220 private: 00221 int iMidiPort; 00222 midi_chan_t midiChannel; 00223 ListenerList<EngineChangeListener*> llEngineChangeListeners; 00224 }; 00225 00281 class Sampler { 00282 public: 00286 Sampler(); 00287 00291 virtual ~Sampler(); 00292 00296 uint SamplerChannels(); 00297 00307 SamplerChannel* AddSamplerChannel(); 00308 00315 SamplerChannel* GetSamplerChannel(uint uiSamplerChannel); 00316 00320 std::map<uint, SamplerChannel*> GetSamplerChannels(); 00321 00328 void RemoveSamplerChannel(SamplerChannel* pSamplerChannel); 00329 00337 void RemoveSamplerChannel(uint uiSamplerChannel); 00338 00343 void RemoveAllSamplerChannels(); 00344 00348 std::vector<String> AvailableAudioOutputDrivers(); 00349 00353 std::vector<String> AvailableMidiInputDrivers(); 00354 00359 std::vector<String> AvailableEngineTypes(); 00360 00370 AudioOutputDevice* CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception); 00371 00381 MidiInputDevice* CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception); 00382 00386 uint AudioOutputDevices(); 00387 00391 uint MidiInputDevices(); 00392 00396 std::map<uint, AudioOutputDevice*> GetAudioOutputDevices(); 00397 00401 std::map<uint, MidiInputDevice*> GetMidiInputDevices(); 00402 00410 void DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception); 00411 00423 void DestroyAllAudioOutputDevices() throw (Exception); 00424 00432 void DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception); 00433 00445 void DestroyAllMidiInputDevices() throw (Exception); 00446 00451 int GetDiskStreamCount(); 00452 00457 int GetVoiceCount(); 00458 00463 void Reset(); 00464 00466 // Event Listener methods 00467 00472 void AddChannelCountListener(ChannelCountListener* l); 00473 00477 void RemoveChannelCountListener(ChannelCountListener* l); 00478 00483 void AddAudioDeviceCountListener(AudioDeviceCountListener* l); 00484 00488 void RemoveAudioDeviceCountListener(AudioDeviceCountListener* l); 00489 00494 void AddMidiDeviceCountListener(MidiDeviceCountListener* l); 00495 00499 void RemoveMidiDeviceCountListener(MidiDeviceCountListener* l); 00500 00505 void AddVoiceCountListener(VoiceCountListener* l); 00506 00510 void RemoveVoiceCountListener(VoiceCountListener* l); 00511 00518 void fireVoiceCountChanged(int ChannelId, int NewCount); 00519 00524 void AddStreamCountListener(StreamCountListener* l); 00525 00529 void RemoveStreamCountListener(StreamCountListener* l); 00530 00537 void fireStreamCountChanged(int ChannelId, int NewCount); 00538 00544 void AddBufferFillListener(BufferFillListener* l); 00545 00549 void RemoveBufferFillListener(BufferFillListener* l); 00550 00557 void fireBufferFillChanged(int ChannelId, String FillData); 00558 00563 void AddTotalVoiceCountListener(TotalVoiceCountListener* l); 00564 00568 void RemoveTotalVoiceCountListener(TotalVoiceCountListener* l); 00569 00574 void fireTotalVoiceCountChanged(int NewCount); 00575 00580 void AddTotalStreamCountListener(TotalStreamCountListener* l); 00581 00585 void RemoveTotalStreamCountListener(TotalStreamCountListener* l); 00586 00591 void fireTotalStreamCountChanged(int NewCount); 00592 00597 void AddFxSendCountListener(FxSendCountListener* l); 00598 00602 void RemoveFxSendCountListener(FxSendCountListener* l); 00603 00609 void fireStatistics(); 00610 00612 // system specific methods 00613 00621 static bool EnableDenormalsAreZeroMode(); 00622 00623 #if defined(WIN32) 00624 00629 static String GetInstallDir(); 00630 #endif 00631 protected: 00636 void fireChannelCountChanged(int NewCount); 00637 00643 void fireChannelAdded(SamplerChannel* pChannel); 00644 00650 void fireChannelToBeRemoved(SamplerChannel* pChannel); 00651 00656 void fireAudioDeviceCountChanged(int NewCount); 00657 00662 void fireMidiDeviceCountChanged(int NewCount); 00663 00669 void fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice); 00670 00676 void fireMidiDeviceCreated(MidiInputDevice* pDevice); 00677 00684 void fireFxSendCountChanged(int ChannelId, int NewCount); 00685 00686 typedef std::map<uint, SamplerChannel*> SamplerChannelMap; 00687 00688 SamplerChannelMap mSamplerChannels; 00689 00690 // statistics cache 00691 uint uiOldTotalVoiceCount; 00692 uint uiOldTotalStreamCount; 00693 std::map<uint, uint> mOldVoiceCounts; 00694 std::map<uint, uint> mOldStreamCounts; 00695 00696 friend class SamplerChannel; 00697 00698 private: 00699 ListenerList<ChannelCountListener*> llChannelCountListeners; 00700 ListenerList<AudioDeviceCountListener*> llAudioDeviceCountListeners; 00701 ListenerList<MidiDeviceCountListener*> llMidiDeviceCountListeners; 00702 ListenerList<VoiceCountListener*> llVoiceCountListeners; 00703 ListenerList<StreamCountListener*> llStreamCountListeners; 00704 ListenerList<BufferFillListener*> llBufferFillListeners; 00705 ListenerList<TotalStreamCountListener*> llTotalStreamCountListeners; 00706 ListenerList<TotalVoiceCountListener*> llTotalVoiceCountListeners; 00707 ListenerList<FxSendCountListener*> llFxSendCountListeners; 00708 00709 class EventHandler : public EngineChangeListener, public FxSendCountListener { 00710 public: 00711 void SetSampler(Sampler* pSampler) { this->pSampler = pSampler; } 00712 00718 virtual void EngineToBeChanged(int ChannelId); 00719 00726 virtual void EngineChanged(int ChannelId); 00727 00734 virtual void FxSendCountChanged(int ChannelId, int NewCount); 00735 00736 private: 00737 Sampler* pSampler; 00738 } eventHandler; 00739 }; 00740 } 00741 00742 #endif // __LS_SAMPLER_H__