/[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 554 by schoenebeck, Thu May 19 19:25:14 2005 UTC revision 1298 by iliev, Fri Aug 17 12:55:37 2007 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                              *   *   Copyright (C) 2005 - 2007 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 30  namespace LinuxSampler { namespace gig { Line 30  namespace LinuxSampler { namespace gig {
30          pEngine      = NULL;          pEngine      = NULL;
31          pInstrument  = NULL;          pInstrument  = NULL;
32          pEvents      = NULL; // we allocate when we retrieve the right Engine object          pEvents      = NULL; // we allocate when we retrieve the right Engine object
33          pCCEvents    = NULL; // we allocate when we retrieve the right Engine object          pEventQueue  = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);
         pEventQueue  = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);  
34          pActiveKeys  = new Pool<uint>(128);          pActiveKeys  = new Pool<uint>(128);
35          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
36              pMIDIKeyInfo[i].pActiveVoices  = NULL; // we allocate when we retrieve the right Engine object              pMIDIKeyInfo[i].pActiveVoices  = NULL; // we allocate when we retrieve the right Engine object
# Line 42  namespace LinuxSampler { namespace gig { Line 41  namespace LinuxSampler { namespace gig {
41              pMIDIKeyInfo[i].VoiceTheftsQueued = 0;              pMIDIKeyInfo[i].VoiceTheftsQueued = 0;
42              pMIDIKeyInfo[i].RoundRobinIndex = 0;              pMIDIKeyInfo[i].RoundRobinIndex = 0;
43          }          }
         for (uint i = 0; i < Event::destination_count; i++) {  
             pSynthesisEvents[i] = NULL; // we allocate when we retrieve the right Engine object  
         }  
44          InstrumentIdx  = -1;          InstrumentIdx  = -1;
45          InstrumentStat = -1;          InstrumentStat = -1;
46            pChannelLeft  = NULL;
47            pChannelRight = NULL;
48          AudioDeviceChannelLeft  = -1;          AudioDeviceChannelLeft  = -1;
49          AudioDeviceChannelRight = -1;          AudioDeviceChannelRight = -1;
50            pMidiInputPort = NULL;
51            midiChannel = midi_chan_all;
52            ResetControllers();
53            SoloMode       = false;
54            PortamentoMode = false;
55            PortamentoTime = CONFIG_PORTAMENTO_TIME_DEFAULT;
56      }      }
57    
58      EngineChannel::~EngineChannel() {      EngineChannel::~EngineChannel() {
# Line 57  namespace LinuxSampler { namespace gig { Line 61  namespace LinuxSampler { namespace gig {
61          if (pEventQueue) delete pEventQueue;          if (pEventQueue) delete pEventQueue;
62          if (pActiveKeys) delete pActiveKeys;          if (pActiveKeys) delete pActiveKeys;
63          if (pMIDIKeyInfo) delete[] pMIDIKeyInfo;          if (pMIDIKeyInfo) delete[] pMIDIKeyInfo;
64            RemoveAllFxSends();
65        }
66    
67        /**
68         * Implementation of virtual method from abstract EngineChannel interface.
69         * This method will periodically be polled (e.g. by the LSCP server) to
70         * check if some engine channel parameter has changed since the last
71         * StatusChanged() call.
72         *
73         * This method can also be used to mark the engine channel as changed
74         * from outside, e.g. by a MIDI input device. The optional argument
75         * \a nNewStatus can be used for this.
76         *
77         * TODO: This "poll method" is just a lazy solution and might be
78         *       replaced in future.
79         * @param bNewStatus - (optional, default: false) sets the new status flag
80         * @returns true if engine channel status has changed since last
81         *          StatusChanged() call
82         */
83        bool EngineChannel::StatusChanged(bool bNewStatus) {
84            bool b = bStatusChanged;
85            bStatusChanged = bNewStatus;
86            return b;
87        }
88    
89        void EngineChannel::Reset() {
90            if (pEngine) pEngine->DisableAndLock();
91            ResetInternal();
92            ResetControllers();
93            if (pEngine) {
94                pEngine->Enable();
95                pEngine->Reset();
96            }
97      }      }
98    
99      /**      /**
100       * This method is not thread safe!       * This method is not thread safe!
101       */       */
102      void EngineChannel::ResetInternal() {      void EngineChannel::ResetInternal() {
         Pitch               = 0;  
         SustainPedal        = false;  
         GlobalVolume        = 1.0;  
         GlobalPanLeft       = 1.0f;  
         GlobalPanRight      = 1.0f;  
103          CurrentKeyDimension = 0;          CurrentKeyDimension = 0;
104    
         ResetControllers();  
   
105          // reset key info          // reset key info
106          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
107              if (pMIDIKeyInfo[i].pActiveVoices)              if (pMIDIKeyInfo[i].pActiveVoices)
# Line 84  namespace LinuxSampler { namespace gig { Line 114  namespace LinuxSampler { namespace gig {
114              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();
115              pMIDIKeyInfo[i].VoiceTheftsQueued = 0;              pMIDIKeyInfo[i].VoiceTheftsQueued = 0;
116          }          }
117            SoloKey       = -1;    // no solo key active yet
118            PortamentoPos = -1.0f; // no portamento active yet
119    
120          // reset all key groups          // reset all key groups
121          std::map<uint,uint*>::iterator iter = ActiveKeyGroups.begin();          std::map<uint,uint*>::iterator iter = ActiveKeyGroups.begin();
# Line 96  namespace LinuxSampler { namespace gig { Line 128  namespace LinuxSampler { namespace gig {
128          pEventQueue->init();          pEventQueue->init();
129    
130          if (pEngine) pEngine->ResetInternal();          if (pEngine) pEngine->ResetInternal();
131    
132            // status of engine channel has changed, so set notify flag
133            bStatusChanged = true;
134      }      }
135    
136      LinuxSampler::Engine* EngineChannel::GetEngine() {      LinuxSampler::Engine* EngineChannel::GetEngine() {
# Line 124  namespace LinuxSampler { namespace gig { Line 159  namespace LinuxSampler { namespace gig {
159       * This method will then actually start to load the instrument and block       * This method will then actually start to load the instrument and block
160       * the calling thread until loading was completed.       * the calling thread until loading was completed.
161       *       *
      * @returns detailed description of the method call result  
162       * @see PrepareLoadInstrument()       * @see PrepareLoadInstrument()
163       */       */
164      void EngineChannel::LoadInstrument() {      void EngineChannel::LoadInstrument() {
165            ::gig::Instrument* oldInstrument = pInstrument;
         if (pEngine) pEngine->DisableAndLock();  
   
         ResetInternal();  
166    
167          // free old instrument          // free old instrument
168          if (pInstrument) {          if (oldInstrument) {
169              // give old instrument back to instrument manager              if (pEngine) {
170              Engine::instruments.HandBack(pInstrument, this);                  // make sure we don't trigger any new notes with the
171                    // old instrument
172                    ::gig::DimensionRegion** dimRegionsInUse = pEngine->ChangeInstrument(this, 0);
173    
174                    // give old instrument back to instrument manager, but
175                    // keep the dimension regions and samples that are in
176                    // use
177                    Engine::instruments.HandBackInstrument(oldInstrument, this, dimRegionsInUse);
178                } else {
179                    Engine::instruments.HandBack(oldInstrument, this);
180                }
181          }          }
182    
183          // delete all key groups          // delete all key groups
184          ActiveKeyGroups.clear();          ActiveKeyGroups.clear();
185    
186          // request gig instrument from instrument manager          // request gig instrument from instrument manager
187            ::gig::Instrument* newInstrument;
188          try {          try {
189              instrument_id_t instrid;              InstrumentManager::instrument_id_t instrid;
190              instrid.FileName    = InstrumentFile;              instrid.FileName  = InstrumentFile;
191              instrid.iInstrument = InstrumentIdx;              instrid.Index     = InstrumentIdx;
192              pInstrument = Engine::instruments.Borrow(instrid, this);              newInstrument = Engine::instruments.Borrow(instrid, this);
193              if (!pInstrument) {              if (!newInstrument) {
194                  InstrumentStat = -1;                  throw InstrumentManagerException("resource was not created");
                 dmsg(1,("no instrument loaded!!!\n"));  
                 exit(EXIT_FAILURE);  
195              }              }
196          }          }
197          catch (RIFF::Exception e) {          catch (RIFF::Exception e) {
198              InstrumentStat = -2;              InstrumentStat = -2;
199              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message;              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message;
200              throw LinuxSamplerException(msg);              throw Exception(msg);
201          }          }
202          catch (InstrumentResourceManagerException e) {          catch (InstrumentManagerException e) {
203              InstrumentStat = -3;              InstrumentStat = -3;
204              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message();              String msg = "gig::Engine error: Failed to load instrument, cause: " + e.Message();
205              throw LinuxSamplerException(msg);              throw Exception(msg);
206          }          }
207          catch (...) {          catch (...) {
208              InstrumentStat = -4;              InstrumentStat = -4;
209              throw LinuxSamplerException("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file.");              throw Exception("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file.");
210          }          }
211    
212          // rebuild ActiveKeyGroups map with key groups of current instrument          // rebuild ActiveKeyGroups map with key groups of current instrument
213          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())          for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion())
214              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;
215    
216          InstrumentIdxName = pInstrument->pInfo->Name;          InstrumentIdxName = newInstrument->pInfo->Name;
217          InstrumentStat = 100;          InstrumentStat = 100;
218    
219          // inform audio driver for the need of two channels          if (pEngine) pEngine->ChangeInstrument(this, newInstrument);
220          try {          else pInstrument = newInstrument;
221              if (pEngine && pEngine->pAudioOutputDevice)          
222                  pEngine->pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo          StatusChanged(true);
         }  
         catch (AudioOutputException e) {  
             String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();  
             throw LinuxSamplerException(msg);  
         }  
   
         if (pEngine) pEngine->Enable();  
223      }      }
224    
225      /**      /**
# Line 208  namespace LinuxSampler { namespace gig { Line 241  namespace LinuxSampler { namespace gig {
241      void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) {      void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) {
242          this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument())          this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument())
243          if (pEngine) pEngine->Enable();          if (pEngine) pEngine->Enable();
244            bStatusChanged = true; // status of engine has changed, so set notify flag
245      }      }
246    
247      /**      /**
# Line 219  namespace LinuxSampler { namespace gig { Line 253  namespace LinuxSampler { namespace gig {
253      void EngineChannel::OnResourceProgress(float fProgress) {      void EngineChannel::OnResourceProgress(float fProgress) {
254          this->InstrumentStat = int(fProgress * 100.0f);          this->InstrumentStat = int(fProgress * 100.0f);
255          dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat));          dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat));
256            bStatusChanged = true; // status of engine has changed, so set notify flag
257      }      }
258    
259      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {
# Line 228  namespace LinuxSampler { namespace gig { Line 263  namespace LinuxSampler { namespace gig {
263          }          }
264          pEngine = Engine::AcquireEngine(this, pAudioOut);          pEngine = Engine::AcquireEngine(this, pAudioOut);
265          ResetInternal();          ResetInternal();
266          pEvents   = new RTList<Event>(pEngine->pEventPool);          pEvents = new RTList<Event>(pEngine->pEventPool);
         pCCEvents = new RTList<Event>(pEngine->pEventPool);  
         for (uint i = 0; i < Event::destination_count; i++) {  
             pSynthesisEvents[i] = new RTList<Event>(pEngine->pEventPool);  
         }  
267          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
268              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);
269              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);
270          }          }
271          AudioDeviceChannelLeft  = 0;          AudioDeviceChannelLeft  = 0;
272          AudioDeviceChannelRight = 1;          AudioDeviceChannelRight = 1;
273          pOutputLeft             = pAudioOut->Channel(0)->Buffer();          if (fxSends.empty()) { // render directly into the AudioDevice's output buffers
274          pOutputRight            = pAudioOut->Channel(1)->Buffer();              pChannelLeft  = pAudioOut->Channel(AudioDeviceChannelLeft);
275                pChannelRight = pAudioOut->Channel(AudioDeviceChannelRight);
276            } else { // use local buffers for rendering and copy later
277                // ensure the local buffers have the correct size
278                if (pChannelLeft)  delete pChannelLeft;
279                if (pChannelRight) delete pChannelRight;
280                pChannelLeft  = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle());
281                pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle());
282            }
283            if (pEngine->EngineDisabled.GetUnsafe()) pEngine->Enable();
284            MidiInputPort::AddSysexListener(pEngine);
285      }      }
286    
287      void EngineChannel::DisconnectAudioOutputDevice() {      void EngineChannel::DisconnectAudioOutputDevice() {
# Line 250  namespace LinuxSampler { namespace gig { Line 291  namespace LinuxSampler { namespace gig {
291                  delete pEvents;                  delete pEvents;
292                  pEvents = NULL;                  pEvents = NULL;
293              }              }
             if (pCCEvents) {  
                 delete pCCEvents;  
                 pCCEvents = NULL;  
             }  
294              for (uint i = 0; i < 128; i++) {              for (uint i = 0; i < 128; i++) {
295                  if (pMIDIKeyInfo[i].pActiveVoices) {                  if (pMIDIKeyInfo[i].pActiveVoices) {
296                      delete pMIDIKeyInfo[i].pActiveVoices;                      delete pMIDIKeyInfo[i].pActiveVoices;
# Line 264  namespace LinuxSampler { namespace gig { Line 301  namespace LinuxSampler { namespace gig {
301                      pMIDIKeyInfo[i].pEvents = NULL;                      pMIDIKeyInfo[i].pEvents = NULL;
302                  }                  }
303              }              }
             for (uint i = 0; i < Event::destination_count; i++) {  
                 if (pSynthesisEvents[i]) {  
                     delete pSynthesisEvents[i];  
                     pSynthesisEvents[i] = NULL;  
                 }  
             }  
304              Engine* oldEngine = pEngine;              Engine* oldEngine = pEngine;
305              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;
306              pEngine = NULL;              pEngine = NULL;
307              Engine::FreeEngine(this, oldAudioDevice);              Engine::FreeEngine(this, oldAudioDevice);
308              AudioDeviceChannelLeft  = -1;              AudioDeviceChannelLeft  = -1;
309              AudioDeviceChannelRight = -1;              AudioDeviceChannelRight = -1;
310                if (!fxSends.empty()) { // free the local rendering buffers
311                    if (pChannelLeft)  delete pChannelLeft;
312                    if (pChannelRight) delete pChannelRight;
313                }
314                pChannelLeft  = NULL;
315                pChannelRight = NULL;
316          }          }
317      }      }
318    
319        AudioOutputDevice* EngineChannel::GetAudioOutputDevice() {
320            return (pEngine) ? pEngine->pAudioOutputDevice : NULL;
321        }
322    
323      void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {      void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {
324          if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet.");          if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet.");
325    
# Line 286  namespace LinuxSampler { namespace gig { Line 327  namespace LinuxSampler { namespace gig {
327          if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));          if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));
328          switch (EngineAudioChannel) {          switch (EngineAudioChannel) {
329              case 0: // left output channel              case 0: // left output channel
330                  pOutputLeft = pChannel->Buffer();                  if (fxSends.empty()) pChannelLeft = pChannel;
331                  AudioDeviceChannelLeft = AudioDeviceChannel;                  AudioDeviceChannelLeft = AudioDeviceChannel;
332                  break;                  break;
333              case 1: // right output channel              case 1: // right output channel
334                  pOutputRight = pChannel->Buffer();                  if (fxSends.empty()) pChannelRight = pChannel;
335                  AudioDeviceChannelRight = AudioDeviceChannel;                  AudioDeviceChannelRight = AudioDeviceChannel;
336                  break;                  break;
337              default:              default:
338                  throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));                  throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel));
339          }          }
340    
341            bStatusChanged = true;
342      }      }
343    
344      int EngineChannel::OutputChannel(uint EngineAudioChannel) {      int EngineChannel::OutputChannel(uint EngineAudioChannel) {
# Line 309  namespace LinuxSampler { namespace gig { Line 352  namespace LinuxSampler { namespace gig {
352          }          }
353      }      }
354    
355        void EngineChannel::Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) {
356            if (!pMidiPort || pMidiPort == this->pMidiInputPort) return;
357            DisconnectMidiInputPort();
358            this->pMidiInputPort = pMidiPort;
359            this->midiChannel    = MidiChannel;
360            pMidiPort->Connect(this, MidiChannel);
361        }
362    
363        void EngineChannel::DisconnectMidiInputPort() {
364            MidiInputPort* pOldPort = this->pMidiInputPort;
365            this->pMidiInputPort = NULL;
366            if (pOldPort) pOldPort->Disconnect(this);
367        }
368    
369        MidiInputPort* EngineChannel::GetMidiInputPort() {
370            return pMidiInputPort;
371        }
372    
373        midi_chan_t EngineChannel::MidiChannel() {
374            return midiChannel;
375        }
376    
377        FxSend* EngineChannel::AddFxSend(uint8_t MidiCtrl, String Name) throw (Exception) {
378            if (pEngine) pEngine->DisableAndLock();
379            FxSend* pFxSend = new FxSend(this, MidiCtrl, Name);
380            if (fxSends.empty()) {
381                if (pEngine && pEngine->pAudioOutputDevice) {
382                    AudioOutputDevice* pDevice = pEngine->pAudioOutputDevice;
383                    // create local render buffers
384                    pChannelLeft  = new AudioChannel(0, pDevice->MaxSamplesPerCycle());
385                    pChannelRight = new AudioChannel(1, pDevice->MaxSamplesPerCycle());
386                } else {
387                    // postpone local render buffer creation until audio device is assigned
388                    pChannelLeft  = NULL;
389                    pChannelRight = NULL;
390                }
391            }
392            fxSends.push_back(pFxSend);
393            if (pEngine) pEngine->Enable();
394            fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount());
395            
396            return pFxSend;
397        }
398    
399        FxSend* EngineChannel::GetFxSend(uint FxSendIndex) {
400            return (FxSendIndex < fxSends.size()) ? fxSends[FxSendIndex] : NULL;
401        }
402    
403        uint EngineChannel::GetFxSendCount() {
404            return fxSends.size();
405        }
406    
407        void EngineChannel::RemoveFxSend(FxSend* pFxSend) {
408            if (pEngine) pEngine->DisableAndLock();
409            for (
410                std::vector<FxSend*>::iterator iter = fxSends.begin();
411                iter != fxSends.end(); iter++
412            ) {
413                if (*iter == pFxSend) {
414                    delete pFxSend;
415                    fxSends.erase(iter);
416                    if (fxSends.empty()) {
417                        // destroy local render buffers
418                        if (pChannelLeft)  delete pChannelLeft;
419                        if (pChannelRight) delete pChannelRight;
420                        // fallback to render directly into AudioOutputDevice's buffers
421                        if (pEngine && pEngine->pAudioOutputDevice) {
422                            pChannelLeft  = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft);
423                            pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight);
424                        } else { // we update the pointers later
425                            pChannelLeft  = NULL;
426                            pChannelRight = NULL;
427                        }
428                    }
429                    break;
430                }
431            }
432            if (pEngine) pEngine->Enable();
433            fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount());
434        }
435    
436      /**      /**
437       *  Will be called by the MIDIIn Thread to let the audio thread trigger a new       *  Will be called by the MIDIIn Thread to let the audio thread trigger a new
438       *  voice for the given key.       *  voice for the given key. This method is meant for real time rendering,
439         *  that is an event will immediately be created with the current system
440         *  time as time stamp.
441       *       *
442       *  @param Key      - MIDI key number of the triggered key       *  @param Key      - MIDI key number of the triggered key
443       *  @param Velocity - MIDI velocity value of the triggered key       *  @param Velocity - MIDI velocity value of the triggered key
# Line 329  namespace LinuxSampler { namespace gig { Line 455  namespace LinuxSampler { namespace gig {
455      }      }
456    
457      /**      /**
458         *  Will be called by the MIDIIn Thread to let the audio thread trigger a new
459         *  voice for the given key. This method is meant for offline rendering
460         *  and / or for cases where the exact position of the event in the current
461         *  audio fragment is already known.
462         *
463         *  @param Key         - MIDI key number of the triggered key
464         *  @param Velocity    - MIDI velocity value of the triggered key
465         *  @param FragmentPos - sample point position in the current audio
466         *                       fragment to which this event belongs to
467         */
468        void EngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) {
469            if (FragmentPos < 0) {
470                dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!"));
471            }
472            else if (pEngine) {
473                Event event               = pEngine->pEventGenerator->CreateEvent(FragmentPos);
474                event.Type                = Event::type_note_on;
475                event.Param.Note.Key      = Key;
476                event.Param.Note.Velocity = Velocity;
477                event.pEngineChannel      = this;
478                if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
479                else dmsg(1,("EngineChannel: Input event queue full!"));
480            }
481        }
482    
483        /**
484       *  Will be called by the MIDIIn Thread to signal the audio thread to release       *  Will be called by the MIDIIn Thread to signal the audio thread to release
485       *  voice(s) on the given key.       *  voice(s) on the given key. This method is meant for real time rendering,
486         *  that is an event will immediately be created with the current system
487         *  time as time stamp.
488       *       *
489       *  @param Key      - MIDI key number of the released key       *  @param Key      - MIDI key number of the released key
490       *  @param Velocity - MIDI release velocity value of the released key       *  @param Velocity - MIDI release velocity value of the released key
# Line 348  namespace LinuxSampler { namespace gig { Line 502  namespace LinuxSampler { namespace gig {
502      }      }
503    
504      /**      /**
505         *  Will be called by the MIDIIn Thread to signal the audio thread to release
506         *  voice(s) on the given key. This method is meant for offline rendering
507         *  and / or for cases where the exact position of the event in the current
508         *  audio fragment is already known.
509         *
510         *  @param Key         - MIDI key number of the released key
511         *  @param Velocity    - MIDI release velocity value of the released key
512         *  @param FragmentPos - sample point position in the current audio
513         *                       fragment to which this event belongs to
514         */
515        void EngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) {
516            if (FragmentPos < 0) {
517                dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!"));
518            }
519            else if (pEngine) {
520                Event event               = pEngine->pEventGenerator->CreateEvent(FragmentPos);
521                event.Type                = Event::type_note_off;
522                event.Param.Note.Key      = Key;
523                event.Param.Note.Velocity = Velocity;
524                event.pEngineChannel      = this;
525                if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
526                else dmsg(1,("EngineChannel: Input event queue full!"));
527            }
528        }
529    
530        /**
531       *  Will be called by the MIDIIn Thread to signal the audio thread to change       *  Will be called by the MIDIIn Thread to signal the audio thread to change
532       *  the pitch value for all voices.       *  the pitch value for all voices. This method is meant for real time
533         *  rendering, that is an event will immediately be created with the
534         *  current system time as time stamp.
535       *       *
536       *  @param Pitch - MIDI pitch value (-8192 ... +8191)       *  @param Pitch - MIDI pitch value (-8192 ... +8191)
537       */       */
# Line 365  namespace LinuxSampler { namespace gig { Line 547  namespace LinuxSampler { namespace gig {
547      }      }
548    
549      /**      /**
550         *  Will be called by the MIDIIn Thread to signal the audio thread to change
551         *  the pitch value for all voices. This method is meant for offline
552         *  rendering and / or for cases where the exact position of the event in
553         *  the current audio fragment is already known.
554         *
555         *  @param Pitch       - MIDI pitch value (-8192 ... +8191)
556         *  @param FragmentPos - sample point position in the current audio
557         *                       fragment to which this event belongs to
558         */
559        void EngineChannel::SendPitchbend(int Pitch, int32_t FragmentPos) {
560            if (FragmentPos < 0) {
561                dmsg(1,("EngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!"));
562            }
563            else if (pEngine) {
564                Event event             = pEngine->pEventGenerator->CreateEvent(FragmentPos);
565                event.Type              = Event::type_pitchbend;
566                event.Param.Pitch.Pitch = Pitch;
567                event.pEngineChannel    = this;
568                if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
569                else dmsg(1,("EngineChannel: Input event queue full!"));
570            }
571        }
572    
573        /**
574       *  Will be called by the MIDIIn Thread to signal the audio thread that a       *  Will be called by the MIDIIn Thread to signal the audio thread that a
575       *  continuous controller value has changed.       *  continuous controller value has changed. This method is meant for real
576         *  time rendering, that is an event will immediately be created with the
577         *  current system time as time stamp.
578       *       *
579       *  @param Controller - MIDI controller number of the occured control change       *  @param Controller - MIDI controller number of the occured control change
580       *  @param Value      - value of the control change       *  @param Value      - value of the control change
# Line 383  namespace LinuxSampler { namespace gig { Line 591  namespace LinuxSampler { namespace gig {
591          }          }
592      }      }
593    
594        /**
595         *  Will be called by the MIDIIn Thread to signal the audio thread that a
596         *  continuous controller value has changed. This method is meant for
597         *  offline rendering and / or for cases where the exact position of the
598         *  event in the current audio fragment is already known.
599         *
600         *  @param Controller  - MIDI controller number of the occured control change
601         *  @param Value       - value of the control change
602         *  @param FragmentPos - sample point position in the current audio
603         *                       fragment to which this event belongs to
604         */
605        void EngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos) {
606            if (FragmentPos < 0) {
607                dmsg(1,("EngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!"));
608            }
609            else if (pEngine) {
610                Event event               = pEngine->pEventGenerator->CreateEvent(FragmentPos);
611                event.Type                = Event::type_control_change;
612                event.Param.CC.Controller = Controller;
613                event.Param.CC.Value      = Value;
614                event.pEngineChannel      = this;
615                if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
616                else dmsg(1,("EngineChannel: Input event queue full!"));
617            }
618        }
619    
620      void EngineChannel::ClearEventLists() {      void EngineChannel::ClearEventLists() {
621          pEvents->clear();          pEvents->clear();
         pCCEvents->clear();  
         for (uint i = 0; i < Event::destination_count; i++) {  
             pSynthesisEvents[i]->clear();  
         }  
622          // empty MIDI key specific event lists          // empty MIDI key specific event lists
623          {          {
624              RTList<uint>::Iterator iuiKey = pActiveKeys->first();              RTList<uint>::Iterator iuiKey = pActiveKeys->first();
# Line 400  namespace LinuxSampler { namespace gig { Line 630  namespace LinuxSampler { namespace gig {
630      }      }
631    
632      void EngineChannel::ResetControllers() {      void EngineChannel::ResetControllers() {
633            Pitch          = 0;
634            SustainPedal   = false;
635            SostenutoPedal = false;
636            GlobalVolume   = 1.0f;
637            MidiVolume     = 1.0;
638            GlobalPanLeft  = 1.0f;
639            GlobalPanRight = 1.0f;
640            GlobalTranspose = 0;
641          // set all MIDI controller values to zero          // set all MIDI controller values to zero
642          memset(ControllerTable, 0x00, 128);          memset(ControllerTable, 0x00, 129);
643            // reset all FX Send levels
644            for (
645                std::vector<FxSend*>::iterator iter = fxSends.begin();
646                iter != fxSends.end(); iter++
647            ) {
648                (*iter)->Reset();
649            }
650      }      }
651    
652      /**      /**
# Line 418  namespace LinuxSampler { namespace gig { Line 663  namespace LinuxSampler { namespace gig {
663       *                  current audio cycle       *                  current audio cycle
664       */       */
665      void EngineChannel::ImportEvents(uint Samples) {      void EngineChannel::ImportEvents(uint Samples) {
666          RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();          RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
667          Event* pEvent;          Event* pEvent;
668          while (true) {          while (true) {
669              // get next event from input event queue              // get next event from input event queue
# Line 440  namespace LinuxSampler { namespace gig { Line 685  namespace LinuxSampler { namespace gig {
685          eventQueueReader.free(); // free all copied events from input queue          eventQueueReader.free(); // free all copied events from input queue
686      }      }
687    
688        void EngineChannel::RemoveAllFxSends() {
689            if (pEngine) pEngine->DisableAndLock();
690            if (!fxSends.empty()) { // free local render buffers
691                if (pChannelLeft) {
692                    delete pChannelLeft;
693                    if (pEngine && pEngine->pAudioOutputDevice) {
694                        // fallback to render directly to the AudioOutputDevice's buffer
695                        pChannelLeft = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft);
696                    } else pChannelLeft = NULL;
697                }
698                if (pChannelRight) {
699                    delete pChannelRight;
700                    if (pEngine && pEngine->pAudioOutputDevice) {
701                        // fallback to render directly to the AudioOutputDevice's buffer
702                        pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight);
703                    } else pChannelRight = NULL;
704                }
705            }
706            for (int i = 0; i < fxSends.size(); i++) delete fxSends[i];
707            fxSends.clear();
708            if (pEngine) pEngine->Enable();
709        }
710    
711      float EngineChannel::Volume() {      float EngineChannel::Volume() {
712          return GlobalVolume;          return GlobalVolume;
713      }      }
714    
715      void EngineChannel::Volume(float f) {      void EngineChannel::Volume(float f) {
716          GlobalVolume = f;          GlobalVolume = f;
717            bStatusChanged = true; // status of engine channel has changed, so set notify flag
718      }      }
719    
720      uint EngineChannel::Channels() {      uint EngineChannel::Channels() {
# Line 471  namespace LinuxSampler { namespace gig { Line 740  namespace LinuxSampler { namespace gig {
740      String EngineChannel::EngineName() {      String EngineChannel::EngineName() {
741          return LS_GIG_ENGINE_NAME;          return LS_GIG_ENGINE_NAME;
742      }      }
743        
744  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.554  
changed lines
  Added in v.1298

  ViewVC Help
Powered by ViewVC