/[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 351 by schoenebeck, Tue Jan 25 22:11:43 2005 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 166  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 209  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       * @param FileName   - file name of the Gigasampler instrument file
224       *  @param Instrument - index of the instrument in the .gig file       * @param Instrument - index of the instrument in the .gig file
225       *  @throws LinuxSamplerException  on error       * @see LoadInstrument()
      *  @returns          detailed description of the method call result  
226       */       */
227      void Engine::LoadInstrument(const char* FileName, uint Instrument) {      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         * @returns detailed description of the method call result
240         * @see PrepareLoadInstrument()
241         */
242        void Engine::LoadInstrument() {
243    
244          DisableAndLock();          DisableAndLock();
245    
# Line 228  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 266  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 352  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 662  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 736  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 746  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 1161  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 1174  namespace LinuxSampler { namespace gig { Line 1212  namespace LinuxSampler { namespace gig {
1212      }      }
1213    
1214      String Engine::Version() {      String Engine::Version() {
1215          String s = "$Revision: 1.21 $";          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.351  
changed lines
  Added in v.392

  ViewVC Help
Powered by ViewVC