/[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 3335 by schoenebeck, Sun Jul 30 14:33:15 2017 UTC
# Line 838  namespace LinuxSampler { Line 838  namespace LinuxSampler {
838    
839      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {
840          int attack = args->arg(1)->asInt()->evalInt();          int attack = args->arg(1)->asInt()->evalInt();
841          if (attack > VM_EG_PAR_MAX_VALUE) {          // note: intentionally not checking against a max. value here!
842              wrnMsg("change_attack(): argument 2 may not be larger than 1000000");          // (to allow i.e. passing 2000000 for doubling the attack time)
843              attack = VM_EG_PAR_MAX_VALUE;          if (attack < 0) {
         } else if (attack < 0) {  
844              wrnMsg("change_attack(): argument 2 may not be negative");              wrnMsg("change_attack(): argument 2 may not be negative");
845              attack = 0;              attack = 0;
846          }          }
# Line 925  namespace LinuxSampler { Line 924  namespace LinuxSampler {
924    
925      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {
926          int decay = args->arg(1)->asInt()->evalInt();          int decay = args->arg(1)->asInt()->evalInt();
927          if (decay > VM_EG_PAR_MAX_VALUE) {          // note: intentionally not checking against a max. value here!
928              wrnMsg("change_decay(): argument 2 may not be larger than 1000000");          // (to allow i.e. passing 2000000 for doubling the decay time)
929              decay = VM_EG_PAR_MAX_VALUE;          if (decay < 0) {
         } else if (decay < 0) {  
930              wrnMsg("change_decay(): argument 2 may not be negative");              wrnMsg("change_decay(): argument 2 may not be negative");
931              decay = 0;              decay = 0;
932          }          }
# Line 1012  namespace LinuxSampler { Line 1010  namespace LinuxSampler {
1010    
1011      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {
1012          int release = args->arg(1)->asInt()->evalInt();          int release = args->arg(1)->asInt()->evalInt();
1013          if (release > VM_EG_PAR_MAX_VALUE) {          // note: intentionally not checking against a max. value here!
1014              wrnMsg("change_release(): argument 2 may not be larger than 1000000");          // (to allow i.e. passing 2000000 for doubling the release time)
1015              release = VM_EG_PAR_MAX_VALUE;          if (release < 0) {
         } else if (release < 0) {  
1016              wrnMsg("change_release(): argument 2 may not be negative");              wrnMsg("change_release(): argument 2 may not be negative");
1017              release = 0;              release = 0;
1018          }          }
# Line 1177  namespace LinuxSampler { Line 1174  namespace LinuxSampler {
1174          return successResult();          return successResult();
1175      }      }
1176    
1177        // change_sustain() function
1178    
1179        VMFnResult* InstrumentScriptVMFunction_change_sustain::exec(VMFnArgs* args) {
1180            return VMChangeSynthParamFunction::execTemplate<
1181            &NoteBase::_Override::Sustain,
1182            Event::synth_param_sustain,
1183            true, NO_LIMIT, 0>( args, "change_sustain" );
1184        }
1185    
1186      // change_amp_lfo_depth() function      // change_amp_lfo_depth() function
1187    
1188      VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) {
# Line 1231  namespace LinuxSampler { Line 1237  namespace LinuxSampler {
1237                      false, NO_LIMIT, 0>( args, "change_tune_time" );                      false, NO_LIMIT, 0>( args, "change_tune_time" );
1238      }      }
1239    
1240        // change_pan_time() function
1241    
1242        VMFnResult* InstrumentScriptVMFunction_change_pan_time::exec(VMFnArgs* args) {
1243            return VMChangeSynthParamFunction::execTemplate<
1244            &NoteBase::_Override::PanTime,
1245            Event::synth_param_pan_time,
1246            false, NO_LIMIT, 0>( args, "change_pan_time" );
1247        }
1248    
1249      // template for change_*_curve() functions      // template for change_*_curve() functions
1250    
1251      bool VMChangeFadeCurveFunction::acceptsArgType(int iArg, ExprType_t type) const {      bool VMChangeFadeCurveFunction::acceptsArgType(int iArg, ExprType_t type) const {
# Line 1332  namespace LinuxSampler { Line 1347  namespace LinuxSampler {
1347                      Event::synth_param_pitch_curve>( args, "change_tune_curve" );                      Event::synth_param_pitch_curve>( args, "change_tune_curve" );
1348      }      }
1349    
1350        // change_pan_curve() function
1351    
1352        VMFnResult* InstrumentScriptVMFunction_change_pan_curve::exec(VMFnArgs* args) {
1353            return VMChangeFadeCurveFunction::execTemplate<
1354            &NoteBase::_Override::PanCurve,
1355            Event::synth_param_pan_curve>( args, "change_pan_curve" );
1356        }
1357    
1358      // fade_in() function      // fade_in() function
1359    
1360      InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent)
# Line 1805  namespace LinuxSampler { Line 1828  namespace LinuxSampler {
1828          return successResult();          return successResult();
1829      }      }
1830    
1831        // change_play_pos() function
1832    
1833        InstrumentScriptVMFunction_change_play_pos::InstrumentScriptVMFunction_change_play_pos(InstrumentScriptVM* parent)
1834        : m_vm(parent)
1835        {
1836        }
1837    
1838        VMFnResult* InstrumentScriptVMFunction_change_play_pos::exec(VMFnArgs* args) {
1839            const ScriptID id = args->arg(0)->asInt()->evalInt();
1840            if (!id) {
1841                wrnMsg("change_play_pos(): note ID for argument 1 may not be zero");
1842                return successResult();
1843            }
1844            if (!id.isNoteID()) {
1845                wrnMsg("change_play_pos(): argument 1 is not a note ID");
1846                return successResult();
1847            }
1848    
1849            const int pos = args->arg(1)->asInt()->evalInt();
1850            if (pos < 0) {
1851                wrnMsg("change_play_pos(): playback position of argument 2 may not be negative");
1852                return successResult();
1853            }
1854    
1855            AbstractEngineChannel* pEngineChannel =
1856                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1857    
1858            NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1859            if (!pNote) return successResult();
1860    
1861            pNote->Override.SampleOffset = pos;
1862    
1863            return successResult();
1864        }
1865    
1866      // event_status() function      // event_status() function
1867    
1868      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)
# Line 1830  namespace LinuxSampler { Line 1888  namespace LinuxSampler {
1888          return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE);          return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE);
1889      }      }
1890    
1891        // callback_status() function
1892    
1893        InstrumentScriptVMFunction_callback_status::InstrumentScriptVMFunction_callback_status(InstrumentScriptVM* parent)
1894            : m_vm(parent)
1895        {
1896        }
1897    
1898        VMFnResult* InstrumentScriptVMFunction_callback_status::exec(VMFnArgs* args) {
1899            const script_callback_id_t id = args->arg(0)->asInt()->evalInt();
1900            if (!id) {
1901                wrnMsg("callback_status(): callback ID for argument 1 may not be zero");
1902                return successResult();
1903            }
1904    
1905            AbstractEngineChannel* pEngineChannel =
1906                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1907    
1908            RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id);
1909            if (!itCallback)
1910                return successResult(CALLBACK_STATUS_TERMINATED);
1911    
1912            return successResult(
1913                (m_vm->m_event->execCtx == itCallback->execCtx) ?
1914                    CALLBACK_STATUS_RUNNING : CALLBACK_STATUS_QUEUE
1915            );
1916        }
1917    
1918      // wait() function (overrides core wait() implementation)      // wait() function (overrides core wait() implementation)
1919    
1920      InstrumentScriptVMFunction_wait::InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_wait::InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent)
# Line 1876  namespace LinuxSampler { Line 1961  namespace LinuxSampler {
1961          return successResult();          return successResult();
1962      }      }
1963    
1964        // abort() function
1965    
1966        InstrumentScriptVMFunction_abort::InstrumentScriptVMFunction_abort(InstrumentScriptVM* parent)
1967            : m_vm(parent)
1968        {
1969        }
1970    
1971        VMFnResult* InstrumentScriptVMFunction_abort::exec(VMFnArgs* args) {
1972            const script_callback_id_t id = args->arg(0)->asInt()->evalInt();
1973            if (!id) {
1974                wrnMsg("abort(): callback ID for argument 1 may not be zero");
1975                return successResult();
1976            }
1977    
1978            AbstractEngineChannel* pEngineChannel =
1979                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1980    
1981            RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id);
1982            if (!itCallback) return successResult(); // ignore if callback is i.e. not alive anymore
1983    
1984            itCallback->execCtx->signalAbort();
1985    
1986            return successResult();
1987        }
1988    
1989        // fork() function
1990    
1991        InstrumentScriptVMFunction_fork::InstrumentScriptVMFunction_fork(InstrumentScriptVM* parent)
1992            : m_vm(parent)
1993        {
1994        }
1995    
1996        VMFnResult* InstrumentScriptVMFunction_fork::exec(VMFnArgs* args) {
1997            // check if this is actually the parent going to fork, or rather one of
1998            // the children which is already forked
1999            if (m_vm->m_event->forkIndex != 0) { // this is the entry point for a child ...
2000                int forkResult = m_vm->m_event->forkIndex;
2001                // reset so that this child may i.e. also call fork() later on
2002                m_vm->m_event->forkIndex = 0;
2003                return successResult(forkResult);
2004            }
2005    
2006            // if we are here, then this is the parent, so we must fork this parent
2007    
2008            const int n =
2009                (args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1;
2010            const bool bAutoAbort =
2011                (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true;
2012    
2013            if (m_vm->m_event->countChildHandlers() + n > MAX_FORK_PER_SCRIPT_HANDLER) {
2014                wrnMsg("fork(): requested amount would exceed allowed limit per event handler");
2015                return successResult(-1);
2016            }
2017    
2018            AbstractEngineChannel* pEngineChannel =
2019                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
2020    
2021            if (!pEngineChannel->hasFreeScriptCallbacks(n)) {
2022                wrnMsg("fork(): global limit of event handlers exceeded");
2023                return successResult(-1);
2024            }
2025    
2026            for (int iChild = 0; iChild < n; ++iChild) {
2027                RTList<ScriptEvent>::Iterator itChild =
2028                    pEngineChannel->forkScriptCallback(m_vm->m_event, bAutoAbort);
2029                if (!itChild) { // should never happen, otherwise its a bug ...
2030                    errMsg("fork(): internal error while allocating child");
2031                    return errorResult(-1); // terminate script
2032                }
2033                // since both parent, as well all child script execution instances
2034                // all land in this exect() method, the following is (more or less)
2035                // the only feature that lets us distinguish the parent and
2036                // respective children from each other in this exect() method
2037                itChild->forkIndex = iChild + 1;
2038            }
2039    
2040            return successResult(0);
2041        }
2042    
2043  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC