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

Diff of /linuxsampler/trunk/src/engines/EngineBase.h

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

revision 2962 by schoenebeck, Sun Jul 17 17:54:04 2016 UTC revision 3690 by schoenebeck, Fri Jan 3 10:18:21 2020 UTC
# Line 5  Line 5 
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-2008 Christian Schoenebeck                         *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *
8   *   Copyright (C) 2012-2016 Christian Schoenebeck and Andreas Persson     *   *   Copyright (C) 2012-2017 Christian Schoenebeck and Andreas Persson     *
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   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 58  namespace LinuxSampler { Line 58  namespace LinuxSampler {
58              typedef typename RTList<RR*>::Iterator RootRegionIterator;              typedef typename RTList<RR*>::Iterator RootRegionIterator;
59              typedef typename MidiKeyboardManager<V>::MidiKey MidiKey;              typedef typename MidiKeyboardManager<V>::MidiKey MidiKey;
60                            
61              EngineBase() : SuspendedRegions(128), noteIDPool(GLOBAL_MAX_NOTES) {              EngineBase() : noteIDPool(GLOBAL_MAX_NOTES), SuspendedRegions(128) {
62                  pDiskThread          = NULL;                  pDiskThread          = NULL;
63                  pNotePool            = new Pool< Note<V> >(GLOBAL_MAX_NOTES);                  pNotePool            = new Pool< Note<V> >(GLOBAL_MAX_NOTES);
64                  pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS);                  pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS);
# Line 163  namespace LinuxSampler { Line 163  namespace LinuxSampler {
163                                  dmsg(5,("Engine: Sysex received\n"));                                  dmsg(5,("Engine: Sysex received\n"));
164                                  ProcessSysex(itEvent);                                  ProcessSysex(itEvent);
165                                  break;                                  break;
166                                default: ; // noop
167                          }                          }
168                      }                      }
169                  }                  }
# Line 201  namespace LinuxSampler { Line 202  namespace LinuxSampler {
202                      PostProcess(engineChannels[i]);                      PostProcess(engineChannels[i]);
203                  }                  }
204    
205                    // Just for debugging: dump the amount of free Note objects to
206                    // the terminal (note due to the static variables being used,
207                    // this is currently just intended for debugging with only one
208                    // engine channel).
209                    #if (CONFIG_DEBUG_LEVEL >= 3)
210                    {
211                        static int slice = 0;
212                        static int noteCount = -1;
213                        if (slice++ % 10 == 0) {
214                            int n = pNotePool->countFreeElements();
215                            if (n != noteCount) {
216                                noteCount = n;
217                                dmsg(1,("[%d] free Note objects count = %d\n", slice / 10, n));
218                            }
219                        }
220                    }
221                    #endif
222    
223                  // empty the engine's event list for the next audio fragment                  // empty the engine's event list for the next audio fragment
224                  ClearEventLists();                  ClearEventLists();
# Line 378  namespace LinuxSampler { Line 396  namespace LinuxSampler {
396                  }                  }
397                  pVoicePool->clear();                  pVoicePool->clear();
398    
399                  // (re)create event generator                  // update event generator
400                  if (pEventGenerator) delete pEventGenerator;                  pEventGenerator->SetSampleRate(pAudioOut->SampleRate());
                 pEventGenerator = new EventGenerator(pAudioOut->SampleRate());  
401    
402                  dmsg(1,("Starting disk thread..."));                  dmsg(1,("Starting disk thread..."));
403                  pDiskThread->StartThread();                  pDiskThread->StartThread();
# Line 596  namespace LinuxSampler { Line 613  namespace LinuxSampler {
613              }              }
614    
615              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'
616              virtual Pool<R*>* GetRegionPool(int index) {              virtual Pool<R*>* GetRegionPool(int index) OVERRIDE {
617                  if (index < 0 || index > 1) throw Exception("Index out of bounds");                  if (index < 0 || index > 1) throw Exception("Index out of bounds");
618                  return pRegionPool[index];                  return pRegionPool[index];
619              }              }
# Line 604  namespace LinuxSampler { Line 621  namespace LinuxSampler {
621              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'
622              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }
623              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }
624              virtual Pool<note_id_t>* GetNodeIDPool() OVERRIDE { return &noteIDPool; }              virtual Pool<note_id_t>* GetNoteIDPool() OVERRIDE { return &noteIDPool; }
625    
626              D* GetDiskThread() { return pDiskThread; }              D* GetDiskThread() { return pDiskThread; }
627    
# Line 675  namespace LinuxSampler { Line 692  namespace LinuxSampler {
692               * @param pNoteOnEvent - event which caused this               * @param pNoteOnEvent - event which caused this
693               * @returns new note's unique ID (or zero on error)               * @returns new note's unique ID (or zero on error)
694               */               */
695              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE {              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
696                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
697                  Pool< Note<V> >* pNotePool = GetNotePool();                  Pool< Note<V> >* pNotePool = GetNotePool();
698    
# Line 690  namespace LinuxSampler { Line 707  namespace LinuxSampler {
707                  const note_id_t newNoteID = pNotePool->getID(itNewNote);                  const note_id_t newNoteID = pNotePool->getID(itNewNote);
708    
709                  // remember the engine's time when this note was triggered exactly                  // remember the engine's time when this note was triggered exactly
710                  itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime();                  itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime();
711    
712                  // usually the new note (and its subsequent voices) will be                  // usually the new note (and its subsequent voices) will be
713                  // allocated on the key provided by the event's note number,                  // allocated on the key provided by the event's note number,
# Line 698  namespace LinuxSampler { Line 715  namespace LinuxSampler {
715                  // note, but rather a child note, then this new note will be                  // note, but rather a child note, then this new note will be
716                  // allocated on the parent note's key instead in order to                  // allocated on the parent note's key instead in order to
717                  // release the child note simultaniously with its parent note                  // release the child note simultaniously with its parent note
718                  itNewNote->hostKey = pNoteOnEvent->Param.Note.Key;                  itNewNote->hostKey = itNoteOnEvent->Param.Note.Key;
719    
720                  // in case this new note was requested to be a child note,                  // in case this new note was requested to be a child note,
721                  // then retrieve its parent note and link them with each other                  // then retrieve its parent note and link them with each other
722                  const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID;                  const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID;
723                  if (parentNoteID) {                  if (parentNoteID) {
724                      NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                                              NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                        
725                      if (itParentNote) {                      if (itParentNote) {
# Line 730  namespace LinuxSampler { Line 747  namespace LinuxSampler {
747                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));
748    
749                  // copy event which caused this note                  // copy event which caused this note
750                  itNewNote->cause = *pNoteOnEvent;                  itNewNote->cause = *itNoteOnEvent;
751                  itNewNote->eventID = pEventPool->getID(pNoteOnEvent);                  itNewNote->eventID = pEventPool->getID(itNoteOnEvent);
752                    if (!itNewNote->eventID) {
753                        dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n"));
754                    }
755    
756                  // move new note to its host key                  // move new note to its host key
757                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];
758                  itNewNote.moveToEndOf(pKey->pActiveNotes);                  itNewNote.moveToEndOf(pKey->pActiveNotes);
759                    pChannel->markKeyAsActive(pKey);
760    
761                  // assign unique note ID of this new note to the original note on event                  // assign unique note ID of this new note to the original note on event
762                  pNoteOnEvent->Param.Note.ID = newNoteID;                  itNoteOnEvent->Param.Note.ID = newNoteID;
763    
764                  return newNoteID; // success                  return newNoteID; // success
765              }              }
# Line 798  namespace LinuxSampler { Line 819  namespace LinuxSampler {
819                              case Event::type_note_pressure:                              case Event::type_note_pressure:
820                                  //TODO: ...                                  //TODO: ...
821                                  break;                                  break;
822    
823                                case Event::type_sysex:
824                                    //TODO: ...
825                                    break;
826    
827                                case Event::type_cancel_release_key:
828                                case Event::type_release_key:
829                                case Event::type_release_note:
830                                case Event::type_play_note:
831                                case Event::type_stop_note:
832                                case Event::type_kill_note:
833                                case Event::type_note_synth_param:
834                                    break; // noop
835                          }                          }
836    
837                          // see HACK comment above                          // see HACK comment above
# Line 868  namespace LinuxSampler { Line 902  namespace LinuxSampler {
902                                  dmsg(5,("Engine: Stop Note received\n"));                                  dmsg(5,("Engine: Stop Note received\n"));
903                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
904                                  break;                                  break;
905                                case Event::type_kill_note:
906                                    dmsg(5,("Engine: Kill Note received\n"));
907                                    ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent);
908                                    break;
909                              case Event::type_control_change:                              case Event::type_control_change:
910                                  dmsg(5,("Engine: MIDI CC received\n"));                                  dmsg(5,("Engine: MIDI CC received\n"));
911                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);
# Line 888  namespace LinuxSampler { Line 926  namespace LinuxSampler {
926                                  dmsg(5,("Engine: Note Synth Param received\n"));                                  dmsg(5,("Engine: Note Synth Param received\n"));
927                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);
928                                  break;                                  break;
929                                case Event::type_sysex:
930                                    break; // TODO ...
931    
932                                case Event::type_cancel_release_key:
933                                case Event::type_release_key:
934                                case Event::type_release_note:
935                                    break; // noop
936                          }                          }
937                      }                      }
938                  }                  }
# Line 956  namespace LinuxSampler { Line 1001  namespace LinuxSampler {
1001                      // script event object                      // script event object
1002                      RTList<ScriptEvent>::Iterator itScriptEvent =                      RTList<ScriptEvent>::Iterator itScriptEvent =
1003                          pChannel->pScript->pEvents->allocAppend();                          pChannel->pScript->pEvents->allocAppend();
1004                        // if event handler uses polyphonic variables, reset them
1005                        // to zero values before starting to execute the handler
1006                        if (pEventHandler->isPolyphonic())
1007                            itScriptEvent->execCtx->resetPolyphonicData();
1008                      ProcessScriptEvent(                      ProcessScriptEvent(
1009                          pChannel, itEvent, pEventHandler, itScriptEvent                          pChannel, itEvent, pEventHandler, itScriptEvent
1010                      );                      );
# Line 988  namespace LinuxSampler { Line 1037  namespace LinuxSampler {
1037    
1038                  // initialize/reset other members                  // initialize/reset other members
1039                  itScriptEvent->cause = *itEvent;                  itScriptEvent->cause = *itEvent;
1040                    itScriptEvent->scheduleTime = itEvent->SchedTime();
1041                  itScriptEvent->currentHandler = 0;                  itScriptEvent->currentHandler = 0;
1042                  itScriptEvent->executionSlices = 0;                  itScriptEvent->executionSlices = 0;
1043                  itScriptEvent->ignoreAllWaitCalls = false;                  itScriptEvent->ignoreAllWaitCalls = false;
1044                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();
1045                    itScriptEvent->parentHandlerID = 0;
1046                    itScriptEvent->childHandlerID[0] = 0;
1047                    itScriptEvent->autoAbortByParent = false;
1048                    itScriptEvent->forkIndex = 0;
1049                  // this is the native representation of the $EVENT_ID script variable                  // this is the native representation of the $EVENT_ID script variable
1050                  itScriptEvent->id =                  itScriptEvent->id =
1051                      (itEvent->Type == Event::type_note_on)                      (itEvent->Type == Event::type_note_on)
# Line 1104  namespace LinuxSampler { Line 1158  namespace LinuxSampler {
1158               *  @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing               *  @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing
1159               */               */
1160              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
1161                    dmsg(3,("StealVoice()\n"));
1162                  if (VoiceSpawnsLeft <= 0) {                  if (VoiceSpawnsLeft <= 0) {
1163                      dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n"));                      dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n"));
1164                      return -1;                      return -1;
# Line 1128  namespace LinuxSampler { Line 1183  namespace LinuxSampler {
1183                  int                          iChannelIndex;                  int                          iChannelIndex;
1184                  VoiceIterator                itSelectedVoice;                  VoiceIterator                itSelectedVoice;
1185    
1186                    #if CONFIG_DEVMODE
1187                    EngineChannel* pBegin = NULL; // to detect endless loop
1188                    #endif
1189    
1190                  // select engine channel                  // select engine channel
1191                  if (pLastStolenChannel) {                  if (pLastStolenChannel) {
1192                      pSelectedChannel = pLastStolenChannel;                      pSelectedChannel = pLastStolenChannel;
# Line 1170  namespace LinuxSampler { Line 1229  namespace LinuxSampler {
1229                  }                  }
1230    
1231                  #if CONFIG_DEVMODE                  #if CONFIG_DEVMODE
1232                  EngineChannel* pBegin = pSelectedChannel; // to detect endless loop                  pBegin = pSelectedChannel; // to detect endless loop
1233                  #endif // CONFIG_DEVMODE                  #endif // CONFIG_DEVMODE
1234    
1235                  while (true) { // iterate through engine channels                                          while (true) { // iterate through engine channels                        
# Line 1259  namespace LinuxSampler { Line 1318  namespace LinuxSampler {
1318                          // the script's "init" event handler is only executed                          // the script's "init" event handler is only executed
1319                          // once (when the script is loaded or reloaded)                          // once (when the script is loaded or reloaded)
1320                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {
1321                                dmsg(5,("Engine: exec handlerInit %p\n", pEngineChannel->pScript->handlerInit));
1322                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1323                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1324    
1325                                itScriptEvent->cause = pEventGenerator->CreateEvent(0);
1326                                itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing
1327                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1328                                itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort();
1329                                itScriptEvent->id = 0;
1330                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1331                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1332                                itScriptEvent->currentHandler = 0;
1333                              VMExecStatus_t res = pScriptVM->exec(                              itScriptEvent->executionSlices = 0;
1334                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                              itScriptEvent->ignoreAllWaitCalls = false;
1335                              );                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1336                                itScriptEvent->parentHandlerID = 0;
1337                                itScriptEvent->childHandlerID[0] = 0;
1338                                itScriptEvent->autoAbortByParent = false;
1339                                itScriptEvent->forkIndex = 0;
1340    
1341                                VMExecStatus_t res;
1342                                size_t instructionsCount = 0;
1343                                const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction)
1344                                bool bWarningShown = false;
1345                                do {
1346                                    res = pScriptVM->exec(
1347                                        pEngineChannel->pScript->parserContext, &*itScriptEvent
1348                                    );
1349                                    instructionsCount += itScriptEvent->execCtx->instructionsPerformed();
1350                                    if (instructionsCount > maxInstructions && !bWarningShown) {
1351                                        bWarningShown = true;
1352                                        dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n"));
1353                                    }
1354                                } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR));
1355    
1356                              pEngineChannel->pScript->pEvents->free(itScriptEvent);                              pEngineChannel->pScript->pEvents->free(itScriptEvent);
1357                          }                          }
# Line 1329  namespace LinuxSampler { Line 1412  namespace LinuxSampler {
1412                          // usually there should already be a new Note object                          // usually there should already be a new Note object
1413                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);
1414                          if (!itNote) { // should not happen, but just to be sure ...                          if (!itNote) { // should not happen, but just to be sure ...
1415                              const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent);                              dmsg(2,("Engine: No Note object for stolen voice!\n"));
1416                                const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);
1417                              if (!noteID) {                              if (!noteID) {
1418                                  dmsg(1,("Engine: Voice stealing failed; No Note object and Note pool empty!\n"));                                  dmsg(1,("Engine: Voice stealing failed; No Note object and Note pool empty!\n"));
1419                                  continue;                                  continue;
# Line 1373  namespace LinuxSampler { Line 1457  namespace LinuxSampler {
1457              void PostProcess(EngineChannel* pEngineChannel) {              void PostProcess(EngineChannel* pEngineChannel) {
1458                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1459                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1460                   pChannel->FreeAllInactiveKyes();                   pChannel->FreeAllInactiveKeys();
1461    
1462                  // empty the engine channel's own event lists                  // empty the engine channel's own event lists
1463                  // (only events of the current audio fragment cycle)                  // (only events of the current audio fragment cycle)
# Line 1400  namespace LinuxSampler { Line 1484  namespace LinuxSampler {
1484                          pChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN;                          pChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN;
1485                          break;                          break;
1486                      }                      }
1487                      case 6: { // data entry (currently only used for RPN and NRPN controllers)                      case 6: { // data entry (MSB)
1488                          //dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value));                          //dmsg(1,("DATA ENTRY MSB %d\n", itControlChangeEvent->Param.CC.Value));
1489                          if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ...  
1490                              dmsg(4,("Guess it's an RPN ...\n"));                          // look-ahead: if next MIDI event is data entry LSB,
1491                              if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones                          // then skip this event here for now (to avoid double
1492                                  int transpose = (int) itControlChangeEvent->Param.CC.Value - 64;                          // handling of what's supposed to be one RPN/NRPN event)
1493                                  // limit to +- two octaves for now                          if (isNextEventCCNr(itControlChangeEvent, 38))
1494                                  transpose = RTMath::Min(transpose,  24);                              break;
1495                                  transpose = RTMath::Max(transpose, -24);  
1496                                  pChannel->GlobalTranspose = transpose;                          if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1497                                  // workaround, so we won't have hanging notes                              int ch = itControlChangeEvent->Param.CC.Channel;
1498                                  pChannel->ReleaseAllVoices(itControlChangeEvent);                              int param = pChannel->GetMidiRpnParameter();
1499                              }                              int value = itControlChangeEvent->Param.CC.Value << 7;
1500                              // to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data  
1501                              pChannel->ResetMidiRpnController();                              // transform event type: CC event -> RPN event
1502                          } else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ...                              itControlChangeEvent->Type = Event::type_rpn;
1503                              dmsg(4,("Guess it's an NRPN ...\n"));                              itControlChangeEvent->Param.RPN.Channel = ch;
1504                              const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8;                              itControlChangeEvent->Param.RPN.Parameter = param;
1505                              const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff;                              itControlChangeEvent->Param.RPN.Value = value;
1506                              dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value));  
1507                              switch (NrpnCtrlMSB) {                              // if there's a RPN script handler, run it ...
1508                                  case 0x1a: { // volume level of note (Roland GS NRPN)                              if (pChannel->pScript->handlerRpn) {
1509                                      const uint note = NrpnCtrlLSB;                                  const event_id_t eventID =
1510                                      const uint vol  = itControlChangeEvent->Param.CC.Value;                                      pEventPool->getID(itControlChangeEvent);
1511                                      dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));                                  // run the RPN script handler
1512                                      if (note < 128 && vol < 128)                                  ProcessEventByScript(
1513                                          pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];                                      pChannel, itControlChangeEvent,
1514                                      break;                                      pChannel->pScript->handlerRpn
1515                                  }                                  );
1516                                  case 0x1c: { // panpot of note (Roland GS NRPN)                                  // if RPN event was dropped by script, abort
1517                                      const uint note = NrpnCtrlLSB;                                  // here to avoid hard coded RPN processing below
1518                                      const uint pan  = itControlChangeEvent->Param.CC.Value;                                  if (!pEventPool->fromID(eventID)) {
1519                                      dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));                                      // to prevent other data entry messages to be misenterpreted as RPN value
1520                                      if (note < 128 && pan < 128) {                                      pChannel->ResetMidiRpnParameter();
                                         pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];  
                                         pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];  
                                     }  
                                     break;  
                                 }  
                                 case 0x1d: { // reverb send of note (Roland GS NRPN)  
                                     const uint note = NrpnCtrlLSB;  
                                     const float reverb = float(itControlChangeEvent->Param.CC.Value) / 127.0f;  
                                     dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb));  
                                     if (note < 128)  
                                         pChannel->pMIDIKeyInfo[note].ReverbSend = reverb;  
1521                                      break;                                      break;
1522                                  }                                  }
1523                                  case 0x1e: { // chorus send of note (Roland GS NRPN)                              }
1524                                      const uint note = NrpnCtrlLSB;  
1525                                      const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f;                              // do the actual (hard-coded) RPN value change processing
1526                                      dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));                              ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1527                                      if (note < 128)  
1528                                          pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;                              // to prevent other data entry messages to be misenterpreted as RPN value
1529                                pChannel->ResetMidiRpnParameter();
1530                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1531                                int ch = itControlChangeEvent->Param.CC.Channel;
1532                                int param = pChannel->GetMidiNrpnParameter();
1533                                int value = itControlChangeEvent->Param.CC.Value << 7;
1534    
1535                                // transform event type: CC event -> NRPN event
1536                                itControlChangeEvent->Type = Event::type_nrpn;
1537                                itControlChangeEvent->Param.RPN.Channel = ch;
1538                                itControlChangeEvent->Param.RPN.Parameter = param;
1539                                itControlChangeEvent->Param.RPN.Value = value;
1540    
1541                                // if there's a NRPN script handler, run it ...
1542                                if (pChannel->pScript->handlerNrpn) {
1543                                    const event_id_t eventID =
1544                                        pEventPool->getID(itControlChangeEvent);
1545                                    // run the NRPN script handler
1546                                    ProcessEventByScript(
1547                                        pChannel, itControlChangeEvent,
1548                                        pChannel->pScript->handlerNrpn
1549                                    );
1550                                    // if NRPN event was dropped by script, abort
1551                                    // here to avoid hard coded NRPN processing below
1552                                    if (!pEventPool->fromID(eventID)) {
1553                                        // to prevent other data entry messages to be misenterpreted as NRPN value
1554                                        pChannel->ResetMidiNrpnParameter();
1555                                      break;                                      break;
1556                                  }                                  }
1557                              }                              }
1558                              // to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data  
1559                              pChannel->ResetMidiNrpnController();                              // do the actual (hard-coded) NRPN value change processing
1560                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1561    
1562                                // to prevent other data entry messages to be misenterpreted as NRPN value
1563                                pChannel->ResetMidiNrpnParameter();
1564                          }                          }
1565                          break;                          break;
1566                      }                      }
# Line 1472  namespace LinuxSampler { Line 1575  namespace LinuxSampler {
1575                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;
1576                          break;                          break;
1577                      }                      }
1578                        case 38: { // data entry (LSB)
1579                            //dmsg(1,("DATA ENTRY LSB %d\n", itControlChangeEvent->Param.CC.Value));
1580                            int value = 0;
1581    
1582                            // look-back: if previous MIDI event was data entry MSB,
1583                            // then obtain that value for the MSB value portion
1584                            if (isPrevEventCCNr(itControlChangeEvent, 6))
1585                                value = prevEventOf(itControlChangeEvent)->Param.CC.Value << 7;
1586    
1587                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1588                                int ch = itControlChangeEvent->Param.CC.Channel;
1589                                int param = pChannel->GetMidiRpnParameter();
1590                                value |= itControlChangeEvent->Param.CC.Value;
1591    
1592                                // transform event type: CC event -> RPN event
1593                                itControlChangeEvent->Type = Event::type_rpn;
1594                                itControlChangeEvent->Param.RPN.Channel = ch;
1595                                itControlChangeEvent->Param.RPN.Parameter = param;
1596                                itControlChangeEvent->Param.RPN.Value = value;
1597    
1598                                // if there's a RPN script handler, run it ...
1599                                if (pChannel->pScript->handlerRpn) {
1600                                    const event_id_t eventID =
1601                                        pEventPool->getID(itControlChangeEvent);
1602                                    // run the RPN script handler
1603                                    ProcessEventByScript(
1604                                        pChannel, itControlChangeEvent,
1605                                        pChannel->pScript->handlerRpn
1606                                    );
1607                                    // if RPN event was dropped by script, abort
1608                                    // here to avoid hard coded RPN processing below
1609                                    if (!pEventPool->fromID(eventID)) {
1610                                        // to prevent other data entry messages to be misenterpreted as RPN value
1611                                        pChannel->ResetMidiRpnParameter();
1612                                        break;
1613                                    }
1614                                }
1615    
1616                                // do the actual (hard-coded) RPN value change processing
1617                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1618    
1619                                // to prevent other data entry messages to be misenterpreted as RPN value
1620                                pChannel->ResetMidiRpnParameter();
1621                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1622                                int ch = itControlChangeEvent->Param.CC.Channel;
1623                                int param = pChannel->GetMidiNrpnParameter();
1624                                value |= itControlChangeEvent->Param.CC.Value;
1625    
1626                                // transform event type: CC event -> NRPN event
1627                                itControlChangeEvent->Type = Event::type_nrpn;
1628                                itControlChangeEvent->Param.RPN.Channel = ch;
1629                                itControlChangeEvent->Param.RPN.Parameter = param;
1630                                itControlChangeEvent->Param.RPN.Value = value;
1631    
1632                                // if there's a NRPN script handler, run it ...
1633                                if (pChannel->pScript->handlerNrpn) {
1634                                    const event_id_t eventID =
1635                                        pEventPool->getID(itControlChangeEvent);
1636                                    // run the NRPN script handler
1637                                    ProcessEventByScript(
1638                                        pChannel, itControlChangeEvent,
1639                                        pChannel->pScript->handlerNrpn
1640                                    );
1641                                    // if NRPN event was dropped by script, abort
1642                                    // here to avoid hard coded NRPN processing below
1643                                    if (!pEventPool->fromID(eventID)) {
1644                                        // to prevent other data entry messages to be misenterpreted as NRPN value
1645                                        pChannel->ResetMidiNrpnParameter();
1646                                        break;
1647                                    }
1648                                }
1649    
1650                                // do the actual (hard-coded) NRPN value change processing
1651                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1652    
1653                                // to prevent other data entry messages to be misenterpreted as NRPN value
1654                                pChannel->ResetMidiNrpnParameter();
1655                            }
1656                            break;
1657                        }
1658                      case 64: { // sustain                      case 64: { // sustain
1659                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {
1660                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
# Line 1545  namespace LinuxSampler { Line 1728  namespace LinuxSampler {
1728                          }                          }
1729                          break;                          break;
1730                      }                      }
1731                      case 98: { // NRPN controller LSB                      case 98: { // NRPN parameter LSB
1732                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1733                          pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiNrpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1734                          break;                          break;
1735                      }                      }
1736                      case 99: { // NRPN controller MSB                      case 99: { // NRPN parameter MSB
1737                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1738                          pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiNrpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1739                          break;                          break;
1740                      }                      }
1741                      case 100: { // RPN controller LSB                      case 100: { // RPN parameter LSB
1742                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1743                          pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiRpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1744                          break;                          break;
1745                      }                      }
1746                      case 101: { // RPN controller MSB                      case 101: { // RPN parameter MSB
1747                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1748                          pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiRpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1749                          break;                          break;
1750                      }                      }
1751    
# Line 1598  namespace LinuxSampler { Line 1781  namespace LinuxSampler {
1781                  }                  }
1782              }              }
1783    
1784                /**
1785                 * Process MIDI RPN events with hard coded behavior.
1786                 *
1787                 * @param pEngineChannel - engine channel on which the MIDI RPN
1788                 *                         event was received
1789                 * @param itRpnEvent - the actual MIDI RPN event
1790                 */
1791                void ProcessHardcodedRpn(EngineChannel* pEngineChannel,
1792                                         Pool<Event>::Iterator& itRpnEvent)
1793                {
1794                    EngineChannelBase<V, R, I>* pChannel =
1795                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1796    
1797                    if (itRpnEvent->Param.RPN.Parameter == 2) { // coarse tuning in half tones
1798                        int transpose = (int) itRpnEvent->Param.RPN.ValueMSB() - 64;
1799                        // limit to +- two octaves for now
1800                        transpose = RTMath::Min(transpose,  24);
1801                        transpose = RTMath::Max(transpose, -24);
1802                        pChannel->GlobalTranspose = transpose;
1803                        // workaround, so we won't have hanging notes
1804                        pChannel->ReleaseAllVoices(itRpnEvent);
1805                    }
1806                }
1807    
1808                /**
1809                 * Process MIDI NRPN events with hard coded behavior.
1810                 *
1811                 * @param pEngineChannel - engine channel on which the MIDI NRPN
1812                 *                         event was received
1813                 * @param itRpnEvent - the actual MIDI NRPN event
1814                 */
1815                void ProcessHardcodedNrpn(EngineChannel* pEngineChannel,
1816                                          Pool<Event>::Iterator& itNrpnEvent)
1817                {
1818                    EngineChannelBase<V, R, I>* pChannel =
1819                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1820    
1821                    switch (itNrpnEvent->Param.NRPN.ParameterMSB()) {
1822                        case 0x1a: { // volume level of note (Roland GS NRPN)
1823                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1824                            const uint vol  = itNrpnEvent->Param.NRPN.ValueMSB();
1825                            dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));
1826                            if (note < 128 && vol < 128)
1827                                pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];
1828                            break;
1829                        }
1830                        case 0x1c: { // panpot of note (Roland GS NRPN)
1831                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1832                            const uint pan  = itNrpnEvent->Param.NRPN.ValueMSB();
1833                            dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));
1834                            if (note < 128 && pan < 128) {
1835                                pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];
1836                                pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];
1837                            }
1838                            break;
1839                        }
1840                        case 0x1d: { // reverb send of note (Roland GS NRPN)
1841                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1842                            const float reverb = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
1843                            dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb));
1844                            if (note < 128)
1845                                pChannel->pMIDIKeyInfo[note].ReverbSend = reverb;
1846                            break;
1847                        }
1848                        case 0x1e: { // chorus send of note (Roland GS NRPN)
1849                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1850                            const float chorus = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
1851                            dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));
1852                            if (note < 128)
1853                                pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;
1854                            break;
1855                        }
1856                    }
1857                }
1858    
1859              virtual D* CreateDiskThread() = 0;              virtual D* CreateDiskThread() = 0;
1860    
1861              /**              /**
# Line 1606  namespace LinuxSampler { Line 1864  namespace LinuxSampler {
1864               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
1865               *  @param itNoteOnEvent - key, velocity and time stamp of the event               *  @param itNoteOnEvent - key, velocity and time stamp of the event
1866               */               */
1867              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
1868                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1869                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1870    
# Line 1737  namespace LinuxSampler { Line 1995  namespace LinuxSampler {
1995               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
1996               *  @param itNoteOffEvent - key, velocity and time stamp of the event               *  @param itNoteOffEvent - key, velocity and time stamp of the event
1997               */               */
1998              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE {
1999                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2000    
2001                  const int iKey = itNoteOffEvent->Param.Note.Key;                  const int iKey = itNoteOffEvent->Param.Note.Key;
# Line 1806  namespace LinuxSampler { Line 2064  namespace LinuxSampler {
2064                                          itPseudoNoteOnEvent->Param.Note.Key      = i;                                          itPseudoNoteOnEvent->Param.Note.Key      = i;
2065                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
2066                                          // assign a new note to this note-on event                                          // assign a new note to this note-on event
2067                                          if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) {                                          if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) {
2068                                              // allocate and trigger new voice(s) for the other key                                              // allocate and trigger new voice(s) for the other key
2069                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);
2070                                          }                                          }
# Line 1838  namespace LinuxSampler { Line 2096  namespace LinuxSampler {
2096                      if (bShouldRelease) {                      if (bShouldRelease) {
2097                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type
2098                          // spawn release triggered voice(s) if needed                          // spawn release triggered voice(s) if needed
2099                          ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);                          if (pKey->ReleaseTrigger & release_trigger_noteoff)
2100                                ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);
2101                      }                      }
2102                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {
2103                      // This programmatically caused event is caused by a call to                      // This programmatically caused event is caused by a call to
# Line 1869  namespace LinuxSampler { Line 2128  namespace LinuxSampler {
2128               * @param pEngineChannel - engine channel on which this event occurred on               * @param pEngineChannel - engine channel on which this event occurred on
2129               * @param itEvent - release trigger event (contains note number)               * @param itEvent - release trigger event (contains note number)
2130               */               */
2131              virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {              virtual void ProcessReleaseTriggerBySustain(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {
2132                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2133    
2134                  const int iKey = itEvent->Param.Note.Key;                  const int iKey = itEvent->Param.Note.Key;
# Line 1893  namespace LinuxSampler { Line 2152  namespace LinuxSampler {
2152                  // spawn release triggered voice(s) if needed                  // spawn release triggered voice(s) if needed
2153                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {
2154                      // assign a new note to this release event                      // assign a new note to this release event
2155                      if (LaunchNewNote(pChannel, &*itEvent)) {                      if (LaunchNewNote(pChannel, itEvent)) {
2156                          // allocate and trigger new release voice(s)                          // allocate and trigger new release voice(s)
2157                          TriggerReleaseVoices(pChannel, itEvent);                          TriggerReleaseVoices(pChannel, itEvent);
2158                      }                      }
2159                      pKey->ReleaseTrigger = false;                      pKey->ReleaseTrigger = release_trigger_none;
2160                  }                  }
2161              }              }
2162    
2163              /**              /**
2164                 * Called on "kill note" events, which currently only happens on
2165                 * built-in real-time instrument script function fade_out(). This
2166                 * method only fulfills one task: moving the even to the Note's own
2167                 * event list so that its voices can process the kill event sample
2168                 * accurately.
2169                 */
2170                void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
2171                    EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2172    
2173                    NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID );
2174                    if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2175    
2176                    // move note kill event to its MIDI key
2177                    MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey];
2178                    itEvent.moveToEndOf(pKey->pEvents);
2179                }
2180    
2181                /**
2182               * Called on note synthesis parameter change events. These are               * Called on note synthesis parameter change events. These are
2183               * internal events caused by calling built-in real-time instrument               * internal events caused by calling built-in real-time instrument
2184               * script functions like change_vol(), change_pitch(), etc.               * script functions like change_vol(), change_tune(), etc.
2185               *               *
2186               * This method performs two tasks:               * This method performs two tasks:
2187               *               *
# Line 1925  namespace LinuxSampler { Line 2202  namespace LinuxSampler {
2202                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );
2203                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2204    
                 const bool& relative = itEvent->Param.NoteSynthParam.Relative;  
   
2205                  switch (itEvent->Param.NoteSynthParam.Type) {                  switch (itEvent->Param.NoteSynthParam.Type) {
2206                      case Event::synth_param_volume:                      case Event::synth_param_volume:
2207                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Volume);
2208                              pNote->Override.Volume *= itEvent->Param.NoteSynthParam.Delta;                          break;
2209                          else                      case Event::synth_param_volume_time:
2210                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2211                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;                          break;
2212                        case Event::synth_param_volume_curve:
2213                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2214                            pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2215                          break;                          break;
2216                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
2217                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Pitch);
2218                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;                          break;
2219                          else                      case Event::synth_param_pitch_time:
2220                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2221                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;                          break;
2222                        case Event::synth_param_pitch_curve:
2223                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2224                            pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2225                          break;                          break;
2226                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2227                          if (relative) {                          pNote->apply(itEvent, &NoteBase::_Override::Pan);
2228                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);                          break;
2229                          } else {                      case Event::synth_param_pan_time:
2230                              pNote->Override.Pan = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2231                              pNote->Override.PanSources = 1; // only relevant on subsequent change_pan() instrument script calls on same note with 'relative' argument being set                          break;
2232                          }                      case Event::synth_param_pan_curve:
2233                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan;                          itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2234                            pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2235                          break;                          break;
2236                      case Event::synth_param_cutoff:                      case Event::synth_param_cutoff:
2237                          pNote->Override.Cutoff = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Cutoff);
2238                          break;                          break;
2239                      case Event::synth_param_resonance:                      case Event::synth_param_resonance:
2240                          pNote->Override.Resonance = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Resonance);
2241                          break;                          break;
2242                      case Event::synth_param_attack:                      case Event::synth_param_attack:
2243                          pNote->Override.Attack = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Attack);
2244                          break;                          break;
2245                      case Event::synth_param_decay:                      case Event::synth_param_decay:
2246                          pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Decay);
2247                            break;
2248                        case Event::synth_param_sustain:
2249                            pNote->apply(itEvent, &NoteBase::_Override::Sustain);
2250                          break;                          break;
2251                      case Event::synth_param_release:                      case Event::synth_param_release:
2252                          pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Release);
2253                            break;
2254    
2255                        case Event::synth_param_cutoff_attack:
2256                            pNote->apply(itEvent, &NoteBase::_Override::CutoffAttack);
2257                            break;
2258                        case Event::synth_param_cutoff_decay:
2259                            pNote->apply(itEvent, &NoteBase::_Override::CutoffDecay);
2260                            break;
2261                        case Event::synth_param_cutoff_sustain:
2262                            pNote->apply(itEvent, &NoteBase::_Override::CutoffSustain);
2263                            break;
2264                        case Event::synth_param_cutoff_release:
2265                            pNote->apply(itEvent, &NoteBase::_Override::CutoffRelease);
2266                            break;
2267    
2268                        case Event::synth_param_amp_lfo_depth:
2269                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFODepth);
2270                            break;
2271                        case Event::synth_param_amp_lfo_freq:
2272                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFOFreq);
2273                            break;
2274                        case Event::synth_param_cutoff_lfo_depth:
2275                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFODepth);
2276                            break;
2277                        case Event::synth_param_cutoff_lfo_freq:
2278                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFOFreq);
2279                            break;
2280                        case Event::synth_param_pitch_lfo_depth:
2281                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFODepth);
2282                            break;
2283                        case Event::synth_param_pitch_lfo_freq:
2284                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFOFreq);
2285                          break;                          break;
2286                  }                  }
2287    
# Line 1977  namespace LinuxSampler { Line 2294  namespace LinuxSampler {
2294               *  Reset all voices and disk thread and clear input event queue and all               *  Reset all voices and disk thread and clear input event queue and all
2295               *  control and status variables. This method is protected by a mutex.               *  control and status variables. This method is protected by a mutex.
2296               */               */
2297              virtual void ResetInternal() {              virtual void ResetInternal() OVERRIDE {
2298                  LockGuard lock(ResetInternalMutex);                  LockGuard lock(ResetInternalMutex);
2299    
2300                  // make sure that the engine does not get any sysex messages                  // make sure that the engine does not get any sysex messages
# Line 2036  namespace LinuxSampler { Line 2353  namespace LinuxSampler {
2353               * @param pEngineChannel - engine channel on which all voices should be killed               * @param pEngineChannel - engine channel on which all voices should be killed
2354               * @param itKillEvent    - event which caused this killing of all voices               * @param itKillEvent    - event which caused this killing of all voices
2355               */               */
2356              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) {              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE {
2357                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2358                  int count = pChannel->KillAllVoices(itKillEvent);                  int count = pChannel->KillAllVoices(itKillEvent);
2359                  VoiceSpawnsLeft -= count; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead                  VoiceSpawnsLeft -= count; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead
# Line 2071  namespace LinuxSampler { Line 2388  namespace LinuxSampler {
2388                  bool                    HandleKeyGroupConflicts                  bool                    HandleKeyGroupConflicts
2389              ) = 0;              ) = 0;
2390    
2391              virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; }              virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; }
2392    
2393              int InitNewVoice (              int InitNewVoice (
2394                  EngineChannelBase<V, R, I>*  pChannel,                  EngineChannelBase<V, R, I>*  pChannel,
# Line 2094  namespace LinuxSampler { Line 2411  namespace LinuxSampler {
2411                      }                      }
2412                      else { // on success                      else { // on success
2413                          --VoiceSpawnsLeft;                          --VoiceSpawnsLeft;
2414                          if (!pKey->Active) { // mark as active key  
2415                              pKey->Active = true;                          // should actually be superfluous now, since this is
2416                              pKey->itSelf = pChannel->pActiveKeys->allocAppend();                          // already done in LaunchNewNote()
2417                              *pKey->itSelf = itNoteOnEvent->Param.Note.Key;                          pChannel->markKeyAsActive(pKey);
2418                          }  
2419                          if (itNewVoice->Type & Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s)                          if (itNewVoice->Type & Voice::type_release_trigger_required)
2420                                pKey->ReleaseTrigger |= itNewVoice->GetReleaseTriggerFlags(); // mark key for the need of release triggered voice(s)
2421                          return 0; // success                          return 0; // success
2422                      }                      }
2423                  }                  }

Legend:
Removed from v.2962  
changed lines
  Added in v.3690

  ViewVC Help
Powered by ViewVC