/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3253 by schoenebeck, Tue May 30 12:08:45 2017 UTC revision 3293 by schoenebeck, Tue Jun 27 22:19:19 2017 UTC
# Line 1805  namespace LinuxSampler { Line 1805  namespace LinuxSampler {
1805          return successResult();          return successResult();
1806      }      }
1807    
1808        // change_play_pos() function
1809    
1810        InstrumentScriptVMFunction_change_play_pos::InstrumentScriptVMFunction_change_play_pos(InstrumentScriptVM* parent)
1811        : m_vm(parent)
1812        {
1813        }
1814    
1815        VMFnResult* InstrumentScriptVMFunction_change_play_pos::exec(VMFnArgs* args) {
1816            const ScriptID id = args->arg(0)->asInt()->evalInt();
1817            if (!id) {
1818                wrnMsg("change_play_pos(): note ID for argument 1 may not be zero");
1819                return successResult();
1820            }
1821            if (!id.isNoteID()) {
1822                wrnMsg("change_play_pos(): argument 1 is not a note ID");
1823                return successResult();
1824            }
1825    
1826            const int pos = args->arg(1)->asInt()->evalInt();
1827            if (pos < 0) {
1828                wrnMsg("change_play_pos(): playback position of argument 2 may not be negative");
1829                return successResult();
1830            }
1831    
1832            AbstractEngineChannel* pEngineChannel =
1833                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1834    
1835            NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1836            if (!pNote) return successResult();
1837    
1838            pNote->Override.SampleOffset = pos;
1839    
1840            return successResult();
1841        }
1842    
1843      // event_status() function      // event_status() function
1844    
1845      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)
# Line 1876  namespace LinuxSampler { Line 1911  namespace LinuxSampler {
1911          return successResult();          return successResult();
1912      }      }
1913    
1914        // abort() function
1915    
1916        InstrumentScriptVMFunction_abort::InstrumentScriptVMFunction_abort(InstrumentScriptVM* parent)
1917            : m_vm(parent)
1918        {
1919        }
1920    
1921        VMFnResult* InstrumentScriptVMFunction_abort::exec(VMFnArgs* args) {
1922            const script_callback_id_t id = args->arg(0)->asInt()->evalInt();
1923            if (!id) {
1924                wrnMsg("abort(): callback ID for argument 1 may not be zero");
1925                return successResult();
1926            }
1927    
1928            AbstractEngineChannel* pEngineChannel =
1929                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1930    
1931            RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id);
1932            if (!itCallback) return successResult(); // ignore if callback is i.e. not alive anymore
1933    
1934            itCallback->execCtx->signalAbort();
1935    
1936            return successResult();
1937        }
1938    
1939        // fork() function
1940    
1941        InstrumentScriptVMFunction_fork::InstrumentScriptVMFunction_fork(InstrumentScriptVM* parent)
1942            : m_vm(parent)
1943        {
1944        }
1945    
1946        VMFnResult* InstrumentScriptVMFunction_fork::exec(VMFnArgs* args) {
1947            // check if this is actually the parent going to fork, or rather one of
1948            // the children which is already forked
1949            if (m_vm->m_event->forkIndex != 0) { // this is the entry point for a child ...
1950                int forkResult = m_vm->m_event->forkIndex;
1951                // reset so that this child may i.e. also call fork() later on
1952                m_vm->m_event->forkIndex = 0;
1953                return successResult(forkResult);
1954            }
1955    
1956            // if we are here, then this is the parent, so we must fork this parent
1957    
1958            const int n =
1959                (args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1;
1960            const bool bAutoAbort =
1961                (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true;
1962    
1963            if (m_vm->m_event->countChildHandlers() + n > MAX_FORK_PER_SCRIPT_HANDLER) {
1964                wrnMsg("fork(): requested amount would exceed allowed limit per event handler");
1965                return successResult(-1);
1966            }
1967    
1968            AbstractEngineChannel* pEngineChannel =
1969                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1970    
1971            if (!pEngineChannel->hasFreeScriptCallbacks(n)) {
1972                wrnMsg("fork(): global limit of event handlers exceeded");
1973                return successResult(-1);
1974            }
1975    
1976            for (int iChild = 0; iChild < n; ++iChild) {
1977                RTList<ScriptEvent>::Iterator itChild =
1978                    pEngineChannel->forkScriptCallback(m_vm->m_event, bAutoAbort);
1979                if (!itChild) { // should never happen, otherwise its a bug ...
1980                    errMsg("fork(): internal error while allocating child");
1981                    return errorResult(-1); // terminate script
1982                }
1983                // since both parent, as well all child script execution instances
1984                // all land in this exect() method, the following is (more or less)
1985                // the only feature that lets us distinguish the parent and
1986                // respective children from each other in this exect() method
1987                itChild->forkIndex = iChild + 1;
1988            }
1989    
1990            return successResult(0);
1991        }
1992    
1993  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC