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

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

  ViewVC Help
Powered by ViewVC