/[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 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC revision 438 by persson, Wed Mar 9 22:12:15 2005 UTC
# Line 23  Line 23 
23    
24  #include "EngineChannel.h"  #include "EngineChannel.h"
25    
26  namespace LinuxSampler { namespace gig {      namespace LinuxSampler { namespace gig {
27    
28      EngineChannel::EngineChannel() {      EngineChannel::EngineChannel() {
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          pEventQueue  = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0);                  pEventQueue  = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0);
33          pActiveKeys  = new Pool<uint>(128);          pActiveKeys  = new Pool<uint>(128);
34          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
35              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 37  namespace LinuxSampler { namespace gig { Line 37  namespace LinuxSampler { namespace gig {
37              pMIDIKeyInfo[i].Active         = false;              pMIDIKeyInfo[i].Active         = false;
38              pMIDIKeyInfo[i].ReleaseTrigger = false;              pMIDIKeyInfo[i].ReleaseTrigger = false;
39              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
40                pMIDIKeyInfo[i].RoundRobinIndex = 0;
41          }          }
42          InstrumentIdx  = -1;          InstrumentIdx  = -1;
43          InstrumentStat = -1;          InstrumentStat = -1;
# Line 68  namespace LinuxSampler { namespace gig { Line 69  namespace LinuxSampler { namespace gig {
69          Pitch               = 0;          Pitch               = 0;
70          SustainPedal        = false;          SustainPedal        = false;
71          GlobalVolume        = 1.0;          GlobalVolume        = 1.0;
72            GlobalPanLeft       = 1.0f;
73            GlobalPanRight      = 1.0f;
74          CurrentKeyDimension = 0;          CurrentKeyDimension = 0;
75    
76          // set all MIDI controller values to zero          // set all MIDI controller values to zero
77          memset(ControllerTable, 0x00, 128);          memset(ControllerTable, 0x00, 128);
78    
79            // reset voice stealing parameters
80            itLastStolenVoice = RTList<Voice>::Iterator();
81            iuiLastStolenKey  = RTList<uint>::Iterator();
82    
83          // reset key info          // reset key info
84          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
85              if (pMIDIKeyInfo[i].pActiveVoices)              if (pMIDIKeyInfo[i].pActiveVoices)
# Line 98  namespace LinuxSampler { namespace gig { Line 105  namespace LinuxSampler { namespace gig {
105          if (pEngine) pEngine->ResetInternal();          if (pEngine) pEngine->ResetInternal();
106      }      }
107    
     int EngineChannel::RenderAudio(uint Samples) {  
         return (pEngine) ? pEngine->RenderAudio(this, Samples) : 0;  
     }  
   
108      LinuxSampler::Engine* EngineChannel::GetEngine() {      LinuxSampler::Engine* EngineChannel::GetEngine() {
109          return pEngine;          return pEngine;
110      }      }
# Line 134  namespace LinuxSampler { namespace gig { Line 137  namespace LinuxSampler { namespace gig {
137      void EngineChannel::LoadInstrument() {      void EngineChannel::LoadInstrument() {
138    
139          if (pEngine) pEngine->DisableAndLock();          if (pEngine) pEngine->DisableAndLock();
140            
141          ResetInternal();          ResetInternal();
142            
143          // free old instrument          // free old instrument
144          if (pInstrument) {          if (pInstrument) {
145              // give old instrument back to instrument manager              // give old instrument back to instrument manager
# Line 214  namespace LinuxSampler { namespace gig { Line 217  namespace LinuxSampler { namespace gig {
217          if (pEngine) pEngine->Enable();          if (pEngine) pEngine->Enable();
218      }      }
219    
220      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {              void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {
221            if (pEngine && pEngine->pAudioOutputDevice != pAudioOut) {
222                DisconnectAudioOutputDevice();
223            }
224          pEngine = Engine::AcquireEngine(this, pAudioOut);          pEngine = Engine::AcquireEngine(this, pAudioOut);
225          ResetInternal();                  ResetInternal();
226          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
227              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);              pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool);
228              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);              pMIDIKeyInfo[i].pEvents       = new RTList<Event>(pEngine->pEventPool);
# Line 231  namespace LinuxSampler { namespace gig { Line 237  namespace LinuxSampler { namespace gig {
237          if (pEngine) { // if clause to prevent disconnect loops          if (pEngine) { // if clause to prevent disconnect loops
238              ResetInternal();              ResetInternal();
239              for (uint i = 0; i < 128; i++) {              for (uint i = 0; i < 128; i++) {
240                  if (pMIDIKeyInfo[i].pActiveVoices) delete pMIDIKeyInfo[i].pActiveVoices;                  if (pMIDIKeyInfo[i].pActiveVoices) {
241                  if (pMIDIKeyInfo[i].pEvents)       delete pMIDIKeyInfo[i].pEvents;                      delete pMIDIKeyInfo[i].pActiveVoices;
242                        pMIDIKeyInfo[i].pActiveVoices = NULL;
243                    }
244                    if (pMIDIKeyInfo[i].pEvents) {
245                        delete pMIDIKeyInfo[i].pEvents;
246                        pMIDIKeyInfo[i].pEvents = NULL;
247                    }
248              }              }
249              Engine* oldEngine = pEngine;              Engine* oldEngine = pEngine;
250              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;              AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice;
# Line 240  namespace LinuxSampler { namespace gig { Line 252  namespace LinuxSampler { namespace gig {
252              Engine::FreeEngine(this, oldAudioDevice);              Engine::FreeEngine(this, oldAudioDevice);
253              AudioDeviceChannelLeft  = -1;              AudioDeviceChannelLeft  = -1;
254              AudioDeviceChannelRight = -1;              AudioDeviceChannelRight = -1;
             oldAudioDevice->Disconnect(this);  
255          }          }
256      }      }
257    
258      void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {      void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) {
259          if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet.");          if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet.");
260            
261          AudioChannel* pChannel = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannel);          AudioChannel* pChannel = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannel);
262          if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));          if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel));
263          switch (EngineAudioChannel) {          switch (EngineAudioChannel) {
# Line 287  namespace LinuxSampler { namespace gig { Line 298  namespace LinuxSampler { namespace gig {
298              event.Type                = Event::type_note_on;              event.Type                = Event::type_note_on;
299              event.Param.Note.Key      = Key;              event.Param.Note.Key      = Key;
300              event.Param.Note.Velocity = Velocity;              event.Param.Note.Velocity = Velocity;
301                event.pEngineChannel      = this;
302              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
303              else dmsg(1,("Engine: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
304          }          }
305      }      }
306    
# Line 305  namespace LinuxSampler { namespace gig { Line 317  namespace LinuxSampler { namespace gig {
317              event.Type                = Event::type_note_off;              event.Type                = Event::type_note_off;
318              event.Param.Note.Key      = Key;              event.Param.Note.Key      = Key;
319              event.Param.Note.Velocity = Velocity;              event.Param.Note.Velocity = Velocity;
320                event.pEngineChannel      = this;
321              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
322              else dmsg(1,("Engine: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
323          }          }
324      }      }
325    
# Line 317  namespace LinuxSampler { namespace gig { Line 330  namespace LinuxSampler { namespace gig {
330       *  @param Pitch - MIDI pitch value (-8192 ... +8191)       *  @param Pitch - MIDI pitch value (-8192 ... +8191)
331       */       */
332      void EngineChannel::SendPitchbend(int Pitch) {      void EngineChannel::SendPitchbend(int Pitch) {
333          if (pEngine) {                  if (pEngine) {
334              Event event             = pEngine->pEventGenerator->CreateEvent();              Event event             = pEngine->pEventGenerator->CreateEvent();
335              event.Type              = Event::type_pitchbend;              event.Type              = Event::type_pitchbend;
336              event.Param.Pitch.Pitch = Pitch;              event.Param.Pitch.Pitch = Pitch;
337                event.pEngineChannel    = this;
338              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
339              else dmsg(1,("Engine: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
340          }          }
341      }      }
342    
# Line 339  namespace LinuxSampler { namespace gig { Line 353  namespace LinuxSampler { namespace gig {
353              event.Type                = Event::type_control_change;              event.Type                = Event::type_control_change;
354              event.Param.CC.Controller = Controller;              event.Param.CC.Controller = Controller;
355              event.Param.CC.Value      = Value;              event.Param.CC.Value      = Value;
356                event.pEngineChannel      = this;
357              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);              if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event);
358              else dmsg(1,("Engine: Input event queue full!"));              else dmsg(1,("EngineChannel: Input event queue full!"));
359          }          }
360      }      }
361    
# Line 370  namespace LinuxSampler { namespace gig { Line 385  namespace LinuxSampler { namespace gig {
385    
386      int EngineChannel::InstrumentStatus() {      int EngineChannel::InstrumentStatus() {
387          return InstrumentStat;          return InstrumentStat;
388      }          }
389    
390  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC