/[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 2952 by persson, Sat Jul 16 11:19:31 2016 UTC revision 3188 by schoenebeck, Fri May 19 14:23:12 2017 UTC
# Line 5  Line 5 
5   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *
6   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *
8   *   Copyright (C) 2012-2016 Christian Schoenebeck and Andreas Persson     *   *   Copyright (C) 2012-2017 Christian Schoenebeck and Andreas Persson     *
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 58  namespace LinuxSampler { Line 58  namespace LinuxSampler {
58              typedef typename RTList<RR*>::Iterator RootRegionIterator;              typedef typename RTList<RR*>::Iterator RootRegionIterator;
59              typedef typename MidiKeyboardManager<V>::MidiKey MidiKey;              typedef typename MidiKeyboardManager<V>::MidiKey MidiKey;
60                            
61              EngineBase() : SuspendedRegions(128), noteIDPool(GLOBAL_MAX_NOTES) {              EngineBase() : noteIDPool(GLOBAL_MAX_NOTES), SuspendedRegions(128) {
62                  pDiskThread          = NULL;                  pDiskThread          = NULL;
63                  pNotePool            = new Pool< Note<V> >(GLOBAL_MAX_NOTES);                  pNotePool            = new Pool< Note<V> >(GLOBAL_MAX_NOTES);
64                  pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS);                  pNotePool->setPoolElementIDsReservedBits(INSTR_SCRIPT_EVENT_ID_RESERVED_BITS);
# Line 163  namespace LinuxSampler { Line 163  namespace LinuxSampler {
163                                  dmsg(5,("Engine: Sysex received\n"));                                  dmsg(5,("Engine: Sysex received\n"));
164                                  ProcessSysex(itEvent);                                  ProcessSysex(itEvent);
165                                  break;                                  break;
166                                default: ; // noop
167                          }                          }
168                      }                      }
169                  }                  }
# Line 596  namespace LinuxSampler { Line 597  namespace LinuxSampler {
597              }              }
598    
599              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'              // implementation of abstract method derived from class 'LinuxSampler::RegionPools'
600              virtual Pool<R*>* GetRegionPool(int index) {              virtual Pool<R*>* GetRegionPool(int index) OVERRIDE {
601                  if (index < 0 || index > 1) throw Exception("Index out of bounds");                  if (index < 0 || index > 1) throw Exception("Index out of bounds");
602                  return pRegionPool[index];                  return pRegionPool[index];
603              }              }
# Line 604  namespace LinuxSampler { Line 605  namespace LinuxSampler {
605              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'              // implementation of abstract methods derived from class 'LinuxSampler::NotePool'
606              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }              virtual Pool<V>* GetVoicePool() OVERRIDE { return pVoicePool; }
607              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }              virtual Pool< Note<V> >* GetNotePool() OVERRIDE { return pNotePool; }
608              virtual Pool<note_id_t>* GetNodeIDPool() OVERRIDE { return &noteIDPool; }              virtual Pool<note_id_t>* GetNoteIDPool() OVERRIDE { return &noteIDPool; }
609    
610              D* GetDiskThread() { return pDiskThread; }              D* GetDiskThread() { return pDiskThread; }
611    
# Line 689  namespace LinuxSampler { Line 690  namespace LinuxSampler {
690                  NoteIterator itNewNote = pNotePool->allocAppend();                  NoteIterator itNewNote = pNotePool->allocAppend();
691                  const note_id_t newNoteID = pNotePool->getID(itNewNote);                  const note_id_t newNoteID = pNotePool->getID(itNewNote);
692    
693                    // remember the engine's time when this note was triggered exactly
694                    itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime();
695    
696                  // usually the new note (and its subsequent voices) will be                  // usually the new note (and its subsequent voices) will be
697                  // allocated on the key provided by the event's note number,                  // allocated on the key provided by the event's note number,
698                  // however if this new note is requested not to be a regular                  // however if this new note is requested not to be a regular
# Line 795  namespace LinuxSampler { Line 799  namespace LinuxSampler {
799                              case Event::type_note_pressure:                              case Event::type_note_pressure:
800                                  //TODO: ...                                  //TODO: ...
801                                  break;                                  break;
802    
803                                case Event::type_sysex:
804                                    //TODO: ...
805                                    break;
806    
807                                case Event::type_cancel_release_key:
808                                case Event::type_release_key:
809                                case Event::type_release_note:
810                                case Event::type_play_note:
811                                case Event::type_stop_note:
812                                case Event::type_kill_note:
813                                case Event::type_note_synth_param:
814                                    break; // noop
815                          }                          }
816    
817                          // see HACK comment above                          // see HACK comment above
# Line 865  namespace LinuxSampler { Line 882  namespace LinuxSampler {
882                                  dmsg(5,("Engine: Stop Note received\n"));                                  dmsg(5,("Engine: Stop Note received\n"));
883                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
884                                  break;                                  break;
885                                case Event::type_kill_note:
886                                    dmsg(5,("Engine: Kill Note received\n"));
887                                    ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent);
888                                    break;
889                              case Event::type_control_change:                              case Event::type_control_change:
890                                  dmsg(5,("Engine: MIDI CC received\n"));                                  dmsg(5,("Engine: MIDI CC received\n"));
891                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);
# Line 885  namespace LinuxSampler { Line 906  namespace LinuxSampler {
906                                  dmsg(5,("Engine: Note Synth Param received\n"));                                  dmsg(5,("Engine: Note Synth Param received\n"));
907                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);                                  ProcessNoteSynthParam(itEvent->pEngineChannel, itEvent);
908                                  break;                                  break;
909                                case Event::type_sysex:
910                                    break; // TODO ...
911    
912                                case Event::type_cancel_release_key:
913                                case Event::type_release_key:
914                                case Event::type_release_note:
915                                    break; // noop
916                          }                          }
917                      }                      }
918                  }                  }
# Line 1256  namespace LinuxSampler { Line 1284  namespace LinuxSampler {
1284                          // the script's "init" event handler is only executed                          // the script's "init" event handler is only executed
1285                          // once (when the script is loaded or reloaded)                          // once (when the script is loaded or reloaded)
1286                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {                          if (pEngineChannel->pScript && pEngineChannel->pScript->handlerInit) {
1287                                dmsg(5,("Engine: exec handlerInit %p\n", pEngineChannel->pScript->handlerInit));
1288                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1289                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1290    
1291                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1292                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1293                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1294                                itScriptEvent->currentHandler = 0;
1295                                itScriptEvent->executionSlices = 0;
1296                                itScriptEvent->ignoreAllWaitCalls = false;
1297                                itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1298    
1299                              VMExecStatus_t res = pScriptVM->exec(                              /*VMExecStatus_t res = */ pScriptVM->exec(
1300                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                                  pEngineChannel->pScript->parserContext, &*itScriptEvent
1301                              );                              );
1302    
# Line 1603  namespace LinuxSampler { Line 1636  namespace LinuxSampler {
1636               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
1637               *  @param itNoteOnEvent - key, velocity and time stamp of the event               *  @param itNoteOnEvent - key, velocity and time stamp of the event
1638               */               */
1639              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) {              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
1640                  EngineChannelBase<V, R, I>* pChannel =                  EngineChannelBase<V, R, I>* pChannel =
1641                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                          static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1642    
# Line 1734  namespace LinuxSampler { Line 1767  namespace LinuxSampler {
1767               *  @param pEngineChannel - engine channel on which this event occurred on               *  @param pEngineChannel - engine channel on which this event occurred on
1768               *  @param itNoteOffEvent - key, velocity and time stamp of the event               *  @param itNoteOffEvent - key, velocity and time stamp of the event
1769               */               */
1770              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) {              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) OVERRIDE {
1771                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1772    
1773                  const int iKey = itNoteOffEvent->Param.Note.Key;                  const int iKey = itNoteOffEvent->Param.Note.Key;
# Line 1899  namespace LinuxSampler { Line 1932  namespace LinuxSampler {
1932              }              }
1933    
1934              /**              /**
1935                 * Called on "kill note" events, which currently only happens on
1936                 * built-in real-time instrument script function fade_out(). This
1937                 * method only fulfills one task: moving the even to the Note's own
1938                 * event list so that its voices can process the kill event sample
1939                 * accurately.
1940                 */
1941                void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
1942                    EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1943    
1944                    NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID );
1945                    if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
1946    
1947                    // move note kill event to its MIDI key
1948                    MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey];
1949                    itEvent.moveToEndOf(pKey->pEvents);
1950                }
1951    
1952                /**
1953               * Called on note synthesis parameter change events. These are               * Called on note synthesis parameter change events. These are
1954               * internal events caused by calling built-in real-time instrument               * internal events caused by calling built-in real-time instrument
1955               * script functions like change_vol(), change_pitch(), etc.               * script functions like change_vol(), change_tune(), etc.
1956               *               *
1957               * This method performs two tasks:               * This method performs two tasks:
1958               *               *
# Line 1932  namespace LinuxSampler { Line 1983  namespace LinuxSampler {
1983                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;
1984                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;
1985                          break;                          break;
1986                        case Event::synth_param_volume_time:
1987                            pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
1988                            break;
1989                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
1990                          if (relative)                          if (relative)
1991                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;
# Line 1939  namespace LinuxSampler { Line 1993  namespace LinuxSampler {
1993                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;
1994                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;
1995                          break;                          break;
1996                        case Event::synth_param_pitch_time:
1997                            pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
1998                            break;
1999                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2000                          if (relative) {                          if (relative) {
2001                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);                              pNote->Override.Pan = RTMath::RelativeSummedAvg(pNote->Override.Pan, itEvent->Param.NoteSynthParam.Delta, ++pNote->Override.PanSources);
# Line 1954  namespace LinuxSampler { Line 2011  namespace LinuxSampler {
2011                      case Event::synth_param_resonance:                      case Event::synth_param_resonance:
2012                          pNote->Override.Resonance = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;                          pNote->Override.Resonance = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2013                          break;                          break;
2014                        case Event::synth_param_attack:
2015                            pNote->Override.Attack = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2016                            break;
2017                        case Event::synth_param_decay:
2018                            pNote->Override.Decay = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2019                            break;
2020                        case Event::synth_param_release:
2021                            pNote->Override.Release = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2022                            break;
2023                        case Event::synth_param_amp_lfo_depth:
2024                            pNote->Override.AmpLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2025                            break;
2026                        case Event::synth_param_amp_lfo_freq:
2027                            pNote->Override.AmpLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2028                            break;
2029                        case Event::synth_param_pitch_lfo_depth:
2030                            pNote->Override.PitchLFODepth = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2031                            break;
2032                        case Event::synth_param_pitch_lfo_freq:
2033                            pNote->Override.PitchLFOFreq = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2034                            break;
2035                  }                  }
2036    
2037                  // move note parameter event to its MIDI key                  // move note parameter event to its MIDI key
# Line 1965  namespace LinuxSampler { Line 2043  namespace LinuxSampler {
2043               *  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
2044               *  control and status variables. This method is protected by a mutex.               *  control and status variables. This method is protected by a mutex.
2045               */               */
2046              virtual void ResetInternal() {              virtual void ResetInternal() OVERRIDE {
2047                  LockGuard lock(ResetInternalMutex);                  LockGuard lock(ResetInternalMutex);
2048    
2049                  // make sure that the engine does not get any sysex messages                  // make sure that the engine does not get any sysex messages
# Line 2024  namespace LinuxSampler { Line 2102  namespace LinuxSampler {
2102               * @param pEngineChannel - engine channel on which all voices should be killed               * @param pEngineChannel - engine channel on which all voices should be killed
2103               * @param itKillEvent    - event which caused this killing of all voices               * @param itKillEvent    - event which caused this killing of all voices
2104               */               */
2105              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) {              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) OVERRIDE {
2106                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
2107                  int count = pChannel->KillAllVoices(itKillEvent);                  int count = pChannel->KillAllVoices(itKillEvent);
2108                  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 2059  namespace LinuxSampler { Line 2137  namespace LinuxSampler {
2137                  bool                    HandleKeyGroupConflicts                  bool                    HandleKeyGroupConflicts
2138              ) = 0;              ) = 0;
2139    
2140              virtual int GetMinFadeOutSamples() { return MinFadeOutSamples; }              virtual int GetMinFadeOutSamples() OVERRIDE { return MinFadeOutSamples; }
2141    
2142              int InitNewVoice (              int InitNewVoice (
2143                  EngineChannelBase<V, R, I>*  pChannel,                  EngineChannelBase<V, R, I>*  pChannel,

Legend:
Removed from v.2952  
changed lines
  Added in v.3188

  ViewVC Help
Powered by ViewVC