/[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 3034 by schoenebeck, Mon Oct 31 00:05:00 2016 UTC revision 3706 by schoenebeck, Wed Jan 8 20:39:59 2020 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-2020 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Grigor Iliev                                  *
8   *   Copyright (C) 2012-2016 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 597  namespace LinuxSampler { Line 615  namespace LinuxSampler {
615              }              }
616    
617              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'
618              virtual Pool<R*>* GetRegionPool(int index) {              virtual Pool<R*>* GetRegionPool(int index) OVERRIDE {
619                  if (index < 0 || index > 1) throw Exception("Index out of bounds");                  if (index < 0 || index > 1) throw Exception("Index out of bounds");
620                  return pRegionPool[index];                  return pRegionPool[index];
621              }              }
# Line 605  namespace LinuxSampler { Line 623  namespace LinuxSampler {
623              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'
624              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }
625              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }
626              virtual Pool<note_id_t>* GetNodeIDPool() OVERRIDE { return &noteIDPool; }              virtual Pool<note_id_t>* GetNoteIDPool() OVERRIDE { return &noteIDPool; }
627    
628              D* GetDiskThread() { return pDiskThread; }              D* GetDiskThread() { return pDiskThread; }
629    
# Line 676  namespace LinuxSampler { Line 694  namespace LinuxSampler {
694               * @param pNoteOnEvent - event which caused this               * @param pNoteOnEvent - event which caused this
695               * @returns new note's unique ID (or zero on error)               * @returns new note's unique ID (or zero on error)
696               */               */
697              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE {              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
698                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
699                  Pool< Note<V> >* pNotePool = GetNotePool();                  Pool< Note<V> >* pNotePool = GetNotePool();
700    
# Line 691  namespace LinuxSampler { Line 709  namespace LinuxSampler {
709                  const note_id_t newNoteID = pNotePool->getID(itNewNote);                  const note_id_t newNoteID = pNotePool->getID(itNewNote);
710    
711                  // remember the engine's time when this note was triggered exactly                  // remember the engine's time when this note was triggered exactly
712                  itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime();                  itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime();
713    
714                  // usually the new note (and its subsequent voices) will be                  // usually the new note (and its subsequent voices) will be
715                  // allocated on the key provided by the event's note number,                  // allocated on the key provided by the event's note number,
# Line 699  namespace LinuxSampler { Line 717  namespace LinuxSampler {
717                  // note, but rather a child note, then this new note will be                  // note, but rather a child note, then this new note will be
718                  // allocated on the parent note's key instead in order to                  // allocated on the parent note's key instead in order to
719                  // release the child note simultaniously with its parent note                  // release the child note simultaniously with its parent note
720                  itNewNote->hostKey = pNoteOnEvent->Param.Note.Key;                  itNewNote->hostKey = itNoteOnEvent->Param.Note.Key;
721    
722                  // in case this new note was requested to be a child note,                  // in case this new note was requested to be a child note,
723                  // then retrieve its parent note and link them with each other                  // then retrieve its parent note and link them with each other
724                  const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID;                  const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID;
725                  if (parentNoteID) {                  if (parentNoteID) {
726                      NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                                              NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                        
727                      if (itParentNote) {                      if (itParentNote) {
# Line 731  namespace LinuxSampler { Line 749  namespace LinuxSampler {
749                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));
750    
751                  // copy event which caused this note                  // copy event which caused this note
752                  itNewNote->cause = *pNoteOnEvent;                  itNewNote->cause = *itNoteOnEvent;
753                  itNewNote->eventID = pEventPool->getID(pNoteOnEvent);                  itNewNote->eventID = pEventPool->getID(itNoteOnEvent);
754                    if (!itNewNote->eventID) {
755                        dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n"));
756                    }
757    
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                  pNoteOnEvent->Param.Note.ID = newNoteID;                  itNoteOnEvent->Param.Note.ID = newNoteID;
765    
766                  return newNoteID; // success                  return newNoteID; // success
767              }              }
# Line 804  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:
834                              case Event::type_play_note:                              case Event::type_play_note:
835                              case Event::type_stop_note:                              case Event::type_stop_note:
836                                case Event::type_kill_note:
837                              case Event::type_note_synth_param:                              case Event::type_note_synth_param:
838                                  break; // noop                                  break; // noop
839                          }                          }
# Line 864  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 881  namespace LinuxSampler { Line 907  namespace LinuxSampler {
907                                  dmsg(5,("Engine: Stop Note received\n"));                                  dmsg(5,("Engine: Stop Note received\n"));
908                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
909                                  break;                                  break;
910                                case Event::type_kill_note:
911                                    dmsg(5,("Engine: Kill Note received\n"));
912                                    ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent);
913                                    break;
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 909  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 976  namespace LinuxSampler { Line 1025  namespace LinuxSampler {
1025                      // script event object                      // script event object
1026                      RTList<ScriptEvent>::Iterator itScriptEvent =                      RTList<ScriptEvent>::Iterator itScriptEvent =
1027                          pChannel->pScript->pEvents->allocAppend();                          pChannel->pScript->pEvents->allocAppend();
1028                        // if event handler uses polyphonic variables, reset them
1029                        // to zero values before starting to execute the handler
1030                        if (pEventHandler->isPolyphonic())
1031                            itScriptEvent->execCtx->resetPolyphonicData();
1032                      ProcessScriptEvent(                      ProcessScriptEvent(
1033                          pChannel, itEvent, pEventHandler, itScriptEvent                          pChannel, itEvent, pEventHandler, itScriptEvent
1034                      );                      );
# Line 1008  namespace LinuxSampler { Line 1061  namespace LinuxSampler {
1061    
1062                  // initialize/reset other members                  // initialize/reset other members
1063                  itScriptEvent->cause = *itEvent;                  itScriptEvent->cause = *itEvent;
1064                    itScriptEvent->scheduleTime = itEvent->SchedTime();
1065                  itScriptEvent->currentHandler = 0;                  itScriptEvent->currentHandler = 0;
1066                  itScriptEvent->executionSlices = 0;                  itScriptEvent->executionSlices = 0;
1067                  itScriptEvent->ignoreAllWaitCalls = false;                  itScriptEvent->ignoreAllWaitCalls = false;
1068                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();
1069                    itScriptEvent->parentHandlerID = 0;
1070                    itScriptEvent->childHandlerID[0] = 0;
1071                    itScriptEvent->autoAbortByParent = false;
1072                    itScriptEvent->forkIndex = 0;
1073                  // this is the native representation of the $EVENT_ID script variable                  // this is the native representation of the $EVENT_ID script variable
1074                  itScriptEvent->id =                  itScriptEvent->id =
1075                      (itEvent->Type == Event::type_note_on)                      (itEvent->Type == Event::type_note_on)
# Line 1124  namespace LinuxSampler { Line 1182  namespace LinuxSampler {
1182               *  @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
1183               */               */
1184              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              int StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {
1185                    dmsg(3,("StealVoice()\n"));
1186                  if (VoiceSpawnsLeft <= 0) {                  if (VoiceSpawnsLeft <= 0) {
1187                      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"));
1188                      return -1;                      return -1;
# Line 1145  namespace LinuxSampler { Line 1204  namespace LinuxSampler {
1204                  // steal oldest voice on the oldest key from any other engine channel                  // steal oldest voice on the oldest key from any other engine channel
1205                  // (the smaller engine channel number, the higher priority)                  // (the smaller engine channel number, the higher priority)
1206                  EngineChannelBase<V, R, I>*  pSelectedChannel;                  EngineChannelBase<V, R, I>*  pSelectedChannel;
1207                  int                          iChannelIndex;                  ssize_t                      iChannelIndex;
1208                  VoiceIterator                itSelectedVoice;                  VoiceIterator                itSelectedVoice;
1209    
1210                    #if CONFIG_DEVMODE
1211                    EngineChannel* pBegin = NULL; // to detect endless loop
1212                    #endif
1213    
1214                  // select engine channel                  // select engine channel
1215                  if (pLastStolenChannel) {                  if (pLastStolenChannel) {
1216                      pSelectedChannel = pLastStolenChannel;                      pSelectedChannel = pLastStolenChannel;
# Line 1190  namespace LinuxSampler { Line 1253  namespace LinuxSampler {
1253                  }                  }
1254    
1255                  #if CONFIG_DEVMODE                  #if CONFIG_DEVMODE
1256                  EngineChannel* pBegin = pSelectedChannel; // to detect endless loop                  pBegin = pSelectedChannel; // to detect endless loop
1257                  #endif // CONFIG_DEVMODE                  #endif // CONFIG_DEVMODE
1258    
1259                  while (true) { // iterate through engine channels                                          while (true) { // iterate through engine channels                        
# Line 1283  namespace LinuxSampler { Line 1346  namespace LinuxSampler {
1346                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1347                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1348    
1349                                itScriptEvent->cause = pEventGenerator->CreateEvent(0);
1350                                itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing
1351                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1352                                itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort();
1353                                itScriptEvent->id = 0;
1354                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1355                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1356                              itScriptEvent->currentHandler = 0;                              itScriptEvent->currentHandler = 0;
1357                              itScriptEvent->executionSlices = 0;                              itScriptEvent->executionSlices = 0;
1358                              itScriptEvent->ignoreAllWaitCalls = false;                              itScriptEvent->ignoreAllWaitCalls = false;
1359                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1360                                itScriptEvent->parentHandlerID = 0;
1361                              /*VMExecStatus_t res = */ pScriptVM->exec(                              itScriptEvent->childHandlerID[0] = 0;
1362                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                              itScriptEvent->autoAbortByParent = false;
1363                              );                              itScriptEvent->forkIndex = 0;
1364    
1365                                VMExecStatus_t res;
1366                                size_t instructionsCount = 0;
1367                                const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction)
1368                                bool bWarningShown = false;
1369                                do {
1370                                    res = pScriptVM->exec(
1371                                        pEngineChannel->pScript->parserContext, &*itScriptEvent
1372                                    );
1373                                    instructionsCount += itScriptEvent->execCtx->instructionsPerformed();
1374                                    if (instructionsCount > maxInstructions && !bWarningShown) {
1375                                        bWarningShown = true;
1376                                        dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n"));
1377                                    }
1378                                } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR));
1379    
1380                              pEngineChannel->pScript->pEvents->free(itScriptEvent);                              pEngineChannel->pScript->pEvents->free(itScriptEvent);
1381                          }                          }
# Line 1354  namespace LinuxSampler { Line 1436  namespace LinuxSampler {
1436                          // usually there should already be a new Note object                          // usually there should already be a new Note object
1437                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);
1438                          if (!itNote) { // should not happen, but just to be sure ...                          if (!itNote) { // should not happen, but just to be sure ...
1439                              const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent);                              dmsg(2,("Engine: No Note object for stolen voice!\n"));
1440                                const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);
1441                              if (!noteID) {                              if (!noteID) {
1442                                  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"));
1443                                  continue;                                  continue;
# Line 1398  namespace LinuxSampler { Line 1481  namespace LinuxSampler {
1481              void PostProcess(EngineChannel* pEngineChannel) {              void PostProcess(EngineChannel* pEngineChannel) {
1482                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1483                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1484                   pChannel->FreeAllInactiveKyes();                   pChannel->FreeAllInactiveKeys();
1485    
1486                  // empty the engine channel's own event lists                  // empty the engine channel's own event lists
1487                  // (only events of the current audio fragment cycle)                  // (only events of the current audio fragment cycle)
# Line 1420  namespace LinuxSampler { Line 1503  namespace LinuxSampler {
1503                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1504                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                      static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1505    
1506                    // will be set to true if this CC event has anything to do with RPN/NRPN
1507                    bool bIsRpn = false, bIsNrpn = false;
1508    
1509                  switch (itControlChangeEvent->Param.CC.Controller) {                  switch (itControlChangeEvent->Param.CC.Controller) {
1510                      case 5: { // portamento time                      case 5: { // portamento time
1511                          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;
1512                          break;                          break;
1513                      }                      }
1514                      case 6: { // data entry (currently only used for RPN and NRPN controllers)                      case 6: { // data entry (MSB)
1515                          //dmsg(1,("DATA ENTRY %d\n", itControlChangeEvent->Param.CC.Value));                          //dmsg(1,("DATA ENTRY MSB %d\n", itControlChangeEvent->Param.CC.Value));
1516                          if (pChannel->GetMidiRpnController() >= 0) { // RPN controller number was sent previously ...                          if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1517                              dmsg(4,("Guess it's an RPN ...\n"));                              pChannel->SetMidiRpnDataMsb(
1518                              if (pChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones                                  itControlChangeEvent->Param.CC.Value
1519                                  int transpose = (int) itControlChangeEvent->Param.CC.Value - 64;                              );
1520                                  // limit to +- two octaves for now                              bIsRpn = true;
1521                                  transpose = RTMath::Min(transpose,  24);  
1522                                  transpose = RTMath::Max(transpose, -24);                              // look-ahead: if next MIDI event is data entry LSB,
1523                                  pChannel->GlobalTranspose = transpose;                              // then skip this event here for now (to avoid double
1524                                  // workaround, so we won't have hanging notes                              // handling of what's supposed to be one RPN event)
1525                                  pChannel->ReleaseAllVoices(itControlChangeEvent);                              if (isNextEventCCNr(itControlChangeEvent, 38))
1526                              }                                  break;
1527                              // to prevent other MIDI CC #6 messages to be misenterpreted as RPN controller data  
1528                              pChannel->ResetMidiRpnController();                              int ch = itControlChangeEvent->Param.CC.Channel;
1529                          } else if (pChannel->GetMidiNrpnController() >= 0) { // NRPN controller number was sent previously ...                              int param = pChannel->GetMidiRpnParameter();
1530                              dmsg(4,("Guess it's an NRPN ...\n"));                              int value = pChannel->GetMidiRpnData();
1531                              const int NrpnCtrlMSB = pChannel->GetMidiNrpnController() >> 8;  
1532                              const int NrpnCtrlLSB = pChannel->GetMidiNrpnController() & 0xff;                              // transform event type: CC event -> RPN event
1533                              dmsg(4,("NRPN MSB=%d LSB=%d Data=%d\n", NrpnCtrlMSB, NrpnCtrlLSB, itControlChangeEvent->Param.CC.Value));                              itControlChangeEvent->Type = Event::type_rpn;
1534                              switch (NrpnCtrlMSB) {                              itControlChangeEvent->Param.RPN.Channel = ch;
1535                                  case 0x1a: { // volume level of note (Roland GS NRPN)                              itControlChangeEvent->Param.RPN.Parameter = param;
1536                                      const uint note = NrpnCtrlLSB;                              itControlChangeEvent->Param.RPN.Value = value;
1537                                      const uint vol  = itControlChangeEvent->Param.CC.Value;  
1538                                      dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));                              // if there's a RPN script handler, run it ...
1539                                      if (note < 128 && vol < 128)                              if (pChannel->pScript->handlerRpn) {
1540                                          pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];                                  const event_id_t eventID =
1541                                      break;                                      pEventPool->getID(itControlChangeEvent);
1542                                  }                                  // run the RPN script handler
1543                                  case 0x1c: { // panpot of note (Roland GS NRPN)                                  ProcessEventByScript(
1544                                      const uint note = NrpnCtrlLSB;                                      pChannel, itControlChangeEvent,
1545                                      const uint pan  = itControlChangeEvent->Param.CC.Value;                                      pChannel->pScript->handlerRpn
1546                                      dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));                                  );
1547                                      if (note < 128 && pan < 128) {                                  // if RPN event was dropped by script, abort
1548                                          pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];                                  // here to avoid hard coded RPN processing below
1549                                          pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];                                  if (!pEventPool->fromID(eventID))
                                     }  
                                     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;  
1550                                      break;                                      break;
1551                                  }                              }
1552                                  case 0x1e: { // chorus send of note (Roland GS NRPN)  
1553                                      const uint note = NrpnCtrlLSB;                              // do the actual (hard-coded) RPN value change processing
1554                                      const float chorus = float(itControlChangeEvent->Param.CC.Value) / 127.0f;                              ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1555                                      dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));  
1556                                      if (note < 128)                          } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1557                                          pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;                              pChannel->SetMidiNrpnDataMsb(
1558                                    itControlChangeEvent->Param.CC.Value
1559                                );
1560                                bIsNrpn = true;
1561    
1562                                // look-ahead: if next MIDI event is data entry LSB,
1563                                // then skip this event here for now (to avoid double
1564                                // handling of what's supposed to be one NRPN event)
1565                                if (isNextEventCCNr(itControlChangeEvent, 38))
1566                                    break;
1567    
1568                                int ch = itControlChangeEvent->Param.CC.Channel;
1569                                int param = pChannel->GetMidiNrpnParameter();
1570                                int value = pChannel->GetMidiNrpnData();
1571    
1572                                // transform event type: CC event -> NRPN event
1573                                itControlChangeEvent->Type = Event::type_nrpn;
1574                                itControlChangeEvent->Param.NRPN.Channel = ch;
1575                                itControlChangeEvent->Param.NRPN.Parameter = param;
1576                                itControlChangeEvent->Param.NRPN.Value = value;
1577    
1578                                // if there's a NRPN script handler, run it ...
1579                                if (pChannel->pScript->handlerNrpn) {
1580                                    const event_id_t eventID =
1581                                        pEventPool->getID(itControlChangeEvent);
1582                                    // run the NRPN script handler
1583                                    ProcessEventByScript(
1584                                        pChannel, itControlChangeEvent,
1585                                        pChannel->pScript->handlerNrpn
1586                                    );
1587                                    // if NRPN event was dropped by script, abort
1588                                    // here to avoid hard coded NRPN processing below
1589                                    if (!pEventPool->fromID(eventID))
1590                                      break;                                      break;
                                 }  
1591                              }                              }
1592                              // to prevent other MIDI CC #6 messages to be misenterpreted as NRPN controller data  
1593                              pChannel->ResetMidiNrpnController();                              // do the actual (hard-coded) NRPN value change processing
1594                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1595                          }                          }
1596                          break;                          break;
1597                      }                      }
# Line 1497  namespace LinuxSampler { Line 1606  namespace LinuxSampler {
1606                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;                          pChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;
1607                          break;                          break;
1608                      }                      }
1609                        case 38: { // data entry (LSB)
1610                            //dmsg(1,("DATA ENTRY LSB %d\n", itControlChangeEvent->Param.CC.Value));
1611                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1612                                pChannel->SetMidiRpnDataLsb(
1613                                    itControlChangeEvent->Param.CC.Value
1614                                );
1615                                bIsRpn = true;
1616    
1617                                int ch = itControlChangeEvent->Param.CC.Channel;
1618                                int param = pChannel->GetMidiRpnParameter();
1619                                int value = pChannel->GetMidiRpnData();
1620    
1621                                // transform event type: CC event -> RPN event
1622                                itControlChangeEvent->Type = Event::type_rpn;
1623                                itControlChangeEvent->Param.RPN.Channel = ch;
1624                                itControlChangeEvent->Param.RPN.Parameter = param;
1625                                itControlChangeEvent->Param.RPN.Value = value;
1626    
1627                                // if there's a RPN script handler, run it ...
1628                                if (pChannel->pScript->handlerRpn) {
1629                                    const event_id_t eventID =
1630                                        pEventPool->getID(itControlChangeEvent);
1631                                    // run the RPN script handler
1632                                    ProcessEventByScript(
1633                                        pChannel, itControlChangeEvent,
1634                                        pChannel->pScript->handlerRpn
1635                                    );
1636                                    // if RPN event was dropped by script, abort
1637                                    // here to avoid hard coded RPN processing below
1638                                    if (!pEventPool->fromID(eventID))
1639                                        break;
1640                                }
1641    
1642                                // do the actual (hard-coded) RPN value change processing
1643                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1644    
1645                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1646                                pChannel->SetMidiNrpnDataLsb(
1647                                    itControlChangeEvent->Param.CC.Value
1648                                );
1649                                bIsNrpn = true;
1650    
1651                                int ch = itControlChangeEvent->Param.CC.Channel;
1652                                int param = pChannel->GetMidiNrpnParameter();
1653                                int value = pChannel->GetMidiNrpnData();
1654    
1655                                // transform event type: CC event -> NRPN event
1656                                itControlChangeEvent->Type = Event::type_nrpn;
1657                                itControlChangeEvent->Param.NRPN.Channel = ch;
1658                                itControlChangeEvent->Param.NRPN.Parameter = param;
1659                                itControlChangeEvent->Param.NRPN.Value = value;
1660    
1661                                // if there's a NRPN script handler, run it ...
1662                                if (pChannel->pScript->handlerNrpn) {
1663                                    const event_id_t eventID =
1664                                        pEventPool->getID(itControlChangeEvent);
1665                                    // run the NRPN script handler
1666                                    ProcessEventByScript(
1667                                        pChannel, itControlChangeEvent,
1668                                        pChannel->pScript->handlerNrpn
1669                                    );
1670                                    // if NRPN event was dropped by script, abort
1671                                    // here to avoid hard coded NRPN processing below
1672                                    if (!pEventPool->fromID(eventID))
1673                                        break;
1674                                }
1675    
1676                                // do the actual (hard-coded) NRPN value change processing
1677                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1678                            }
1679                            break;
1680                        }
1681                      case 64: { // sustain                      case 64: { // sustain
1682                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {                          if (itControlChangeEvent->Param.CC.Value >= 64 && !pChannel->SustainPedal) {
1683                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));                              dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
# Line 1570  namespace LinuxSampler { Line 1751  namespace LinuxSampler {
1751                          }                          }
1752                          break;                          break;
1753                      }                      }
1754                      case 98: { // NRPN controller LSB                      case 96: { // data increment (data entry +1)
1755                            //dmsg(1,("DATA INC\n"));
1756                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1757                                pChannel->SetMidiRpnData(
1758                                    pChannel->GetMidiRpnData() + 1
1759                                );
1760                                bIsRpn = true;
1761    
1762                                int ch = itControlChangeEvent->Param.CC.Channel;
1763                                int param = pChannel->GetMidiRpnParameter();
1764                                int value = pChannel->GetMidiRpnData();
1765    
1766                                // transform event type: CC event -> RPN event
1767                                itControlChangeEvent->Type = Event::type_rpn;
1768                                itControlChangeEvent->Param.RPN.Channel = ch;
1769                                itControlChangeEvent->Param.RPN.Parameter = param;
1770                                itControlChangeEvent->Param.RPN.Value = value;
1771    
1772                                // if there's a RPN script handler, run it ...
1773                                if (pChannel->pScript->handlerRpn) {
1774                                    const event_id_t eventID =
1775                                        pEventPool->getID(itControlChangeEvent);
1776                                    // run the RPN script handler
1777                                    ProcessEventByScript(
1778                                        pChannel, itControlChangeEvent,
1779                                        pChannel->pScript->handlerRpn
1780                                    );
1781                                    // if RPN event was dropped by script, abort
1782                                    // here to avoid hard coded RPN processing below
1783                                    if (!pEventPool->fromID(eventID))
1784                                        break;
1785                                }
1786    
1787                                // do the actual (hard-coded) RPN value change processing
1788                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1789    
1790                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1791                                pChannel->SetMidiNrpnData(
1792                                    pChannel->GetMidiNrpnData() + 1
1793                                );
1794                                bIsNrpn = true;
1795    
1796                                int ch = itControlChangeEvent->Param.CC.Channel;
1797                                int param = pChannel->GetMidiNrpnParameter();
1798                                int value = pChannel->GetMidiNrpnData();
1799    
1800                                // transform event type: CC event -> NRPN event
1801                                itControlChangeEvent->Type = Event::type_nrpn;
1802                                itControlChangeEvent->Param.NRPN.Channel = ch;
1803                                itControlChangeEvent->Param.NRPN.Parameter = param;
1804                                itControlChangeEvent->Param.NRPN.Value = value;
1805    
1806                                // if there's a NRPN script handler, run it ...
1807                                if (pChannel->pScript->handlerNrpn) {
1808                                    const event_id_t eventID =
1809                                        pEventPool->getID(itControlChangeEvent);
1810                                    // run the NRPN script handler
1811                                    ProcessEventByScript(
1812                                        pChannel, itControlChangeEvent,
1813                                        pChannel->pScript->handlerNrpn
1814                                    );
1815                                    // if NRPN event was dropped by script, abort
1816                                    // here to avoid hard coded NRPN processing below
1817                                    if (!pEventPool->fromID(eventID))
1818                                        break;
1819                                }
1820    
1821                                // do the actual (hard-coded) NRPN value change processing
1822                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1823                            }
1824                            break;
1825                        }
1826                        case 97: { // data decrement (data entry -1)
1827                            //dmsg(1,("DATA DEC\n"));
1828                            if (pChannel->GetMidiRpnParameter() >= 0) { // RPN parameter number was sent previously ...
1829                                pChannel->SetMidiRpnData(
1830                                    pChannel->GetMidiRpnData() - 1
1831                                );
1832                                bIsRpn = true;
1833    
1834                                int ch = itControlChangeEvent->Param.CC.Channel;
1835                                int param = pChannel->GetMidiRpnParameter();
1836                                int value = pChannel->GetMidiRpnData();
1837    
1838                                // transform event type: CC event -> RPN event
1839                                itControlChangeEvent->Type = Event::type_rpn;
1840                                itControlChangeEvent->Param.RPN.Channel = ch;
1841                                itControlChangeEvent->Param.RPN.Parameter = param;
1842                                itControlChangeEvent->Param.RPN.Value = value;
1843    
1844                                // if there's a RPN script handler, run it ...
1845                                if (pChannel->pScript->handlerRpn) {
1846                                    const event_id_t eventID =
1847                                        pEventPool->getID(itControlChangeEvent);
1848                                    // run the RPN script handler
1849                                    ProcessEventByScript(
1850                                        pChannel, itControlChangeEvent,
1851                                        pChannel->pScript->handlerRpn
1852                                    );
1853                                    // if RPN event was dropped by script, abort
1854                                    // here to avoid hard coded RPN processing below
1855                                    if (!pEventPool->fromID(eventID))
1856                                        break;
1857                                }
1858    
1859                                // do the actual (hard-coded) RPN value change processing
1860                                ProcessHardcodedRpn(pEngineChannel, itControlChangeEvent);
1861    
1862                            } else if (pChannel->GetMidiNrpnParameter() >= 0) { // NRPN parameter number was sent previously ...
1863                                pChannel->SetMidiNrpnData(
1864                                    pChannel->GetMidiNrpnData() - 1
1865                                );
1866                                bIsNrpn = true;
1867    
1868                                int ch = itControlChangeEvent->Param.CC.Channel;
1869                                int param = pChannel->GetMidiNrpnParameter();
1870                                int value = pChannel->GetMidiNrpnData();
1871    
1872                                // transform event type: CC event -> NRPN event
1873                                itControlChangeEvent->Type = Event::type_nrpn;
1874                                itControlChangeEvent->Param.NRPN.Channel = ch;
1875                                itControlChangeEvent->Param.NRPN.Parameter = param;
1876                                itControlChangeEvent->Param.NRPN.Value = value;
1877    
1878                                // if there's a NRPN script handler, run it ...
1879                                if (pChannel->pScript->handlerNrpn) {
1880                                    const event_id_t eventID =
1881                                        pEventPool->getID(itControlChangeEvent);
1882                                    // run the NRPN script handler
1883                                    ProcessEventByScript(
1884                                        pChannel, itControlChangeEvent,
1885                                        pChannel->pScript->handlerNrpn
1886                                    );
1887                                    // if NRPN event was dropped by script, abort
1888                                    // here to avoid hard coded NRPN processing below
1889                                    if (!pEventPool->fromID(eventID))
1890                                        break;
1891                                }
1892    
1893                                // do the actual (hard-coded) NRPN value change processing
1894                                ProcessHardcodedNrpn(pEngineChannel, itControlChangeEvent);
1895                            }
1896                            break;
1897                        }
1898                        case 98: { // NRPN parameter LSB
1899                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1900                          pEngineChannel->SetMidiNrpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          bIsNrpn = true;
1901                            pEngineChannel->SetMidiNrpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1902                          break;                          break;
1903                      }                      }
1904                      case 99: { // NRPN controller MSB                      case 99: { // NRPN parameter MSB
1905                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("NRPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1906                          pEngineChannel->SetMidiNrpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          bIsNrpn = true;
1907                            pEngineChannel->SetMidiNrpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1908                          break;                          break;
1909                      }                      }
1910                      case 100: { // RPN controller LSB                      case 100: { // RPN parameter LSB
1911                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN LSB %d\n", itControlChangeEvent->Param.CC.Value));
1912                          pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value);                          bIsRpn = true;
1913                            pEngineChannel->SetMidiRpnParameterLsb(itControlChangeEvent->Param.CC.Value);
1914                          break;                          break;
1915                      }                      }
1916                      case 101: { // RPN controller MSB                      case 101: { // RPN parameter MSB
1917                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));                          dmsg(4,("RPN MSB %d\n", itControlChangeEvent->Param.CC.Value));
1918                          pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value);                          bIsRpn = true;
1919                            pEngineChannel->SetMidiRpnParameterMsb(itControlChangeEvent->Param.CC.Value);
1920                          break;                          break;
1921                      }                      }
1922    
# Line 1621  namespace LinuxSampler { Line 1950  namespace LinuxSampler {
1950                          break;                          break;
1951                      }                      }
1952                  }                  }
1953    
1954                    // reset cached RPN/NRPN parameter number and data in case this
1955                    // CC event had nothing to do with RPN/NRPN
1956                    if (!bIsRpn && pChannel->GetMidiRpnParameter() >= 0)
1957                        pChannel->ResetMidiRpnParameter();
1958                    if (!bIsNrpn && pChannel->GetMidiNrpnParameter() >= 0)
1959                        pChannel->ResetMidiNrpnParameter();
1960                }
1961    
1962                /**
1963                 * Process MIDI RPN events with hard coded behavior.
1964                 *
1965                 * @param pEngineChannel - engine channel on which the MIDI RPN
1966                 *                         event was received
1967                 * @param itRpnEvent - the actual MIDI RPN event
1968                 */
1969                void ProcessHardcodedRpn(EngineChannel* pEngineChannel,
1970                                         Pool<Event>::Iterator& itRpnEvent)
1971                {
1972                    EngineChannelBase<V, R, I>* pChannel =
1973                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1974    
1975                    if (itRpnEvent->Param.RPN.Parameter == 2) { // coarse tuning in half tones
1976                        int transpose = (int) itRpnEvent->Param.RPN.ValueMSB() - 64;
1977                        // limit to +- two octaves for now
1978                        transpose = RTMath::Min(transpose,  24);
1979                        transpose = RTMath::Max(transpose, -24);
1980                        pChannel->GlobalTranspose = transpose;
1981                        // workaround, so we won't have hanging notes
1982                        pChannel->ReleaseAllVoices(itRpnEvent);
1983                    } else if (itRpnEvent->Param.RPN.Parameter == 16383) { // null function RPN
1984                        // disable subsequent data entry/increment/decrement processing
1985                        pChannel->ResetMidiRpnParameter();
1986                    }
1987                }
1988    
1989                /**
1990                 * Process MIDI NRPN events with hard coded behavior.
1991                 *
1992                 * @param pEngineChannel - engine channel on which the MIDI NRPN
1993                 *                         event was received
1994                 * @param itRpnEvent - the actual MIDI NRPN event
1995                 */
1996                void ProcessHardcodedNrpn(EngineChannel* pEngineChannel,
1997                                          Pool<Event>::Iterator& itNrpnEvent)
1998                {
1999                    EngineChannelBase<V, R, I>* pChannel =
2000                        static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2001    
2002                    switch (itNrpnEvent->Param.NRPN.ParameterMSB()) {
2003                        case 0x1a: { // volume level of note (Roland GS NRPN)
2004                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2005                            const uint vol  = itNrpnEvent->Param.NRPN.ValueMSB();
2006                            dmsg(4,("Note Volume NRPN received (note=%d,vol=%d).\n", note, vol));
2007                            if (note < 128 && vol < 128)
2008                                pChannel->pMIDIKeyInfo[note].Volume = VolumeCurve[vol];
2009                            break;
2010                        }
2011                        case 0x1c: { // panpot of note (Roland GS NRPN)
2012                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2013                            const uint pan  = itNrpnEvent->Param.NRPN.ValueMSB();
2014                            dmsg(4,("Note Pan NRPN received (note=%d,pan=%d).\n", note, pan));
2015                            if (note < 128 && pan < 128) {
2016                                pChannel->pMIDIKeyInfo[note].PanLeft  = PanCurve[128 - pan];
2017                                pChannel->pMIDIKeyInfo[note].PanRight = PanCurve[pan];
2018                            }
2019                            break;
2020                        }
2021                        case 0x1d: { // reverb send of note (Roland GS NRPN)
2022                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2023                            const float reverb = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
2024                            dmsg(4,("Note Reverb Send NRPN received (note=%d,send=%f).\n", note, reverb));
2025                            if (note < 128)
2026                                pChannel->pMIDIKeyInfo[note].ReverbSend = reverb;
2027                            break;
2028                        }
2029                        case 0x1e: { // chorus send of note (Roland GS NRPN)
2030                            const uint note = itNrpnEvent->Param.NRPN.ParameterLSB();
2031                            const float chorus = float(itNrpnEvent->Param.NRPN.Value) / 16383.f;
2032                            dmsg(4,("Note Chorus Send NRPN received (note=%d,send=%f).\n", note, chorus));
2033                            if (note < 128)
2034                                pChannel->pMIDIKeyInfo[note].ChorusSend = chorus;
2035                            break;
2036                        }
2037                        case 0x7f: {
2038                            if (itNrpnEvent->Param.NRPN.ParameterLSB() == 0x7f) { // null function NRPN
2039                                // disable subsequent data entry/increment/decrement processing
2040                                pChannel->ResetMidiNrpnParameter();
2041                            }
2042                            break;
2043                        }
2044                    }
2045              }              }
2046    
2047              virtual D* CreateDiskThread() = 0;              virtual D* CreateDiskThread() = 0;
# Line 1631  namespace LinuxSampler { Line 2052  namespace LinuxSampler {
2052               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
2053               *  @param itNoteOnEvent - key, velocity and time stamp of the event               *  @param itNoteOnEvent - key, velocity and time stamp of the event
2054               */               */
2055              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
2056                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
2057                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2058    
# Line 1762  namespace LinuxSampler { Line 2183  namespace LinuxSampler {
2183               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
2184               *  @param itNoteOffEvent - key, velocity and time stamp of the event               *  @param itNoteOffEvent - key, velocity and time stamp of the event
2185               */               */
2186              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE {
2187                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2188    
2189                  const int iKey = itNoteOffEvent->Param.Note.Key;                  const int iKey = itNoteOffEvent->Param.Note.Key;
# Line 1831  namespace LinuxSampler { Line 2252  namespace LinuxSampler {
2252                                          itPseudoNoteOnEvent->Param.Note.Key      = i;                                          itPseudoNoteOnEvent->Param.Note.Key      = i;
2253                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
2254                                          // assign a new note to this note-on event                                          // assign a new note to this note-on event
2255                                          if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) {                                          if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) {
2256                                              // allocate and trigger new voice(s) for the other key                                              // allocate and trigger new voice(s) for the other key
2257                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);
2258                                          }                                          }
# Line 1863  namespace LinuxSampler { Line 2284  namespace LinuxSampler {
2284                      if (bShouldRelease) {                      if (bShouldRelease) {
2285                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type                          itNoteOffEventOnKeyList->Type = Event::type_release_key; // transform event type
2286                          // spawn release triggered voice(s) if needed                          // spawn release triggered voice(s) if needed
2287                          ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);                          if (pKey->ReleaseTrigger & release_trigger_noteoff)
2288                                ProcessReleaseTrigger(pChannel, itNoteOffEventOnKeyList, pKey);
2289                      }                      }
2290                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {                  } else if (itNoteOffEventOnKeyList->Type == Event::type_stop_note) {
2291                      // This programmatically caused event is caused by a call to                      // This programmatically caused event is caused by a call to
# Line 1894  namespace LinuxSampler { Line 2316  namespace LinuxSampler {
2316               * @param pEngineChannel - engine channel on which this event occurred on               * @param pEngineChannel - engine channel on which this event occurred on
2317               * @param itEvent - release trigger event (contains note number)               * @param itEvent - release trigger event (contains note number)
2318               */               */
2319              virtual void ProcessReleaseTrigger(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {              virtual void ProcessReleaseTriggerBySustain(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) OVERRIDE {
2320                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2321    
2322                  const int iKey = itEvent->Param.Note.Key;                  const int iKey = itEvent->Param.Note.Key;
# Line 1918  namespace LinuxSampler { Line 2340  namespace LinuxSampler {
2340                  // spawn release triggered voice(s) if needed                  // spawn release triggered voice(s) if needed
2341                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {
2342                      // assign a new note to this release event                      // assign a new note to this release event
2343                      if (LaunchNewNote(pChannel, &*itEvent)) {                      if (LaunchNewNote(pChannel, itEvent)) {
2344                          // allocate and trigger new release voice(s)                          // allocate and trigger new release voice(s)
2345                          TriggerReleaseVoices(pChannel, itEvent);                          TriggerReleaseVoices(pChannel, itEvent);
2346                      }                      }
2347                      pKey->ReleaseTrigger = false;                      pKey->ReleaseTrigger = release_trigger_none;
2348                  }                  }
2349              }              }
2350    
2351              /**              /**
2352                 * Called on "kill note" events, which currently only happens on
2353                 * built-in real-time instrument script function fade_out(). This
2354                 * method only fulfills one task: moving the even to the Note's own
2355                 * event list so that its voices can process the kill event sample
2356                 * accurately.
2357                 */
2358                void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
2359                    EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2360    
2361                    NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID );
2362                    if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2363    
2364                    // move note kill event to its MIDI key
2365                    MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey];
2366                    itEvent.moveToEndOf(pKey->pEvents);
2367                }
2368    
2369                /**
2370               * Called on note synthesis parameter change events. These are               * Called on note synthesis parameter change events. These are
2371               * internal events caused by calling built-in real-time instrument               * internal events caused by calling built-in real-time instrument
2372               * script functions like change_vol(), change_pitch(), etc.               * script functions like change_vol(), change_tune(), etc.
2373               *               *
2374               * This method performs two tasks:               * This method performs two tasks:
2375               *               *
# Line 1950  namespace LinuxSampler { Line 2390  namespace LinuxSampler {
2390                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );                  NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID );
2391                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;                  if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
2392    
                 const bool& relative = itEvent->Param.NoteSynthParam.Relative;  
   
2393                  switch (itEvent->Param.NoteSynthParam.Type) {                  switch (itEvent->Param.NoteSynthParam.Type) {
2394                      case Event::synth_param_volume:                      case Event::synth_param_volume:
2395                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Volume);
2396                              pNote->Override.Volume *= itEvent->Param.NoteSynthParam.Delta;                          break;
2397                          else                      case Event::synth_param_volume_time:
2398                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2399                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;                          break;
2400                        case Event::synth_param_volume_curve:
2401                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2402                            pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2403                          break;                          break;
2404                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
2405                          if (relative)                          pNote->apply(itEvent, &NoteBase::_Override::Pitch);
2406                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;                          break;
2407                          else                      case Event::synth_param_pitch_time:
2408                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2409                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;                          break;
2410                        case Event::synth_param_pitch_curve:
2411                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2412                            pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2413                          break;                          break;
2414                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2415                          if (relative) {                          pNote->apply(itEvent, &NoteBase::_Override::Pan);
2416                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);                          break;
2417                          } else {                      case Event::synth_param_pan_time:
2418                              pNote->Override.Pan = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.PanTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2419                              pNote->Override.PanSources = 1; // only relevant on subsequent change_pan() instrument script calls on same note with 'relative' argument being set                          break;
2420                          }                      case Event::synth_param_pan_curve:
2421                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pan;                          itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2422                            pNote->Override.PanCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2423                          break;                          break;
2424                      case Event::synth_param_cutoff:                      case Event::synth_param_cutoff:
2425                          pNote->Override.Cutoff = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Cutoff);
2426                          break;                          break;
2427                      case Event::synth_param_resonance:                      case Event::synth_param_resonance:
2428                          pNote->Override.Resonance = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Resonance);
2429                          break;                          break;
2430                      case Event::synth_param_attack:                      case Event::synth_param_attack:
2431                          pNote->Override.Attack = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Attack);
2432                          break;                          break;
2433                      case Event::synth_param_decay:                      case Event::synth_param_decay:
2434                          pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Decay);
2435                            break;
2436                        case Event::synth_param_sustain:
2437                            pNote->apply(itEvent, &NoteBase::_Override::Sustain);
2438                          break;                          break;
2439                      case Event::synth_param_release:                      case Event::synth_param_release:
2440                          pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->apply(itEvent, &NoteBase::_Override::Release);
2441                            break;
2442    
2443                        case Event::synth_param_cutoff_attack:
2444                            pNote->apply(itEvent, &NoteBase::_Override::CutoffAttack);
2445                            break;
2446                        case Event::synth_param_cutoff_decay:
2447                            pNote->apply(itEvent, &NoteBase::_Override::CutoffDecay);
2448                            break;
2449                        case Event::synth_param_cutoff_sustain:
2450                            pNote->apply(itEvent, &NoteBase::_Override::CutoffSustain);
2451                            break;
2452                        case Event::synth_param_cutoff_release:
2453                            pNote->apply(itEvent, &NoteBase::_Override::CutoffRelease);
2454                            break;
2455    
2456                        case Event::synth_param_amp_lfo_depth:
2457                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFODepth);
2458                            break;
2459                        case Event::synth_param_amp_lfo_freq:
2460                            pNote->apply(itEvent, &NoteBase::_Override::AmpLFOFreq);
2461                            break;
2462                        case Event::synth_param_cutoff_lfo_depth:
2463                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFODepth);
2464                            break;
2465                        case Event::synth_param_cutoff_lfo_freq:
2466                            pNote->apply(itEvent, &NoteBase::_Override::CutoffLFOFreq);
2467                            break;
2468                        case Event::synth_param_pitch_lfo_depth:
2469                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFODepth);
2470                            break;
2471                        case Event::synth_param_pitch_lfo_freq:
2472                            pNote->apply(itEvent, &NoteBase::_Override::PitchLFOFreq);
2473                          break;                          break;
2474                  }                  }
2475    
# Line 2002  namespace LinuxSampler { Line 2482  namespace LinuxSampler {
2482               *  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
2483               *  control and status variables. This method is protected by a mutex.               *  control and status variables. This method is protected by a mutex.
2484               */               */
2485              virtual void ResetInternal() {              virtual void ResetInternal() OVERRIDE {
2486                  LockGuard lock(ResetInternalMutex);                  LockGuard lock(ResetInternalMutex);
2487    
2488                  // make sure that the engine does not get any sysex messages                  // make sure that the engine does not get any sysex messages
# Line 2061  namespace LinuxSampler { Line 2541  namespace LinuxSampler {
2541               * @param pEngineChannel - engine channel on which all voices should be killed               * @param pEngineChannel - engine channel on which all voices should be killed
2542               * @param itKillEvent    - event which caused this killing of all voices               * @param itKillEvent    - event which caused this killing of all voices
2543               */               */
2544              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) {              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE {
2545                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2546                  int count = pChannel->KillAllVoices(itKillEvent);                  int count = pChannel->KillAllVoices(itKillEvent);
2547                  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 2096  namespace LinuxSampler { Line 2576  namespace LinuxSampler {
2576                  bool                    HandleKeyGroupConflicts                  bool                    HandleKeyGroupConflicts
2577              ) = 0;              ) = 0;
2578    
2579              virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; }              virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; }
2580    
2581              int InitNewVoice (              int InitNewVoice (
2582                  EngineChannelBase<V, R, I>*  pChannel,                  EngineChannelBase<V, R, I>*  pChannel,
# Line 2119  namespace LinuxSampler { Line 2599  namespace LinuxSampler {
2599                      }                      }
2600                      else { // on success                      else { // on success
2601                          --VoiceSpawnsLeft;                          --VoiceSpawnsLeft;
2602                          if (!pKey->Active) { // mark as active key  
2603                              pKey->Active = true;                          // should actually be superfluous now, since this is
2604                              pKey->itSelf = pChannel->pActiveKeys->allocAppend();                          // already done in LaunchNewNote()
2605                              *pKey->itSelf = itNoteOnEvent->Param.Note.Key;                          pChannel->markKeyAsActive(pKey);
2606                          }  
2607                          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)
2608                                pKey->ReleaseTrigger |= itNewVoice->GetReleaseTriggerFlags(); // mark key for the need of release triggered voice(s)
2609                          return 0; // success                          return 0; // success
2610                      }                      }
2611                  }                  }

Legend:
Removed from v.3034  
changed lines
  Added in v.3706

  ViewVC Help
Powered by ViewVC