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

Diff of /linuxsampler/trunk/src/engines/gig/Engine.cpp

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

revision 319 by schoenebeck, Mon Dec 13 00:46:42 2004 UTC revision 392 by schoenebeck, Sat Feb 19 02:40:24 2005 UTC
# Line 26  Line 26 
26  #include "EGADSR.h"  #include "EGADSR.h"
27    
28  #include "Engine.h"  #include "Engine.h"
29  #include <malloc.h>  
30    #if defined(__APPLE__)
31    # include <stdlib.h>
32    #else
33    # include <malloc.h>
34    #endif
35    
36  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
37    
# Line 77  namespace LinuxSampler { namespace gig { Line 82  namespace LinuxSampler { namespace gig {
82    
83      Engine::~Engine() {      Engine::~Engine() {
84          if (pDiskThread) {          if (pDiskThread) {
85                dmsg(1,("Stopping disk thread..."));
86              pDiskThread->StopThread();              pDiskThread->StopThread();
87              delete pDiskThread;              delete pDiskThread;
88                dmsg(1,("OK\n"));
89          }          }
90    
91            if (pInstrument) Instruments.HandBack(pInstrument, this);
92    
93          if (pGig)  delete pGig;          if (pGig)  delete pGig;
94          if (pRIFF) delete pRIFF;          if (pRIFF) delete pRIFF;
95          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
# Line 89  namespace LinuxSampler { namespace gig { Line 99  namespace LinuxSampler { namespace gig {
99          for (uint i = 0; i < Event::destination_count; i++) {          for (uint i = 0; i < Event::destination_count; i++) {
100              if (pSynthesisEvents[i]) delete pSynthesisEvents[i];              if (pSynthesisEvents[i]) delete pSynthesisEvents[i];
101          }          }
         delete[] pSynthesisEvents;  
102          if (pEvents)     delete pEvents;          if (pEvents)     delete pEvents;
103          if (pCCEvents)   delete pCCEvents;          if (pCCEvents)   delete pCCEvents;
104          if (pEventQueue) delete pEventQueue;          if (pEventQueue) delete pEventQueue;
105          if (pEventPool)  delete pEventPool;          if (pEventPool)  delete pEventPool;
106          if (pVoicePool)  delete pVoicePool;          if (pVoicePool) {
107                    pVoicePool->clear();
108                    delete pVoicePool;
109            }
110          if (pActiveKeys) delete pActiveKeys;          if (pActiveKeys) delete pActiveKeys;
111          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
112          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
# Line 159  namespace LinuxSampler { namespace gig { Line 171  namespace LinuxSampler { namespace gig {
171          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
172          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
173          GlobalVolume        = 1.0;          GlobalVolume        = 1.0;
174            CurrentKeyDimension = 0;
175    
176          // reset voice stealing parameters          // reset voice stealing parameters
177          itLastStolenVoice = RTList<Voice>::Iterator();          itLastStolenVoice = RTList<Voice>::Iterator();
# Line 202  namespace LinuxSampler { namespace gig { Line 215  namespace LinuxSampler { namespace gig {
215      }      }
216    
217      /**      /**
218       *  Load an instrument from a .gig file.       * More or less a workaround to set the instrument name, index and load
219         * status variable to zero percent immediately, that is without blocking
220         * the calling thread. It might be used in future for other preparations
221         * as well though.
222         *
223         * @param FileName   - file name of the Gigasampler instrument file
224         * @param Instrument - index of the instrument in the .gig file
225         * @see LoadInstrument()
226         */
227        void Engine::PrepareLoadInstrument(const char* FileName, uint Instrument) {
228            InstrumentFile = FileName;
229            InstrumentIdx  = Instrument;
230            InstrumentStat = 0;
231        }
232    
233        /**
234         * Load an instrument from a .gig file. PrepareLoadInstrument() has to
235         * be called first to provide the information which instrument to load.
236         * This method will then actually start to load the instrument and block
237         * the calling thread until loading was completed.
238       *       *
239       *  @param FileName   - file name of the Gigasampler instrument file       * @returns detailed description of the method call result
240       *  @param Instrument - index of the instrument in the .gig file       * @see PrepareLoadInstrument()
      *  @throws LinuxSamplerException  on error  
      *  @returns          detailed description of the method call result  
241       */       */
242      void Engine::LoadInstrument(const char* FileName, uint Instrument) {      void Engine::LoadInstrument() {
243    
244          DisableAndLock();          DisableAndLock();
245    
# Line 221  namespace LinuxSampler { namespace gig { Line 251  namespace LinuxSampler { namespace gig {
251              Instruments.HandBack(pInstrument, this);              Instruments.HandBack(pInstrument, this);
252          }          }
253    
         InstrumentFile = FileName;  
         InstrumentIdx = Instrument;  
         InstrumentStat = 0;  
   
254          // delete all key groups          // delete all key groups
255          ActiveKeyGroups.clear();          ActiveKeyGroups.clear();
256    
257          // request gig instrument from instrument manager          // request gig instrument from instrument manager
258          try {          try {
259              instrument_id_t instrid;              instrument_id_t instrid;
260              instrid.FileName    = FileName;              instrid.FileName    = InstrumentFile;
261              instrid.iInstrument = Instrument;              instrid.iInstrument = InstrumentIdx;
262              pInstrument = Instruments.Borrow(instrid, this);              pInstrument = Instruments.Borrow(instrid, this);
263              if (!pInstrument) {              if (!pInstrument) {
264                  InstrumentStat = -1;                  InstrumentStat = -1;
# Line 259  namespace LinuxSampler { namespace gig { Line 285  namespace LinuxSampler { namespace gig {
285          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())
286              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;
287    
288            InstrumentIdxName = pInstrument->pInfo->Name;
289          InstrumentStat = 100;          InstrumentStat = 100;
290    
291          // inform audio driver for the need of two channels          // inform audio driver for the need of two channels
# Line 322  namespace LinuxSampler { namespace gig { Line 349  namespace LinuxSampler { namespace gig {
349    
350          // (re)create disk thread          // (re)create disk thread
351          if (this->pDiskThread) {          if (this->pDiskThread) {
352                dmsg(1,("Stopping disk thread..."));
353              this->pDiskThread->StopThread();              this->pDiskThread->StopThread();
354              delete this->pDiskThread;              delete this->pDiskThread;
355                dmsg(1,("OK\n"));
356          }          }
357          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo
358          if (!pDiskThread) {          if (!pDiskThread) {
# Line 343  namespace LinuxSampler { namespace gig { Line 372  namespace LinuxSampler { namespace gig {
372    
373          // (re)allocate synthesis parameter matrix          // (re)allocate synthesis parameter matrix
374          if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);          if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);
375    
376            #if defined(__APPLE__)
377            pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle());
378            #else
379          pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));          pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));
380            #endif
381          for (int dst = 1; dst < Event::destination_count; dst++)          for (int dst = 1; dst < Event::destination_count; dst++)
382              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();
383    
# Line 653  namespace LinuxSampler { namespace gig { Line 687  namespace LinuxSampler { namespace gig {
687       *  @param itNoteOnEvent - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
688       */       */
689      void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) {      void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) {
690          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];  
691            const int key = itNoteOnEvent->Param.Note.Key;
692    
693            // Change key dimension value if key is in keyswitching area
694            if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
695                CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /
696                    (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
697    
698            midi_key_info_t* pKey = &pMIDIKeyInfo[key];
699    
700          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
701    
# Line 727  namespace LinuxSampler { namespace gig { Line 769  namespace LinuxSampler { namespace gig {
769       *                               when there is no free voice       *                               when there is no free voice
770       *                               (optional, default = true)       *                               (optional, default = true)
771       *  @returns pointer to new voice or NULL if there was no free voice or       *  @returns pointer to new voice or NULL if there was no free voice or
772       *           if an error occured while trying to trigger the new voice       *           if the voice wasn't triggered (for example when no region is
773         *           defined for the given key).
774       */       */
775      Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {      Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {
776          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];
# Line 737  namespace LinuxSampler { namespace gig { Line 780  namespace LinuxSampler { namespace gig {
780          if (itNewVoice) {          if (itNewVoice) {
781              // launch the new voice              // launch the new voice
782              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {
783                  dmsg(1,("Triggering new voice failed!\n"));                  dmsg(4,("Voice not triggered\n"));
784                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
785              }              }
786              else { // on success              else { // on success
# Line 1152  namespace LinuxSampler { namespace gig { Line 1195  namespace LinuxSampler { namespace gig {
1195          return InstrumentFile;          return InstrumentFile;
1196      }      }
1197    
1198        String Engine::InstrumentName() {
1199            return InstrumentIdxName;
1200        }
1201    
1202      int Engine::InstrumentIndex() {      int Engine::InstrumentIndex() {
1203          return InstrumentIdx;          return InstrumentIdx;
1204      }      }
# Line 1165  namespace LinuxSampler { namespace gig { Line 1212  namespace LinuxSampler { namespace gig {
1212      }      }
1213    
1214      String Engine::Version() {      String Engine::Version() {
1215          String s = "$Revision: 1.19 $";          String s = "$Revision: 1.25 $";
1216          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
1217      }      }
1218    

Legend:
Removed from v.319  
changed lines
  Added in v.392

  ViewVC Help
Powered by ViewVC