/[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 738 by schoenebeck, Tue Aug 16 17:14:25 2005 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 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program 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  *
# Line 24  Line 25 
25  #include "DiskThread.h"  #include "DiskThread.h"
26  #include "Voice.h"  #include "Voice.h"
27  #include "EGADSR.h"  #include "EGADSR.h"
28    #include "../EngineFactory.h"
29    
30  #include "Engine.h"  #include "Engine.h"
 #include <malloc.h>  
31    
32  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
33    
34      InstrumentResourceManager Engine::Instruments;      InstrumentResourceManager Engine::instruments;
35    
36        std::map<AudioOutputDevice*,Engine*> Engine::engines;
37    
38        /**
39         * Get a gig::Engine object for the given gig::EngineChannel and the
40         * given AudioOutputDevice. All engine channels which are connected to
41         * the same audio output device will use the same engine instance. This
42         * method will be called by a gig::EngineChannel whenever it's
43         * connecting to a audio output device.
44         *
45         * @param pChannel - engine channel which acquires an engine object
46         * @param pDevice  - the audio output device \a pChannel is connected to
47         */
48        Engine* Engine::AcquireEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice) {
49            Engine* pEngine = NULL;
50            // check if there's already an engine for the given audio output device
51            if (engines.count(pDevice)) {
52                dmsg(4,("Using existing gig::Engine.\n"));
53                pEngine = engines[pDevice];
54            } else { // create a new engine (and disk thread) instance for the given audio output device
55                dmsg(4,("Creating new gig::Engine.\n"));
56                pEngine = (Engine*) EngineFactory::Create("gig");
57                pEngine->Connect(pDevice);
58                engines[pDevice] = pEngine;
59            }
60            // register engine channel to the engine instance
61            pEngine->engineChannels.add(pChannel);
62            // remember index in the ArrayList
63            pChannel->iEngineIndexSelf = pEngine->engineChannels.size() - 1;
64            dmsg(4,("This gig::Engine has now %d EngineChannels.\n",pEngine->engineChannels.size()));
65            return pEngine;
66        }
67    
68        /**
69         * Once an engine channel is disconnected from an audio output device,
70         * it wil immediately call this method to unregister itself from the
71         * engine instance and if that engine instance is not used by any other
72         * engine channel anymore, then that engine instance will be destroyed.
73         *
74         * @param pChannel - engine channel which wants to disconnect from it's
75         *                   engine instance
76         * @param pDevice  - audio output device \a pChannel was connected to
77         */
78        void Engine::FreeEngine(LinuxSampler::gig::EngineChannel* pChannel, AudioOutputDevice* pDevice) {
79            dmsg(4,("Disconnecting EngineChannel from gig::Engine.\n"));
80            Engine* pEngine = engines[pDevice];
81            // unregister EngineChannel from the Engine instance
82            pEngine->engineChannels.remove(pChannel);
83            // if the used Engine instance is not used anymore, then destroy it
84            if (pEngine->engineChannels.empty()) {
85                pDevice->Disconnect(pEngine);
86                engines.erase(pDevice);
87                delete pEngine;
88                dmsg(4,("Destroying gig::Engine.\n"));
89            }
90            else dmsg(4,("This gig::Engine has now %d EngineChannels.\n",pEngine->engineChannels.size()));
91        }
92    
93        /**
94         * Constructor
95         */
96      Engine::Engine() {      Engine::Engine() {
         pRIFF              = NULL;  
         pGig               = NULL;  
         pInstrument        = NULL;  
97          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
98          pDiskThread        = NULL;          pDiskThread        = NULL;
99          pEventGenerator    = NULL;          pEventGenerator    = NULL;
100          pSysexBuffer       = new RingBuffer<uint8_t>(SYSEX_BUFFER_SIZE, 0);          pSysexBuffer       = new RingBuffer<uint8_t>(CONFIG_SYSEX_BUFFER_SIZE, 0);
101          pEventQueue        = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0);          pEventQueue        = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);
102          pEventPool         = new Pool<Event>(MAX_EVENTS_PER_FRAGMENT);          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);
103          pVoicePool         = new Pool<Voice>(MAX_AUDIO_VOICES);          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);
         pActiveKeys        = new Pool<uint>(128);  
104          pVoiceStealingQueue = new RTList<Event>(pEventPool);          pVoiceStealingQueue = new RTList<Event>(pEventPool);
105          pEvents            = new RTList<Event>(pEventPool);          pGlobalEvents      = new RTList<Event>(pEventPool);
         pCCEvents          = new RTList<Event>(pEventPool);  
         for (uint i = 0; i < Event::destination_count; i++) {  
             pSynthesisEvents[i] = new RTList<Event>(pEventPool);  
         }  
         for (uint i = 0; i < 128; i++) {  
             pMIDIKeyInfo[i].pActiveVoices  = new RTList<Voice>(pVoicePool);  
             pMIDIKeyInfo[i].KeyPressed     = false;  
             pMIDIKeyInfo[i].Active         = false;  
             pMIDIKeyInfo[i].ReleaseTrigger = false;  
             pMIDIKeyInfo[i].pEvents        = new RTList<Event>(pEventPool);  
         }  
106          for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {          for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
107              iterVoice->SetEngine(this);              iterVoice->SetEngine(this);
108          }          }
109          pVoicePool->clear();          pVoicePool->clear();
110    
         pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected  
         pBasicFilterParameters  = NULL;  
         pMainFilterParameters   = NULL;  
   
         InstrumentIdx = -1;  
         InstrumentStat = -1;  
   
         AudioDeviceChannelLeft  = -1;  
         AudioDeviceChannelRight = -1;  
   
111          ResetInternal();          ResetInternal();
112            ResetScaleTuning();
113      }      }
114    
115        /**
116         * Destructor
117         */
118      Engine::~Engine() {      Engine::~Engine() {
119          if (pDiskThread) {          if (pDiskThread) {
120                dmsg(1,("Stopping disk thread..."));
121              pDiskThread->StopThread();              pDiskThread->StopThread();
122              delete pDiskThread;              delete pDiskThread;
123                dmsg(1,("OK\n"));
124          }          }
         if (pGig)  delete pGig;  
         if (pRIFF) delete pRIFF;  
         for (uint i = 0; i < 128; i++) {  
             if (pMIDIKeyInfo[i].pActiveVoices) delete pMIDIKeyInfo[i].pActiveVoices;  
             if (pMIDIKeyInfo[i].pEvents)       delete pMIDIKeyInfo[i].pEvents;  
         }  
         for (uint i = 0; i < Event::destination_count; i++) {  
             if (pSynthesisEvents[i]) delete pSynthesisEvents[i];  
         }  
         delete[] pSynthesisEvents;  
         if (pEvents)     delete pEvents;  
         if (pCCEvents)   delete pCCEvents;  
125          if (pEventQueue) delete pEventQueue;          if (pEventQueue) delete pEventQueue;
126          if (pEventPool)  delete pEventPool;          if (pEventPool)  delete pEventPool;
127          if (pVoicePool)  delete pVoicePool;          if (pVoicePool) {
128          if (pActiveKeys) delete pActiveKeys;              pVoicePool->clear();
129          if (pSysexBuffer) delete pSysexBuffer;              delete pVoicePool;
130            }
131          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
         if (pMainFilterParameters) delete[] pMainFilterParameters;  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
132          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
133            if (pSysexBuffer) delete pSysexBuffer;
134            EngineFactory::Destroy(this);
135      }      }
136    
137      void Engine::Enable() {      void Engine::Enable() {
# Line 128  namespace LinuxSampler { namespace gig { Line 158  namespace LinuxSampler { namespace gig {
158       */       */
159      void Engine::Reset() {      void Engine::Reset() {
160          DisableAndLock();          DisableAndLock();
   
         //if (pAudioOutputDevice->IsPlaying()) { // if already running  
             /*  
             // signal audio thread not to enter render part anymore  
             SuspensionRequested = true;  
             // sleep until wakened by audio thread  
             pthread_mutex_lock(&__render_state_mutex);  
             pthread_cond_wait(&__render_exit_condition, &__render_state_mutex);  
             pthread_mutex_unlock(&__render_state_mutex);  
             */  
         //}  
   
         //if (wasplaying) pAudioOutputDevice->Stop();  
   
161          ResetInternal();          ResetInternal();
162            ResetScaleTuning();
         // signal audio thread to continue with rendering  
         //SuspensionRequested = false;  
163          Enable();          Enable();
164      }      }
165    
# Line 154  namespace LinuxSampler { namespace gig { Line 168  namespace LinuxSampler { namespace gig {
168       *  control and status variables. This method is not thread safe!       *  control and status variables. This method is not thread safe!
169       */       */
170      void Engine::ResetInternal() {      void Engine::ResetInternal() {
         Pitch               = 0;  
         SustainPedal        = false;  
171          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
172          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
         GlobalVolume        = 1.0;  
173    
174          // reset voice stealing parameters          // reset voice stealing parameters
         itLastStolenVoice = RTList<Voice>::Iterator();  
         iuiLastStolenKey  = RTList<uint>::Iterator();  
175          pVoiceStealingQueue->clear();          pVoiceStealingQueue->clear();
176            itLastStolenVoice          = RTList<Voice>::Iterator();
177          // reset to normal chromatic scale (means equal temper)          itLastStolenVoiceGlobally  = RTList<Voice>::Iterator();
178          memset(&ScaleTuning[0], 0x00, 12);          iuiLastStolenKey           = RTList<uint>::Iterator();
179            iuiLastStolenKeyGlobally   = RTList<uint>::Iterator();
180          // set all MIDI controller values to zero          pLastStolenChannel         = NULL;
         memset(ControllerTable, 0x00, 128);  
   
         // reset key info  
         for (uint i = 0; i < 128; i++) {  
             pMIDIKeyInfo[i].pActiveVoices->clear();  
             pMIDIKeyInfo[i].pEvents->clear();  
             pMIDIKeyInfo[i].KeyPressed     = false;  
             pMIDIKeyInfo[i].Active         = false;  
             pMIDIKeyInfo[i].ReleaseTrigger = false;  
             pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();  
         }  
   
         // reset all key groups  
         map<uint,uint*>::iterator iter = ActiveKeyGroups.begin();  
         for (; iter != ActiveKeyGroups.end(); iter++) iter->second = NULL;  
181    
182          // reset all voices          // reset all voices
183          for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {          for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
# Line 191  namespace LinuxSampler { namespace gig { Line 185  namespace LinuxSampler { namespace gig {
185          }          }
186          pVoicePool->clear();          pVoicePool->clear();
187    
         // free all active keys  
         pActiveKeys->clear();  
   
188          // reset disk thread          // reset disk thread
189          if (pDiskThread) pDiskThread->Reset();          if (pDiskThread) pDiskThread->Reset();
190    
# Line 202  namespace LinuxSampler { namespace gig { Line 193  namespace LinuxSampler { namespace gig {
193      }      }
194    
195      /**      /**
196       *  Load an instrument from a .gig file.       * Reset to normal, chromatic scale (means equal tempered).
      *  
      *  @param FileName   - file name of the Gigasampler instrument file  
      *  @param Instrument - index of the instrument in the .gig file  
      *  @throws LinuxSamplerException  on error  
      *  @returns          detailed description of the method call result  
      */  
     void Engine::LoadInstrument(const char* FileName, uint Instrument) {  
   
         DisableAndLock();  
   
         ResetInternal(); // reset engine  
   
         // free old instrument  
         if (pInstrument) {  
             // give old instrument back to instrument manager  
             Instruments.HandBack(pInstrument, this);  
         }  
   
         InstrumentFile = FileName;  
         InstrumentIdx = Instrument;  
         InstrumentStat = 0;  
   
         // delete all key groups  
         ActiveKeyGroups.clear();  
   
         // request gig instrument from instrument manager  
         try {  
             instrument_id_t instrid;  
             instrid.FileName    = FileName;  
             instrid.iInstrument = Instrument;  
             pInstrument = Instruments.Borrow(instrid, this);  
             if (!pInstrument) {  
                 InstrumentStat = -1;  
                 dmsg(1,("no instrument loaded!!!\n"));  
                 exit(EXIT_FAILURE);  
             }  
         }  
         catch (RIFF::Exception e) {  
             InstrumentStat = -2;  
             String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message;  
             throw LinuxSamplerException(msg);  
         }  
         catch (InstrumentResourceManagerException e) {  
             InstrumentStat = -3;  
             String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message();  
             throw LinuxSamplerException(msg);  
         }  
         catch (...) {  
             InstrumentStat = -4;  
             throw LinuxSamplerException("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file.");  
         }  
   
         // rebuild ActiveKeyGroups map with key groups of current instrument  
         for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())  
             if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;  
   
         InstrumentStat = 100;  
   
         // inform audio driver for the need of two channels  
         try {  
             if (pAudioOutputDevice) pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo  
         }  
         catch (AudioOutputException e) {  
             String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();  
             throw LinuxSamplerException(msg);  
         }  
   
         Enable();  
     }  
   
     /**  
      * Will be called by the InstrumentResourceManager when the instrument  
      * we are currently using in this engine is going to be updated, so we  
      * can stop playback before that happens.  
197       */       */
198      void Engine::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) {      void Engine::ResetScaleTuning() {
199          dmsg(3,("gig::Engine: Received instrument update message.\n"));          memset(&ScaleTuning[0], 0x00, 12);
         DisableAndLock();  
         ResetInternal();  
         this->pInstrument = NULL;  
200      }      }
201    
202      /**      /**
203       * Will be called by the InstrumentResourceManager when the instrument       * Connect this engine instance with the given audio output device.
204       * update process was completed, so we can continue with playback.       * This method will be called when an Engine instance is created.
205         * All of the engine's data structures which are dependant to the used
206         * audio output device / driver will be (re)allocated and / or
207         * adjusted appropriately.
208         *
209         * @param pAudioOut - audio output device to connect to
210       */       */
     void Engine::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) {  
         this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument())  
         Enable();  
     }  
   
211      void Engine::Connect(AudioOutputDevice* pAudioOut) {      void Engine::Connect(AudioOutputDevice* pAudioOut) {
212          pAudioOutputDevice = pAudioOut;          pAudioOutputDevice = pAudioOut;
213    
# Line 308  namespace LinuxSampler { namespace gig { Line 222  namespace LinuxSampler { namespace gig {
222              throw LinuxSamplerException(msg);              throw LinuxSamplerException(msg);
223          }          }
224    
225          this->AudioDeviceChannelLeft  = 0;          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();
226          this->AudioDeviceChannelRight = 1;          this->SampleRate         = pAudioOutputDevice->SampleRate();
         this->pOutputLeft             = pAudioOutputDevice->Channel(0)->Buffer();  
         this->pOutputRight            = pAudioOutputDevice->Channel(1)->Buffer();  
         this->MaxSamplesPerCycle      = pAudioOutputDevice->MaxSamplesPerCycle();  
         this->SampleRate              = pAudioOutputDevice->SampleRate();  
227    
228          // FIXME: audio drivers with varying fragment sizes might be a problem here          // FIXME: audio drivers with varying fragment sizes might be a problem here
229          MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * EG_MIN_RELEASE_TIME) - 1;          MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1;
230          if (MaxFadeOutPos < 0)          if (MaxFadeOutPos < 0) {
231              throw LinuxSamplerException("EG_MIN_RELEASE_TIME in EGADSR.h to big for current audio fragment size / sampling rate!");              std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME "
232                          << "too big for current audio fragment size & sampling rate! "
233                          << "May lead to click sounds if voice stealing chimes in!\n" << std::flush;
234                // force volume ramp downs at the beginning of each fragment
235                MaxFadeOutPos = 0;
236                // lower minimum release time
237                const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
238                for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
239                    iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate);
240                }
241                pVoicePool->clear();
242            }
243    
244          // (re)create disk thread          // (re)create disk thread
245          if (this->pDiskThread) {          if (this->pDiskThread) {
246                dmsg(1,("Stopping disk thread..."));
247              this->pDiskThread->StopThread();              this->pDiskThread->StopThread();
248              delete this->pDiskThread;              delete this->pDiskThread;
249                dmsg(1,("OK\n"));
250          }          }
251          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6); //FIXME: assuming stereo
252          if (!pDiskThread) {          if (!pDiskThread) {
253              dmsg(0,("gig::Engine  new diskthread = NULL\n"));              dmsg(0,("gig::Engine  new diskthread = NULL\n"));
254              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
# Line 341  namespace LinuxSampler { namespace gig { Line 264  namespace LinuxSampler { namespace gig {
264          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
265          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
266    
         // (re)allocate synthesis parameter matrix  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
         pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));  
         for (int dst = 1; dst < Event::destination_count; dst++)  
             pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();  
   
         // (re)allocate biquad filter parameter sequence  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pMainFilterParameters)  delete[] pMainFilterParameters;  
         pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
         pMainFilterParameters  = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
   
267          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
268          pDiskThread->StartThread();          pDiskThread->StartThread();
269          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 365  namespace LinuxSampler { namespace gig { Line 276  namespace LinuxSampler { namespace gig {
276          }          }
277      }      }
278    
279      void Engine::DisconnectAudioOutputDevice() {      /**
280          if (pAudioOutputDevice) { // if clause to prevent disconnect loops       * Clear all engine global event lists.
281              AudioOutputDevice* olddevice = pAudioOutputDevice;       */
282              pAudioOutputDevice = NULL;      void Engine::ClearEventLists() {
283              olddevice->Disconnect(this);          pGlobalEvents->clear();
284              AudioDeviceChannelLeft  = -1;      }
285              AudioDeviceChannelRight = -1;  
286        /**
287         * Copy all events from the engine's global input queue buffer to the
288         * engine's internal event list. This will be done at the beginning of
289         * each audio cycle (that is each RenderAudio() call) to distinguish
290         * all global events which have to be processed in the current audio
291         * cycle. These events are usually just SysEx messages. Every
292         * EngineChannel has it's own input event queue buffer and event list
293         * to handle common events like NoteOn, NoteOff and ControlChange
294         * events.
295         *
296         * @param Samples - number of sample points to be processed in the
297         *                  current audio cycle
298         */
299        void Engine::ImportEvents(uint Samples) {
300            RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
301            Event* pEvent;
302            while (true) {
303                // get next event from input event queue
304                if (!(pEvent = eventQueueReader.pop())) break;
305                // if younger event reached, ignore that and all subsequent ones for now
306                if (pEvent->FragmentPos() >= Samples) {
307                    eventQueueReader--;
308                    dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples));
309                    pEvent->ResetFragmentPos();
310                    break;
311                }
312                // copy event to internal event list
313                if (pGlobalEvents->poolIsEmpty()) {
314                    dmsg(1,("Event pool emtpy!\n"));
315                    break;
316                }
317                *pGlobalEvents->allocAppend() = *pEvent;
318          }          }
319            eventQueueReader.free(); // free all copied events from input queue
320      }      }
321    
322      /**      /**
# Line 388  namespace LinuxSampler { namespace gig { Line 332  namespace LinuxSampler { namespace gig {
332      int Engine::RenderAudio(uint Samples) {      int Engine::RenderAudio(uint Samples) {
333          dmsg(5,("RenderAudio(Samples=%d)\n", Samples));          dmsg(5,("RenderAudio(Samples=%d)\n", Samples));
334    
335          // return if no instrument loaded or engine disabled          // return if engine disabled
336          if (EngineDisabled.Pop()) {          if (EngineDisabled.Pop()) {
337              dmsg(5,("gig::Engine: engine disabled (val=%d)\n",EngineDisabled.GetUnsafe()));              dmsg(5,("gig::Engine: engine disabled (val=%d)\n",EngineDisabled.GetUnsafe()));
338              return 0;              return 0;
339          }          }
         if (!pInstrument) {  
             dmsg(5,("gig::Engine: no instrument loaded\n"));  
             return 0;  
         }  
   
340    
341          // update time of start and end of this audio fragment (as events' time stamps relate to this)          // update time of start and end of this audio fragment (as events' time stamps relate to this)
342          pEventGenerator->UpdateFragmentTime(Samples);          pEventGenerator->UpdateFragmentTime(Samples);
343    
344            // We only allow a maximum of CONFIG_MAX_VOICES voices to be spawned
345            // in each audio fragment. All subsequent request for spawning new
346            // voices in the same audio fragment will be ignored.
347            VoiceSpawnsLeft = CONFIG_MAX_VOICES;
348    
349            // get all events from the engine's global input event queue which belong to the current fragment
350            // (these are usually just SysEx messages)
351            ImportEvents(Samples);
352    
353          // empty the event lists for the new fragment          // process engine global events (these are currently only MIDI System Exclusive messages)
         pEvents->clear();  
         pCCEvents->clear();  
         for (uint i = 0; i < Event::destination_count; i++) {  
             pSynthesisEvents[i]->clear();  
         }  
354          {          {
355              RTList<uint>::Iterator iuiKey = pActiveKeys->first();              RTList<Event>::Iterator itEvent = pGlobalEvents->first();
356              RTList<uint>::Iterator end    = pActiveKeys->end();              RTList<Event>::Iterator end     = pGlobalEvents->end();
357              for(; iuiKey != end; ++iuiKey) {              for (; itEvent != end; ++itEvent) {
358                  pMIDIKeyInfo[*iuiKey].pEvents->clear(); // free all events on the key                  switch (itEvent->Type) {
359                        case Event::type_sysex:
360                            dmsg(5,("Engine: Sysex received\n"));
361                            ProcessSysex(itEvent);
362                            break;
363                    }
364              }              }
365          }          }
366    
367            // reset internal voice counter (just for statistic of active voices)
368            ActiveVoiceCountTemp = 0;
369    
370          // get all events from the input event queue which belong to the current fragment          // handle events on all engine channels
371          {          for (int i = 0; i < engineChannels.size(); i++) {
372              RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();              if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded
373              Event* pEvent;              ProcessEvents(engineChannels[i], Samples);
374              while (true) {          }
375                  // get next event from input event queue  
376                  if (!(pEvent = eventQueueReader.pop())) break;          // render all 'normal', active voices on all engine channels
377                  // if younger event reached, ignore that and all subsequent ones for now          for (int i = 0; i < engineChannels.size(); i++) {
378                  if (pEvent->FragmentPos() >= Samples) {              if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded
379                      eventQueueReader--;              RenderActiveVoices(engineChannels[i], Samples);
                     dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples));  
                     pEvent->ResetFragmentPos();  
                     break;  
                 }  
                 // copy event to internal event list  
                 if (pEvents->poolIsEmpty()) {  
                     dmsg(1,("Event pool emtpy!\n"));  
                     break;  
                 }  
                 *pEvents->allocAppend() = *pEvent;  
             }  
             eventQueueReader.free(); // free all copied events from input queue  
380          }          }
381    
382            // now that all ordinary voices on ALL engine channels are rendered, render new stolen voices
383            RenderStolenVoices(Samples);
384    
385            // handle cleanup on all engine channels for the next audio fragment
386            for (int i = 0; i < engineChannels.size(); i++) {
387                if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded
388                PostProcess(engineChannels[i]);
389            }
390    
391    
392            // empty the engine's event list for the next audio fragment
393            ClearEventLists();
394    
395            // reset voice stealing for the next audio fragment
396            pVoiceStealingQueue->clear();
397    
398            // just some statistics about this engine instance
399            ActiveVoiceCount = ActiveVoiceCountTemp;
400            if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount;
401    
402            FrameTime += Samples;
403    
404            return 0;
405        }
406    
407        /**
408         * Dispatch and handle all events in this audio fragment for the given
409         * engine channel.
410         *
411         * @param pEngineChannel - engine channel on which events should be
412         *                         processed
413         * @param Samples        - amount of sample points to be processed in
414         *                         this audio fragment cycle
415         */
416        void Engine::ProcessEvents(EngineChannel* pEngineChannel, uint Samples) {
417            // get all events from the engine channels's input event queue which belong to the current fragment
418            // (these are the common events like NoteOn, NoteOff, ControlChange, etc.)
419            pEngineChannel->ImportEvents(Samples);
420    
421          // process events          // process events
422          {          {
423              RTList<Event>::Iterator itEvent = pEvents->first();              RTList<Event>::Iterator itEvent = pEngineChannel->pEvents->first();
424              RTList<Event>::Iterator end     = pEvents->end();              RTList<Event>::Iterator end     = pEngineChannel->pEvents->end();
425              for (; itEvent != end; ++itEvent) {              for (; itEvent != end; ++itEvent) {
426                  switch (itEvent->Type) {                  switch (itEvent->Type) {
427                      case Event::type_note_on:                      case Event::type_note_on:
428                          dmsg(5,("Engine: Note on received\n"));                          dmsg(5,("Engine: Note on received\n"));
429                          ProcessNoteOn(itEvent);                          ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent);
430                          break;                          break;
431                      case Event::type_note_off:                      case Event::type_note_off:
432                          dmsg(5,("Engine: Note off received\n"));                          dmsg(5,("Engine: Note off received\n"));
433                          ProcessNoteOff(itEvent);                          ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
434                          break;                          break;
435                      case Event::type_control_change:                      case Event::type_control_change:
436                          dmsg(5,("Engine: MIDI CC received\n"));                          dmsg(5,("Engine: MIDI CC received\n"));
437                          ProcessControlChange(itEvent);                          ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);
438                          break;                          break;
439                      case Event::type_pitchbend:                      case Event::type_pitchbend:
440                          dmsg(5,("Engine: Pitchbend received\n"));                          dmsg(5,("Engine: Pitchbend received\n"));
441                          ProcessPitchbend(itEvent);                          ProcessPitchbend((EngineChannel*)itEvent->pEngineChannel, itEvent);
                         break;  
                     case Event::type_sysex:  
                         dmsg(5,("Engine: Sysex received\n"));  
                         ProcessSysex(itEvent);  
442                          break;                          break;
443                  }                  }
444              }              }
445          }          }
446    
447            // reset voice stealing for the next engine channel (or next audio fragment)
448            itLastStolenVoice         = RTList<Voice>::Iterator();
449            itLastStolenVoiceGlobally = RTList<Voice>::Iterator();
450            iuiLastStolenKey          = RTList<uint>::Iterator();
451            iuiLastStolenKeyGlobally  = RTList<uint>::Iterator();
452            pLastStolenChannel        = NULL;
453        }
454    
455          int active_voices = 0;      /**
456         * Render all 'normal' voices (that is voices which were not stolen in
457          // render audio from all active voices       * this fragment) on the given engine channel.
458          {       *
459              RTList<uint>::Iterator iuiKey = pActiveKeys->first();       * @param pEngineChannel - engine channel on which audio should be
460              RTList<uint>::Iterator end    = pActiveKeys->end();       *                         rendered
461              while (iuiKey != end) { // iterate through all active keys       * @param Samples        - amount of sample points to be rendered in
462                  midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];       *                         this audio fragment cycle
463                  ++iuiKey;       */
464        void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) {
465                  RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();          #if !CONFIG_PROCESS_MUTED_CHANNELS
466                  RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
467                  for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key          #endif
468                      // now render current voice  
469                      itVoice->Render(Samples);          RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
470                      if (itVoice->IsActive()) active_voices++; // still active          RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();
471                      else { // voice reached end, is now inactive          while (iuiKey != end) { // iterate through all active keys
472                          FreeVoice(itVoice); // remove voice from the list of active voices              midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
473                      }              ++iuiKey;
474    
475                RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
476                RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
477                for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
478                    // now render current voice
479                    itVoice->Render(Samples);
480                    if (itVoice->IsActive()) ActiveVoiceCountTemp++; // still active
481                    else { // voice reached end, is now inactive
482                        FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices
483                  }                  }
484              }              }
485          }          }
486        }
487    
488        /**
489          // now render all postponed voices from voice stealing       * Render all stolen voices (only voices which were stolen in this
490          {       * fragment) on the given engine channel. Stolen voices are rendered
491              RTList<Event>::Iterator itVoiceStealEvent = pVoiceStealingQueue->first();       * after all normal voices have been rendered; this is needed to render
492              RTList<Event>::Iterator end               = pVoiceStealingQueue->end();       * audio of those voices which were selected for voice stealing until
493              for (; itVoiceStealEvent != end; ++itVoiceStealEvent) {       * the point were the stealing (that is the take over of the voice)
494                  Pool<Voice>::Iterator itNewVoice = LaunchVoice(itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false);       * actually happened.
495                  if (itNewVoice) {       *
496                      for (; itNewVoice; itNewVoice = itNewVoice->itChildVoice) {       * @param pEngineChannel - engine channel on which audio should be
497                          itNewVoice->Render(Samples);       *                         rendered
498                          if (itNewVoice->IsActive()) active_voices++; // still active       * @param Samples        - amount of sample points to be rendered in
499                          else { // voice reached end, is now inactive       *                         this audio fragment cycle
500                              FreeVoice(itNewVoice); // remove voice from the list of active voices       */
501                          }      void Engine::RenderStolenVoices(uint Samples) {
502                      }          RTList<Event>::Iterator itVoiceStealEvent = pVoiceStealingQueue->first();
503            RTList<Event>::Iterator end               = pVoiceStealingQueue->end();
504            for (; itVoiceStealEvent != end; ++itVoiceStealEvent) {
505                EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel;
506                Pool<Voice>::Iterator itNewVoice =
507                    LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false);
508                if (itNewVoice) {
509                    itNewVoice->Render(Samples);
510                    if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active
511                    else { // voice reached end, is now inactive
512                        FreeVoice(pEngineChannel, itNewVoice); // remove voice from the list of active voices
513                  }                  }
                 else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n"));  
514              }              }
515          }              else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n"));
         // reset voice stealing for the new fragment  
         pVoiceStealingQueue->clear();  
         itLastStolenVoice = RTList<Voice>::Iterator();  
         iuiLastStolenKey  = RTList<uint>::Iterator();  
516    
517                // we need to clear the key's event list explicitly here in case key was never active
518                midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itVoiceStealEvent->Param.Note.Key];
519                pKey->VoiceTheftsQueued--;
520                if (!pKey->Active && !pKey->VoiceTheftsQueued) pKey->pEvents->clear();
521            }
522        }
523    
524        /**
525         * Free all keys which have turned inactive in this audio fragment, from
526         * the list of active keys and clear all event lists on that engine
527         * channel.
528         *
529         * @param pEngineChannel - engine channel to cleanup
530         */
531        void Engine::PostProcess(EngineChannel* pEngineChannel) {
532          // free all keys which have no active voices left          // free all keys which have no active voices left
533          {          {
534              RTList<uint>::Iterator iuiKey = pActiveKeys->first();              RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
535              RTList<uint>::Iterator end    = pActiveKeys->end();              RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();
536              while (iuiKey != end) { // iterate through all active keys              while (iuiKey != end) { // iterate through all active keys
537                  midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];                  midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
538                  ++iuiKey;                  ++iuiKey;
539                  if (pKey->pActiveVoices->isEmpty()) FreeKey(pKey);                  if (pKey->pActiveVoices->isEmpty()) FreeKey(pEngineChannel, pKey);
540                  #if DEVMODE                  #if CONFIG_DEVMODE
541                  else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)                  else { // just a sanity check for debugging
542                      RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();                      RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
543                      RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();                      RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
544                      for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key                      for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
# Line 540  namespace LinuxSampler { namespace gig { Line 547  namespace LinuxSampler { namespace gig {
547                          }                          }
548                      }                      }
549                  }                  }
550                  #endif // DEVMODE                  #endif // CONFIG_DEVMODE
551              }              }
552          }          }
553    
554            // empty the engine channel's own event lists
555          // write that to the disk thread class so that it can print it          pEngineChannel->ClearEventLists();
         // on the console for debugging purposes  
         ActiveVoiceCount = active_voices;  
         if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount;  
   
   
         return 0;  
     }  
   
     /**  
      *  Will be called by the MIDIIn Thread to let the audio thread trigger a new  
      *  voice for the given key.  
      *  
      *  @param Key      - MIDI key number of the triggered key  
      *  @param Velocity - MIDI velocity value of the triggered key  
      */  
     void Engine::SendNoteOn(uint8_t Key, uint8_t Velocity) {  
         Event event               = pEventGenerator->CreateEvent();  
         event.Type                = Event::type_note_on;  
         event.Param.Note.Key      = Key;  
         event.Param.Note.Velocity = Velocity;  
         if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);  
         else dmsg(1,("Engine: Input event queue full!"));  
     }  
   
     /**  
      *  Will be called by the MIDIIn Thread to signal the audio thread to release  
      *  voice(s) on the given key.  
      *  
      *  @param Key      - MIDI key number of the released key  
      *  @param Velocity - MIDI release velocity value of the released key  
      */  
     void Engine::SendNoteOff(uint8_t Key, uint8_t Velocity) {  
         Event event               = pEventGenerator->CreateEvent();  
         event.Type                = Event::type_note_off;  
         event.Param.Note.Key      = Key;  
         event.Param.Note.Velocity = Velocity;  
         if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);  
         else dmsg(1,("Engine: Input event queue full!"));  
     }  
   
     /**  
      *  Will be called by the MIDIIn Thread to signal the audio thread to change  
      *  the pitch value for all voices.  
      *  
      *  @param Pitch - MIDI pitch value (-8192 ... +8191)  
      */  
     void Engine::SendPitchbend(int Pitch) {  
         Event event             = pEventGenerator->CreateEvent();  
         event.Type              = Event::type_pitchbend;  
         event.Param.Pitch.Pitch = Pitch;  
         if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);  
         else dmsg(1,("Engine: Input event queue full!"));  
     }  
   
     /**  
      *  Will be called by the MIDIIn Thread to signal the audio thread that a  
      *  continuous controller value has changed.  
      *  
      *  @param Controller - MIDI controller number of the occured control change  
      *  @param Value      - value of the control change  
      */  
     void Engine::SendControlChange(uint8_t Controller, uint8_t Value) {  
         Event event               = pEventGenerator->CreateEvent();  
         event.Type                = Event::type_control_change;  
         event.Param.CC.Controller = Controller;  
         event.Param.CC.Value      = Value;  
         if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);  
         else dmsg(1,("Engine: Input event queue full!"));  
556      }      }
557    
558      /**      /**
# Line 627  namespace LinuxSampler { namespace gig { Line 566  namespace LinuxSampler { namespace gig {
566          Event event             = pEventGenerator->CreateEvent();          Event event             = pEventGenerator->CreateEvent();
567          event.Type              = Event::type_sysex;          event.Type              = Event::type_sysex;
568          event.Param.Sysex.Size  = Size;          event.Param.Sysex.Size  = Size;
569            event.pEngineChannel    = NULL; // as Engine global event
570          if (pEventQueue->write_space() > 0) {          if (pEventQueue->write_space() > 0) {
571              if (pSysexBuffer->write_space() >= Size) {              if (pSysexBuffer->write_space() >= Size) {
572                  // copy sysex data to input buffer                  // copy sysex data to input buffer
# Line 642  namespace LinuxSampler { namespace gig { Line 582  namespace LinuxSampler { namespace gig {
582                  // finally place sysex event into input event queue                  // finally place sysex event into input event queue
583                  pEventQueue->push(&event);                  pEventQueue->push(&event);
584              }              }
585              else dmsg(1,("Engine: Sysex message too large (%d byte) for input buffer (%d byte)!",Size,SYSEX_BUFFER_SIZE));              else dmsg(1,("Engine: Sysex message too large (%d byte) for input buffer (%d byte)!",Size,CONFIG_SYSEX_BUFFER_SIZE));
586          }          }
587          else dmsg(1,("Engine: Input event queue full!"));          else dmsg(1,("Engine: Input event queue full!"));
588      }      }
# Line 650  namespace LinuxSampler { namespace gig { Line 590  namespace LinuxSampler { namespace gig {
590      /**      /**
591       *  Assigns and triggers a new voice for the respective MIDI key.       *  Assigns and triggers a new voice for the respective MIDI key.
592       *       *
593         *  @param pEngineChannel - engine channel on which this event occured on
594       *  @param itNoteOnEvent - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
595       */       */
596      void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) {      void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
597          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];          #if !CONFIG_PROCESS_MUTED_CHANNELS
598            if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
599            #endif
600    
601            const int key = itNoteOnEvent->Param.Note.Key;
602    
603            // Change key dimension value if key is in keyswitching area
604            {
605                const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;
606                if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
607                    pEngineChannel->CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /
608                        (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
609            }
610    
611            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];
612    
613          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
614            pKey->Velocity   = itNoteOnEvent->Param.Note.Velocity;
615            pKey->NoteOnTime = FrameTime + itNoteOnEvent->FragmentPos(); // will be used to calculate note length
616    
617          // cancel release process of voices on this key if needed          // cancel release process of voices on this key if needed
618          if (pKey->Active && !SustainPedal) {          if (pKey->Active && !pEngineChannel->SustainPedal) {
619              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();
620              if (itCancelReleaseEvent) {              if (itCancelReleaseEvent) {
621                  *itCancelReleaseEvent = *itNoteOnEvent;                  // copy event                  *itCancelReleaseEvent = *itNoteOnEvent;                  // copy event
# Line 670  namespace LinuxSampler { namespace gig { Line 627  namespace LinuxSampler { namespace gig {
627          // move note on event to the key's own event list          // move note on event to the key's own event list
628          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
629    
630          // allocate and trigger a new voice for the key          // allocate and trigger new voice(s) for the key
631          LaunchVoice(itNoteOnEventOnKeyList, 0, false, true);          {
632                // first, get total amount of required voices (dependant on amount of layers)
633                ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOnEventOnKeyList->Param.Note.Key);
634                if (pRegion) {
635                    int voicesRequired = pRegion->Layers;
636                    // now launch the required amount of voices
637                    for (int i = 0; i < voicesRequired; i++)
638                        LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true, true);
639                }
640            }
641    
642            // if neither a voice was spawned or postponed then remove note on event from key again
643            if (!pKey->Active && !pKey->VoiceTheftsQueued)
644                pKey->pEvents->free(itNoteOnEventOnKeyList);
645    
646            pKey->RoundRobinIndex++;
647      }      }
648    
649      /**      /**
# Line 680  namespace LinuxSampler { namespace gig { Line 652  namespace LinuxSampler { namespace gig {
652       *  sustain pedal will be released or voice turned inactive by itself (e.g.       *  sustain pedal will be released or voice turned inactive by itself (e.g.
653       *  due to completion of sample playback).       *  due to completion of sample playback).
654       *       *
655         *  @param pEngineChannel - engine channel on which this event occured on
656       *  @param itNoteOffEvent - key, velocity and time stamp of the event       *  @param itNoteOffEvent - key, velocity and time stamp of the event
657       */       */
658      void Engine::ProcessNoteOff(Pool<Event>::Iterator& itNoteOffEvent) {      void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {
659          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          #if !CONFIG_PROCESS_MUTED_CHANNELS
660            if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
661            #endif
662    
663            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];
664          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
665    
666          // release voices on this key if needed          // release voices on this key if needed
667          if (pKey->Active && !SustainPedal) {          if (pKey->Active && !pEngineChannel->SustainPedal) {
668              itNoteOffEvent->Type = Event::type_release; // transform event type              itNoteOffEvent->Type = Event::type_release; // transform event type
         }  
669    
670          // move event to the key's own event list              // move event to the key's own event list
671          RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);              RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);
672    
673          // spawn release triggered voice(s) if needed              // spawn release triggered voice(s) if needed
674          if (pKey->ReleaseTrigger) {              if (pKey->ReleaseTrigger) {
675              LaunchVoice(itNoteOffEventOnKeyList, 0, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples                  // first, get total amount of required voices (dependant on amount of layers)
676              pKey->ReleaseTrigger = false;                  ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key);
677                    if (pRegion) {
678                        int voicesRequired = pRegion->Layers;
679    
680                        // MIDI note-on velocity is used instead of note-off velocity
681                        itNoteOffEventOnKeyList->Param.Note.Velocity = pKey->Velocity;
682    
683                        // now launch the required amount of voices
684                        for (int i = 0; i < voicesRequired; i++)
685                            LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples
686                    }
687                    pKey->ReleaseTrigger = false;
688                }
689    
690                // if neither a voice was spawned or postponed then remove note off event from key again
691                if (!pKey->Active && !pKey->VoiceTheftsQueued)
692                    pKey->pEvents->free(itNoteOffEventOnKeyList);
693          }          }
694      }      }
695    
696      /**      /**
697       *  Moves pitchbend event from the general (input) event list to the pitch       *  Moves pitchbend event from the general (input) event list to the engine
698       *  event list.       *  channel's event list. It will actually processed later by the
699         *  respective voice.
700       *       *
701         *  @param pEngineChannel - engine channel on which this event occured on
702       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
703       */       */
704      void Engine::ProcessPitchbend(Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
705          this->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value
706          itPitchbendEvent.moveToEndOf(pSynthesisEvents[Event::destination_vco]);          itPitchbendEvent.moveToEndOf(pEngineChannel->pEvents);
707      }      }
708    
709      /**      /**
# Line 718  namespace LinuxSampler { namespace gig { Line 711  namespace LinuxSampler { namespace gig {
711       *  called by the ProcessNoteOn() method and by the voices itself       *  called by the ProcessNoteOn() method and by the voices itself
712       *  (e.g. to spawn further voices on the same key for layered sounds).       *  (e.g. to spawn further voices on the same key for layered sounds).
713       *       *
714         *  @param pEngineChannel      - engine channel on which this event occured on
715       *  @param itNoteOnEvent       - key, velocity and time stamp of the event       *  @param itNoteOnEvent       - key, velocity and time stamp of the event
716       *  @param iLayer              - layer index for the new voice (optional - only       *  @param iLayer              - layer index for the new voice (optional - only
717       *                               in case of layered sounds of course)       *                               in case of layered sounds of course)
# Line 726  namespace LinuxSampler { namespace gig { Line 720  namespace LinuxSampler { namespace gig {
720       *  @param VoiceStealing       - if voice stealing should be performed       *  @param VoiceStealing       - if voice stealing should be performed
721       *                               when there is no free voice       *                               when there is no free voice
722       *                               (optional, default = true)       *                               (optional, default = true)
723         *  @param HandleKeyGroupConflicts - if voices should be killed due to a
724         *                                   key group conflict
725       *  @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
726       *           if an error occured while trying to trigger the new voice       *           if the voice wasn't triggered (for example when no region is
727         *           defined for the given key).
728       */       */
729      Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {      Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts) {
730          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];          int MIDIKey            = itNoteOnEvent->Param.Note.Key;
731            midi_key_info_t* pKey  = &pEngineChannel->pMIDIKeyInfo[MIDIKey];
732            ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(MIDIKey);
733    
734            // if nothing defined for this key
735            if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do
736    
737            // only mark the first voice of a layered voice (group) to be in a
738            // key group, so the layered voices won't kill each other
739            int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0;
740    
741            // handle key group (a.k.a. exclusive group) conflicts
742            if (HandleKeyGroupConflicts) {
743                if (iKeyGroup) { // if this voice / key belongs to a key group
744                    uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup];
745                    if (*ppKeyGroup) { // if there's already an active key in that key group
746                        midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup];
747                        // kill all voices on the (other) key
748                        RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();
749                        RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();
750                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
751                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger) {
752                                itVoiceToBeKilled->Kill(itNoteOnEvent);
753                                --VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict
754                            }
755                        }
756                    }
757                }
758            }
759    
760            Voice::type_t VoiceType = Voice::type_normal;
761    
762            // get current dimension values to select the right dimension region
763            //TODO: for stolen voices this dimension region selection block is processed twice, this should be changed
764            //FIXME: controller values for selecting the dimension region here are currently not sample accurate
765            uint DimValues[8] = { 0 };
766            for (int i = pRegion->Dimensions - 1; i >= 0; i--) {
767                switch (pRegion->pDimensionDefinitions[i].dimension) {
768                    case ::gig::dimension_samplechannel:
769                        DimValues[i] = 0; //TODO: we currently ignore this dimension
770                        break;
771                    case ::gig::dimension_layer:
772                        DimValues[i] = iLayer;
773                        break;
774                    case ::gig::dimension_velocity:
775                        DimValues[i] = itNoteOnEvent->Param.Note.Velocity;
776                        break;
777                    case ::gig::dimension_channelaftertouch:
778                        DimValues[i] = 0; //TODO: we currently ignore this dimension
779                        break;
780                    case ::gig::dimension_releasetrigger:
781                        VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;
782                        DimValues[i] = (uint) ReleaseTriggerVoice;
783                        break;
784                    case ::gig::dimension_keyboard:
785                        DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension;
786                        break;
787                    case ::gig::dimension_roundrobin:
788                        DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on
789                        break;
790                    case ::gig::dimension_random:
791                        RandomSeed   = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
792                        DimValues[i] = (uint) RandomSeed >> (32 - pRegion->pDimensionDefinitions[i].bits); // highest bits are most random
793                        break;
794                    case ::gig::dimension_modwheel:
795                        DimValues[i] = pEngineChannel->ControllerTable[1];
796                        break;
797                    case ::gig::dimension_breath:
798                        DimValues[i] = pEngineChannel->ControllerTable[2];
799                        break;
800                    case ::gig::dimension_foot:
801                        DimValues[i] = pEngineChannel->ControllerTable[4];
802                        break;
803                    case ::gig::dimension_portamentotime:
804                        DimValues[i] = pEngineChannel->ControllerTable[5];
805                        break;
806                    case ::gig::dimension_effect1:
807                        DimValues[i] = pEngineChannel->ControllerTable[12];
808                        break;
809                    case ::gig::dimension_effect2:
810                        DimValues[i] = pEngineChannel->ControllerTable[13];
811                        break;
812                    case ::gig::dimension_genpurpose1:
813                        DimValues[i] = pEngineChannel->ControllerTable[16];
814                        break;
815                    case ::gig::dimension_genpurpose2:
816                        DimValues[i] = pEngineChannel->ControllerTable[17];
817                        break;
818                    case ::gig::dimension_genpurpose3:
819                        DimValues[i] = pEngineChannel->ControllerTable[18];
820                        break;
821                    case ::gig::dimension_genpurpose4:
822                        DimValues[i] = pEngineChannel->ControllerTable[19];
823                        break;
824                    case ::gig::dimension_sustainpedal:
825                        DimValues[i] = pEngineChannel->ControllerTable[64];
826                        break;
827                    case ::gig::dimension_portamento:
828                        DimValues[i] = pEngineChannel->ControllerTable[65];
829                        break;
830                    case ::gig::dimension_sostenutopedal:
831                        DimValues[i] = pEngineChannel->ControllerTable[66];
832                        break;
833                    case ::gig::dimension_softpedal:
834                        DimValues[i] = pEngineChannel->ControllerTable[67];
835                        break;
836                    case ::gig::dimension_genpurpose5:
837                        DimValues[i] = pEngineChannel->ControllerTable[80];
838                        break;
839                    case ::gig::dimension_genpurpose6:
840                        DimValues[i] = pEngineChannel->ControllerTable[81];
841                        break;
842                    case ::gig::dimension_genpurpose7:
843                        DimValues[i] = pEngineChannel->ControllerTable[82];
844                        break;
845                    case ::gig::dimension_genpurpose8:
846                        DimValues[i] = pEngineChannel->ControllerTable[83];
847                        break;
848                    case ::gig::dimension_effect1depth:
849                        DimValues[i] = pEngineChannel->ControllerTable[91];
850                        break;
851                    case ::gig::dimension_effect2depth:
852                        DimValues[i] = pEngineChannel->ControllerTable[92];
853                        break;
854                    case ::gig::dimension_effect3depth:
855                        DimValues[i] = pEngineChannel->ControllerTable[93];
856                        break;
857                    case ::gig::dimension_effect4depth:
858                        DimValues[i] = pEngineChannel->ControllerTable[94];
859                        break;
860                    case ::gig::dimension_effect5depth:
861                        DimValues[i] = pEngineChannel->ControllerTable[95];
862                        break;
863                    case ::gig::dimension_none:
864                        std::cerr << "gig::Engine::LaunchVoice() Error: dimension=none\n" << std::flush;
865                        break;
866                    default:
867                        std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush;
868                }
869            }
870            ::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);
871    
872            // no need to continue if sample is silent
873            if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator();
874    
875          // allocate a new voice for the key          // allocate a new voice for the key
876          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();
877          if (itNewVoice) {          if (itNewVoice) {
878              // launch the new voice              // launch the new voice
879              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {              if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pDimRgn, VoiceType, iKeyGroup) < 0) {
880                  dmsg(1,("Triggering new voice failed!\n"));                  dmsg(4,("Voice not triggered\n"));
881                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
882              }              }
883              else { // on success              else { // on success
884                  uint** ppKeyGroup = NULL;                  --VoiceSpawnsLeft;
                 if (itNewVoice->KeyGroup) { // if this voice / key belongs to a key group  
                     ppKeyGroup = &ActiveKeyGroups[itNewVoice->KeyGroup];  
                     if (*ppKeyGroup) { // if there's already an active key in that key group  
                         midi_key_info_t* pOtherKey = &pMIDIKeyInfo[**ppKeyGroup];  
                         // kill all voices on the (other) key  
                         RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();  
                         RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();  
                         for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {  
                             if (itVoiceToBeKilled->Type != Voice::type_release_trigger) itVoiceToBeKilled->Kill(itNoteOnEvent);  
                         }  
                     }  
                 }  
885                  if (!pKey->Active) { // mark as active key                  if (!pKey->Active) { // mark as active key
886                      pKey->Active = true;                      pKey->Active = true;
887                      pKey->itSelf = pActiveKeys->allocAppend();                      pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend();
888                      *pKey->itSelf = itNoteOnEvent->Param.Note.Key;                      *pKey->itSelf = itNoteOnEvent->Param.Note.Key;
889                  }                  }
890                  if (itNewVoice->KeyGroup) {                  if (itNewVoice->KeyGroup) {
891                        uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup];
892                      *ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group                      *ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group
893                  }                  }
894                  if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s)                  if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s)
# Line 767  namespace LinuxSampler { namespace gig { Line 896  namespace LinuxSampler { namespace gig {
896              }              }
897          }          }
898          else if (VoiceStealing) {          else if (VoiceStealing) {
899              // first, get total amount of required voices (dependant on amount of layers)              // try to steal one voice
900              ::gig::Region* pRegion = pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key);              int result = StealVoice(pEngineChannel, itNoteOnEvent);
901              if (!pRegion) return Pool<Voice>::Iterator(); // nothing defined for this MIDI key, so no voice needed              if (!result) { // voice stolen successfully
902              int voicesRequired = pRegion->Layers;                  // put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died
903                    RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend();
904              // now steal the (remaining) amount of voices                  if (itStealEvent) {
905              for (int i = iLayer; i < voicesRequired; i++)                      *itStealEvent = *itNoteOnEvent; // copy event
906                  StealVoice(itNoteOnEvent);                      itStealEvent->Param.Note.Layer = iLayer;
907                        itStealEvent->Param.Note.ReleaseTrigger = ReleaseTriggerVoice;
908              // put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died                      pKey->VoiceTheftsQueued++;
909              RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend();                  }
910              if (itStealEvent) {                  else dmsg(1,("Voice stealing queue full!\n"));
                 *itStealEvent = *itNoteOnEvent; // copy event  
                 itStealEvent->Param.Note.Layer = iLayer;  
                 itStealEvent->Param.Note.ReleaseTrigger = ReleaseTriggerVoice;  
911              }              }
             else dmsg(1,("Voice stealing queue full!\n"));  
912          }          }
913    
914          return Pool<Voice>::Iterator(); // no free voice or error          return Pool<Voice>::Iterator(); // no free voice or error
# Line 795  namespace LinuxSampler { namespace gig { Line 920  namespace LinuxSampler { namespace gig {
920       *  voice stealing and postpone the note-on event until the selected       *  voice stealing and postpone the note-on event until the selected
921       *  voice actually died.       *  voice actually died.
922       *       *
923         *  @param pEngineChannel - engine channel on which this event occured on
924       *  @param itNoteOnEvent - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
925         *  @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing
926       */       */
927      void Engine::StealVoice(Pool<Event>::Iterator& itNoteOnEvent) {      int Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
928            if (VoiceSpawnsLeft <= 0) {
929                dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n"));
930                return -1;
931            }
932          if (!pEventPool->poolIsEmpty()) {          if (!pEventPool->poolIsEmpty()) {
933    
934              RTList<uint>::Iterator  iuiOldestKey;              RTList<Voice>::Iterator itSelectedVoice;
             RTList<Voice>::Iterator itOldestVoice;  
935    
936              // Select one voice for voice stealing              // Select one voice for voice stealing
937              switch (VOICE_STEAL_ALGORITHM) {              switch (CONFIG_VOICE_STEAL_ALGO) {
938    
939                  // try to pick the oldest voice on the key where the new                  // try to pick the oldest voice on the key where the new
940                  // voice should be spawned, if there is no voice on that                  // voice should be spawned, if there is no voice on that
941                  // key, or no voice left to kill there, then procceed with                  // key, or no voice left to kill, then procceed with
942                  // 'oldestkey' algorithm                  // 'oldestkey' algorithm
943                  case voice_steal_algo_keymask: {                  case voice_steal_algo_oldestvoiceonkey: {
944                      midi_key_info_t* pOldestKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];                      midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];
945                      if (itLastStolenVoice) {                      itSelectedVoice = pSelectedKey->pActiveVoices->first();
946                          itOldestVoice = itLastStolenVoice;                      // proceed iterating if voice was created in this fragment cycle
947                          ++itOldestVoice;                      while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice;
948                      }                      // if we haven't found a voice then proceed with algorithm 'oldestkey'
949                      else { // no voice stolen in this audio fragment cycle yet                      if (itSelectedVoice && itSelectedVoice->IsStealable()) break;
                         itOldestVoice = pOldestKey->pActiveVoices->first();  
                     }  
                     if (itOldestVoice) {  
                         iuiOldestKey = pOldestKey->itSelf;  
                         break; // selection succeeded  
                     }  
950                  } // no break - intentional !                  } // no break - intentional !
951    
952                  // try to pick the oldest voice on the oldest active key                  // try to pick the oldest voice on the oldest active key
953                  // (caution: must stay after 'keymask' algorithm !)                  // from the same engine channel
954                    // (caution: must stay after 'oldestvoiceonkey' algorithm !)
955                  case voice_steal_algo_oldestkey: {                  case voice_steal_algo_oldestkey: {
956                      if (itLastStolenVoice) {                      // if we already stole in this fragment, try to proceed on same key
957                          midi_key_info_t* pOldestKey = &pMIDIKeyInfo[*iuiLastStolenKey];                      if (this->itLastStolenVoice) {
958                          itOldestVoice = itLastStolenVoice;                          itSelectedVoice = this->itLastStolenVoice;
959                          ++itOldestVoice;                          do {
960                          if (!itOldestVoice) {                              ++itSelectedVoice;
961                              iuiOldestKey = iuiLastStolenKey;                          } while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle
962                              ++iuiOldestKey;                          // found a "stealable" voice ?
963                              if (iuiOldestKey) {                          if (itSelectedVoice && itSelectedVoice->IsStealable()) {
964                                  midi_key_info_t* pOldestKey = &pMIDIKeyInfo[*iuiOldestKey];                              // remember which voice we stole, so we can simply proceed on next voice stealing
965                                  itOldestVoice = pOldestKey->pActiveVoices->first();                              this->itLastStolenVoice = itSelectedVoice;
966                              }                              break; // selection succeeded
                             else {  
                                 dmsg(1,("gig::Engine: Warning, too less voices, even for voice stealing! - Better recompile with higher MAX_AUDIO_VOICES.\n"));  
                                 return;  
                             }  
967                          }                          }
                         else iuiOldestKey = iuiLastStolenKey;  
968                      }                      }
969                      else { // no voice stolen in this audio fragment cycle yet                      // get (next) oldest key
970                          iuiOldestKey = pActiveKeys->first();                      RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKey) ? ++this->iuiLastStolenKey : pEngineChannel->pActiveKeys->first();
971                          midi_key_info_t* pOldestKey = &pMIDIKeyInfo[*iuiOldestKey];                      while (iuiSelectedKey) {
972                          itOldestVoice = pOldestKey->pActiveVoices->first();                          midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey];
973                            itSelectedVoice = pSelectedKey->pActiveVoices->first();
974                            // proceed iterating if voice was created in this fragment cycle
975                            while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice;
976                            // found a "stealable" voice ?
977                            if (itSelectedVoice && itSelectedVoice->IsStealable()) {
978                                // remember which voice on which key we stole, so we can simply proceed on next voice stealing
979                                this->iuiLastStolenKey  = iuiSelectedKey;
980                                this->itLastStolenVoice = itSelectedVoice;
981                                break; // selection succeeded
982                            }
983                            ++iuiSelectedKey; // get next oldest key
984                      }                      }
985                      break;                      break;
986                  }                  }
# Line 858  namespace LinuxSampler { namespace gig { Line 989  namespace LinuxSampler { namespace gig {
989                  case voice_steal_algo_none:                  case voice_steal_algo_none:
990                  default: {                  default: {
991                      dmsg(1,("No free voice (voice stealing disabled)!\n"));                      dmsg(1,("No free voice (voice stealing disabled)!\n"));
992                      return;                      return -1;
993                  }                  }
994              }              }
995    
996              //FIXME: can be removed, just a sanity check for debugging              // if we couldn't steal a voice from the same engine channel then
997              if (!itOldestVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n"));              // steal oldest voice on the oldest key from any other engine channel
998                // (the smaller engine channel number, the higher priority)
999                if (!itSelectedVoice || !itSelectedVoice->IsStealable()) {
1000                    EngineChannel* pSelectedChannel;
1001                    int            iChannelIndex;
1002                    // select engine channel
1003                    if (pLastStolenChannel) {
1004                        pSelectedChannel = pLastStolenChannel;
1005                        iChannelIndex    = pSelectedChannel->iEngineIndexSelf;
1006                    } else { // pick the engine channel followed by this engine channel
1007                        iChannelIndex    = (pEngineChannel->iEngineIndexSelf + 1) % engineChannels.size();
1008                        pSelectedChannel = engineChannels[iChannelIndex];
1009                    }
1010    
1011                    // if we already stole in this fragment, try to proceed on same key
1012                    if (this->itLastStolenVoiceGlobally) {
1013                        itSelectedVoice = this->itLastStolenVoiceGlobally;
1014                        do {
1015                            ++itSelectedVoice;
1016                        } while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle
1017                    }
1018    
1019                    #if CONFIG_DEVMODE
1020                    EngineChannel* pBegin = pSelectedChannel; // to detect endless loop
1021                    #endif // CONFIG_DEVMODE
1022    
1023                    // did we find a 'stealable' voice?
1024                    if (itSelectedVoice && itSelectedVoice->IsStealable()) {
1025                        // remember which voice we stole, so we can simply proceed on next voice stealing
1026                        this->itLastStolenVoiceGlobally = itSelectedVoice;
1027                    } else while (true) { // iterate through engine channels
1028                        // get (next) oldest key
1029                        RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKeyGlobally) ? ++this->iuiLastStolenKeyGlobally : pSelectedChannel->pActiveKeys->first();
1030                        this->iuiLastStolenKeyGlobally = RTList<uint>::Iterator(); // to prevent endless loop (see line above)
1031                        while (iuiSelectedKey) {
1032                            midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey];
1033                            itSelectedVoice = pSelectedKey->pActiveVoices->first();
1034                            // proceed iterating if voice was created in this fragment cycle
1035                            while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice;
1036                            // found a "stealable" voice ?
1037                            if (itSelectedVoice && itSelectedVoice->IsStealable()) {
1038                                // remember which voice on which key on which engine channel we stole, so we can simply proceed on next voice stealing
1039                                this->iuiLastStolenKeyGlobally  = iuiSelectedKey;
1040                                this->itLastStolenVoiceGlobally = itSelectedVoice;
1041                                this->pLastStolenChannel        = pSelectedChannel;
1042                                goto stealable_voice_found; // selection succeeded
1043                            }
1044                            ++iuiSelectedKey; // get next key on current engine channel
1045                        }
1046                        // get next engine channel
1047                        iChannelIndex    = (iChannelIndex + 1) % engineChannels.size();
1048                        pSelectedChannel = engineChannels[iChannelIndex];
1049    
1050                        #if CONFIG_DEVMODE
1051                        if (pSelectedChannel == pBegin) {
1052                            dmsg(1,("FATAL ERROR: voice stealing endless loop!\n"));
1053                            dmsg(1,("VoiceSpawnsLeft=%d.\n", VoiceSpawnsLeft));
1054                            dmsg(1,("Exiting.\n"));
1055                            exit(-1);
1056                        }
1057                        #endif // CONFIG_DEVMODE
1058                    }
1059                }
1060    
1061                // jump point if a 'stealable' voice was found
1062                stealable_voice_found:
1063    
1064                #if CONFIG_DEVMODE
1065                if (!itSelectedVoice->IsActive()) {
1066                    dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n"));
1067                    return -1;
1068                }
1069                #endif // CONFIG_DEVMODE
1070    
1071              // now kill the selected voice              // now kill the selected voice
1072              itOldestVoice->Kill(itNoteOnEvent);              itSelectedVoice->Kill(itNoteOnEvent);
1073              // remember which voice on which key we stole, so we can simply proceed for the next voice stealing  
1074              this->itLastStolenVoice = itOldestVoice;              --VoiceSpawnsLeft;
1075              this->iuiLastStolenKey = iuiOldestKey;  
1076                return 0; // success
1077            }
1078            else {
1079                dmsg(1,("Event pool emtpy!\n"));
1080                return -1;
1081          }          }
         else dmsg(1,("Event pool emtpy!\n"));  
1082      }      }
1083    
1084      /**      /**
# Line 880  namespace LinuxSampler { namespace gig { Line 1087  namespace LinuxSampler { namespace gig {
1087       *  it finished to playback its sample, finished its release stage or       *  it finished to playback its sample, finished its release stage or
1088       *  just was killed.       *  just was killed.
1089       *       *
1090         *  @param pEngineChannel - engine channel on which this event occured on
1091       *  @param itVoice - points to the voice to be freed       *  @param itVoice - points to the voice to be freed
1092       */       */
1093      void Engine::FreeVoice(Pool<Voice>::Iterator& itVoice) {      void Engine::FreeVoice(EngineChannel* pEngineChannel, Pool<Voice>::Iterator& itVoice) {
1094          if (itVoice) {          if (itVoice) {
1095              midi_key_info_t* pKey = &pMIDIKeyInfo[itVoice->MIDIKey];              midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itVoice->MIDIKey];
1096    
1097              uint keygroup = itVoice->KeyGroup;              uint keygroup = itVoice->KeyGroup;
1098    
# Line 893  namespace LinuxSampler { namespace gig { Line 1101  namespace LinuxSampler { namespace gig {
1101    
1102              // if no other voices left and member of a key group, remove from key group              // if no other voices left and member of a key group, remove from key group
1103              if (pKey->pActiveVoices->isEmpty() && keygroup) {              if (pKey->pActiveVoices->isEmpty() && keygroup) {
1104                  uint** ppKeyGroup = &ActiveKeyGroups[keygroup];                  uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[keygroup];
1105                  if (*ppKeyGroup == &*pKey->itSelf) *ppKeyGroup = NULL; // remove key from key group                  if (*ppKeyGroup == &*pKey->itSelf) *ppKeyGroup = NULL; // remove key from key group
1106              }              }
1107          }          }
# Line 904  namespace LinuxSampler { namespace gig { Line 1112  namespace LinuxSampler { namespace gig {
1112       *  Called when there's no more voice left on a key, this call will       *  Called when there's no more voice left on a key, this call will
1113       *  update the key info respectively.       *  update the key info respectively.
1114       *       *
1115         *  @param pEngineChannel - engine channel on which this event occured on
1116       *  @param pKey - key which is now inactive       *  @param pKey - key which is now inactive
1117       */       */
1118      void Engine::FreeKey(midi_key_info_t* pKey) {      void Engine::FreeKey(EngineChannel* pEngineChannel, midi_key_info_t* pKey) {
1119          if (pKey->pActiveVoices->isEmpty()) {          if (pKey->pActiveVoices->isEmpty()) {
1120              pKey->Active = false;              pKey->Active = false;
1121              pActiveKeys->free(pKey->itSelf); // remove key from list of active keys              pEngineChannel->pActiveKeys->free(pKey->itSelf); // remove key from list of active keys
1122              pKey->itSelf = RTList<uint>::Iterator();              pKey->itSelf = RTList<uint>::Iterator();
1123              pKey->ReleaseTrigger = false;              pKey->ReleaseTrigger = false;
1124              pKey->pEvents->clear();              pKey->pEvents->clear();
# Line 922  namespace LinuxSampler { namespace gig { Line 1131  namespace LinuxSampler { namespace gig {
1131       *  Reacts on supported control change commands (e.g. pitch bend wheel,       *  Reacts on supported control change commands (e.g. pitch bend wheel,
1132       *  modulation wheel, aftertouch).       *  modulation wheel, aftertouch).
1133       *       *
1134         *  @param pEngineChannel - engine channel on which this event occured on
1135       *  @param itControlChangeEvent - controller, value and time stamp of the event       *  @param itControlChangeEvent - controller, value and time stamp of the event
1136       */       */
1137      void Engine::ProcessControlChange(Pool<Event>::Iterator& itControlChangeEvent) {      void Engine::ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) {
1138          dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value));          dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value));
1139    
1140          switch (itControlChangeEvent->Param.CC.Controller) {          // update controller value in the engine channel's controller table
1141              case 64: {          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1142                  if (itControlChangeEvent->Param.CC.Value >= 64 && !SustainPedal) {  
1143            // move event from the import event list to the engine channel's CC and pitchbend event list
1144            Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pEvents);
1145    
1146            switch (itControlChangeEventOnCCList->Param.CC.Controller) {
1147                case 7: { // volume
1148                    //TODO: not sample accurate yet
1149                    pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;
1150                    pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1151                    break;
1152                }
1153                case 10: { // panpot
1154                    //TODO: not sample accurate yet
1155                    const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;
1156                    pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;
1157                    pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;
1158                    break;
1159                }
1160                case 64: { // sustain
1161                    if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1162                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("PEDAL DOWN\n"));
1163                      SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1164    
1165                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1166                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1167                        #endif
1168    
1169                      // cancel release process of voices if necessary                      // cancel release process of voices if necessary
1170                      RTList<uint>::Iterator iuiKey = pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1171                      if (iuiKey) {                      for (; iuiKey; ++iuiKey) {
1172                          itControlChangeEvent->Type = Event::type_cancel_release; // transform event type                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1173                          while (iuiKey) {                          if (!pKey->KeyPressed) {
1174                              midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1175                              ++iuiKey;                              if (itNewEvent) {
1176                              if (!pKey->KeyPressed) {                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list
1177                                  RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
                                 if (itNewEvent) *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list  
                                 else dmsg(1,("Event pool emtpy!\n"));  
1178                              }                              }
1179                                else dmsg(1,("Event pool emtpy!\n"));
1180                          }                          }
1181                      }                      }
1182                  }                  }
1183                  if (itControlChangeEvent->Param.CC.Value < 64 && SustainPedal) {                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1184                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("PEDAL UP\n"));
1185                      SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1186    
1187                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1188                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1189                        #endif
1190    
1191                      // release voices if their respective key is not pressed                      // release voices if their respective key is not pressed
1192                      RTList<uint>::Iterator iuiKey = pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1193                      if (iuiKey) {                      for (; iuiKey; ++iuiKey) {
1194                          itControlChangeEvent->Type = Event::type_release; // transform event type                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1195                          while (iuiKey) {                          if (!pKey->KeyPressed) {
1196                              midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1197                              ++iuiKey;                              if (itNewEvent) {
1198                              if (!pKey->KeyPressed) {                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list
1199                                  RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                                  itNewEvent->Type = Event::type_release; // transform event type
                                 if (itNewEvent) *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list  
                                 else dmsg(1,("Event pool emtpy!\n"));  
1200                              }                              }
1201                                else dmsg(1,("Event pool emtpy!\n"));
1202                          }                          }
1203                      }                      }
1204                  }                  }
1205                  break;                  break;
1206              }              }
         }  
1207    
         // update controller value in the engine's controller table  
         ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;  
1208    
1209          // move event from the unsorted event list to the control change event list              // Channel Mode Messages
1210          itControlChangeEvent.moveToEndOf(pCCEvents);  
1211                case 120: { // all sound off
1212                    KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);
1213                    break;
1214                }
1215                case 121: { // reset all controllers
1216                    pEngineChannel->ResetControllers();
1217                    break;
1218                }
1219                case 123: { // all notes off
1220                    ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);
1221                    break;
1222                }
1223            }
1224      }      }
1225    
1226      /**      /**
# Line 993  namespace LinuxSampler { namespace gig { Line 1238  namespace LinuxSampler { namespace gig {
1238    
1239          switch (id) {          switch (id) {
1240              case 0x41: { // Roland              case 0x41: { // Roland
1241                    dmsg(3,("Roland Sysex\n"));
1242                  uint8_t device_id, model_id, cmd_id;                  uint8_t device_id, model_id, cmd_id;
1243                  if (!reader.pop(&device_id)) goto free_sysex_data;                  if (!reader.pop(&device_id)) goto free_sysex_data;
1244                  if (!reader.pop(&model_id))  goto free_sysex_data;                  if (!reader.pop(&model_id))  goto free_sysex_data;
# Line 1005  namespace LinuxSampler { namespace gig { Line 1251  namespace LinuxSampler { namespace gig {
1251                  const RingBuffer<uint8_t>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later                  const RingBuffer<uint8_t>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later
1252                  if (reader.read(&addr[0], 3) != 3) goto free_sysex_data;                  if (reader.read(&addr[0], 3) != 3) goto free_sysex_data;
1253                  if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters                  if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters
1254                        dmsg(3,("\tSystem Parameter\n"));
1255                  }                  }
1256                  else if (addr[0] == 0x40 && addr[1] == 0x01) { // Common Parameters                  else if (addr[0] == 0x40 && addr[1] == 0x01) { // Common Parameters
1257                        dmsg(3,("\tCommon Parameter\n"));
1258                  }                  }
1259                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x10) { // Part Parameters (1)                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x10) { // Part Parameters (1)
1260                      switch (addr[3]) {                      dmsg(3,("\tPart Parameter\n"));
1261                        switch (addr[2]) {
1262                          case 0x40: { // scale tuning                          case 0x40: { // scale tuning
1263                                dmsg(3,("\t\tScale Tuning\n"));
1264                              uint8_t scale_tunes[12]; // detuning of all 12 semitones of an octave                              uint8_t scale_tunes[12]; // detuning of all 12 semitones of an octave
1265                              if (reader.read(&scale_tunes[0], 12) != 12) goto free_sysex_data;                              if (reader.read(&scale_tunes[0], 12) != 12) goto free_sysex_data;
1266                              uint8_t checksum;                              uint8_t checksum;
1267                              if (!reader.pop(&checksum))                      goto free_sysex_data;                              if (!reader.pop(&checksum)) goto free_sysex_data;
1268                              if (GSCheckSum(checksum_reader, 12) != checksum) goto free_sysex_data;                              #if CONFIG_ASSERT_GS_SYSEX_CHECKSUM
1269                                if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data;
1270                                #endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM
1271                              for (int i = 0; i < 12; i++) scale_tunes[i] -= 64;                              for (int i = 0; i < 12; i++) scale_tunes[i] -= 64;
1272                              AdjustScale((int8_t*) scale_tunes);                              AdjustScale((int8_t*) scale_tunes);
1273                                dmsg(3,("\t\t\tNew scale applied.\n"));
1274                              break;                              break;
1275                          }                          }
1276                      }                      }
# Line 1062  namespace LinuxSampler { namespace gig { Line 1315  namespace LinuxSampler { namespace gig {
1315      }      }
1316    
1317      /**      /**
1318       * Initialize the parameter sequence for the modulation destination given by       * Releases all voices on an engine channel. All voices will go into
1319       * by 'dst' with the constant value given by val.       * the release stage and thus it might take some time (e.g. dependant to
1320         * their envelope release time) until they actually die.
1321         *
1322         * @param pEngineChannel - engine channel on which all voices should be released
1323         * @param itReleaseEvent - event which caused this releasing of all voices
1324       */       */
1325      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {      void Engine::ReleaseAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itReleaseEvent) {
1326          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();          RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1327          float* m = &pSynthesisParameters[dst][0];          while (iuiKey) {
1328          for (int i = 0; i < maxsamples; i += 4) {              midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1329             m[i]   = val;              ++iuiKey;
1330             m[i+1] = val;              // append a 'release' event to the key's own event list
1331             m[i+2] = val;              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1332             m[i+3] = val;              if (itNewEvent) {
1333          }                  *itNewEvent = *itReleaseEvent; // copy original event (to the key's event list)
1334      }                  itNewEvent->Type = Event::type_release; // transform event type
1335                }
1336      float Engine::Volume() {              else dmsg(1,("Event pool emtpy!\n"));
         return GlobalVolume;  
     }  
   
     void Engine::Volume(float f) {  
         GlobalVolume = f;  
     }  
   
     uint Engine::Channels() {  
         return 2;  
     }  
   
     void Engine::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {  
         AudioChannel* pChannel = pAudioOutputDevice->Channel(AudioDeviceChannel);  
         if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));  
         switch (EngineAudioChannel) {  
             case 0: // left output channel  
                 pOutputLeft = pChannel->Buffer();  
                 AudioDeviceChannelLeft = AudioDeviceChannel;  
                 break;  
             case 1: // right output channel  
                 pOutputRight = pChannel->Buffer();  
                 AudioDeviceChannelRight = AudioDeviceChannel;  
                 break;  
             default:  
                 throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));  
1337          }          }
1338      }      }
1339    
1340      int Engine::OutputChannel(uint EngineAudioChannel) {      /**
1341          switch (EngineAudioChannel) {       * Kills all voices on an engine channel as soon as possible. Voices
1342              case 0: // left channel       * won't get into release state, their volume level will be ramped down
1343                  return AudioDeviceChannelLeft;       * as fast as possible.
1344              case 1: // right channel       *
1345                  return AudioDeviceChannelRight;       * @param pEngineChannel - engine channel on which all voices should be killed
1346              default:       * @param itKillEvent    - event which caused this killing of all voices
1347                  throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));       */
1348        void Engine::KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) {
1349            RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1350            RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();
1351            while (iuiKey != end) { // iterate through all active keys
1352                midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1353                ++iuiKey;
1354                RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
1355                RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
1356                for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
1357                    itVoice->Kill(itKillEvent);
1358                    --VoiceSpawnsLeft; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead
1359                }
1360          }          }
1361      }      }
1362    
# Line 1145  namespace LinuxSampler { namespace gig { Line 1389  namespace LinuxSampler { namespace gig {
1389      }      }
1390    
1391      String Engine::EngineName() {      String Engine::EngineName() {
1392          return "GigEngine";          return LS_GIG_ENGINE_NAME;
     }  
   
     String Engine::InstrumentFileName() {  
         return InstrumentFile;  
     }  
   
     int Engine::InstrumentIndex() {  
         return InstrumentIdx;  
     }  
   
     int Engine::InstrumentStatus() {  
         return InstrumentStat;  
1393      }      }
1394    
1395      String Engine::Description() {      String Engine::Description() {
# Line 1165  namespace LinuxSampler { namespace gig { Line 1397  namespace LinuxSampler { namespace gig {
1397      }      }
1398    
1399      String Engine::Version() {      String Engine::Version() {
1400          String s = "$Revision: 1.19 $";          String s = "$Revision: 1.52 $";
1401          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
1402      }      }
1403    

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

  ViewVC Help
Powered by ViewVC