/[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 2618 by schoenebeck, Wed Jun 11 11:39:44 2014 UTC revision 2645 by schoenebeck, Wed Jun 18 00:14:57 2014 UTC
# Line 723  namespace LinuxSampler { Line 723  namespace LinuxSampler {
723               * @param pEventHandler - script's event handler to be executed               * @param pEventHandler - script's event handler to be executed
724               */               */
725              void ProcessEventByScript(AbstractEngineChannel* pChannel, RTList<Event>::Iterator& itEvent, VMEventHandler* pEventHandler) {              void ProcessEventByScript(AbstractEngineChannel* pChannel, RTList<Event>::Iterator& itEvent, VMEventHandler* pEventHandler) {
726                  RTList<ScriptEvent>::Iterator itScriptEvent =                  const int key = itEvent->Param.Note.Key; // even if this is not a note on/off event, accessing it does not mean any harm
727                      pChannel->pScript->pEvents->allocAppend();                  // check if polyphonic data is passed from "note" to "release"
728                    // script event handlers
729                    if (pEventHandler == pChannel->pScript->handlerRelease &&
730                        pChannel->pScript->handlerNote &&
731                        pChannel->pScript->handlerNote->isPolyphonic() &&
732                        pChannel->pScript->handlerRelease->isPolyphonic() &&
733                        !pChannel->pScript->pKeyEvents[key]->isEmpty())
734                    {
735                        // polyphonic variable data is used/passed from "note" to
736                        // "release" script callback, so we have to recycle the
737                        // original "note on" script event(s)
738                        RTList<ScriptEvent>::Iterator it  = pChannel->pScript->pKeyEvents[key]->first();
739                        RTList<ScriptEvent>::Iterator end = pChannel->pScript->pKeyEvents[key]->end();
740                        for (; it != end; ++it) {
741                            ProcessScriptEvent(
742                                pChannel, itEvent, pEventHandler, it
743                            );
744                        }
745                    } else {
746                        // no polyphonic data is used/passed from "note" to
747                        // "release" script callback, so just use a new fresh
748                        // script event object
749                        RTList<ScriptEvent>::Iterator itScriptEvent =
750                            pChannel->pScript->pEvents->allocAppend();
751                        ProcessScriptEvent(
752                            pChannel, itEvent, pEventHandler, itScriptEvent
753                        );
754                    }
755                }
756    
757                  if (!itScriptEvent) return; // no free script event left for execution              void ProcessScriptEvent(AbstractEngineChannel* pChannel, RTList<Event>::Iterator& itEvent, VMEventHandler* pEventHandler, RTList<ScriptEvent>::Iterator& itScriptEvent) {
758                    if (!itScriptEvent) return; // not a valid script event (i.e. because no free script event was left in the script event pool)
759    
760                  // fill the list of script handlers to be executed by this event                  // fill the list of script handlers to be executed by this event
761                  int i = 0;                  int i = 0;
# Line 745  namespace LinuxSampler { Line 774  namespace LinuxSampler {
774                  );                  );
775    
776                  // in case the script was suspended, keep it on the allocated                  // in case the script was suspended, keep it on the allocated
777                  // ScriptEvent list to be continued on the next audio cycle,                  // ScriptEvent list to be continued on the next audio cycle
778                  // otherwise if execution has been finished, free it for a new                  if (!(res & VM_EXEC_SUSPENDED)) { // script execution has finished without 'suspended' status ...
779                  // future script event to be triggered from start                      // if "polyphonic" variable data is passed from script's
780                  if (!(res & VM_EXEC_SUSPENDED))                      // "note" event handler to its "release" event handler, then
781                      pChannel->pScript->pEvents->free(itScriptEvent);                      // the script event must be kept and recycled for the later
782                        // occuring "release" script event ...
783                        if (pEventHandler == pChannel->pScript->handlerNote &&
784                            pChannel->pScript->handlerRelease &&
785                            pChannel->pScript->handlerNote->isPolyphonic() &&
786                            pChannel->pScript->handlerRelease->isPolyphonic())
787                        {
788                            const int key = itEvent->Param.Note.Key;
789                            itScriptEvent.moveToEndOf(pChannel->pScript->pKeyEvents[key & 127]);
790                        } else {
791                            // ... otherwise if no polyphonic data is passed and
792                            // script's execution has finished without suspension
793                            // status, then free the script event for a new future
794                            // script event to be triggered from start
795                            pChannel->pScript->pEvents->free(itScriptEvent);
796                        }
797                    }
798              }              }
799    
800              /** @brief Resume execution of instrument script.              /** @brief Resume execution of instrument script.
# Line 770  namespace LinuxSampler { Line 815  namespace LinuxSampler {
815               * @param itScriptEvent - script execution that shall be resumed               * @param itScriptEvent - script execution that shall be resumed
816               */               */
817              void ResumeScriptEvent(AbstractEngineChannel* pChannel, RTList<ScriptEvent>::Iterator& itScriptEvent) {              void ResumeScriptEvent(AbstractEngineChannel* pChannel, RTList<ScriptEvent>::Iterator& itScriptEvent) {
818                    VMEventHandler* handler = itScriptEvent->handlers[itScriptEvent->currentHandler];
819    
820                  // run script                  // run script
821                  VMExecStatus_t res = pScriptVM->exec(                  VMExecStatus_t res = pScriptVM->exec(
822                      pChannel->pScript->parserContext, &*itScriptEvent                      pChannel->pScript->parserContext, &*itScriptEvent
823                  );                  );
824                  // in case the script was again suspended, keep it on the allocated  
825                  // ScriptEvent list to be continued on the next audio cycle,                  // in case the script was suspended, keep it on the allocated
826                  // otherwise if execution has been finished, free it for a new                  // ScriptEvent list to be continued on the next audio cycle
827                  // future script event to be triggered from start                  if (!(res & VM_EXEC_SUSPENDED)) { // script execution has finished without 'suspended' status ...
828                  if (!(res & VM_EXEC_SUSPENDED))                      // if "polyphonic" variable data is passed from script's
829                      pChannel->pScript->pEvents->free(itScriptEvent);                      // "note" event handler to its "release" event handler, then
830                        // the script event must be kept and recycled for the later
831                        // occuring "release" script event ...
832                        if (handler && handler == pChannel->pScript->handlerNote &&
833                            pChannel->pScript->handlerRelease &&
834                            pChannel->pScript->handlerNote->isPolyphonic() &&
835                            pChannel->pScript->handlerRelease->isPolyphonic())
836                        {
837                            const int key = itScriptEvent->cause.Param.Note.Key;
838                            itScriptEvent.moveToEndOf(pChannel->pScript->pKeyEvents[key & 127]);
839                        } else {
840                            // ... otherwise if no polyphonic data is passed and
841                            // script's execution has finished without suspension
842                            // status, then free the script event for a new future
843                            // script event to be triggered from start
844                            pChannel->pScript->pEvents->free(itScriptEvent);
845                        }
846                    }
847              }              }
848    
849              /**              /**

Legend:
Removed from v.2618  
changed lines
  Added in v.2645

  ViewVC Help
Powered by ViewVC