1 |
/* |
/* |
2 |
* Copyright (c) 2014-2016 Christian Schoenebeck |
* Copyright (c) 2014-2019 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
20 |
|
|
21 |
class ParserContext; |
class ParserContext; |
22 |
class ExecContext; |
class ExecContext; |
|
class CoreVMFunction_message; |
|
|
class CoreVMFunction_exit; |
|
|
class CoreVMFunction_wait; |
|
|
class CoreVMFunction_abs; |
|
|
class CoreVMFunction_random; |
|
|
class CoreVMFunction_num_elements; |
|
23 |
|
|
24 |
/** @brief Core virtual machine for real-time instrument scripts. |
/** @brief Core virtual machine for real-time instrument scripts. |
25 |
* |
* |
66 |
* parser errors, you may pass the VMParserContext object to method |
* parser errors, you may pass the VMParserContext object to method |
67 |
* exec() for actually executing the script. |
* exec() for actually executing the script. |
68 |
* |
* |
69 |
|
* It is your responsibility to free the returned VMParserContext |
70 |
|
* object once you don't need it anymore. |
71 |
|
* |
72 |
* @param s - entire source code of the script to be loaded |
* @param s - entire source code of the script to be loaded |
73 |
* @returns parsed representation of the script |
* @returns parsed representation of the script |
74 |
*/ |
*/ |
173 |
VMFunction* functionByName(const String& name) OVERRIDE; |
VMFunction* functionByName(const String& name) OVERRIDE; |
174 |
|
|
175 |
/** |
/** |
176 |
|
* Whether the passed built-in function is disabled and should thus be |
177 |
|
* ignored by the parser at the passed parser context (parser state |
178 |
|
* where the built-in function call occurs). |
179 |
|
* |
180 |
|
* @param fn - built-in function to be checked |
181 |
|
* @param ctx - parser context at the position where the built-in |
182 |
|
* function call is located within the script |
183 |
|
*/ |
184 |
|
bool isFunctionDisabled(VMFunction* fn, VMParserContext* ctx) OVERRIDE; |
185 |
|
|
186 |
|
/** |
187 |
* Returns all built-in integer script variables. This method returns a |
* Returns all built-in integer script variables. This method returns a |
188 |
* STL map, where the map's key is the variable name and the map's value |
* STL map, where the map's key is the variable name and the map's value |
189 |
* is the native pointer to the actual built-in variable. |
* is the native pointer to the actual built-in variable. |
191 |
* This method is re-implemented by deriving classes to add more use |
* This method is re-implemented by deriving classes to add more use |
192 |
* case specific built-in variables. |
* case specific built-in variables. |
193 |
*/ |
*/ |
194 |
std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE; |
std::map<String,VMIntPtr*> builtInIntVariables() OVERRIDE; |
195 |
|
|
196 |
/** |
/** |
197 |
* Returns all built-in (8 bit) integer array script variables. This |
* Returns all built-in (8 bit) integer array script variables. This |
205 |
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
206 |
|
|
207 |
/** |
/** |
208 |
* Returns all built-in constant integer script variables, which can |
* Returns all built-in constant integer script variables, which are |
209 |
* only be read, but not be altered by scripts. This method returns a |
* constant and their final data is already available at parser time |
210 |
* STL map, where the map's key is the variable name and the map's value |
* and won't change during runtime. Providing your built-in constants |
211 |
* is the native pointer to the actual built-in constant variable. |
* this way may lead to performance benefits compared to using other |
212 |
|
* ways of providing built-in variables, because the script parser |
213 |
|
* can perform optimizations when the script is refering to such |
214 |
|
* constants. |
215 |
|
* |
216 |
|
* This type of built-in variable can only be read, but not be altered |
217 |
|
* by scripts. This method returns a STL map, where the map's key is |
218 |
|
* the variable name and the map's value is the final constant data. |
219 |
* |
* |
220 |
* This method is re-implemented by deriving classes to add more use |
* This method is re-implemented by deriving classes to add more use |
221 |
* case specific built-in constant integers. |
* case specific built-in constant integers. |
222 |
* |
* |
223 |
* @b Note: the term "constant" is a bit misleading here, since |
* @b Note: In case your built-in variable should be read-only but its |
224 |
* built-in constant integer variables may indeed change, i.e. for |
* value is not already available at parser time (i.e. because its |
225 |
* built-in constant integers which i.e. reflect some kind of status of |
* value may change at runtime), then you should add it to |
226 |
* the sampler. So rather see them as "read only" variables, not as |
* builtInIntVariables() instead and use the macro |
227 |
* being actually consistent in time. |
* DECLARE_VMINT_READONLY() to define the variable for read-only |
228 |
|
* access by scripts. |
229 |
|
*/ |
230 |
|
std::map<String,vmint> builtInConstIntVariables() OVERRIDE; |
231 |
|
|
232 |
|
/** |
233 |
|
* Returns all built-in constant real number (floating point) script |
234 |
|
* variables, which are constant and their final data is already |
235 |
|
* available at parser time and won't change during runtime. Providing |
236 |
|
* your built-in constants this way may lead to performance benefits |
237 |
|
* compared to using other ways of providing built-in variables, because |
238 |
|
* the script parser can perform optimizations when the script is |
239 |
|
* refering to such constants. |
240 |
|
* |
241 |
|
* This type of built-in variable can only be read, but not be altered |
242 |
|
* by scripts. This method returns a STL map, where the map's key is |
243 |
|
* the variable name and the map's value is the final constant data. |
244 |
|
* |
245 |
|
* This method is re-implemented by deriving classes to add more use |
246 |
|
* case specific built-in constant real numbers. |
247 |
|
*/ |
248 |
|
std::map<String,vmfloat> builtInConstRealVariables() OVERRIDE; |
249 |
|
|
250 |
|
/** |
251 |
|
* Returns all built-in dynamic variables. This method returns a STL |
252 |
|
* map, where the map's key is the dynamic variable's name and the |
253 |
|
* map's value is the pointer to the actual object implementing the |
254 |
|
* behavior which is actually generating the content of the dynamic |
255 |
|
* variable. |
256 |
|
* |
257 |
|
* This method is re-implemented by deriving classes to add more use |
258 |
|
* case specific built-in dynamic variables. |
259 |
|
*/ |
260 |
|
std::map<String,VMDynVar*> builtInDynamicVariables() OVERRIDE; |
261 |
|
|
262 |
|
/** |
263 |
|
* Enables or disables automatic suspension of scripts by the VM. |
264 |
|
* If automatic suspension is enabled then scripts are monitored |
265 |
|
* regarding their execution time and in case they are execution |
266 |
|
* for too long, then they are automatically suspended by the VM for |
267 |
|
* a certain amount of time in order to avoid any RT instablity |
268 |
|
* issues caused by bugs in the script, i.e. endless while() loops |
269 |
|
* or very large scripts. |
270 |
|
* |
271 |
|
* Automatic suspension is enabled by default due to the aimed |
272 |
|
* real-time context of this virtual machine. |
273 |
|
* |
274 |
|
* @param b - true: enable auto suspension [default], |
275 |
|
* false: disable auto suspension |
276 |
|
*/ |
277 |
|
void setAutoSuspendEnabled(bool b = true); |
278 |
|
|
279 |
|
/** |
280 |
|
* Returns true in case automatic suspension of scripts by the VM is |
281 |
|
* enabled. See setAutoSuspendEnabled() for details. |
282 |
|
* |
283 |
|
* Automatic suspension is enabled by default due to the aimed |
284 |
|
* real-time context of this virtual machine. |
285 |
|
*/ |
286 |
|
bool isAutoSuspendEnabled() const; |
287 |
|
|
288 |
|
/** |
289 |
|
* By default (i.e. in production use) the built-in exit() function |
290 |
|
* prohibits any arguments to be passed to its function by scripts. So |
291 |
|
* by default, scripts trying to pass any arguments to the built-in |
292 |
|
* exit() function will yield in a parser error. |
293 |
|
* |
294 |
|
* By calling this method the built-in exit() function will optionally |
295 |
|
* accept one argument to be passed to its function call by scripts. The |
296 |
|
* value of that function argument will become available by calling |
297 |
|
* VMExecContext::exitResult() after execution of the script. |
298 |
|
* |
299 |
|
* @see VMExecContext::exitResult() |
300 |
|
*/ |
301 |
|
void setExitResultEnabled(bool b = true); |
302 |
|
|
303 |
|
/** |
304 |
|
* Returns @c true if the built-in exit() function optionally accepts |
305 |
|
* a function argument by scripts. |
306 |
|
* |
307 |
|
* @see setExitResultEnabled() |
308 |
*/ |
*/ |
309 |
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
bool isExitResultEnabled() const; |
310 |
|
|
311 |
VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
VMEventHandler* currentVMEventHandler(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
312 |
VMParserContext* currentVMParserContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
VMParserContext* currentVMParserContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
315 |
protected: |
protected: |
316 |
VMEventHandler* m_eventHandler; |
VMEventHandler* m_eventHandler; |
317 |
ParserContext* m_parserContext; |
ParserContext* m_parserContext; |
318 |
CoreVMFunction_message* m_fnMessage; |
bool m_autoSuspend; |
319 |
CoreVMFunction_exit* m_fnExit; |
bool m_acceptExitRes; |
320 |
CoreVMFunction_wait* m_fnWait; |
class CoreVMFunction_message* m_fnMessage; |
321 |
CoreVMFunction_abs* m_fnAbs; |
class CoreVMFunction_exit* m_fnExit; |
322 |
CoreVMFunction_random* m_fnRandom; |
class CoreVMFunction_wait* m_fnWait; |
323 |
CoreVMFunction_num_elements* m_fnNumElements; |
class CoreVMFunction_abs* m_fnAbs; |
324 |
|
class CoreVMFunction_random* m_fnRandom; |
325 |
|
class CoreVMFunction_num_elements* m_fnNumElements; |
326 |
|
class CoreVMFunction_inc* m_fnInc; |
327 |
|
class CoreVMFunction_dec* m_fnDec; |
328 |
|
class CoreVMFunction_in_range* m_fnInRange; |
329 |
|
class CoreVMFunction_sh_left* m_fnShLeft; |
330 |
|
class CoreVMFunction_sh_right* m_fnShRight; |
331 |
|
class CoreVMFunction_min* m_fnMin; |
332 |
|
class CoreVMFunction_max* m_fnMax; |
333 |
|
class CoreVMFunction_array_equal* m_fnArrayEqual; |
334 |
|
class CoreVMFunction_search* m_fnSearch; |
335 |
|
class CoreVMFunction_sort* m_fnSort; |
336 |
|
class CoreVMFunction_int_to_real* m_fnIntToReal; |
337 |
|
class CoreVMFunction_real_to_int* m_fnRealToInt; |
338 |
|
class CoreVMFunction_round* m_fnRound; |
339 |
|
class CoreVMFunction_ceil* m_fnCeil; |
340 |
|
class CoreVMFunction_floor* m_fnFloor; |
341 |
|
class CoreVMFunction_sqrt* m_fnSqrt; |
342 |
|
class CoreVMFunction_log* m_fnLog; |
343 |
|
class CoreVMFunction_log2* m_fnLog2; |
344 |
|
class CoreVMFunction_log10* m_fnLog10; |
345 |
|
class CoreVMFunction_exp* m_fnExp; |
346 |
|
class CoreVMFunction_pow* m_fnPow; |
347 |
|
class CoreVMFunction_sin* m_fnSin; |
348 |
|
class CoreVMFunction_cos* m_fnCos; |
349 |
|
class CoreVMFunction_tan* m_fnTan; |
350 |
|
class CoreVMFunction_asin* m_fnAsin; |
351 |
|
class CoreVMFunction_acos* m_fnAcos; |
352 |
|
class CoreVMFunction_atan* m_fnAtan; |
353 |
|
class CoreVMDynVar_NKSP_REAL_TIMER* m_varRealTimer; |
354 |
|
class CoreVMDynVar_NKSP_PERF_TIMER* m_varPerfTimer; |
355 |
}; |
}; |
356 |
|
|
357 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |