/[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 3118 by schoenebeck, Fri Apr 21 13:33:03 2017 UTC revision 3293 by schoenebeck, Tue Jun 27 22:19:19 2017 UTC
# Line 379  namespace LinuxSampler { Line 379  namespace LinuxSampler {
379                  }                  }
380                  pVoicePool->clear();                  pVoicePool->clear();
381    
382                  // (re)create event generator                  // update event generator
383                  if (pEventGenerator) delete pEventGenerator;                  pEventGenerator->SetSampleRate(pAudioOut->SampleRate());
                 pEventGenerator = new EventGenerator(pAudioOut->SampleRate());  
384    
385                  dmsg(1,("Starting disk thread..."));                  dmsg(1,("Starting disk thread..."));
386                  pDiskThread->StartThread();                  pDiskThread->StartThread();
# Line 676  namespace LinuxSampler { Line 675  namespace LinuxSampler {
675               * @param pNoteOnEvent - event which caused this               * @param pNoteOnEvent - event which caused this
676               * @returns new note's unique ID (or zero on error)               * @returns new note's unique ID (or zero on error)
677               */               */
678              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Event* pNoteOnEvent) OVERRIDE {              note_id_t LaunchNewNote(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) OVERRIDE {
679                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);                  EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
680                  Pool< Note<V> >* pNotePool = GetNotePool();                  Pool< Note<V> >* pNotePool = GetNotePool();
681    
# Line 691  namespace LinuxSampler { Line 690  namespace LinuxSampler {
690                  const note_id_t newNoteID = pNotePool->getID(itNewNote);                  const note_id_t newNoteID = pNotePool->getID(itNewNote);
691    
692                  // remember the engine's time when this note was triggered exactly                  // remember the engine's time when this note was triggered exactly
693                  itNewNote->triggerSchedTime = pNoteOnEvent->SchedTime();                  itNewNote->triggerSchedTime = itNoteOnEvent->SchedTime();
694    
695                  // usually the new note (and its subsequent voices) will be                  // usually the new note (and its subsequent voices) will be
696                  // 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 698  namespace LinuxSampler {
698                  // note, but rather a child note, then this new note will be                  // note, but rather a child note, then this new note will be
699                  // allocated on the parent note's key instead in order to                  // allocated on the parent note's key instead in order to
700                  // release the child note simultaniously with its parent note                  // release the child note simultaniously with its parent note
701                  itNewNote->hostKey = pNoteOnEvent->Param.Note.Key;                  itNewNote->hostKey = itNoteOnEvent->Param.Note.Key;
702    
703                  // in case this new note was requested to be a child note,                  // in case this new note was requested to be a child note,
704                  // then retrieve its parent note and link them with each other                  // then retrieve its parent note and link them with each other
705                  const note_id_t parentNoteID = pNoteOnEvent->Param.Note.ParentNoteID;                  const note_id_t parentNoteID = itNoteOnEvent->Param.Note.ParentNoteID;
706                  if (parentNoteID) {                  if (parentNoteID) {
707                      NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                                              NoteIterator itParentNote = pNotePool->fromID(parentNoteID);                        
708                      if (itParentNote) {                      if (itParentNote) {
# Line 731  namespace LinuxSampler { Line 730  namespace LinuxSampler {
730                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));                  dmsg(2,("Launched new note on host key %d\n", itNewNote->hostKey));
731    
732                  // copy event which caused this note                  // copy event which caused this note
733                  itNewNote->cause = *pNoteOnEvent;                  itNewNote->cause = *itNoteOnEvent;
734                  itNewNote->eventID = pEventPool->getID(pNoteOnEvent);                  itNewNote->eventID = pEventPool->getID(itNoteOnEvent);
735                    if (!itNewNote->eventID) {
736                        dmsg(0,("Engine: No valid event ID resolved for note. This is a bug!!!\n"));
737                    }
738    
739                  // move new note to its host key                  // move new note to its host key
740                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];                  MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNewNote->hostKey];
741                  itNewNote.moveToEndOf(pKey->pActiveNotes);                  itNewNote.moveToEndOf(pKey->pActiveNotes);
742    
743                  // 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
744                  pNoteOnEvent->Param.Note.ID = newNoteID;                  itNoteOnEvent->Param.Note.ID = newNoteID;
745    
746                  return newNoteID; // success                  return newNoteID; // success
747              }              }
# Line 809  namespace LinuxSampler { Line 811  namespace LinuxSampler {
811                              case Event::type_release_note:                              case Event::type_release_note:
812                              case Event::type_play_note:                              case Event::type_play_note:
813                              case Event::type_stop_note:                              case Event::type_stop_note:
814                                case Event::type_kill_note:
815                              case Event::type_note_synth_param:                              case Event::type_note_synth_param:
816                                  break; // noop                                  break; // noop
817                          }                          }
# Line 881  namespace LinuxSampler { Line 884  namespace LinuxSampler {
884                                  dmsg(5,("Engine: Stop Note received\n"));                                  dmsg(5,("Engine: Stop Note received\n"));
885                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessNoteOff((EngineChannel*)itEvent->pEngineChannel, itEvent);
886                                  break;                                  break;
887                                case Event::type_kill_note:
888                                    dmsg(5,("Engine: Kill Note received\n"));
889                                    ProcessKillNote((EngineChannel*)itEvent->pEngineChannel, itEvent);
890                                    break;
891                              case Event::type_control_change:                              case Event::type_control_change:
892                                  dmsg(5,("Engine: MIDI CC received\n"));                                  dmsg(5,("Engine: MIDI CC received\n"));
893                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);                                  ProcessControlChange((EngineChannel*)itEvent->pEngineChannel, itEvent);
# Line 976  namespace LinuxSampler { Line 983  namespace LinuxSampler {
983                      // script event object                      // script event object
984                      RTList<ScriptEvent>::Iterator itScriptEvent =                      RTList<ScriptEvent>::Iterator itScriptEvent =
985                          pChannel->pScript->pEvents->allocAppend();                          pChannel->pScript->pEvents->allocAppend();
986                        // if event handler uses polyphonic variables, reset them
987                        // to zero values before starting to execute the handler
988                        if (pEventHandler->isPolyphonic())
989                            itScriptEvent->execCtx->resetPolyphonicData();
990                      ProcessScriptEvent(                      ProcessScriptEvent(
991                          pChannel, itEvent, pEventHandler, itScriptEvent                          pChannel, itEvent, pEventHandler, itScriptEvent
992                      );                      );
# Line 1008  namespace LinuxSampler { Line 1019  namespace LinuxSampler {
1019    
1020                  // initialize/reset other members                  // initialize/reset other members
1021                  itScriptEvent->cause = *itEvent;                  itScriptEvent->cause = *itEvent;
1022                    itScriptEvent->scheduleTime = itEvent->SchedTime();
1023                  itScriptEvent->currentHandler = 0;                  itScriptEvent->currentHandler = 0;
1024                  itScriptEvent->executionSlices = 0;                  itScriptEvent->executionSlices = 0;
1025                  itScriptEvent->ignoreAllWaitCalls = false;                  itScriptEvent->ignoreAllWaitCalls = false;
1026                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();                  itScriptEvent->handlerType = pEventHandler->eventHandlerType();
1027                    itScriptEvent->parentHandlerID = 0;
1028                    itScriptEvent->childHandlerID[0] = 0;
1029                    itScriptEvent->autoAbortByParent = false;
1030                    itScriptEvent->forkIndex = 0;
1031                  // this is the native representation of the $EVENT_ID script variable                  // this is the native representation of the $EVENT_ID script variable
1032                  itScriptEvent->id =                  itScriptEvent->id =
1033                      (itEvent->Type == Event::type_note_on)                      (itEvent->Type == Event::type_note_on)
# Line 1283  namespace LinuxSampler { Line 1299  namespace LinuxSampler {
1299                              RTList<ScriptEvent>::Iterator itScriptEvent =                              RTList<ScriptEvent>::Iterator itScriptEvent =
1300                                  pEngineChannel->pScript->pEvents->allocAppend();                                  pEngineChannel->pScript->pEvents->allocAppend();
1301    
1302                                itScriptEvent->cause = pEventGenerator->CreateEvent(0);
1303                                itScriptEvent->cause.Type = (Event::type_t) -1; // some invalid type to avoid random event processing
1304                              itScriptEvent->cause.pEngineChannel = pEngineChannel;                              itScriptEvent->cause.pEngineChannel = pEngineChannel;
1305                                itScriptEvent->cause.pMidiInputPort = pEngineChannel->GetMidiInputPort();
1306                                itScriptEvent->id = 0;
1307                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;                              itScriptEvent->handlers[0] = pEngineChannel->pScript->handlerInit;
1308                              itScriptEvent->handlers[1] = NULL;                              itScriptEvent->handlers[1] = NULL;
1309                              itScriptEvent->currentHandler = 0;                              itScriptEvent->currentHandler = 0;
1310                              itScriptEvent->executionSlices = 0;                              itScriptEvent->executionSlices = 0;
1311                              itScriptEvent->ignoreAllWaitCalls = false;                              itScriptEvent->ignoreAllWaitCalls = false;
1312                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;                              itScriptEvent->handlerType = VM_EVENT_HANDLER_INIT;
1313                                itScriptEvent->parentHandlerID = 0;
1314                              /*VMExecStatus_t res = */ pScriptVM->exec(                              itScriptEvent->childHandlerID[0] = 0;
1315                                  pEngineChannel->pScript->parserContext, &*itScriptEvent                              itScriptEvent->autoAbortByParent = false;
1316                              );                              itScriptEvent->forkIndex = 0;
1317    
1318                                VMExecStatus_t res;
1319                                size_t instructionsCount = 0;
1320                                const size_t maxInstructions = 200000; // aiming approx. 1 second max. (based on very roughly 5us / instruction)
1321                                bool bWarningShown = false;
1322                                do {
1323                                    res = pScriptVM->exec(
1324                                        pEngineChannel->pScript->parserContext, &*itScriptEvent
1325                                    );
1326                                    instructionsCount += itScriptEvent->execCtx->instructionsPerformed();
1327                                    if (instructionsCount > maxInstructions && !bWarningShown) {
1328                                        bWarningShown = true;
1329                                        dmsg(0,("[ScriptVM] WARNING: \"init\" event handler of instrument script executing for long time!\n"));
1330                                    }
1331                                } while (res & VM_EXEC_SUSPENDED && !(res & VM_EXEC_ERROR));
1332    
1333                              pEngineChannel->pScript->pEvents->free(itScriptEvent);                              pEngineChannel->pScript->pEvents->free(itScriptEvent);
1334                          }                          }
# Line 1354  namespace LinuxSampler { Line 1389  namespace LinuxSampler {
1389                          // usually there should already be a new Note object                          // usually there should already be a new Note object
1390                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);                          NoteIterator itNote = GetNotePool()->fromID(itVoiceStealEvent->Param.Note.ID);
1391                          if (!itNote) { // should not happen, but just to be sure ...                          if (!itNote) { // should not happen, but just to be sure ...
1392                              const note_id_t noteID = LaunchNewNote(pEngineChannel, &*itVoiceStealEvent);                              const note_id_t noteID = LaunchNewNote(pEngineChannel, itVoiceStealEvent);
1393                              if (!noteID) {                              if (!noteID) {
1394                                  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"));
1395                                  continue;                                  continue;
# Line 1831  namespace LinuxSampler { Line 1866  namespace LinuxSampler {
1866                                          itPseudoNoteOnEvent->Param.Note.Key      = i;                                          itPseudoNoteOnEvent->Param.Note.Key      = i;
1867                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;                                          itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
1868                                          // assign a new note to this note-on event                                          // assign a new note to this note-on event
1869                                          if (LaunchNewNote(pChannel, &*itPseudoNoteOnEvent)) {                                          if (LaunchNewNote(pChannel, itPseudoNoteOnEvent)) {
1870                                              // allocate and trigger new voice(s) for the other key                                              // allocate and trigger new voice(s) for the other key
1871                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);                                              TriggerNewVoices(pChannel, itPseudoNoteOnEvent, false);
1872                                          }                                          }
# Line 1918  namespace LinuxSampler { Line 1953  namespace LinuxSampler {
1953                  // spawn release triggered voice(s) if needed                  // spawn release triggered voice(s) if needed
1954                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {                  if (pKey->ReleaseTrigger && pChannel->pInstrument) {
1955                      // assign a new note to this release event                      // assign a new note to this release event
1956                      if (LaunchNewNote(pChannel, &*itEvent)) {                      if (LaunchNewNote(pChannel, itEvent)) {
1957                          // allocate and trigger new release voice(s)                          // allocate and trigger new release voice(s)
1958                          TriggerReleaseVoices(pChannel, itEvent);                          TriggerReleaseVoices(pChannel, itEvent);
1959                      }                      }
# Line 1927  namespace LinuxSampler { Line 1962  namespace LinuxSampler {
1962              }              }
1963    
1964              /**              /**
1965                 * Called on "kill note" events, which currently only happens on
1966                 * built-in real-time instrument script function fade_out(). This
1967                 * method only fulfills one task: moving the even to the Note's own
1968                 * event list so that its voices can process the kill event sample
1969                 * accurately.
1970                 */
1971                void ProcessKillNote(EngineChannel* pEngineChannel, RTList<Event>::Iterator& itEvent) {
1972                    EngineChannelBase<V, R, I>* pChannel = static_cast<EngineChannelBase<V, R, I>*>(pEngineChannel);
1973    
1974                    NoteBase* pNote = pChannel->pEngine->NoteByID( itEvent->Param.Note.ID );
1975                    if (!pNote || pNote->hostKey < 0 || pNote->hostKey >= 128) return;
1976    
1977                    // move note kill event to its MIDI key
1978                    MidiKey* pKey = &pChannel->pMIDIKeyInfo[pNote->hostKey];
1979                    itEvent.moveToEndOf(pKey->pEvents);
1980                }
1981    
1982                /**
1983               * Called on note synthesis parameter change events. These are               * Called on note synthesis parameter change events. These are
1984               * internal events caused by calling built-in real-time instrument               * internal events caused by calling built-in real-time instrument
1985               * script functions like change_vol(), change_pitch(), etc.               * script functions like change_vol(), change_tune(), etc.
1986               *               *
1987               * This method performs two tasks:               * This method performs two tasks:
1988               *               *
# Line 1960  namespace LinuxSampler { Line 2013  namespace LinuxSampler {
2013                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Volume = itEvent->Param.NoteSynthParam.Delta;
2014                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Volume;
2015                          break;                          break;
2016                        case Event::synth_param_volume_time:
2017                            pNote->Override.VolumeTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2018                            break;
2019                        case Event::synth_param_volume_curve:
2020                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2021                            pNote->Override.VolumeCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2022                            break;
2023                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
2024                          if (relative)                          if (relative)
2025                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Pitch *= itEvent->Param.NoteSynthParam.Delta;
# Line 1967  namespace LinuxSampler { Line 2027  namespace LinuxSampler {
2027                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;                              pNote->Override.Pitch = itEvent->Param.NoteSynthParam.Delta;
2028                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;                          itEvent->Param.NoteSynthParam.AbsValue = pNote->Override.Pitch;
2029                          break;                          break;
2030                        case Event::synth_param_pitch_time:
2031                            pNote->Override.PitchTime = itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2032                            break;
2033                        case Event::synth_param_pitch_curve:
2034                            itEvent->Param.NoteSynthParam.AbsValue = itEvent->Param.NoteSynthParam.Delta;
2035                            pNote->Override.PitchCurve = (fade_curve_t) itEvent->Param.NoteSynthParam.AbsValue;
2036                            break;
2037                      case Event::synth_param_pan:                      case Event::synth_param_pan:
2038                          if (relative) {                          if (relative) {
2039                              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);

Legend:
Removed from v.3118  
changed lines
  Added in v.3293

  ViewVC Help
Powered by ViewVC