/[svn]/linuxsampler/trunk/src/engines/common/MidiKeyboardManager.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/MidiKeyboardManager.h

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

revision 2121 by schoenebeck, Tue Sep 14 17:09:08 2010 UTC revision 2613 by schoenebeck, Tue Jun 10 15:17:01 2014 UTC
# Line 121  namespace LinuxSampler { Line 121  namespace LinuxSampler {
121              optional<float> ChorusSend;     ///< Optional individual chorus send level for this MIDI key (usually not set, unless Roland GS NRPN 0x1Enn was received, nn reflecting the note number, see EngineBase::ProcessHardcodedControllers())              optional<float> ChorusSend;     ///< Optional individual chorus send level for this MIDI key (usually not set, unless Roland GS NRPN 0x1Enn was received, nn reflecting the note number, see EngineBase::ProcessHardcodedControllers())
122      };      };
123    
124        class MidiKeyboardManagerBase {
125        public:
126            Pool<uint>*           pActiveKeys;  ///< Holds all keys in it's allocation list with active voices.
127            bool                  SoloMode;                 ///< in Solo Mode we only play one voice (group) at a time
128            int                   SoloKey;                  ///< Currently 'active' solo key, that is the key to which the currently sounding voice belongs to (only if SoloMode is enabled)
129            bool                  SustainPedal;             ///< true if sustain pedal is down
130            bool                  SostenutoPedal;           ///< true if sostenuto pedal is down
131            int                   SostenutoKeys[128];
132            int                   SostenutoKeyCount;
133            uint32_t              RoundRobinIndexes[128];
134            int8_t                KeyDown[128]; ///< True if the respective key is currently pressed down. Currently only used as built-in instrument script array variable %KEY_DOWN. It is currently not used by the sampler for any other purpose.
135        };
136    
137      template <class V>      template <class V>
138      class MidiKeyboardManager {      class MidiKeyboardManager : public MidiKeyboardManagerBase {
139          public:          public:
140              /** @brief Voice Stealing Algorithms              /** @brief Voice Stealing Algorithms
141               *               *
# Line 156  namespace LinuxSampler { Line 169  namespace LinuxSampler {
169                  }                  }
170    
171                  void Reset() {                  void Reset() {
172                      if (pActiveVoices) pActiveVoices->clear();                      if (pActiveVoices) {
173                            RTListVoiceIterator itVoice = pActiveVoices->first();
174                            RTListVoiceIterator itVoicesEnd = pActiveVoices->end();
175                            for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
176                                itVoice->VoiceFreed();
177                            }
178                            pActiveVoices->clear();
179                        }
180                      if (pEvents) pEvents->clear();                      if (pEvents) pEvents->clear();
181                      KeyPressed        = false;                      KeyPressed        = false;
182                      Active            = false;                      Active            = false;
# Line 197  namespace LinuxSampler { Line 217  namespace LinuxSampler {
217              };              };
218    
219              MidiKey*              pMIDIKeyInfo; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key              MidiKey*              pMIDIKeyInfo; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
             Pool<uint>*           pActiveKeys;  ///< Holds all keys in it's allocation list with active voices.  
             bool                  SoloMode;                 ///< in Solo Mode we only play one voice (group) at a time  
             int                   SoloKey;                  ///< Currently 'active' solo key, that is the key to which the currently sounding voice belongs to (only if SoloMode is enabled)  
             bool                  SustainPedal;             ///< true if sustain pedal is down  
             bool                  SostenutoPedal;           ///< true if sostenuto pedal is down  
             int                   SostenutoKeys[128];  
             int                   SostenutoKeyCount;  
             uint32_t              RoundRobinIndexes[128];  
220    
221              MidiKeyboardManager() {              MidiKeyboardManager() {
222                  pMIDIKeyInfo = new MidiKey[128];                  pMIDIKeyInfo = new MidiKey[128];
# Line 214  namespace LinuxSampler { Line 226  namespace LinuxSampler {
226                  SostenutoPedal = false;                  SostenutoPedal = false;
227                  for (int i = 0 ; i < 128 ; i++) {                  for (int i = 0 ; i < 128 ; i++) {
228                      RoundRobinIndexes[i] = 0;                      RoundRobinIndexes[i] = 0;
229                        KeyDown[i] = false;
230    
231                      // by default use one counter for each key (the                      // by default use one counter for each key (the
232                      // gig engine will change this to one counter per                      // gig engine will change this to one counter per
# Line 232  namespace LinuxSampler { Line 245  namespace LinuxSampler {
245                  SoloKey = -1;    // no solo key active yet                  SoloKey = -1;    // no solo key active yet
246    
247                  // reset key info                  // reset key info
248                  for (uint i = 0; i < 128; i++) pMIDIKeyInfo[i].Reset();                  for (uint i = 0; i < 128; i++) {
249                        pMIDIKeyInfo[i].Reset();
250                        KeyDown[i] = false;
251                    }
252    
253                  // free all active keys                  // free all active keys
254                  pActiveKeys->clear();                  pActiveKeys->clear();
# Line 495  namespace LinuxSampler { Line 511  namespace LinuxSampler {
511                              iPendingStreamDeletions++;                              iPendingStreamDeletions++;
512                          }                          }
513                          // free the voice to the voice pool and update key info                          // free the voice to the voice pool and update key info
514                            itVoice->VoiceFreed();
515                          FreeVoice(itVoice);                          FreeVoice(itVoice);
516                      }                      }
517                  }                  }
# Line 535  namespace LinuxSampler { Line 552  namespace LinuxSampler {
552                      }                      }
553                  }                  }
554              }              }
555                
556                /**
557                 * Recalculate the pitch of all active voices.
558                 */
559                void OnScaleTuningChanged() {
560                    RTList<uint>::Iterator iuiKey = pActiveKeys->first();
561                    for (; iuiKey; ++iuiKey) {
562                        MidiKey* pKey = &pMIDIKeyInfo[*iuiKey];
563                        RTListVoiceIterator itVoice = pKey->pActiveVoices->first();
564                        for (; itVoice; ++itVoice) {
565                            itVoice->onScaleTuningChanged();
566                        }
567                    }
568                }
569                
570              void ProcessSustainPedalDown(Pool<Event>::Iterator& itEvent) {              void ProcessSustainPedalDown(Pool<Event>::Iterator& itEvent) {
571                  // Cancel release process of all voices                  // Cancel release process of all voices
572                  RTList<uint>::Iterator iuiKey = pActiveKeys->first();                  RTList<uint>::Iterator iuiKey = pActiveKeys->first();

Legend:
Removed from v.2121  
changed lines
  Added in v.2613

  ViewVC Help
Powered by ViewVC