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

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

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

revision 438 by persson, Wed Mar 9 22:12:15 2005 UTC revision 473 by schoenebeck, Thu Mar 17 20:13:08 2005 UTC
# Line 29  namespace LinuxSampler { namespace gig { Line 29  namespace LinuxSampler { namespace gig {
29          pMIDIKeyInfo = new midi_key_info_t[128];          pMIDIKeyInfo = new midi_key_info_t[128];
30          pEngine      = NULL;          pEngine      = NULL;
31          pInstrument  = NULL;          pInstrument  = NULL;
32            pEvents      = NULL; // we allocate when we retrieve the right Engine object
33            pCCEvents    = NULL; // we allocate when we retrieve the right Engine object
34          pEventQueue  = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0);          pEventQueue  = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0);
35          pActiveKeys  = new Pool<uint>(128);          pActiveKeys  = new Pool<uint>(128);
36          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
# Line 37  namespace LinuxSampler { namespace gig { Line 39  namespace LinuxSampler { namespace gig {
39              pMIDIKeyInfo[i].Active         = false;              pMIDIKeyInfo[i].Active         = false;
40              pMIDIKeyInfo[i].ReleaseTrigger = false;              pMIDIKeyInfo[i].ReleaseTrigger = false;
41              pMIDIKeyInfo[i].pEvents        = NULL; // we allocate when we retrieve the right Engine object              pMIDIKeyInfo[i].pEvents        = NULL; // we allocate when we retrieve the right Engine object
42                pMIDIKeyInfo[i].VoiceTheftsQueued = 0;
43              pMIDIKeyInfo[i].RoundRobinIndex = 0;              pMIDIKeyInfo[i].RoundRobinIndex = 0;
44          }          }
45            for (uint i = 0; i < Event::destination_count; i++) {
46                pSynthesisEvents[i] = NULL; // we allocate when we retrieve the right Engine object
47            }
48          InstrumentIdx  = -1;          InstrumentIdx  = -1;
49          InstrumentStat = -1;          InstrumentStat = -1;
50          AudioDeviceChannelLeft  = -1;          AudioDeviceChannelLeft  = -1;
# Line 46  namespace LinuxSampler { namespace gig { Line 52  namespace LinuxSampler { namespace gig {
52      }      }
53    
54      EngineChannel::~EngineChannel() {      EngineChannel::~EngineChannel() {
55            DisconnectAudioOutputDevice();
56          if (pInstrument) Engine::instruments.HandBack(pInstrument, this);          if (pInstrument) Engine::instruments.HandBack(pInstrument, this);
         for (uint i = 0; i < 128; i++) {  
             if (pMIDIKeyInfo[i].pActiveVoices) {  
                 pMIDIKeyInfo[i].pActiveVoices->clear();  
                 delete pMIDIKeyInfo[i].pActiveVoices;  
             }  
             if (pMIDIKeyInfo[i].pEvents) {  
                 pMIDIKeyInfo[i].pEvents->clear();  
                 delete pMIDIKeyInfo[i].pEvents;  
             }  
         }  
57          if (pEventQueue) delete pEventQueue;          if (pEventQueue) delete pEventQueue;
58          if (pActiveKeys) delete pActiveKeys;          if (pActiveKeys) delete pActiveKeys;
59          if (pMIDIKeyInfo) delete[] pMIDIKeyInfo;          if (pMIDIKeyInfo) delete[] pMIDIKeyInfo;
# Line 73  namespace LinuxSampler { namespace gig { Line 70  namespace LinuxSampler { namespace gig {
70          GlobalPanRight      = 1.0f;          GlobalPanRight      = 1.0f;
71          CurrentKeyDimension = 0;          CurrentKeyDimension = 0;
72    
73          // set all MIDI controller values to zero          ResetControllers();
         memset(ControllerTable, 0x00, 128);  
   
         // reset voice stealing parameters  
         itLastStolenVoice = RTList<Voice>::Iterator();  
         iuiLastStolenKey  = RTList<uint>::Iterator();  
74    
75          // reset key info          // reset key info
76          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
# Line 90  namespace LinuxSampler { namespace gig { Line 82  namespace LinuxSampler { namespace gig {
82              pMIDIKeyInfo[i].Active         = false;              pMIDIKeyInfo[i].Active         = false;
83              pMIDIKeyInfo[i].ReleaseTrigger = false;              pMIDIKeyInfo[i].ReleaseTrigger = false;
84              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();
85                pMIDIKeyInfo[i].VoiceTheftsQueued = 0;
86          }          }
87    
88          // reset all key groups          // reset all key groups
# Line 218  namespace LinuxSampler { namespace gig { Line 211  namespace LinuxSampler { namespace gig {
211      }      }
212    
213      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {
214          if (pEngine && pEngine->pAudioOutputDevice != pAudioOut) {          if (pEngine) {
215                if (pEngine->pAudioOutputDevice == pAudioOut) return;
216              DisconnectAudioOutputDevice();              DisconnectAudioOutputDevice();
217          }          }
218          pEngine = Engine::AcquireEngine(this, pAudioOut);          pEngine = Engine::AcquireEngine(this, pAudioOut);
219          ResetInternal();          ResetInternal();
220            pEvents   = new RTList<Event>(pEngine->pEventPool);
221            pCCEvents = new RTList<Event>(pEngine->pEventPool);
222            for (uint i = 0; i < Event::destination_count; i++) {
223                pSynthesisEvents[i] = new RTList<Event>(pEngine->pEventPool);
224            }
225          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
226              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);
227              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);
# Line 236  namespace LinuxSampler { namespace gig { Line 235  namespace LinuxSampler { namespace gig {
235      void EngineChannel::DisconnectAudioOutputDevice() {      void EngineChannel::DisconnectAudioOutputDevice() {
236          if (pEngine) { // if clause to prevent disconnect loops          if (pEngine) { // if clause to prevent disconnect loops
237              ResetInternal();              ResetInternal();
238                if (pEvents) {
239                    delete pEvents;
240                    pEvents = NULL;
241                }
242                if (pCCEvents) {
243                    delete pCCEvents;
244                    pCCEvents = NULL;
245                }
246              for (uint i = 0; i < 128; i++) {              for (uint i = 0; i < 128; i++) {
247                  if (pMIDIKeyInfo[i].pActiveVoices) {                  if (pMIDIKeyInfo[i].pActiveVoices) {
248                      delete pMIDIKeyInfo[i].pActiveVoices;                      delete pMIDIKeyInfo[i].pActiveVoices;
# Line 246  namespace LinuxSampler { namespace gig { Line 253  namespace LinuxSampler { namespace gig {
253                      pMIDIKeyInfo[i].pEvents = NULL;                      pMIDIKeyInfo[i].pEvents = NULL;
254                  }                  }
255              }              }
256                for (uint i = 0; i < Event::destination_count; i++) {
257                    if (pSynthesisEvents[i]) {
258                        delete pSynthesisEvents[i];
259                        pSynthesisEvents[i] = NULL;
260                    }
261                }
262              Engine* oldEngine = pEngine;              Engine* oldEngine = pEngine;
263              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;
264              pEngine = NULL;              pEngine = NULL;
# Line 359  namespace LinuxSampler { namespace gig { Line 372  namespace LinuxSampler { namespace gig {
372          }          }
373      }      }
374    
375        void EngineChannel::ClearEventLists() {
376            pEvents->clear();
377            pCCEvents->clear();
378            for (uint i = 0; i < Event::destination_count; i++) {
379                pSynthesisEvents[i]->clear();
380            }
381            // empty MIDI key specific event lists
382            {
383                RTList<uint>::Iterator iuiKey = pActiveKeys->first();
384                RTList<uint>::Iterator end    = pActiveKeys->end();
385                for(; iuiKey != end; ++iuiKey) {
386                    pMIDIKeyInfo[*iuiKey].pEvents->clear(); // free all events on the key
387                }
388            }
389        }
390    
391        void EngineChannel::ResetControllers() {
392            // set all MIDI controller values to zero
393            memset(ControllerTable, 0x00, 128);
394        }
395    
396        /**
397         * Copy all events from the engine channel's input event queue buffer to
398         * the internal event list. This will be done at the beginning of each
399         * audio cycle (that is each RenderAudio() call) to distinguish all
400         * events which have to be processed in the current audio cycle. Each
401         * EngineChannel has it's own input event queue for the common channel
402         * specific events (like NoteOn, NoteOff and ControlChange events).
403         * Beside that, the engine also has a input event queue for global
404         * events (usually SysEx messages).
405         *
406         * @param Samples - number of sample points to be processed in the
407         *                  current audio cycle
408         */
409        void EngineChannel::ImportEvents(uint Samples) {
410            RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
411            Event* pEvent;
412            while (true) {
413                // get next event from input event queue
414                if (!(pEvent = eventQueueReader.pop())) break;
415                // if younger event reached, ignore that and all subsequent ones for now
416                if (pEvent->FragmentPos() >= Samples) {
417                    eventQueueReader--;
418                    dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples));
419                    pEvent->ResetFragmentPos();
420                    break;
421                }
422                // copy event to internal event list
423                if (pEvents->poolIsEmpty()) {
424                    dmsg(1,("Event pool emtpy!\n"));
425                    break;
426                }
427                *pEvents->allocAppend() = *pEvent;
428            }
429            eventQueueReader.free(); // free all copied events from input queue
430        }
431    
432      float EngineChannel::Volume() {      float EngineChannel::Volume() {
433          return GlobalVolume;          return GlobalVolume;
434      }      }

Legend:
Removed from v.438  
changed lines
  Added in v.473

  ViewVC Help
Powered by ViewVC