| 5592 | } |
| 5593 | |
| 5594 | void ScriptingApi::Synth::startTimer(double intervalInSeconds) |
| 5595 | { |
| 5596 | #if ENABLE_SCRIPTING_SAFE_CHECKS |
| 5597 | if(intervalInSeconds < 0.004) |
| 5598 | { |
| 5599 | reportScriptError("Go easy on the timer!"); |
| 5600 | return; |
| 5601 | } |
| 5602 | #endif |
| 5603 | |
| 5604 | |
| 5605 | |
| 5606 | |
| 5607 | |
| 5608 | |
| 5609 | if (parentMidiProcessor == nullptr) |
| 5610 | reportScriptError("Timers only work in MIDI processors!"); |
| 5611 | |
| 5612 | if(jp != nullptr && jp->isDeferred()) |
| 5613 | { |
| 5614 | owner->stopSynthTimer(parentMidiProcessor->getIndexInChain()); |
| 5615 | jp->startTimer((int)(intervalInSeconds * 1000)); |
| 5616 | parentMidiProcessor->setIndexInChain(-1); |
| 5617 | } |
| 5618 | else |
| 5619 | { |
| 5620 | int freeTimerSlot = parentMidiProcessor->getIndexInChain() != -1 ? parentMidiProcessor->getIndexInChain() : owner->getFreeTimerSlot(); |
| 5621 | |
| 5622 | if (freeTimerSlot == -1) |
| 5623 | { |
| 5624 | reportScriptError("All 4 timers are used"); |
| 5625 | return; |
| 5626 | } |
| 5627 | |
| 5628 | parentMidiProcessor->setIndexInChain(freeTimerSlot); |
| 5629 | |
| 5630 | auto* e = parentMidiProcessor->getCurrentHiseEvent(); |
| 5631 | |
| 5632 | int timestamp = 0; |
| 5633 | |
| 5634 | if (e != nullptr) |
| 5635 | { |
| 5636 | timestamp = e->getTimeStamp(); |
| 5637 | } |
| 5638 | |
| 5639 | owner->startSynthTimer(parentMidiProcessor->getIndexInChain(), intervalInSeconds, timestamp); |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | void ScriptingApi::Synth::stopTimer() |
| 5644 | { |
no test coverage detected