/[svn]/linuxsampler/trunk/src/engines/gig/Engine.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/Engine.cpp

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

revision 716 by iliev, Sun Jul 24 06:57:30 2005 UTC revision 781 by schoenebeck, Mon Sep 26 10:17:00 2005 UTC
# Line 29  Line 29 
29    
30  #include "Engine.h"  #include "Engine.h"
31    
 #if defined(__APPLE__)  
 # include <stdlib.h>  
 #else  
 # include <malloc.h>  
 #endif  
   
32  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
33    
34      InstrumentResourceManager Engine::instruments;      InstrumentResourceManager Engine::instruments;
# Line 114  namespace LinuxSampler { namespace gig { Line 108  namespace LinuxSampler { namespace gig {
108          }          }
109          pVoicePool->clear();          pVoicePool->clear();
110    
         pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected  
         pBasicFilterParameters  = NULL;  
         pMainFilterParameters   = NULL;  
   
111          ResetInternal();          ResetInternal();
112          ResetScaleTuning();          ResetScaleTuning();
113      }      }
# Line 139  namespace LinuxSampler { namespace gig { Line 129  namespace LinuxSampler { namespace gig {
129              delete pVoicePool;              delete pVoicePool;
130          }          }
131          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
         if (pMainFilterParameters) delete[] pMainFilterParameters;  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
132          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
133          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
134          EngineFactory::Destroy(this);          EngineFactory::Destroy(this);
# Line 203  namespace LinuxSampler { namespace gig { Line 190  namespace LinuxSampler { namespace gig {
190    
191          // delete all input events          // delete all input events
192          pEventQueue->init();          pEventQueue->init();
193            pSysexBuffer->init();
194      }      }
195    
196      /**      /**
# Line 249  namespace LinuxSampler { namespace gig { Line 237  namespace LinuxSampler { namespace gig {
237              // lower minimum release time              // lower minimum release time
238              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
239              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
240                  iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate);                  iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate);
241              }              }
242              pVoicePool->clear();              pVoicePool->clear();
243          }          }
# Line 277  namespace LinuxSampler { namespace gig { Line 265  namespace LinuxSampler { namespace gig {
265          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
266          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
267    
         // (re)allocate synthesis parameter matrix  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
   
         #if defined(__APPLE__)  
         pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle());  
         #else  
         pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));  
         #endif  
         for (int dst = 1; dst < Event::destination_count; dst++)  
             pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();  
   
         // (re)allocate biquad filter parameter sequence  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pMainFilterParameters)  delete[] pMainFilterParameters;  
         pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
         pMainFilterParameters  = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
   
268          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
269          pDiskThread->StartThread();          pDiskThread->StartThread();
270          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 694  namespace LinuxSampler { namespace gig { Line 665  namespace LinuxSampler { namespace gig {
665          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
666    
667          // release voices on this key if needed          // release voices on this key if needed
668          if (pKey->Active && !pEngineChannel->SustainPedal) {          if (pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEvent->Param.Note.Key)) {
669              itNoteOffEvent->Type = Event::type_release; // transform event type              itNoteOffEvent->Type = Event::type_release; // transform event type
670    
671              // move event to the key's own event list              // move event to the key's own event list
# Line 724  namespace LinuxSampler { namespace gig { Line 695  namespace LinuxSampler { namespace gig {
695      }      }
696    
697      /**      /**
698       *  Moves pitchbend event from the general (input) event list to the pitch       *  Moves pitchbend event from the general (input) event list to the engine
699       *  event list.       *  channel's event list. It will actually processed later by the
700         *  respective voice.
701       *       *
702       *  @param pEngineChannel - engine channel on which this event occured on       *  @param pEngineChannel - engine channel on which this event occured on
703       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
704       */       */
705      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
706          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value
         itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]);  
707      }      }
708    
709      /**      /**
# Line 1169  namespace LinuxSampler { namespace gig { Line 1140  namespace LinuxSampler { namespace gig {
1140          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1141          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1142    
1143          // move event from the unsorted event list to the control change event list          switch (itControlChangeEvent->Param.CC.Controller) {
         Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents);  
   
         switch (itControlChangeEventOnCCList->Param.CC.Controller) {  
1144              case 7: { // volume              case 7: { // volume
1145                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1146                  pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;                  pEngineChannel->GlobalVolume = (float) itControlChangeEvent->Param.CC.Value / 127.0f *  CONFIG_GLOBAL_ATTENUATION;
1147                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1148                  break;                  break;
1149              }              }
1150              case 10: { // panpot              case 10: { // panpot
1151                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1152                  const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;                  const int pan = (int) itControlChangeEvent->Param.CC.Value - 64;
1153                  pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;                  pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;
1154                  pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;                  pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;
1155                  break;                  break;
1156              }              }
1157              case 64: { // sustain              case 64: { // sustain
1158                  if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1159                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
1160                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1161    
1162                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1202  namespace LinuxSampler { namespace gig { Line 1170  namespace LinuxSampler { namespace gig {
1170                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1171                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1172                              if (itNewEvent) {                              if (itNewEvent) {
1173                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1174                                  itNewEvent->Type = Event::type_cancel_release; // transform event type                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
1175                              }                              }
1176                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
1177                          }                          }
1178                      }                      }
1179                  }                  }
1180                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1181                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL UP\n"));
1182                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1183    
1184                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1221  namespace LinuxSampler { namespace gig { Line 1189  namespace LinuxSampler { namespace gig {
1189                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1190                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
1191                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1192                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) {
1193                                RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1194                                if (itNewEvent) {
1195                                    *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1196                                    itNewEvent->Type = Event::type_release; // transform event type
1197                                }
1198                                else dmsg(1,("Event pool emtpy!\n"));
1199                            }
1200                        }
1201                    }
1202                    break;
1203                }
1204                case 66: { // sostenuto
1205                    if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) {
1206                        dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n"));
1207                        pEngineChannel->SostenutoPedal = true;
1208    
1209                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1210                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1211                        #endif
1212    
1213                        SostenutoKeyCount = 0;
1214                        // Remeber the pressed keys
1215                        RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1216                        for (; iuiKey; ++iuiKey) {
1217                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1218                            if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey;
1219                        }
1220                    }
1221                    if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) {
1222                        dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n"));
1223                        pEngineChannel->SostenutoPedal = false;
1224    
1225                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1226                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1227                        #endif
1228    
1229                        // release voices if the damper pedal is up and their respective key is not pressed
1230                        for (int i = 0; i < SostenutoKeyCount; i++) {
1231                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]];
1232                            if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) {
1233                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1234                              if (itNewEvent) {                              if (itNewEvent) {
1235                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1236                                  itNewEvent->Type = Event::type_release; // transform event type                                  itNewEvent->Type = Event::type_release; // transform event type
1237                              }                              }
1238                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
# Line 1238  namespace LinuxSampler { namespace gig { Line 1246  namespace LinuxSampler { namespace gig {
1246              // Channel Mode Messages              // Channel Mode Messages
1247    
1248              case 120: { // all sound off              case 120: { // all sound off
1249                  KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  KillAllVoices(pEngineChannel, itControlChangeEvent);
1250                  break;                  break;
1251              }              }
1252              case 121: { // reset all controllers              case 121: { // reset all controllers
# Line 1246  namespace LinuxSampler { namespace gig { Line 1254  namespace LinuxSampler { namespace gig {
1254                  break;                  break;
1255              }              }
1256              case 123: { // all notes off              case 123: { // all notes off
1257                  ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1258                  break;                  break;
1259              }              }
1260          }          }
# Line 1390  namespace LinuxSampler { namespace gig { Line 1398  namespace LinuxSampler { namespace gig {
1398      }      }
1399    
1400      /**      /**
1401       * Initialize the parameter sequence for the modulation destination given by       * Determines whether the specified voice should be released.
1402       * by 'dst' with the constant value given by val.       *
1403       */       * @param pEngineChannel - The engine channel on which the voice should be checked
1404      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {       * @param Key - The key number
1405          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();       * @returns true if the specified should be released, false otherwise.
1406          float* m = &pSynthesisParameters[dst][0];       */
1407          for (int i = 0; i < maxsamples; i += 4) {      bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) {
1408             m[i]   = val;          if (pEngineChannel->SustainPedal) return false;
1409             m[i+1] = val;  
1410             m[i+2] = val;          if (pEngineChannel->SostenutoPedal) {
1411             m[i+3] = val;              for (int i = 0; i < SostenutoKeyCount; i++)
1412                    if (Key == SostenutoKeys[i]) return false;
1413          }          }
1414    
1415            return true;
1416      }      }
1417    
1418      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
# Line 1441  namespace LinuxSampler { namespace gig { Line 1452  namespace LinuxSampler { namespace gig {
1452      }      }
1453    
1454      String Engine::Version() {      String Engine::Version() {
1455          String s = "$Revision: 1.51 $";          String s = "$Revision: 1.56 $";
1456          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword          return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
1457      }      }
1458    

Legend:
Removed from v.716  
changed lines
  Added in v.781

  ViewVC Help
Powered by ViewVC