/[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 3205 by schoenebeck, Wed May 24 20:05:38 2017 UTC revision 3854 by schoenebeck, Mon Feb 1 17:37:52 2021 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
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-2021 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Grigor Iliev                                  *
8   *   Copyright (C) 2012-2017 Christian Schoenebeck and Andreas Persson     *   *   Copyright (C) 2012-2017 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 202  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 233  namespace LinuxSampler { Line 250  namespace LinuxSampler {
250                  return 0;                  return 0;
251              }              }
252    
253              virtual int MaxVoices() OVERRIDE { return pVoicePool->poolSize(); }              virtual int MaxVoices() OVERRIDE {
254                    return (int) pVoicePool->poolSize();
255                }
256    
257              virtual void SetMaxVoices(int iVoices) throw (Exception) OVERRIDE {              virtual void SetMaxVoices(int iVoices) throw (Exception) OVERRIDE {
258                  if (iVoices < 1)                  if (iVoices < 1)
# Line 379  namespace LinuxSampler { Line 398  namespace LinuxSampler {
398                  }                  }
399                  pVoicePool->clear();                  pVoicePool->clear();
400    
401                  // (re)create event generator                  // update event generator
402                  if (pEventGenerator) delete pEventGenerator;                  pEventGenerator->SetSampleRate(pAudioOut->SampleRate());
                 pEventGenerator = new EventGenerator(pAudioOut->SampleRate());  
403    
404                  dmsg(1,("Starting disk thread..."));                  dmsg(1,("Starting disk thread..."));
405                  pDiskThread->StartThread();                  pDiskThread->StartThread();
# Line 740  namespace LinuxSampler { Line 758  namespace LinuxSampler {
758                  // move new note to its host key                  // move new note to its host key
759                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];
760                  itNewNote.moveToEndOf(pKey->pActiveNotes);                  itNewNote.moveToEndOf(pKey->pActiveNotes);
761                    pChannel->markKeyAsActive(pKey);
762    
763                  // 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
764                  itNoteOnEvent->Param.Note.ID = newNoteID;                  itNoteOnEvent->Param.Note.ID = newNoteID;
# Line 807  namespace LinuxSampler { Line 826  namespace LinuxSampler {
826                                  //TODO: ...                                  //TODO: ...
827                                  break;                                  break;
828    
829                                case Event::type_rpn: // rpn handled in ProcessHardcodedControllers() instead ATM
830                                case Event::type_nrpn: // nrpn handled in ProcessHardcodedControllers() instead ATM
831                              case Event::type_cancel_release_key:                              case Event::type_cancel_release_key:
832                              case Event::type_release_key:                              case Event::type_release_key:
833                              case Event::type_release_note:                              case Event::type_release_note:
# Line 868  namespace LinuxSampler { Line 889  namespace LinuxSampler {
889                      RTList<Event>::Iterator itEvent = pChannel->pEvents->first();                      RTList<Event>::Iterator itEvent = pChannel->pEvents->first();
890                      RTList<Event>::Iterator end     = pChannel->pEvents->end();                      RTList<Event>::Iterator end     = pChannel->pEvents->end();
891                      for (; itEvent != end; ++itEvent) {                      for (; itEvent != end; ++itEvent) {
892                            bool bIsCC = false; // just for resetting RPN/NRPN below
893                          switch (itEvent->Type) {                          switch (itEvent->Type) {
894                              case Event::type_note_on:                              case Event::type_note_on:
895                                  dmsg(5,("Engine: Note on received\n"));                                  dmsg(5,("Engine: Note on received\n"));
# Line 892  namespace LinuxSampler { Line 914  namespace LinuxSampler {
914                              case Event::type_control_change:                              case Event::type_control_change:
915                                  dmsg(5,("Engine: MIDI CC received\n"));                                  dmsg(5,("Engine: MIDI CC received\n"));
916                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);
917                                    bIsCC = true;
918                                    break;
919                                case Event::type_rpn: // this can only be reached here by an instrument script having called set_rpn()
920                                    dmsg(5,("Engine: MIDI RPN received\n"));
921                                    ProcessHardcodedRpn((EngineChannel*)itEvent->pEngineChannel, itEvent);
922                                    bIsCC = true;
923                                    break;
924                                case Event::type_nrpn: // this can only be reached here by an instrument script having called set_nrpn()
925                                    dmsg(5,("Engine: MIDI NRPN received\n"));
926                                    ProcessHardcodedNrpn((EngineChannel*)itEvent->pEngineChannel, itEvent);
927                                    bIsCC = true;
928                                  break;                                  break;
929                              case Event::type_channel_pressure:                              case Event::type_channel_pressure:
930                                  dmsg(5,("Engine: MIDI Chan. Pressure received\n"));                                  dmsg(5,("Engine: MIDI Chan. Pressure received\n"));
# Line 917  namespace LinuxSampler { Line 950  namespace LinuxSampler {
950                              case Event::type_release_note:                              case Event::type_release_note:
951                                  break; // noop                                  break; // noop
952                          }                          }
953                            // reset cached RPN/NRPN parameter number and data in
954                            // case this event was not a control change event
955                            if (!bIsCC) {
956                                if (pChannel->GetMidiRpnParameter() >= 0)
957                                    pChannel->ResetMidiRpnParameter();
958                                if (pChannel->GetMidiNrpnParameter() >= 0)
959                                    pChannel->ResetMidiNrpnParameter();
960                            }
961                      }                      }
962                  }                  }
963    
# Line 965  namespace LinuxSampler { Line 1006  namespace LinuxSampler {
1006                  if (pEventHandler == pChannel->pScript->handlerRelease &&                  if (pEventHandler == pChannel->pScript->handlerRelease &&
1007                      pChannel->pScript->handlerNote &&                      pChannel->pScript->handlerNote &&
1008                      pChannel->pScript->handlerNote->isPolyphonic() &&                      pChannel->pScript->handlerNote->isPolyphonic() &&
1009                      pChannel->pScript->handlerRelease->isPolyphonic() &&                      pChannel->pScript->handlerRelease->isPolyphonic())
                     !pChannel->pScript->pKeyEvents[key]->isEmpty())  
1010                  {                  {
1011                      // polyphonic variable data is used/passed from "note" to                      // polyphonic variable data is used/passed from "note" to
1012                      // "release" script callback, so we have to recycle the                      // "release" script callback; first assume the "note" script
1013                      // original "note on" script event(s)                      // callback already finished execution and waits for being
1014                        // recycled for the "release" script handler ...
1015                      RTList<ScriptEvent>::Iterator it  = pChannel->pScript->pKeyEvents[key]->first();                      RTList<ScriptEvent>::Iterator it  = pChannel->pScript->pKeyEvents[key]->first();
1016                      RTList<ScriptEvent>::Iterator end = pChannel->pScript->pKeyEvents[key]->end();                      RTList<ScriptEvent>::Iterator end = pChannel->pScript->pKeyEvents[key]->end();
1017                      for (; it != end; ++it) {                      for (; it != end; ++it) {
1018                            // Despite the loop, in fact we're just picking and
1019                            // running EXACTLY ONE script event here and then leave
1020                            // the loop immediately.
1021                            if (it->handlerType != VM_EVENT_HANDLER_NOTE)
1022                                continue;
1023                            // Skip "note" script callbacks which have already been
1024                            // picked (in this loop) for a "release" callback
1025                            // before. This ensures that a "note" script callback is
1026                            // really just used once for a "release" callback.
1027                            if (it->releaseMatched)
1028                                continue;
1029                            it->releaseMatched = true;
1030                            // Now recycle the picked old "note" script callback for
1031                            // the "release" script callback.
1032                          ProcessScriptEvent(                          ProcessScriptEvent(
1033                              pChannel, itEvent, pEventHandler, it                              pChannel, itEvent, pEventHandler, it
1034                          );                          );
1035                            // We don't want to run the "release" handler of more
1036                            // than one (previously being "note" handler) script
1037                            // event here, because the precise relationship between
1038                            // exactly one "note" handler instance and one "release"
1039                            // handler instance must always be preserved to prevent
1040                            // misbehaviours with scripts (e.g. a script author
1041                            // might increment a script variable in the "note"
1042                            // handler and decrement the variable in the "release"
1043                            // handler to count the currently pressed down keys).
1044                            return;
1045                        }
1046                        // If we're here then the original "note" script callback
1047                        // has not finished execution yet (i.e. it is currently
1048                        // suspended). This requires a more expensive solution:
1049                        // search on the list of all yet active script callbacks.
1050                        it  = pChannel->pScript->pEvents->first();
1051                        end = pChannel->pScript->pEvents->end();
1052                        for (; it != end; ++it) {
1053                            if (it->handlerType != VM_EVENT_HANDLER_NOTE)
1054                                continue;
1055                            if (it->cause.Param.Note.Key != itEvent->Param.Note.Key)
1056                                continue;
1057                            if (it->releaseMatched)
1058                                continue;
1059                            it->releaseMatched = true;
1060                            // As the original "note" callback is still running, we
1061                            // cannot recycle it, instead we spawn a completely new
1062                            // script handler and just copy the "note" handler's
1063                            // polyphonic data.
1064                            RTList<ScriptEvent>::Iterator itScriptEvent =
1065                                pChannel->pScript->pEvents->allocAppend();
1066                            itScriptEvent->execCtx->copyPolyphonicDataFrom(it->execCtx);
1067                            // Now run the new "release" handler with the polyphonic
1068                            // data copied from the original "note" handler.
1069                            ProcessScriptEvent(
1070                                pChannel, itEvent, pEventHandler, itScriptEvent
1071                            );
1072                            // Done. Matched exactly one note <-> release handler.
1073                            return;
1074                      }                      }
1075                        // This should never happen. Otherwise it's a bug.
1076                        dmsg(0,("[ScriptVM] WARNING: No matching previous \"note\" event handler found for polyphonic \"release\" event handler!\n"));
1077                  } else {                  } else {
1078                      // no polyphonic data is used/passed from "note" to                      // no polyphonic data is used/passed from "note" to
1079                      // "release" script callback, so just use a new fresh                      // "release" script callback, so just use a new fresh
1080                      // script event object                      // script event object
1081                      RTList<ScriptEvent>::Iterator itScriptEvent =                      RTList<ScriptEvent>::Iterator itScriptEvent =
1082                          pChannel->pScript->pEvents->allocAppend();                          pChannel->pScript->pEvents->allocAppend();
1083                        // if event handler uses polyphonic variables, reset them
1084                        // to zero values before starting to execute the handler
1085                        if (pEventHandler->isPolyphonic())
1086                            itScriptEvent->execCtx->resetPolyphonicData();
1087                      ProcessScriptEvent(                      ProcessScriptEvent(
1088                          pChannel, itEvent, pEventHandler, itScriptEvent                          pChannel, itEvent, pEventHandler, itScriptEvent
1089                      );                      );
# Line 1020  namespace LinuxSampler { Line 1120  namespace LinuxSampler {
1120                  itScriptEvent->currentHandler = 0;                  itScriptEvent->currentHandler = 0;
1121                  itScriptEvent->executionSlices = 0;                  itScriptEvent->executionSlices = 0;
1122                  itScriptEvent->ignoreAllWaitCalls = false;                  itScriptEvent->ignoreAllWaitCalls = false;
1123                    itScriptEvent->releaseMatched = false;
1124                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();
1125                    itScriptEvent->parentHandlerID = 0;
1126                    itScriptEvent->childHandlerID[0] = 0;
1127                    itScriptEvent->autoAbortByParent = false;
1128                    itScriptEvent->forkIndex = 0;
1129                  // this is the native representation of the $EVENT_ID script variable                  // this is the native representation of the $EVENT_ID script variable
1130                  itScriptEvent->id =                  itScriptEvent->id =
1131                      (itEvent->Type == Event::type_note_on)                      (itEvent->Type == Event::type_note_on)
# Line 1133  namespace LinuxSampler { Line 1238  namespace LinuxSampler {
1238               *  @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
1239               */               */
1240              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
1241                    dmsg(3,("StealVoice()\n"));
1242                  if (VoiceSpawnsLeft <= 0) {                  if (VoiceSpawnsLeft <= 0) {
1243                      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"));
1244                      return -1;                      return -1;
# Line 1154  namespace LinuxSampler { Line 1260  namespace LinuxSampler {
1260                  // steal oldest voice on the oldest key from any other engine channel                  // steal oldest voice on the oldest key from any other engine channel
1261                  // (the smaller engine channel number, the higher priority)                  // (the smaller engine channel number, the higher priority)
1262                  EngineChannelBase<V, R, I>*  pSelectedChannel;                  EngineChannelBase<V, R, I>*  pSelectedChannel;
1263                  int                          iChannelIndex;                  ssize_t                      iChannelIndex;
1264                  VoiceIterator                itSelectedVoice;                  VoiceIterator                itSelectedVoice;
1265    
1266                    #if CONFIG_DEVMODE
1267                    EngineChannel* pBegin = NULL; // to detect endless loop
1268                    #endif
1269    
1270                  // select engine channel                  // select engine channel
1271                  if (pLastStolenChannel) {                  if (pLastStolenChannel) {
1272                      pSelectedChannel = pLastStolenChannel;                      pSelectedChannel = pLastStolenChannel;
# Line 1199  namespace LinuxSampler { Line 1309  namespace LinuxSampler {
1309                  }                  }
1310    
1311                  #if CONFIG_DEVMODE                  #if CONFIG_DEVMODE
1312                  EngineChannel* pBegin = pSelectedChannel; // to detect endless loop                  pBegin = pSelectedChannel; // to detect endless loop
1313                  #endif // CONFIG_DEVMODE                  #endif // CONFIG_DEVMODE
1314    
1315                  while (true) { // iterate through engine channels                                          while (true) { // iterate through engine channels                        
# Line 1292  namespace LinuxSampler { Line 1402  namespace LinuxSampler {
1402                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1403                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1404    
1405                                itScriptEvent->cause = pEventGenerator->CreateEvent(0);
1406                                itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing
1407                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1408                                itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort();
1409                                itScriptEvent->id = 0;
1410                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1411                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1412                              itScriptEvent->currentHandler = 0;                              itScriptEvent->currentHandler = 0;
1413                              itScriptEvent->executionSlices = 0;                              itScriptEvent->executionSlices = 0;
1414                              itScriptEvent->ignoreAllWaitCalls = false;                              itScriptEvent->ignoreAllWaitCalls = false;
1415                                itScriptEvent->releaseMatched = false; // not relevant for init handler actually
1416                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1417                                itScriptEvent->parentHandlerID = 0;
1418                              /*VMExecStatus_t res = */ pScriptVM->exec(                              itScriptEvent->childHandlerID[0] = 0;
1419                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                              itScriptEvent->autoAbortByParent = false;
1420                              );                              itScriptEvent->forkIndex = 0;
1421    
1422                                VMExecStatus_t res;
1423                                size_t instructionsCount = 0;
1424                                const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction)
1425                                bool bWarningShown = false;
1426                                do {
1427                                    res = pScriptVM->exec(
1428                                        pEngineChannel->pScript->parserContext, &*itScriptEvent
1429                                    );
1430                                    instructionsCount += itScriptEvent->execCtx->instructionsPerformed();
1431                                    if (instructionsCount > maxInstructions && !bWarningShown) {
1432                                        bWarningShown = true;
1433                                        dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n"));
1434                                    }
1435                                } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR));
1436    
1437                              pEngineChannel->pScript->pEvents->free(itScriptEvent);                              pEngineChannel->pScript->pEvents->free(itScriptEvent);
1438                          }                          }
# Line 1363  namespace LinuxSampler { Line 1493  namespace LinuxSampler {
1493                          // usually there should already be a new Note object                          // usually there should already be a new Note object
1494                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);
1495                          if (!itNote) { // should not happen, but just to be sure ...                          if (!itNote) { // should not happen, but just to be sure ...
1496                                dmsg(2,("Engine: No Note object for stolen voice!\n"));
1497                              const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);                              const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);
1498                              if (!noteID) {                              if (!noteID) {
1499                                  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"));
# Line 1407  namespace LinuxSampler { Line 1538  namespace LinuxSampler {
1538              void PostProcess(EngineChannel* pEngineChannel) {              void PostProcess(EngineChannel* pEngineChannel) {
1539                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1540                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1541                   pChannel->FreeAllInactiveKyes();                   pChannel->FreeAllInactiveKeys();
1542    
1543                  // empty the engine channel's own event lists                  // empty the engine channel's own event lists
1544                  // (only events of the current audio fragment cycle)                  // (only events of the current audio fragment cycle)
# Line 1429  namespace LinuxSampler { Line 1560  namespace LinuxSampler {
1560                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1561                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1562    
1563                    // will be set to true if this CC event has anything to do with RPN/NRPN
1564                    bool bIsRpn = false, bIsNrpn = false;
1565    
1566                  switch (itControlChangeEvent->Param.CC.Controller) {                  switch (itControlChangeEvent->Param.CC.Controller) {
1567                      case 5: { // portamento time                      case 5: { // portamento time
1568                          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;
1569                          break;                          break;
1570                      }                      }
1571                      case 6: { // data entry (currently only used for RPN and NRPN controllers)                      case 6: { // data entry (MSB)
1572                          //dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value));                          //dmsg(1,("DATA ENTRY MSB %d\n", itControlChangeEvent->Param.CC.Value));
1573                          if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ...                          if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1574                              dmsg(4,("Guess it's an RPN ...\n"));                              pChannel->SetMidiRpnDataMsb(
1575                              if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones                                  itControlChangeEvent->Param.CC.Value
1576                                  int transpose = (int) itControlChangeEvent->Param.CC.Value - 64;                              );
1577                                  // limit to +- two octaves for now                              bIsRpn = true;
1578                                  transpose = RTMath::Min(transpose,  24);  
1579                                  transpose = RTMath::Max(transpose, -24);                              // look-ahead: if next MIDI event is data entry LSB,
1580                                  pChannel->GlobalTranspose = transpose;                              // then skip this event here for now (to avoid double
1581                                  // workaround, so we won't have hanging notes                              // handling of what's supposed to be one RPN event)
1582                                  pChannel->ReleaseAllVoices(itControlChangeEvent);                              if (isNextEventCCNr(itControlChangeEvent, 38))
1583                              }                                  break;
1584                              // to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data  
1585                              pChannel->ResetMidiRpnController();                              int ch = itControlChangeEvent->Param.CC.Channel;
1586                          } else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ...                              int param = pChannel->GetMidiRpnParameter();
1587                              dmsg(4,("Guess it's an NRPN ...\n"));                              int value = pChannel->GetMidiRpnData();
1588                              const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8;  
1589                              const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff;                              // transform event type: CC event -> RPN event
1590                              dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value));                              itControlChangeEvent->Type = Event::type_rpn;
1591                              switch (NrpnCtrlMSB) {                              itControlChangeEvent->Param.RPN.Channel = ch;
1592                                  case 0x1a: { // volume level of note (Roland GS NRPN)                              itControlChangeEvent->Param.RPN.Parameter = param;
1593                                      const uint note = NrpnCtrlLSB;                              itControlChangeEvent->Param.RPN.Value = value;
1594                                      const uint vol  = itControlChangeEvent->Param.CC.Value;  
1595                                      dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));                              // if there's a RPN script handler, run it ...
1596                                      if (note < 128 && vol < 128)                              if (pChannel->pScript &&
1597                                          pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];                                  pChannel->pScript->handlerRpn)
1598                                      break;                              {
1599                                  }                                  const event_id_t eventID =
1600                                  case 0x1c: { // panpot of note (Roland GS NRPN)                                      pEventPool->getID(itControlChangeEvent);
1601                                      const uint note = NrpnCtrlLSB;                                  // run the RPN script handler
1602                                      const uint pan  = itControlChangeEvent->Param.CC.Value;                                  ProcessEventByScript(
1603                                      dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));                                      pChannel, itControlChangeEvent,
1604                                      if (note < 128 && pan < 128) {                                      pChannel->pScript->handlerRpn
1605                                          pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];                                  );
1606                                          pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];                                  // if RPN event was dropped by script, abort
1607                                      }                                  // here to avoid hard coded RPN processing below
1608                                      break;                                  if (!pEventPool->fromID(eventID))
                                 }  
                                 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;  
1609                                      break;                                      break;
1610                                  }                              }
1611                                  case 0x1e: { // chorus send of note (Roland GS NRPN)  
1612                                      const uint note = NrpnCtrlLSB;                              // do the actual (hard-coded) RPN value change processing
1613                                      const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f;                              ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1614                                      dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));  
1615                                      if (note < 128)                          } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1616                                          pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;                              pChannel->SetMidiNrpnDataMsb(
1617                                    itControlChangeEvent->Param.CC.Value
1618                                );
1619                                bIsNrpn = true;
1620    
1621                                // look-ahead: if next MIDI event is data entry LSB,
1622                                // then skip this event here for now (to avoid double
1623                                // handling of what's supposed to be one NRPN event)
1624                                if (isNextEventCCNr(itControlChangeEvent, 38))
1625                                    break;
1626    
1627                                int ch = itControlChangeEvent->Param.CC.Channel;
1628                                int param = pChannel->GetMidiNrpnParameter();
1629                                int value = pChannel->GetMidiNrpnData();
1630    
1631                                // transform event type: CC event -> NRPN event
1632                                itControlChangeEvent->Type = Event::type_nrpn;
1633                                itControlChangeEvent->Param.NRPN.Channel = ch;
1634                                itControlChangeEvent->Param.NRPN.Parameter = param;
1635                                itControlChangeEvent->Param.NRPN.Value = value;
1636    
1637                                // if there's a NRPN script handler, run it ...
1638                                if (pChannel->pScript &&
1639                                    pChannel->pScript->handlerNrpn)
1640                                {
1641                                    const event_id_t eventID =
1642                                        pEventPool->getID(itControlChangeEvent);
1643                                    // run the NRPN script handler
1644                                    ProcessEventByScript(
1645                                        pChannel, itControlChangeEvent,
1646                                        pChannel->pScript->handlerNrpn
1647                                    );
1648                                    // if NRPN event was dropped by script, abort
1649                                    // here to avoid hard coded NRPN processing below
1650                                    if (!pEventPool->fromID(eventID))
1651                                      break;                                      break;
                                 }  
1652                              }                              }
1653                              // to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data  
1654                              pChannel->ResetMidiNrpnController();                              // do the actual (hard-coded) NRPN value change processing
1655                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1656                          }                          }
1657                          break;                          break;
1658                      }                      }
# Line 1506  namespace LinuxSampler { Line 1667  namespace LinuxSampler {
1667                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;
1668                          break;                          break;
1669                      }                      }
1670                        case 38: { // data entry (LSB)
1671                            //dmsg(1,("DATA ENTRY LSB %d\n", itControlChangeEvent->Param.CC.Value));
1672                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1673                                pChannel->SetMidiRpnDataLsb(
1674                                    itControlChangeEvent->Param.CC.Value
1675                                );
1676                                bIsRpn = true;
1677    
1678                                int ch = itControlChangeEvent->Param.CC.Channel;
1679                                int param = pChannel->GetMidiRpnParameter();
1680                                int value = pChannel->GetMidiRpnData();
1681    
1682                                // transform event type: CC event -> RPN event
1683                                itControlChangeEvent->Type = Event::type_rpn;
1684                                itControlChangeEvent->Param.RPN.Channel = ch;
1685                                itControlChangeEvent->Param.RPN.Parameter = param;
1686                                itControlChangeEvent->Param.RPN.Value = value;
1687    
1688                                // if there's a RPN script handler, run it ...
1689                                if (pChannel->pScript &&
1690                                    pChannel->pScript->handlerRpn)
1691                                {
1692                                    const event_id_t eventID =
1693                                        pEventPool->getID(itControlChangeEvent);
1694                                    // run the RPN script handler
1695                                    ProcessEventByScript(
1696                                        pChannel, itControlChangeEvent,
1697                                        pChannel->pScript->handlerRpn
1698                                    );
1699                                    // if RPN event was dropped by script, abort
1700                                    // here to avoid hard coded RPN processing below
1701                                    if (!pEventPool->fromID(eventID))
1702                                        break;
1703                                }
1704    
1705                                // do the actual (hard-coded) RPN value change processing
1706                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1707    
1708                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1709                                pChannel->SetMidiNrpnDataLsb(
1710                                    itControlChangeEvent->Param.CC.Value
1711                                );
1712                                bIsNrpn = true;
1713    
1714                                int ch = itControlChangeEvent->Param.CC.Channel;
1715                                int param = pChannel->GetMidiNrpnParameter();
1716                                int value = pChannel->GetMidiNrpnData();
1717    
1718                                // transform event type: CC event -> NRPN event
1719                                itControlChangeEvent->Type = Event::type_nrpn;
1720                                itControlChangeEvent->Param.NRPN.Channel = ch;
1721                                itControlChangeEvent->Param.NRPN.Parameter = param;
1722                                itControlChangeEvent->Param.NRPN.Value = value;
1723    
1724                                // if there's a NRPN script handler, run it ...
1725                                if (pChannel->pScript &&
1726                                    pChannel->pScript->handlerNrpn)
1727                                {
1728                                    const event_id_t eventID =
1729                                        pEventPool->getID(itControlChangeEvent);
1730                                    // run the NRPN script handler
1731                                    ProcessEventByScript(
1732                                        pChannel, itControlChangeEvent,
1733                                        pChannel->pScript->handlerNrpn
1734                                    );
1735                                    // if NRPN event was dropped by script, abort
1736                                    // here to avoid hard coded NRPN processing below
1737                                    if (!pEventPool->fromID(eventID))
1738                                        break;
1739                                }
1740    
1741                                // do the actual (hard-coded) NRPN value change processing
1742                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1743                            }
1744                            break;
1745                        }
1746                      case 64: { // sustain                      case 64: { // sustain
1747                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {
1748                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
# Line 1579  namespace LinuxSampler { Line 1816  namespace LinuxSampler {
1816                          }                          }
1817                          break;                          break;
1818                      }                      }
1819                      case 98: { // NRPN controller LSB                      case 96: { // data increment (data entry +1)
1820                            //dmsg(1,("DATA INC\n"));
1821                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1822                                pChannel->SetMidiRpnData(
1823                                    pChannel->GetMidiRpnData() + 1
1824                                );
1825                                bIsRpn = true;
1826    
1827                                int ch = itControlChangeEvent->Param.CC.Channel;
1828                                int param = pChannel->GetMidiRpnParameter();
1829                                int value = pChannel->GetMidiRpnData();
1830    
1831                                // transform event type: CC event -> RPN event
1832                                itControlChangeEvent->Type = Event::type_rpn;
1833                                itControlChangeEvent->Param.RPN.Channel = ch;
1834                                itControlChangeEvent->Param.RPN.Parameter = param;
1835                                itControlChangeEvent->Param.RPN.Value = value;
1836    
1837                                // if there's a RPN script handler, run it ...
1838                                if (pChannel->pScript &&
1839                                    pChannel->pScript->handlerRpn)
1840                                {
1841                                    const event_id_t eventID =
1842                                        pEventPool->getID(itControlChangeEvent);
1843                                    // run the RPN script handler
1844                                    ProcessEventByScript(
1845                                        pChannel, itControlChangeEvent,
1846                                        pChannel->pScript->handlerRpn
1847                                    );
1848                                    // if RPN event was dropped by script, abort
1849                                    // here to avoid hard coded RPN processing below
1850                                    if (!pEventPool->fromID(eventID))
1851                                        break;
1852                                }
1853    
1854                                // do the actual (hard-coded) RPN value change processing
1855                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1856    
1857                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1858                                pChannel->SetMidiNrpnData(
1859                                    pChannel->GetMidiNrpnData() + 1
1860                                );
1861                                bIsNrpn = true;
1862    
1863                                int ch = itControlChangeEvent->Param.CC.Channel;
1864                                int param = pChannel->GetMidiNrpnParameter();
1865                                int value = pChannel->GetMidiNrpnData();
1866    
1867                                // transform event type: CC event -> NRPN event
1868                                itControlChangeEvent->Type = Event::type_nrpn;
1869                                itControlChangeEvent->Param.NRPN.Channel = ch;
1870                                itControlChangeEvent->Param.NRPN.Parameter = param;
1871                                itControlChangeEvent->Param.NRPN.Value = value;
1872    
1873                                // if there's a NRPN script handler, run it ...
1874                                if (pChannel->pScript &&
1875                                    pChannel->pScript->handlerNrpn)
1876                                {
1877                                    const event_id_t eventID =
1878                                        pEventPool->getID(itControlChangeEvent);
1879                                    // run the NRPN script handler
1880                                    ProcessEventByScript(
1881                                        pChannel, itControlChangeEvent,
1882                                        pChannel->pScript->handlerNrpn
1883                                    );
1884                                    // if NRPN event was dropped by script, abort
1885                                    // here to avoid hard coded NRPN processing below
1886                                    if (!pEventPool->fromID(eventID))
1887                                        break;
1888                                }
1889    
1890                                // do the actual (hard-coded) NRPN value change processing
1891                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1892                            }
1893                            break;
1894                        }
1895                        case 97: { // data decrement (data entry -1)
1896                            //dmsg(1,("DATA DEC\n"));
1897                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1898                                pChannel->SetMidiRpnData(
1899                                    pChannel->GetMidiRpnData() - 1
1900                                );
1901                                bIsRpn = true;
1902    
1903                                int ch = itControlChangeEvent->Param.CC.Channel;
1904                                int param = pChannel->GetMidiRpnParameter();
1905                                int value = pChannel->GetMidiRpnData();
1906    
1907                                // transform event type: CC event -> RPN event
1908                                itControlChangeEvent->Type = Event::type_rpn;
1909                                itControlChangeEvent->Param.RPN.Channel = ch;
1910                                itControlChangeEvent->Param.RPN.Parameter = param;
1911                                itControlChangeEvent->Param.RPN.Value = value;
1912    
1913                                // if there's a RPN script handler, run it ...
1914                                if (pChannel->pScript &&
1915                                    pChannel->pScript->handlerRpn)
1916                                {
1917                                    const event_id_t eventID =
1918                                        pEventPool->getID(itControlChangeEvent);
1919                                    // run the RPN script handler
1920                                    ProcessEventByScript(
1921                                        pChannel, itControlChangeEvent,
1922                                        pChannel->pScript->handlerRpn
1923                                    );
1924                                    // if RPN event was dropped by script, abort
1925                                    // here to avoid hard coded RPN processing below
1926                                    if (!pEventPool->fromID(eventID))
1927                                        break;
1928                                }
1929    
1930                                // do the actual (hard-coded) RPN value change processing
1931                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1932    
1933                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1934                                pChannel->SetMidiNrpnData(
1935                                    pChannel->GetMidiNrpnData() - 1
1936                                );
1937                                bIsNrpn = true;
1938    
1939                                int ch = itControlChangeEvent->Param.CC.Channel;
1940                                int param = pChannel->GetMidiNrpnParameter();
1941                                int value = pChannel->GetMidiNrpnData();
1942    
1943                                // transform event type: CC event -> NRPN event
1944                                itControlChangeEvent->Type = Event::type_nrpn;
1945                                itControlChangeEvent->Param.NRPN.Channel = ch;
1946                                itControlChangeEvent->Param.NRPN.Parameter = param;
1947                                itControlChangeEvent->Param.NRPN.Value = value;
1948    
1949                                // if there's a NRPN script handler, run it ...
1950                                if (pChannel->pScript &&
1951                                    pChannel->pScript->handlerNrpn)
1952                                {
1953                                    const event_id_t eventID =
1954                                        pEventPool->getID(itControlChangeEvent);
1955                                    // run the NRPN script handler
1956                                    ProcessEventByScript(
1957                                        pChannel, itControlChangeEvent,
1958                                        pChannel->pScript->handlerNrpn
1959                                    );
1960                                    // if NRPN event was dropped by script, abort
1961                                    // here to avoid hard coded NRPN processing below
1962                                    if (!pEventPool->fromID(eventID))
1963                                        break;
1964                                }
1965    
1966                                // do the actual (hard-coded) NRPN value change processing
1967                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1968                            }
1969                            break;
1970                        }
1971                        case 98: { // NRPN parameter LSB
1972                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1973                          pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          bIsNrpn = true;
1974                            pEngineChannel->SetMidiNrpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1975                          break;                          break;
1976                      }                      }
1977                      case 99: { // NRPN controller MSB                      case 99: { // NRPN parameter MSB
1978                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1979                          pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          bIsNrpn = true;
1980                            pEngineChannel->SetMidiNrpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1981                          break;                          break;
1982                      }                      }
1983                      case 100: { // RPN controller LSB                      case 100: { // RPN parameter LSB
1984                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1985                          pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          bIsRpn = true;
1986                            pEngineChannel->SetMidiRpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1987                          break;                          break;
1988                      }                      }
1989                      case 101: { // RPN controller MSB                      case 101: { // RPN parameter MSB
1990                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1991                          pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          bIsRpn = true;
1992                            pEngineChannel->SetMidiRpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1993                          break;                          break;
1994                      }                      }
1995    
# Line 1630  namespace LinuxSampler { Line 2023  namespace LinuxSampler {
2023                          break;                          break;
2024                      }                      }
2025                  }                  }
2026    
2027                    // reset cached RPN/NRPN parameter number and data in case this
2028                    // CC event had nothing to do with RPN/NRPN
2029                    if (!bIsRpn && pChannel->GetMidiRpnParameter() >= 0)
2030                        pChannel->ResetMidiRpnParameter();
2031                    if (!bIsNrpn && pChannel->GetMidiNrpnParameter() >= 0)
2032                        pChannel->ResetMidiNrpnParameter();
2033                }
2034    
2035                /**
2036                 * Process MIDI RPN events with hard coded behavior.
2037                 *
2038                 * @param pEngineChannel - engine channel on which the MIDI RPN
2039                 *                         event was received
2040                 * @param itRpnEvent - the actual MIDI RPN event
2041                 */
2042                void ProcessHardcodedRpn(EngineChannel* pEngineChannel,
2043                                         Pool<Event>::Iterator& itRpnEvent)
2044                {
2045                    EngineChannelBase<V, R, I>* pChannel =
2046                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2047    
2048                    if (itRpnEvent->Param.RPN.Parameter == 2) { // coarse tuning in half tones
2049                        int transpose = (int) itRpnEvent->Param.RPN.ValueMSB() - 64;
2050                        // limit to +- two octaves for now
2051                        transpose = RTMath::Min(transpose,  24);
2052                        transpose = RTMath::Max(transpose, -24);
2053                        pChannel->GlobalTranspose = transpose;
2054                        // workaround, so we won't have hanging notes
2055                        pChannel->ReleaseAllVoices(itRpnEvent);
2056                    } else if (itRpnEvent->Param.RPN.Parameter == 16383) { // null function RPN
2057                        // disable subsequent data entry/increment/decrement processing
2058                        pChannel->ResetMidiRpnParameter();
2059                    }
2060                }
2061    
2062                /**
2063                 * Process MIDI NRPN events with hard coded behavior.
2064                 *
2065                 * @param pEngineChannel - engine channel on which the MIDI NRPN
2066                 *                         event was received
2067                 * @param itRpnEvent - the actual MIDI NRPN event
2068                 */
2069                void ProcessHardcodedNrpn(EngineChannel* pEngineChannel,
2070                                          Pool<Event>::Iterator& itNrpnEvent)
2071                {
2072                    EngineChannelBase<V, R, I>* pChannel =
2073                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2074    
2075                    switch (itNrpnEvent->Param.NRPN.ParameterMSB()) {
2076                        case 0x1a: { // volume level of note (Roland GS NRPN)
2077                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2078                            const uint vol  = itNrpnEvent->Param.NRPN.ValueMSB();
2079                            dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));
2080                            if (note < 128 && vol < 128)
2081                                pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];
2082                            break;
2083                        }
2084                        case 0x1c: { // panpot of note (Roland GS NRPN)
2085                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2086                            const uint pan  = itNrpnEvent->Param.NRPN.ValueMSB();
2087                            dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));
2088                            if (note < 128 && pan < 128) {
2089                                pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];
2090                                pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];
2091                            }
2092                            break;
2093                        }
2094                        case 0x1d: { // reverb send of note (Roland GS NRPN)
2095                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2096                            const float reverb = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
2097                            dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb));
2098                            if (note < 128)
2099                                pChannel->pMIDIKeyInfo[note].ReverbSend = reverb;
2100                            break;
2101                        }
2102                        case 0x1e: { // chorus send of note (Roland GS NRPN)
2103                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2104                            const float chorus = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
2105                            dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));
2106                            if (note < 128)
2107                                pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;
2108                            break;
2109                        }
2110                        case 0x7f: {
2111                            if (itNrpnEvent->Param.NRPN.ParameterLSB() == 0x7f) { // null function NRPN
2112                                // disable subsequent data entry/increment/decrement processing
2113                                pChannel->ResetMidiNrpnParameter();
2114                            }
2115                            break;
2116                        }
2117                    }
2118              }              }
2119    
2120              virtual D* CreateDiskThread() = 0;              virtual D* CreateDiskThread() = 0;
# Line 1872  namespace LinuxSampler { Line 2357  namespace LinuxSampler {
2357                      if (bShouldRelease) {                      if (bShouldRelease) {
2358                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type
2359                          // spawn release triggered voice(s) if needed                          // spawn release triggered voice(s) if needed
2360                          ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);                          if (pKey->ReleaseTrigger & release_trigger_noteoff)
2361                                ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);
2362                      }                      }
2363                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {
2364                      // This programmatically caused event is caused by a call to                      // This programmatically caused event is caused by a call to
# Line 1903  namespace LinuxSampler { Line 2389  namespace LinuxSampler {
2389               * @param pEngineChannel - engine channel on which this event occurred on               * @param pEngineChannel - engine channel on which this event occurred on
2390               * @param itEvent - release trigger event (contains note number)               * @param itEvent - release trigger event (contains note number)
2391               */               */
2392              virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {              virtual void ProcessReleaseTriggerBySustain(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {
2393                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2394    
2395                  const int iKey = itEvent->Param.Note.Key;                  const int iKey = itEvent->Param.Note.Key;
# Line 1931  namespace LinuxSampler { Line 2417  namespace LinuxSampler {
2417                          // allocate and trigger new release voice(s)                          // allocate and trigger new release voice(s)
2418                          TriggerReleaseVoices(pChannel, itEvent);                          TriggerReleaseVoices(pChannel, itEvent);
2419                      }                      }
2420                      pKey->ReleaseTrigger = false;                      pKey->ReleaseTrigger = release_trigger_none;
2421                  }                  }
2422              }              }
2423    
# Line 1977  namespace LinuxSampler { Line 2463  namespace LinuxSampler {
2463                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );
2464                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2465    
                 const bool& relative = itEvent->Param.NoteSynthParam.Relative;  
   
2466                  switch (itEvent->Param.NoteSynthParam.Type) {                  switch (itEvent->Param.NoteSynthParam.Type) {
2467                      case Event::synth_param_volume:                      case Event::synth_param_volume:
2468                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Volume);
                             pNote->Override.Volume *= itEvent->Param.NoteSynthParam.Delta;  
                         else  
                             pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;  
                         itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;  
2469                          break;                          break;
2470                      case Event::synth_param_volume_time:                      case Event::synth_param_volume_time:
2471                          pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2472                          break;                          break;
2473                        case Event::synth_param_volume_curve:
2474                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2475                            pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2476                            break;
2477                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
2478                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Pitch);
                             pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;  
                         else  
                             pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;  
                         itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;  
2479                          break;                          break;
2480                      case Event::synth_param_pitch_time:                      case Event::synth_param_pitch_time:
2481                          pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2482                          break;                          break;
2483                        case Event::synth_param_pitch_curve:
2484                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2485                            pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2486                            break;
2487                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2488                          if (relative) {                          pNote->apply(itEvent, &NoteBase::_Override::Pan);
2489                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);                          break;
2490                          } else {                      case Event::synth_param_pan_time:
2491                              pNote->Override.Pan = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2492                              pNote->Override.PanSources = 1; // only relevant on subsequent change_pan() instrument script calls on same note with 'relative' argument being set                          break;
2493                          }                      case Event::synth_param_pan_curve:
2494                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan;                          itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2495                            pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2496                          break;                          break;
2497                      case Event::synth_param_cutoff:                      case Event::synth_param_cutoff:
2498                          pNote->Override.Cutoff = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Cutoff);
2499                          break;                          break;
2500                      case Event::synth_param_resonance:                      case Event::synth_param_resonance:
2501                          pNote->Override.Resonance = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Resonance);
2502                          break;                          break;
2503                      case Event::synth_param_attack:                      case Event::synth_param_attack:
2504                          pNote->Override.Attack = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Attack);
2505                          break;                          break;
2506                      case Event::synth_param_decay:                      case Event::synth_param_decay:
2507                          pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Decay);
2508                            break;
2509                        case Event::synth_param_sustain:
2510                            pNote->apply(itEvent, &NoteBase::_Override::Sustain);
2511                          break;                          break;
2512                      case Event::synth_param_release:                      case Event::synth_param_release:
2513                          pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Release);
2514                            break;
2515    
2516                        case Event::synth_param_cutoff_attack:
2517                            pNote->apply(itEvent, &NoteBase::_Override::CutoffAttack);
2518                            break;
2519                        case Event::synth_param_cutoff_decay:
2520                            pNote->apply(itEvent, &NoteBase::_Override::CutoffDecay);
2521                            break;
2522                        case Event::synth_param_cutoff_sustain:
2523                            pNote->apply(itEvent, &NoteBase::_Override::CutoffSustain);
2524                          break;                          break;
2525                        case Event::synth_param_cutoff_release:
2526                            pNote->apply(itEvent, &NoteBase::_Override::CutoffRelease);
2527                            break;
2528    
2529                      case Event::synth_param_amp_lfo_depth:                      case Event::synth_param_amp_lfo_depth:
2530                          pNote->Override.AmpLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::AmpLFODepth);
2531                          break;                          break;
2532                      case Event::synth_param_amp_lfo_freq:                      case Event::synth_param_amp_lfo_freq:
2533                          pNote->Override.AmpLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::AmpLFOFreq);
2534                            break;
2535                        case Event::synth_param_cutoff_lfo_depth:
2536                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFODepth);
2537                            break;
2538                        case Event::synth_param_cutoff_lfo_freq:
2539                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFOFreq);
2540                          break;                          break;
2541                      case Event::synth_param_pitch_lfo_depth:                      case Event::synth_param_pitch_lfo_depth:
2542                          pNote->Override.PitchLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::PitchLFODepth);
2543                          break;                          break;
2544                      case Event::synth_param_pitch_lfo_freq:                      case Event::synth_param_pitch_lfo_freq:
2545                          pNote->Override.PitchLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::PitchLFOFreq);
2546                          break;                          break;
2547                  }                  }
2548    
# Line 2164  namespace LinuxSampler { Line 2672  namespace LinuxSampler {
2672                      }                      }
2673                      else { // on success                      else { // on success
2674                          --VoiceSpawnsLeft;                          --VoiceSpawnsLeft;
2675                          if (!pKey->Active) { // mark as active key  
2676                              pKey->Active = true;                          // should actually be superfluous now, since this is
2677                              pKey->itSelf = pChannel->pActiveKeys->allocAppend();                          // already done in LaunchNewNote()
2678                              *pKey->itSelf = itNoteOnEvent->Param.Note.Key;                          pChannel->markKeyAsActive(pKey);
2679                          }  
2680                          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)
2681                                pKey->ReleaseTrigger |= itNewVoice->GetReleaseTriggerFlags(); // mark key for the need of release triggered voice(s)
2682                          return 0; // success                          return 0; // success
2683                      }                      }
2684                  }                  }

Legend:
Removed from v.3205  
changed lines
  Added in v.3854

  ViewVC Help
Powered by ViewVC