/[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 460 by schoenebeck, Mon Mar 14 22:35:44 2005 UTC revision 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 31  namespace LinuxSampler { namespace gig { Line 31  namespace LinuxSampler { namespace gig {
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          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>(CONFIG_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++) {
37              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 39  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++) {          for (uint i = 0; i < Event::destination_count; i++) {
# Line 48  namespace LinuxSampler { namespace gig { Line 49  namespace LinuxSampler { namespace gig {
49          InstrumentStat = -1;          InstrumentStat = -1;
50          AudioDeviceChannelLeft  = -1;          AudioDeviceChannelLeft  = -1;
51          AudioDeviceChannelRight = -1;          AudioDeviceChannelRight = -1;
52            pMidiInputPort = NULL;
53            midiChannel = midi_chan_all;
54            ResetControllers();
55      }      }
56    
57      EngineChannel::~EngineChannel() {      EngineChannel::~EngineChannel() {
# Line 59  namespace LinuxSampler { namespace gig { Line 63  namespace LinuxSampler { namespace gig {
63      }      }
64    
65      /**      /**
66         * Implementation of virtual method from abstract EngineChannel interface.
67         * This method will periodically be polled (e.g. by the LSCP server) to
68         * check if some engine channel parameter has changed since the last
69         * StatusChanged() call.
70         *
71         * This method can also be used to mark the engine channel as changed
72         * from outside, e.g. by a MIDI input device. The optional argument
73         * \a nNewStatus can be used for this.
74         *
75         * TODO: This "poll method" is just a lazy solution and might be
76         *       replaced in future.
77         * @param bNewStatus - (optional, default: false) sets the new status flag
78         * @returns true if engine channel status has changed since last
79         *          StatusChanged() call
80         */
81        bool EngineChannel::StatusChanged(bool bNewStatus) {
82            bool b = bStatusChanged;
83            bStatusChanged = bNewStatus;
84            return b;
85        }
86    
87        void EngineChannel::Reset() {
88            if (pEngine) pEngine->DisableAndLock();
89            ResetInternal();
90            ResetControllers();
91            if (pEngine) {
92                pEngine->Enable();
93                pEngine->Reset();
94            }
95        }
96    
97        /**
98       * This method is not thread safe!       * This method is not thread safe!
99       */       */
100      void EngineChannel::ResetInternal() {      void EngineChannel::ResetInternal() {
         Pitch               = 0;  
         SustainPedal        = false;  
         GlobalVolume        = 1.0;  
         GlobalPanLeft       = 1.0f;  
         GlobalPanRight      = 1.0f;  
101          CurrentKeyDimension = 0;          CurrentKeyDimension = 0;
102    
         // set all MIDI controller values to zero  
         memset(ControllerTable, 0x00, 128);  
   
103          // reset key info          // reset key info
104          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
105              if (pMIDIKeyInfo[i].pActiveVoices)              if (pMIDIKeyInfo[i].pActiveVoices)
# Line 82  namespace LinuxSampler { namespace gig { Line 110  namespace LinuxSampler { namespace gig {
110              pMIDIKeyInfo[i].Active         = false;              pMIDIKeyInfo[i].Active         = false;
111              pMIDIKeyInfo[i].ReleaseTrigger = false;              pMIDIKeyInfo[i].ReleaseTrigger = false;
112              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();              pMIDIKeyInfo[i].itSelf         = Pool<uint>::Iterator();
113                pMIDIKeyInfo[i].VoiceTheftsQueued = 0;
114          }          }
115    
116          // reset all key groups          // reset all key groups
# Line 95  namespace LinuxSampler { namespace gig { Line 124  namespace LinuxSampler { namespace gig {
124          pEventQueue->init();          pEventQueue->init();
125    
126          if (pEngine) pEngine->ResetInternal();          if (pEngine) pEngine->ResetInternal();
127    
128            // status of engine channel has changed, so set notify flag
129            bStatusChanged = true;
130      }      }
131    
132      LinuxSampler::Engine* EngineChannel::GetEngine() {      LinuxSampler::Engine* EngineChannel::GetEngine() {
# Line 190  namespace LinuxSampler { namespace gig { Line 222  namespace LinuxSampler { namespace gig {
222    
223      /**      /**
224       * Will be called by the InstrumentResourceManager when the instrument       * Will be called by the InstrumentResourceManager when the instrument
225       * we are currently using in this engine is going to be updated, so we       * we are currently using on this EngineChannel is going to be updated,
226       * can stop playback before that happens.       * so we can stop playback before that happens.
227       */       */
228      void EngineChannel::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) {      void EngineChannel::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) {
229          dmsg(3,("gig::Engine: Received instrument update message.\n"));          dmsg(3,("gig::Engine: Received instrument update message.\n"));
# Line 207  namespace LinuxSampler { namespace gig { Line 239  namespace LinuxSampler { namespace gig {
239      void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) {      void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) {
240          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())
241          if (pEngine) pEngine->Enable();          if (pEngine) pEngine->Enable();
242            bStatusChanged = true; // status of engine has changed, so set notify flag
243        }
244    
245        /**
246         * Will be called by the InstrumentResourceManager on progress changes
247         * while loading or realoading an instrument for this EngineChannel.
248         *
249         * @param fProgress - current progress as value between 0.0 and 1.0
250         */
251        void EngineChannel::OnResourceProgress(float fProgress) {
252            this->InstrumentStat = int(fProgress * 100.0f);
253            dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat));
254            bStatusChanged = true; // status of engine has changed, so set notify flag
255      }      }
256    
257      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {      void EngineChannel::Connect(AudioOutputDevice* pAudioOut) {
# Line 297  namespace LinuxSampler { namespace gig { Line 342  namespace LinuxSampler { namespace gig {
342          }          }
343      }      }
344    
345        void EngineChannel::Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) {
346            if (!pMidiPort || pMidiPort == this->pMidiInputPort) return;
347            DisconnectMidiInputPort();
348            this->pMidiInputPort = pMidiPort;
349            this->midiChannel    = MidiChannel;
350            pMidiPort->Connect(this, MidiChannel);
351        }
352    
353        void EngineChannel::DisconnectMidiInputPort() {
354            MidiInputPort* pOldPort = this->pMidiInputPort;
355            this->pMidiInputPort = NULL;
356            if (pOldPort) pOldPort->Disconnect(this);
357        }
358    
359        MidiInputPort* EngineChannel::GetMidiInputPort() {
360            return pMidiInputPort;
361        }
362    
363        midi_chan_t EngineChannel::MidiChannel() {
364            return midiChannel;
365        }
366    
367      /**      /**
368       *  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
369       *  voice for the given key.       *  voice for the given key.
# Line 387  namespace LinuxSampler { namespace gig { Line 454  namespace LinuxSampler { namespace gig {
454          }          }
455      }      }
456    
457        void EngineChannel::ResetControllers() {
458            Pitch          = 0;
459            SustainPedal   = false;
460            GlobalVolume   = 1.0;
461            GlobalPanLeft  = 1.0f;
462            GlobalPanRight = 1.0f;
463            // set all MIDI controller values to zero
464            memset(ControllerTable, 0x00, 128);
465        }
466    
467      /**      /**
468       * Copy all events from the engine channel's input event queue buffer to       * Copy all events from the engine channel's input event queue buffer to
469       * the internal event list. This will be done at the beginning of each       * the internal event list. This will be done at the beginning of each
# Line 429  namespace LinuxSampler { namespace gig { Line 506  namespace LinuxSampler { namespace gig {
506    
507      void EngineChannel::Volume(float f) {      void EngineChannel::Volume(float f) {
508          GlobalVolume = f;          GlobalVolume = f;
509            bStatusChanged = true; // status of engine channel has changed, so set notify flag
510      }      }
511    
512      uint EngineChannel::Channels() {      uint EngineChannel::Channels() {
# Line 451  namespace LinuxSampler { namespace gig { Line 529  namespace LinuxSampler { namespace gig {
529          return InstrumentStat;          return InstrumentStat;
530      }      }
531    
532        String EngineChannel::EngineName() {
533            return LS_GIG_ENGINE_NAME;
534        }
535    
536  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC