/[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 2931 by schoenebeck, Sat Jul 9 14:38:33 2016 UTC revision 3696 by schoenebeck, Sat Jan 4 11:30:38 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 689  namespace LinuxSampler { Line 706  namespace LinuxSampler {
706                  NoteIterator itNewNote = pNotePool->allocAppend();                  NoteIterator itNewNote = pNotePool->allocAppend();
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
710                    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,
714                  // however if this new note is requested not to be a regular                  // however if this new note is requested not to be a regular
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 727  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 795  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 853  namespace LinuxSampler { Line 890  namespace LinuxSampler {
890                                  dmsg(5,("Engine: Note on received\n"));                                  dmsg(5,("Engine: Note on received\n"));
891                                  ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent);
892                                  break;                                  break;
893                                case Event::type_play_note:
894                                    dmsg(5,("Engine: Play Note received\n"));
895                                    ProcessNoteOn((EngineChannel*)itEvent->pEngineChannel, itEvent);
896                                    break;
897                              case Event::type_note_off:                              case Event::type_note_off:
898                                  dmsg(5,("Engine: Note off received\n"));                                  dmsg(5,("Engine: Note off received\n"));
899                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
900                                  break;                                  break;
901                                case Event::type_stop_note:
902                                    dmsg(5,("Engine: Stop Note received\n"));
903                                    ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
904                                    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);
912                                  break;                                  break;
913                                case Event::type_rpn: // this can only be reached here by an instrument script having called set_rpn()
914                                    dmsg(5,("Engine: MIDI RPN received\n"));
915                                    ProcessHardcodedRpn((EngineChannel*)itEvent->pEngineChannel, itEvent);
916                                    break;
917                                case Event::type_nrpn: // this can only be reached here by an instrument script having called set_nrpn()
918                                    dmsg(5,("Engine: MIDI NRPN received\n"));
919                                    ProcessHardcodedNrpn((EngineChannel*)itEvent->pEngineChannel, itEvent);
920                                    break;
921                              case Event::type_channel_pressure:                              case Event::type_channel_pressure:
922                                  dmsg(5,("Engine: MIDI Chan. Pressure received\n"));                                  dmsg(5,("Engine: MIDI Chan. Pressure received\n"));
923                                  ProcessChannelPressure((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessChannelPressure((EngineChannel*)itEvent->pEngineChannel, itEvent);
# Line 877  namespace LinuxSampler { Line 934  namespace LinuxSampler {
934                                  dmsg(5,("Engine: Note Synth Param received\n"));                                  dmsg(5,("Engine: Note Synth Param received\n"));
935                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);
936                                  break;                                  break;
937                                case Event::type_sysex:
938                                    break; // TODO ...
939    
940                                case Event::type_cancel_release_key:
941                                case Event::type_release_key:
942                                case Event::type_release_note:
943                                    break; // noop
944                          }                          }
945                      }                      }
946                  }                  }
# Line 945  namespace LinuxSampler { Line 1009  namespace LinuxSampler {
1009                      // script event object                      // script event object
1010                      RTList<ScriptEvent>::Iterator itScriptEvent =                      RTList<ScriptEvent>::Iterator itScriptEvent =
1011                          pChannel->pScript->pEvents->allocAppend();                          pChannel->pScript->pEvents->allocAppend();
1012                        // if event handler uses polyphonic variables, reset them
1013                        // to zero values before starting to execute the handler
1014                        if (pEventHandler->isPolyphonic())
1015                            itScriptEvent->execCtx->resetPolyphonicData();
1016                      ProcessScriptEvent(                      ProcessScriptEvent(
1017                          pChannel, itEvent, pEventHandler, itScriptEvent                          pChannel, itEvent, pEventHandler, itScriptEvent
1018                      );                      );
# Line 977  namespace LinuxSampler { Line 1045  namespace LinuxSampler {
1045    
1046                  // initialize/reset other members                  // initialize/reset other members
1047                  itScriptEvent->cause = *itEvent;                  itScriptEvent->cause = *itEvent;
1048                    itScriptEvent->scheduleTime = itEvent->SchedTime();
1049                  itScriptEvent->currentHandler = 0;                  itScriptEvent->currentHandler = 0;
1050                  itScriptEvent->executionSlices = 0;                  itScriptEvent->executionSlices = 0;
1051                    itScriptEvent->ignoreAllWaitCalls = false;
1052                    itScriptEvent->handlerType = pEventHandler->eventHandlerType();
1053                    itScriptEvent->parentHandlerID = 0;
1054                    itScriptEvent->childHandlerID[0] = 0;
1055                    itScriptEvent->autoAbortByParent = false;
1056                    itScriptEvent->forkIndex = 0;
1057                  // this is the native representation of the $EVENT_ID script variable                  // this is the native representation of the $EVENT_ID script variable
1058                  itScriptEvent->id =                  itScriptEvent->id =
1059                      (itEvent->Type == Event::type_note_on)                      (itEvent->Type == Event::type_note_on)
# Line 1091  namespace LinuxSampler { Line 1166  namespace LinuxSampler {
1166               *  @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
1167               */               */
1168              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
1169                    dmsg(3,("StealVoice()\n"));
1170                  if (VoiceSpawnsLeft <= 0) {                  if (VoiceSpawnsLeft <= 0) {
1171                      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"));
1172                      return -1;                      return -1;
# Line 1115  namespace LinuxSampler { Line 1191  namespace LinuxSampler {
1191                  int                          iChannelIndex;                  int                          iChannelIndex;
1192                  VoiceIterator                itSelectedVoice;                  VoiceIterator                itSelectedVoice;
1193    
1194                    #if CONFIG_DEVMODE
1195                    EngineChannel* pBegin = NULL; // to detect endless loop
1196                    #endif
1197    
1198                  // select engine channel                  // select engine channel
1199                  if (pLastStolenChannel) {                  if (pLastStolenChannel) {
1200                      pSelectedChannel = pLastStolenChannel;                      pSelectedChannel = pLastStolenChannel;
# Line 1157  namespace LinuxSampler { Line 1237  namespace LinuxSampler {
1237                  }                  }
1238    
1239                  #if CONFIG_DEVMODE                  #if CONFIG_DEVMODE
1240                  EngineChannel* pBegin = pSelectedChannel; // to detect endless loop                  pBegin = pSelectedChannel; // to detect endless loop
1241                  #endif // CONFIG_DEVMODE                  #endif // CONFIG_DEVMODE
1242    
1243                  while (true) { // iterate through engine channels                                          while (true) { // iterate through engine channels                        
# Line 1246  namespace LinuxSampler { Line 1326  namespace LinuxSampler {
1326                          // the script's "init" event handler is only executed                          // the script's "init" event handler is only executed
1327                          // once (when the script is loaded or reloaded)                          // once (when the script is loaded or reloaded)
1328                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {
1329                                dmsg(5,("Engine: exec handlerInit %p\n", pEngineChannel->pScript->handlerInit));
1330                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1331                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1332    
1333                                itScriptEvent->cause = pEventGenerator->CreateEvent(0);
1334                                itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing
1335                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1336                                itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort();
1337                                itScriptEvent->id = 0;
1338                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1339                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1340                                itScriptEvent->currentHandler = 0;
1341                              VMExecStatus_t res = pScriptVM->exec(                              itScriptEvent->executionSlices = 0;
1342                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                              itScriptEvent->ignoreAllWaitCalls = false;
1343                              );                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1344                                itScriptEvent->parentHandlerID = 0;
1345                                itScriptEvent->childHandlerID[0] = 0;
1346                                itScriptEvent->autoAbortByParent = false;
1347                                itScriptEvent->forkIndex = 0;
1348    
1349                                VMExecStatus_t res;
1350                                size_t instructionsCount = 0;
1351                                const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction)
1352                                bool bWarningShown = false;
1353                                do {
1354                                    res = pScriptVM->exec(
1355                                        pEngineChannel->pScript->parserContext, &*itScriptEvent
1356                                    );
1357                                    instructionsCount += itScriptEvent->execCtx->instructionsPerformed();
1358                                    if (instructionsCount > maxInstructions && !bWarningShown) {
1359                                        bWarningShown = true;
1360                                        dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n"));
1361                                    }
1362                                } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR));
1363    
1364                              pEngineChannel->pScript->pEvents->free(itScriptEvent);                              pEngineChannel->pScript->pEvents->free(itScriptEvent);
1365                          }                          }
# Line 1316  namespace LinuxSampler { Line 1420  namespace LinuxSampler {
1420                          // usually there should already be a new Note object                          // usually there should already be a new Note object
1421                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);
1422                          if (!itNote) { // should not happen, but just to be sure ...                          if (!itNote) { // should not happen, but just to be sure ...
1423                              const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent);                              dmsg(2,("Engine: No Note object for stolen voice!\n"));
1424                                const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);
1425                              if (!noteID) {                              if (!noteID) {
1426                                  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"));
1427                                  continue;                                  continue;
# Line 1360  namespace LinuxSampler { Line 1465  namespace LinuxSampler {
1465              void PostProcess(EngineChannel* pEngineChannel) {              void PostProcess(EngineChannel* pEngineChannel) {
1466                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1467                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1468                   pChannel->FreeAllInactiveKyes();                   pChannel->FreeAllInactiveKeys();
1469    
1470                  // empty the engine channel's own event lists                  // empty the engine channel's own event lists
1471                  // (only events of the current audio fragment cycle)                  // (only events of the current audio fragment cycle)
# Line 1387  namespace LinuxSampler { Line 1492  namespace LinuxSampler {
1492                          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;
1493                          break;                          break;
1494                      }                      }
1495                      case 6: { // data entry (currently only used for RPN and NRPN controllers)                      case 6: { // data entry (MSB)
1496                          //dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value));                          //dmsg(1,("DATA ENTRY MSB %d\n", itControlChangeEvent->Param.CC.Value));
1497                          if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ...  
1498                              dmsg(4,("Guess it's an RPN ...\n"));                          // look-ahead: if next MIDI event is data entry LSB,
1499                              if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones                          // then skip this event here for now (to avoid double
1500                                  int transpose = (int) itControlChangeEvent->Param.CC.Value - 64;                          // handling of what's supposed to be one RPN/NRPN event)
1501                                  // limit to +- two octaves for now                          if (isNextEventCCNr(itControlChangeEvent, 38))
1502                                  transpose = RTMath::Min(transpose,  24);                              break;
1503                                  transpose = RTMath::Max(transpose, -24);  
1504                                  pChannel->GlobalTranspose = transpose;                          if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1505                                  // workaround, so we won't have hanging notes                              int ch = itControlChangeEvent->Param.CC.Channel;
1506                                  pChannel->ReleaseAllVoices(itControlChangeEvent);                              int param = pChannel->GetMidiRpnParameter();
1507                              }                              int value = itControlChangeEvent->Param.CC.Value << 7;
1508                              // to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data  
1509                              pChannel->ResetMidiRpnController();                              // transform event type: CC event -> RPN event
1510                          } else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ...                              itControlChangeEvent->Type = Event::type_rpn;
1511                              dmsg(4,("Guess it's an NRPN ...\n"));                              itControlChangeEvent->Param.RPN.Channel = ch;
1512                              const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8;                              itControlChangeEvent->Param.RPN.Parameter = param;
1513                              const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff;                              itControlChangeEvent->Param.RPN.Value = value;
1514                              dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value));  
1515                              switch (NrpnCtrlMSB) {                              // if there's a RPN script handler, run it ...
1516                                  case 0x1a: { // volume level of note (Roland GS NRPN)                              if (pChannel->pScript->handlerRpn) {
1517                                      const uint note = NrpnCtrlLSB;                                  const event_id_t eventID =
1518                                      const uint vol  = itControlChangeEvent->Param.CC.Value;                                      pEventPool->getID(itControlChangeEvent);
1519                                      dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));                                  // run the RPN script handler
1520                                      if (note < 128 && vol < 128)                                  ProcessEventByScript(
1521                                          pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];                                      pChannel, itControlChangeEvent,
1522                                      break;                                      pChannel->pScript->handlerRpn
1523                                  }                                  );
1524                                  case 0x1c: { // panpot of note (Roland GS NRPN)                                  // if RPN event was dropped by script, abort
1525                                      const uint note = NrpnCtrlLSB;                                  // here to avoid hard coded RPN processing below
1526                                      const uint pan  = itControlChangeEvent->Param.CC.Value;                                  if (!pEventPool->fromID(eventID)) {
1527                                      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
1528                                      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;  
1529                                      break;                                      break;
1530                                  }                                  }
1531                                  case 0x1e: { // chorus send of note (Roland GS NRPN)                              }
1532                                      const uint note = NrpnCtrlLSB;  
1533                                      const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f;                              // do the actual (hard-coded) RPN value change processing
1534                                      dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));                              ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1535                                      if (note < 128)  
1536                                          pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;                              // to prevent other data entry messages to be misenterpreted as RPN value
1537                                pChannel->ResetMidiRpnParameter();
1538                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1539                                int ch = itControlChangeEvent->Param.CC.Channel;
1540                                int param = pChannel->GetMidiNrpnParameter();
1541                                int value = itControlChangeEvent->Param.CC.Value << 7;
1542    
1543                                // transform event type: CC event -> NRPN event
1544                                itControlChangeEvent->Type = Event::type_nrpn;
1545                                itControlChangeEvent->Param.NRPN.Channel = ch;
1546                                itControlChangeEvent->Param.NRPN.Parameter = param;
1547                                itControlChangeEvent->Param.NRPN.Value = value;
1548    
1549                                // if there's a NRPN script handler, run it ...
1550                                if (pChannel->pScript->handlerNrpn) {
1551                                    const event_id_t eventID =
1552                                        pEventPool->getID(itControlChangeEvent);
1553                                    // run the NRPN script handler
1554                                    ProcessEventByScript(
1555                                        pChannel, itControlChangeEvent,
1556                                        pChannel->pScript->handlerNrpn
1557                                    );
1558                                    // if NRPN event was dropped by script, abort
1559                                    // here to avoid hard coded NRPN processing below
1560                                    if (!pEventPool->fromID(eventID)) {
1561                                        // to prevent other data entry messages to be misenterpreted as NRPN value
1562                                        pChannel->ResetMidiNrpnParameter();
1563                                      break;                                      break;
1564                                  }                                  }
1565                              }                              }
1566                              // to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data  
1567                              pChannel->ResetMidiNrpnController();                              // do the actual (hard-coded) NRPN value change processing
1568                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1569    
1570                                // to prevent other data entry messages to be misenterpreted as NRPN value
1571                                pChannel->ResetMidiNrpnParameter();
1572                          }                          }
1573                          break;                          break;
1574                      }                      }
# Line 1459  namespace LinuxSampler { Line 1583  namespace LinuxSampler {
1583                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;
1584                          break;                          break;
1585                      }                      }
1586                        case 38: { // data entry (LSB)
1587                            //dmsg(1,("DATA ENTRY LSB %d\n", itControlChangeEvent->Param.CC.Value));
1588                            int value = 0;
1589    
1590                            // look-back: if previous MIDI event was data entry MSB,
1591                            // then obtain that value for the MSB value portion
1592                            if (isPrevEventCCNr(itControlChangeEvent, 6))
1593                                value = prevEventOf(itControlChangeEvent)->Param.CC.Value << 7;
1594    
1595                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1596                                int ch = itControlChangeEvent->Param.CC.Channel;
1597                                int param = pChannel->GetMidiRpnParameter();
1598                                value |= itControlChangeEvent->Param.CC.Value;
1599    
1600                                // transform event type: CC event -> RPN event
1601                                itControlChangeEvent->Type = Event::type_rpn;
1602                                itControlChangeEvent->Param.RPN.Channel = ch;
1603                                itControlChangeEvent->Param.RPN.Parameter = param;
1604                                itControlChangeEvent->Param.RPN.Value = value;
1605    
1606                                // if there's a RPN script handler, run it ...
1607                                if (pChannel->pScript->handlerRpn) {
1608                                    const event_id_t eventID =
1609                                        pEventPool->getID(itControlChangeEvent);
1610                                    // run the RPN script handler
1611                                    ProcessEventByScript(
1612                                        pChannel, itControlChangeEvent,
1613                                        pChannel->pScript->handlerRpn
1614                                    );
1615                                    // if RPN event was dropped by script, abort
1616                                    // here to avoid hard coded RPN processing below
1617                                    if (!pEventPool->fromID(eventID)) {
1618                                        // to prevent other data entry messages to be misenterpreted as RPN value
1619                                        pChannel->ResetMidiRpnParameter();
1620                                        break;
1621                                    }
1622                                }
1623    
1624                                // do the actual (hard-coded) RPN value change processing
1625                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1626    
1627                                // to prevent other data entry messages to be misenterpreted as RPN value
1628                                pChannel->ResetMidiRpnParameter();
1629                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1630                                int ch = itControlChangeEvent->Param.CC.Channel;
1631                                int param = pChannel->GetMidiNrpnParameter();
1632                                value |= itControlChangeEvent->Param.CC.Value;
1633    
1634                                // transform event type: CC event -> NRPN event
1635                                itControlChangeEvent->Type = Event::type_nrpn;
1636                                itControlChangeEvent->Param.NRPN.Channel = ch;
1637                                itControlChangeEvent->Param.NRPN.Parameter = param;
1638                                itControlChangeEvent->Param.NRPN.Value = value;
1639    
1640                                // if there's a NRPN script handler, run it ...
1641                                if (pChannel->pScript->handlerNrpn) {
1642                                    const event_id_t eventID =
1643                                        pEventPool->getID(itControlChangeEvent);
1644                                    // run the NRPN script handler
1645                                    ProcessEventByScript(
1646                                        pChannel, itControlChangeEvent,
1647                                        pChannel->pScript->handlerNrpn
1648                                    );
1649                                    // if NRPN event was dropped by script, abort
1650                                    // here to avoid hard coded NRPN processing below
1651                                    if (!pEventPool->fromID(eventID)) {
1652                                        // to prevent other data entry messages to be misenterpreted as NRPN value
1653                                        pChannel->ResetMidiNrpnParameter();
1654                                        break;
1655                                    }
1656                                }
1657    
1658                                // do the actual (hard-coded) NRPN value change processing
1659                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1660    
1661                                // to prevent other data entry messages to be misenterpreted as NRPN value
1662                                pChannel->ResetMidiNrpnParameter();
1663                            }
1664                            break;
1665                        }
1666                      case 64: { // sustain                      case 64: { // sustain
1667                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {
1668                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
# Line 1532  namespace LinuxSampler { Line 1736  namespace LinuxSampler {
1736                          }                          }
1737                          break;                          break;
1738                      }                      }
1739                      case 98: { // NRPN controller LSB                      case 98: { // NRPN parameter LSB
1740                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1741                          pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiNrpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1742                          break;                          break;
1743                      }                      }
1744                      case 99: { // NRPN controller MSB                      case 99: { // NRPN parameter MSB
1745                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1746                          pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiNrpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1747                          break;                          break;
1748                      }                      }
1749                      case 100: { // RPN controller LSB                      case 100: { // RPN parameter LSB
1750                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1751                          pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiRpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1752                          break;                          break;
1753                      }                      }
1754                      case 101: { // RPN controller MSB                      case 101: { // RPN parameter MSB
1755                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1756                          pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          pEngineChannel->SetMidiRpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1757                          break;                          break;
1758                      }                      }
1759    
# Line 1585  namespace LinuxSampler { Line 1789  namespace LinuxSampler {
1789                  }                  }
1790              }              }
1791    
1792                /**
1793                 * Process MIDI RPN events with hard coded behavior.
1794                 *
1795                 * @param pEngineChannel - engine channel on which the MIDI RPN
1796                 *                         event was received
1797                 * @param itRpnEvent - the actual MIDI RPN event
1798                 */
1799                void ProcessHardcodedRpn(EngineChannel* pEngineChannel,
1800                                         Pool<Event>::Iterator& itRpnEvent)
1801                {
1802                    EngineChannelBase<V, R, I>* pChannel =
1803                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1804    
1805                    if (itRpnEvent->Param.RPN.Parameter == 2) { // coarse tuning in half tones
1806                        int transpose = (int) itRpnEvent->Param.RPN.ValueMSB() - 64;
1807                        // limit to +- two octaves for now
1808                        transpose = RTMath::Min(transpose,  24);
1809                        transpose = RTMath::Max(transpose, -24);
1810                        pChannel->GlobalTranspose = transpose;
1811                        // workaround, so we won't have hanging notes
1812                        pChannel->ReleaseAllVoices(itRpnEvent);
1813                    }
1814                }
1815    
1816                /**
1817                 * Process MIDI NRPN events with hard coded behavior.
1818                 *
1819                 * @param pEngineChannel - engine channel on which the MIDI NRPN
1820                 *                         event was received
1821                 * @param itRpnEvent - the actual MIDI NRPN event
1822                 */
1823                void ProcessHardcodedNrpn(EngineChannel* pEngineChannel,
1824                                          Pool<Event>::Iterator& itNrpnEvent)
1825                {
1826                    EngineChannelBase<V, R, I>* pChannel =
1827                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1828    
1829                    switch (itNrpnEvent->Param.NRPN.ParameterMSB()) {
1830                        case 0x1a: { // volume level of note (Roland GS NRPN)
1831                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1832                            const uint vol  = itNrpnEvent->Param.NRPN.ValueMSB();
1833                            dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));
1834                            if (note < 128 && vol < 128)
1835                                pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];
1836                            break;
1837                        }
1838                        case 0x1c: { // panpot of note (Roland GS NRPN)
1839                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1840                            const uint pan  = itNrpnEvent->Param.NRPN.ValueMSB();
1841                            dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));
1842                            if (note < 128 && pan < 128) {
1843                                pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];
1844                                pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];
1845                            }
1846                            break;
1847                        }
1848                        case 0x1d: { // reverb send of note (Roland GS NRPN)
1849                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1850                            const float reverb = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
1851                            dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb));
1852                            if (note < 128)
1853                                pChannel->pMIDIKeyInfo[note].ReverbSend = reverb;
1854                            break;
1855                        }
1856                        case 0x1e: { // chorus send of note (Roland GS NRPN)
1857                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
1858                            const float chorus = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
1859                            dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));
1860                            if (note < 128)
1861                                pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;
1862                            break;
1863                        }
1864                    }
1865                }
1866    
1867              virtual D* CreateDiskThread() = 0;              virtual D* CreateDiskThread() = 0;
1868    
1869              /**              /**
# Line 1593  namespace LinuxSampler { Line 1872  namespace LinuxSampler {
1872               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
1873               *  @param itNoteOnEvent - key, velocity and time stamp of the event               *  @param itNoteOnEvent - key, velocity and time stamp of the event
1874               */               */
1875              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
1876                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1877                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1878    
# Line 1603  namespace LinuxSampler { Line 1882  namespace LinuxSampler {
1882    
1883                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[key];                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[key];
1884    
1885                  pChannel->listeners.PreProcessNoteOn(key, vel);                  // There are real MIDI note-on events (Event::type_note_on) and
1886                    // programmatically spawned notes (Event::type_play_note). We have
1887                    // to distinguish between them, since certain processing below
1888                    // must only be done on real MIDI note-on events (i.e. for
1889                    // correctly updating which MIDI keys are currently pressed down).
1890                    const bool isRealMIDINoteOnEvent = itNoteOnEvent->Type == Event::type_note_on;
1891    
1892                    if (isRealMIDINoteOnEvent)
1893                        pChannel->listeners.PreProcessNoteOn(key, vel);
1894    
1895                  #if !CONFIG_PROCESS_MUTED_CHANNELS                  #if !CONFIG_PROCESS_MUTED_CHANNELS
1896                  if (pEngineChannel->GetMute()) { // skip if sampler channel is muted                  if (pEngineChannel->GetMute()) { // skip if sampler channel is muted
1897                      pChannel->listeners.PostProcessNoteOn(key, vel);                      if (isRealMIDINoteOnEvent)
1898                            pChannel->listeners.PostProcessNoteOn(key, vel);
1899                      return;                      return;
1900                  }                  }
1901                  #endif                  #endif
1902    
1903                  if (!pChannel->pInstrument) {                  if (!pChannel->pInstrument) {
1904                      pChannel->listeners.PostProcessNoteOn(key, vel);                      if (isRealMIDINoteOnEvent)
1905                            pChannel->listeners.PostProcessNoteOn(key, vel);
1906                      return; // ignore if no instrument loaded                      return; // ignore if no instrument loaded
1907                  }                  }
1908    
# Line 1620  namespace LinuxSampler { Line 1910  namespace LinuxSampler {
1910                  RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);                  RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
1911    
1912                  // if Solo Mode then kill all already active voices                  // if Solo Mode then kill all already active voices
1913                  if (pChannel->SoloMode) {                  if (pChannel->SoloMode && isRealMIDINoteOnEvent) {
1914                      Pool<uint>::Iterator itYoungestKey = pChannel->pActiveKeys->last();                      Pool<uint>::Iterator itYoungestKey = pChannel->pActiveKeys->last();
1915                      if (itYoungestKey) {                      if (itYoungestKey) {
1916                          const int iYoungestKey = *itYoungestKey;                          const int iYoungestKey = *itYoungestKey;
# Line 1649  namespace LinuxSampler { Line 1939  namespace LinuxSampler {
1939                      pChannel->SoloKey = key;                      pChannel->SoloKey = key;
1940                  }                  }
1941    
1942                  pChannel->ProcessKeySwitchChange(key);                  if (isRealMIDINoteOnEvent) {
1943                        pChannel->ProcessKeySwitchChange(key);
1944    
1945                  pKey->KeyPressed = true; // the MIDI key was now pressed down                      pKey->KeyPressed = true; // the MIDI key was now pressed down
1946                  pChannel->KeyDown[key] = true; // just used as built-in %KEY_DOWN script variable                      pChannel->KeyDown[key] = true; // just used as built-in %KEY_DOWN script variable
1947                  pKey->Velocity   = itNoteOnEventOnKeyList->Param.Note.Velocity;                      pKey->Velocity   = itNoteOnEventOnKeyList->Param.Note.Velocity;
1948                  pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length                      pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length
1949                    }
1950    
1951                  // cancel release process of voices on this key if needed                  // cancel release process of voices on this key if needed
1952                  if (pKey->Active && !pChannel->SustainPedal) {                  if (pKey->Active && !pChannel->SustainPedal && isRealMIDINoteOnEvent) {
1953                      RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();                      RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();
1954                      if (itCancelReleaseEvent) {                      if (itCancelReleaseEvent) {
1955                          *itCancelReleaseEvent = *itNoteOnEventOnKeyList;         // copy event                          *itCancelReleaseEvent = *itNoteOnEventOnKeyList;         // copy event
1956                          itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type                          itCancelReleaseEvent->Type = Event::type_cancel_release_key; // transform event type
1957                      }                      }
1958                      else dmsg(1,("Event pool emtpy!\n"));                      else dmsg(1,("Event pool emtpy!\n"));
1959                  }                  }
# Line 1672  namespace LinuxSampler { Line 1964  namespace LinuxSampler {
1964                  if (!pKey->Active && !pKey->VoiceTheftsQueued)                  if (!pKey->Active && !pKey->VoiceTheftsQueued)
1965                      pKey->pEvents->free(itNoteOnEventOnKeyList);                      pKey->pEvents->free(itNoteOnEventOnKeyList);
1966    
1967                  if (!pChannel->SoloMode || pChannel->PortamentoPos < 0.0f) pChannel->PortamentoPos = (float) key;                  if (isRealMIDINoteOnEvent && (!pChannel->SoloMode || pChannel->PortamentoPos < 0.0f))
1968                        pChannel->PortamentoPos = (float) key;
1969    
1970                    //NOTE: Hmm, I guess its a matter of taste whether round robin should be advanced only on real MIDI note-on events, isn't it?
1971                  if (pKey->pRoundRobinIndex) {                  if (pKey->pRoundRobinIndex) {
1972                      (*pKey->pRoundRobinIndex)++; // counter specific for the key or region                      (*pKey->pRoundRobinIndex)++; // counter specific for the key or region
1973                      pChannel->RoundRobinIndex++; // common counter for the channel                      pChannel->RoundRobinIndex++; // common counter for the channel
1974                  }                  }
1975                  pChannel->listeners.PostProcessNoteOn(key, vel);  
1976                    if (isRealMIDINoteOnEvent)
1977                        pChannel->listeners.PostProcessNoteOn(key, vel);
1978              }              }
1979    
1980              /**              /**
# Line 1706  namespace LinuxSampler { Line 2003  namespace LinuxSampler {
2003               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
2004               *  @param itNoteOffEvent - key, velocity and time stamp of the event               *  @param itNoteOffEvent - key, velocity and time stamp of the event
2005               */               */
2006              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE {
2007                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2008    
2009                  const int iKey = itNoteOffEvent->Param.Note.Key;                  const int iKey = itNoteOffEvent->Param.Note.Key;
# Line 1715  namespace LinuxSampler { Line 2012  namespace LinuxSampler {
2012    
2013                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[iKey];                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[iKey];
2014    
2015                  pChannel->listeners.PreProcessNoteOff(iKey, vel);                  // There are real MIDI note-off events (Event::type_note_off) and
2016                    // programmatically spawned notes (Event::type_stop_note). We have
2017                    // to distinguish between them, since certain processing below
2018                    // must only be done on real MIDI note-off events (i.e. for
2019                    // correctly updating which MIDI keys are currently pressed down),
2020                    // plus a stop-note event just releases voices of one particular
2021                    // note, whereas a note-off event releases all voices on a
2022                    // particular MIDI key instead.
2023                    const bool isRealMIDINoteOffEvent = itNoteOffEvent->Type == Event::type_note_off;
2024    
2025                    if (isRealMIDINoteOffEvent)
2026                        pChannel->listeners.PreProcessNoteOff(iKey, vel);
2027    
2028                  #if !CONFIG_PROCESS_MUTED_CHANNELS                  #if !CONFIG_PROCESS_MUTED_CHANNELS
2029                  if (pEngineChannel->GetMute()) { // skip if sampler channel is muted                  if (pEngineChannel->GetMute()) { // skip if sampler channel is muted
2030                      pChannel->listeners.PostProcessNoteOff(iKey, vel);                      if (isRealMIDINoteOffEvent)
2031                            pChannel->listeners.PostProcessNoteOff(iKey, vel);
2032                      return;                      return;
2033                  }                  }
2034                  #endif                  #endif
2035    
2036                  pKey->KeyPressed = false; // the MIDI key was now released                  if (isRealMIDINoteOffEvent) {
2037                  pChannel->KeyDown[iKey] = false; // just used as built-in %KEY_DOWN script variable                      pKey->KeyPressed = false; // the MIDI key was now released
2038                        pChannel->KeyDown[iKey] = false; // just used as built-in %KEY_DOWN script variable
2039                    }
2040    
2041                  // move event to the key's own event list                  // move event to the key's own event list
2042                  RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);                  RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);
2043    
2044                  bool bShouldRelease = pKey->Active && pChannel->ShouldReleaseVoice(itNoteOffEventOnKeyList->Param.Note.Key);                  if (isRealMIDINoteOffEvent) {
2045                        bool bShouldRelease = pKey->Active && pChannel->ShouldReleaseVoice(itNoteOffEventOnKeyList->Param.Note.Key);
2046    
2047                  // in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any)                      // in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any)
2048                  if (pChannel->SoloMode && pChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P                      if (pChannel->SoloMode && pChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P
2049                      bool bOtherKeysPressed = false;                          bool bOtherKeysPressed = false;
2050                      if (iKey == pChannel->SoloKey) {                          if (iKey == pChannel->SoloKey) {
2051                          pChannel->SoloKey = -1;                              pChannel->SoloKey = -1;
2052                          // if there's still a key pressed down, respawn a voice (group) on the highest key                              // if there's still a key pressed down, respawn a voice (group) on the highest key
2053                          for (int i = 127; i > 0; i--) {                              for (int i = 127; i > 0; i--) {
2054                              MidiKey* pOtherKey = &pChannel->pMIDIKeyInfo[i];                                  MidiKey* pOtherKey = &pChannel->pMIDIKeyInfo[i];
2055                              if (pOtherKey->KeyPressed) {                                  if (pOtherKey->KeyPressed) {
2056                                  bOtherKeysPressed = true;                                      bOtherKeysPressed = true;
2057                                  // make the other key the new 'currently active solo key'                                      // make the other key the new 'currently active solo key'
2058                                  pChannel->SoloKey = i;                                      pChannel->SoloKey = i;
2059                                  // get final portamento position of currently active voice                                      // get final portamento position of currently active voice
2060                                  if (pChannel->PortamentoMode) {                                      if (pChannel->PortamentoMode) {
2061                                      NoteIterator itNote = pKey->pActiveNotes->first();                                          NoteIterator itNote = pKey->pActiveNotes->first();
2062                                      VoiceIterator itVoice = itNote->pActiveVoices->first();                                          VoiceIterator itVoice = itNote->pActiveVoices->first();
2063                                      if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList);                                          if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList);
                                 }  
                                 // create a pseudo note on event  
                                 RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend();  
                                 if (itPseudoNoteOnEvent) {  
                                     // copy event  
                                     *itPseudoNoteOnEvent = *itNoteOffEventOnKeyList;  
                                     // transform event to a note on event  
                                     itPseudoNoteOnEvent->Type                = Event::type_note_on;  
                                     itPseudoNoteOnEvent->Param.Note.Key      = i;  
                                     itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;  
                                     // assign a new note to this note-on event  
                                     if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) {  
                                         // allocate and trigger new voice(s) for the other key  
                                         TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);  
2064                                      }                                      }
2065                                      // if neither a voice was spawned or postponed then remove note on event from key again                                      // create a pseudo note on event
2066                                      if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued)                                      RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend();
2067                                          pOtherKey->pEvents->free(itPseudoNoteOnEvent);                                      if (itPseudoNoteOnEvent) {
2068                                            // copy event
2069                                            *itPseudoNoteOnEvent = *itNoteOffEventOnKeyList;
2070                                            // transform event to a note on event
2071                                            itPseudoNoteOnEvent->Type                = Event::type_note_on; //FIXME: should probably use Event::type_play_note instead (to avoid i.e. hanging notes)
2072                                            itPseudoNoteOnEvent->Param.Note.Key      = i;
2073                                            itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
2074                                            // assign a new note to this note-on event
2075                                            if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) {
2076                                                // allocate and trigger new voice(s) for the other key
2077                                                TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);
2078                                            }
2079                                            // if neither a voice was spawned or postponed then remove note on event from key again
2080                                            if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued)
2081                                                pOtherKey->pEvents->free(itPseudoNoteOnEvent);
2082    
2083                                  } else dmsg(1,("Could not respawn voice, no free event left\n"));                                      } else dmsg(1,("Could not respawn voice, no free event left\n"));
2084                                  break; // done                                      break; // done
2085                                    }
2086                              }                              }
2087                          }                          }
2088                      }                          if (bOtherKeysPressed) {
2089                      if (bOtherKeysPressed) {                              if (pKey->Active) { // kill all voices on this key
2090                          if (pKey->Active) { // kill all voices on this key                                  bShouldRelease = false; // no need to release, as we kill it here
2091                              bShouldRelease = false; // no need to release, as we kill it here                                  for (NoteIterator itNote = pKey->pActiveNotes->first(); itNote; ++itNote) {
2092                              for (NoteIterator itNote = pKey->pActiveNotes->first(); itNote; ++itNote) {                                      VoiceIterator itVoiceToBeKilled = itNote->pActiveVoices->first();
2093                                  VoiceIterator itVoiceToBeKilled = itNote->pActiveVoices->first();                                      VoiceIterator end               = itNote->pActiveVoices->end();
2094                                  VoiceIterator end               = itNote->pActiveVoices->end();                                      for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
2095                                  for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {                                          if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger))
2096                                      if (!(itVoiceToBeKilled->Type & Voice::type_release_trigger))                                              itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList);
2097                                          itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList);                                      }
2098                                  }                                  }
2099                              }                              }
2100                          }                          } else pChannel->PortamentoPos = -1.0f;
2101                      } else pChannel->PortamentoPos = -1.0f;                      }
                 }  
2102    
2103                  // if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed                      // if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed
2104                  if (bShouldRelease) {                      if (bShouldRelease) {
2105                      itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type
2106                      // spawn release triggered voice(s) if needed                          // spawn release triggered voice(s) if needed
2107                      ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);                          if (pKey->ReleaseTrigger & release_trigger_noteoff)
2108                                ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);
2109                        }
2110                    } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {
2111                        // This programmatically caused event is caused by a call to
2112                        // the built-in instrument script function note_off(). In
2113                        // contrast to a real MIDI note-off event the stop-note
2114                        // event just intends to release voices of one particular note.
2115                        NoteBase* pNote = pChannel->pEngine->NoteByID( itNoteOffEventOnKeyList->Param.Note.ID );
2116                        if (pNote) { // the requested note is still alive ...
2117                            itNoteOffEventOnKeyList->Type = Event::type_release_note; // transform event type
2118                        } else { // note is dead and gone ..
2119                            pKey->pEvents->free(itNoteOffEventOnKeyList); // remove stop-note event from key again
2120                            return; // prevent event to be removed a 2nd time below
2121                        }
2122                  }                  }
2123    
2124                  // if neither a voice was spawned or postponed on this key then remove note off event from key again                  // if neither a voice was spawned or postponed on this key then remove note off event from key again
2125                  if (!pKey->Active && !pKey->VoiceTheftsQueued)                  if (!pKey->Active && !pKey->VoiceTheftsQueued)
2126                      pKey->pEvents->free(itNoteOffEventOnKeyList);                      pKey->pEvents->free(itNoteOffEventOnKeyList);
2127    
2128                  pChannel->listeners.PostProcessNoteOff(iKey, vel);                  if (isRealMIDINoteOffEvent)
2129                        pChannel->listeners.PostProcessNoteOff(iKey, vel);
2130              }              }
2131    
2132              /**              /**
# Line 1809  namespace LinuxSampler { Line 2136  namespace LinuxSampler {
2136               * @param pEngineChannel - engine channel on which this event occurred on               * @param pEngineChannel - engine channel on which this event occurred on
2137               * @param itEvent - release trigger event (contains note number)               * @param itEvent - release trigger event (contains note number)
2138               */               */
2139              virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {              virtual void ProcessReleaseTriggerBySustain(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {
2140                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2141    
2142                  const int iKey = itEvent->Param.Note.Key;                  const int iKey = itEvent->Param.Note.Key;
# Line 1833  namespace LinuxSampler { Line 2160  namespace LinuxSampler {
2160                  // spawn release triggered voice(s) if needed                  // spawn release triggered voice(s) if needed
2161                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {
2162                      // assign a new note to this release event                      // assign a new note to this release event
2163                      if (LaunchNewNote(pChannel, &*itEvent)) {                      if (LaunchNewNote(pChannel, itEvent)) {
2164                          // allocate and trigger new release voice(s)                          // allocate and trigger new release voice(s)
2165                          TriggerReleaseVoices(pChannel, itEvent);                          TriggerReleaseVoices(pChannel, itEvent);
2166                      }                      }
2167                      pKey->ReleaseTrigger = false;                      pKey->ReleaseTrigger = release_trigger_none;
2168                  }                  }
2169              }              }
2170    
2171              /**              /**
2172                 * Called on "kill note" events, which currently only happens on
2173                 * built-in real-time instrument script function fade_out(). This
2174                 * method only fulfills one task: moving the even to the Note's own
2175                 * event list so that its voices can process the kill event sample
2176                 * accurately.
2177                 */
2178                void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
2179                    EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2180    
2181                    NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID );
2182                    if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2183    
2184                    // move note kill event to its MIDI key
2185                    MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey];
2186                    itEvent.moveToEndOf(pKey->pEvents);
2187                }
2188    
2189                /**
2190               * Called on note synthesis parameter change events. These are               * Called on note synthesis parameter change events. These are
2191               * internal events caused by calling built-in real-time instrument               * internal events caused by calling built-in real-time instrument
2192               * script functions like change_vol(), change_pitch(), etc.               * script functions like change_vol(), change_tune(), etc.
2193               *               *
2194               * This method performs two tasks:               * This method performs two tasks:
2195               *               *
# Line 1859  namespace LinuxSampler { Line 2204  namespace LinuxSampler {
2204               * @param pEngineChannel - engine channel on which this event occurred on               * @param pEngineChannel - engine channel on which this event occurred on
2205               * @param itEvent - note synthesis parameter change event               * @param itEvent - note synthesis parameter change event
2206               */               */
2207              virtual void ProcessNoteSynthParam(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {              virtual void ProcessNoteSynthParam(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
2208                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2209    
2210                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );
2211                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2212    
                 const bool& relative = itEvent->Param.NoteSynthParam.Relative;  
   
2213                  switch (itEvent->Param.NoteSynthParam.Type) {                  switch (itEvent->Param.NoteSynthParam.Type) {
2214                      case Event::synth_param_volume:                      case Event::synth_param_volume:
2215                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Volume);
2216                              pNote->Override.Volume *= itEvent->Param.NoteSynthParam.Delta;                          break;
2217                          else                      case Event::synth_param_volume_time:
2218                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2219                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;                          break;
2220                        case Event::synth_param_volume_curve:
2221                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2222                            pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2223                          break;                          break;
2224                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
2225                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Pitch);
2226                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;                          break;
2227                          else                      case Event::synth_param_pitch_time:
2228                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2229                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;                          break;
2230                        case Event::synth_param_pitch_curve:
2231                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2232                            pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2233                          break;                          break;
2234                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2235                          if (relative) {                          pNote->apply(itEvent, &NoteBase::_Override::Pan);
2236                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);                          break;
2237                          } else {                      case Event::synth_param_pan_time:
2238                              pNote->Override.Pan = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2239                              pNote->Override.PanSources = 1; // only relevant on subsequent change_pan() instrument script calls on same note with 'relative' argument being set                          break;
2240                          }                      case Event::synth_param_pan_curve:
2241                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan;                          itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2242                            pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2243                            break;
2244                        case Event::synth_param_cutoff:
2245                            pNote->apply(itEvent, &NoteBase::_Override::Cutoff);
2246                            break;
2247                        case Event::synth_param_resonance:
2248                            pNote->apply(itEvent, &NoteBase::_Override::Resonance);
2249                            break;
2250                        case Event::synth_param_attack:
2251                            pNote->apply(itEvent, &NoteBase::_Override::Attack);
2252                            break;
2253                        case Event::synth_param_decay:
2254                            pNote->apply(itEvent, &NoteBase::_Override::Decay);
2255                            break;
2256                        case Event::synth_param_sustain:
2257                            pNote->apply(itEvent, &NoteBase::_Override::Sustain);
2258                            break;
2259                        case Event::synth_param_release:
2260                            pNote->apply(itEvent, &NoteBase::_Override::Release);
2261                            break;
2262    
2263                        case Event::synth_param_cutoff_attack:
2264                            pNote->apply(itEvent, &NoteBase::_Override::CutoffAttack);
2265                            break;
2266                        case Event::synth_param_cutoff_decay:
2267                            pNote->apply(itEvent, &NoteBase::_Override::CutoffDecay);
2268                            break;
2269                        case Event::synth_param_cutoff_sustain:
2270                            pNote->apply(itEvent, &NoteBase::_Override::CutoffSustain);
2271                            break;
2272                        case Event::synth_param_cutoff_release:
2273                            pNote->apply(itEvent, &NoteBase::_Override::CutoffRelease);
2274                            break;
2275    
2276                        case Event::synth_param_amp_lfo_depth:
2277                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFODepth);
2278                            break;
2279                        case Event::synth_param_amp_lfo_freq:
2280                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFOFreq);
2281                            break;
2282                        case Event::synth_param_cutoff_lfo_depth:
2283                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFODepth);
2284                            break;
2285                        case Event::synth_param_cutoff_lfo_freq:
2286                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFOFreq);
2287                            break;
2288                        case Event::synth_param_pitch_lfo_depth:
2289                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFODepth);
2290                            break;
2291                        case Event::synth_param_pitch_lfo_freq:
2292                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFOFreq);
2293                          break;                          break;
2294                  }                  }
2295    
# Line 1902  namespace LinuxSampler { Line 2302  namespace LinuxSampler {
2302               *  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
2303               *  control and status variables. This method is protected by a mutex.               *  control and status variables. This method is protected by a mutex.
2304               */               */
2305              virtual void ResetInternal() {              virtual void ResetInternal() OVERRIDE {
2306                  LockGuard lock(ResetInternalMutex);                  LockGuard lock(ResetInternalMutex);
2307    
2308                  // make sure that the engine does not get any sysex messages                  // make sure that the engine does not get any sysex messages
# Line 1961  namespace LinuxSampler { Line 2361  namespace LinuxSampler {
2361               * @param pEngineChannel - engine channel on which all voices should be killed               * @param pEngineChannel - engine channel on which all voices should be killed
2362               * @param itKillEvent    - event which caused this killing of all voices               * @param itKillEvent    - event which caused this killing of all voices
2363               */               */
2364              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) {              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE {
2365                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2366                  int count = pChannel->KillAllVoices(itKillEvent);                  int count = pChannel->KillAllVoices(itKillEvent);
2367                  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 1996  namespace LinuxSampler { Line 2396  namespace LinuxSampler {
2396                  bool                    HandleKeyGroupConflicts                  bool                    HandleKeyGroupConflicts
2397              ) = 0;              ) = 0;
2398    
2399              virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; }              virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; }
2400    
2401              int InitNewVoice (              int InitNewVoice (
2402                  EngineChannelBase<V, R, I>*  pChannel,                  EngineChannelBase<V, R, I>*  pChannel,
# Line 2019  namespace LinuxSampler { Line 2419  namespace LinuxSampler {
2419                      }                      }
2420                      else { // on success                      else { // on success
2421                          --VoiceSpawnsLeft;                          --VoiceSpawnsLeft;
2422                          if (!pKey->Active) { // mark as active key  
2423                              pKey->Active = true;                          // should actually be superfluous now, since this is
2424                              pKey->itSelf = pChannel->pActiveKeys->allocAppend();                          // already done in LaunchNewNote()
2425                              *pKey->itSelf = itNoteOnEvent->Param.Note.Key;                          pChannel->markKeyAsActive(pKey);
2426                          }  
2427                          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)
2428                                pKey->ReleaseTrigger |= itNewVoice->GetReleaseTriggerFlags(); // mark key for the need of release triggered voice(s)
2429                          return 0; // success                          return 0; // success
2430                      }                      }
2431                  }                  }

Legend:
Removed from v.2931  
changed lines
  Added in v.3696

  ViewVC Help
Powered by ViewVC