3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
* Copyright (C) 2005 - 2017 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
188 |
iFragmentPos = FragmentPos; |
iFragmentPos = FragmentPos; |
189 |
} |
} |
190 |
|
|
191 |
|
/** |
192 |
|
* Implements fork() behavior, that is it copies the current state of this |
193 |
|
* script event handler to the new event handler @a e with entire execution |
194 |
|
* state and polyphonic data. |
195 |
|
* |
196 |
|
* After calling this method, addChildHandler() should be called as well. |
197 |
|
*/ |
198 |
|
void ScriptEvent::forkTo(ScriptEvent* e, bool bAutoAbort) const { |
199 |
|
e->scheduleTime = scheduleTime; |
200 |
|
e->cause = cause; |
201 |
|
e->id = id; |
202 |
|
// forked script shall only run the current event handler of parent, |
203 |
|
// no other potentially chained handlers |
204 |
|
e->handlers[0] = handlers[currentHandler]; |
205 |
|
e->handlers[1] = NULL; // NULL termination of list |
206 |
|
e->currentHandler = 0; |
207 |
|
e->executionSlices = 0; |
208 |
|
e->ignoreAllWaitCalls = ignoreAllWaitCalls; |
209 |
|
e->handlerType = handlerType; |
210 |
|
e->parentHandlerID = 0; // just an arbitrary init value, must still be set later! |
211 |
|
e->childHandlerID[0] = 0; |
212 |
|
e->autoAbortByParent = bAutoAbort; |
213 |
|
e->forkIndex = 1; // just an arbitrary init value, must still be set later! |
214 |
|
|
215 |
|
execCtx->forkTo(e->execCtx); |
216 |
|
} |
217 |
|
|
218 |
|
/** |
219 |
|
* Returns amount of child event handlers that have been created so far |
220 |
|
* during the entire life time of this event handler instance by calls of |
221 |
|
* this event handler instace to the built-in script function fork(). |
222 |
|
* |
223 |
|
* To make this clear: this number does never decrease during the entire |
224 |
|
* life time of an event handler instance! It may only increase, i.e. by |
225 |
|
* additional calls to fork(). Consequently even if child event handler |
226 |
|
* instances already terminated, this will not decrease this count. |
227 |
|
*/ |
228 |
|
int ScriptEvent::countChildHandlers() const { |
229 |
|
int n = 0; |
230 |
|
for (int i = 0; i < MAX_FORK_PER_SCRIPT_HANDLER && childHandlerID[i]; ++i) |
231 |
|
++n; |
232 |
|
return n; |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
|
* This must be called after calling forkTo() to stick the script callback |
237 |
|
* ID of the newly forked child execution instance to the parent execution |
238 |
|
* instance. |
239 |
|
* |
240 |
|
* @param childID - script callback ID of the newly forked child handler |
241 |
|
*/ |
242 |
|
void ScriptEvent::addChildHandlerID(script_callback_id_t childID) { |
243 |
|
const int n = countChildHandlers(); |
244 |
|
if (n >= MAX_FORK_PER_SCRIPT_HANDLER) { |
245 |
|
dmsg(1,("ScriptEvent::addChildHandlerID(): MAX_FORK_PER_SCRIPT_HANDLER exceeded, this is a bug!\n")); |
246 |
|
return; |
247 |
|
} |
248 |
|
childHandlerID[n] = childID; |
249 |
|
childHandlerID[n+1] = 0; // zero termination of list |
250 |
|
} |
251 |
|
|
252 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |