// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Tap-tempo sound clock // Not compiled or tested in-world // Setup: Add a short tick. First touch arms, second within 0.25–2 seconds sets tempo, third stops. // Stop / restore: Owner-touch the script prim to stop an active session before removing or resetting it. Loop state can survive script removal; use Stop sound in this prim if necessary. // Notes: Use licensed sounds in this prim. Audio is nearby, not private. Timer timing and asset loading are approximate; no sample synchronization is promised. A long gap cancels tempo capture instead of producing a very slow timer. Server event latency affects results. // License: see LICENSE in this distribution. // Original Incoprea. MIT. Not compiled or tested in-world. integer phase; float first; default { touch_start(integer n) { if(llDetectedKey(0)!=llGetOwner())return; if(phase==0) { phase=1; first=llGetTime(); llOwnerSay("Tap again to set tempo."); llSetTimerEvent(3.0); } else if(phase==1) { float interval=llGetTime()-first; if(interval<0.25||interval>2.0) { phase=0; llSetTimerEvent(0.0); llOwnerSay("Use a quarter to two seconds between taps."); return; } phase=2; llSetTimerEvent(interval); llOwnerSay("Approximate BPM "+(string)(60.0/interval)); } else { phase=0; llSetTimerEvent(0.0); llStopSound(); } } timer() { if(phase==1) { phase=0; llSetTimerEvent(0.0); } else if(phase==2&&llGetInventoryType("tick")==INVENTORY_SOUND)llPlaySound("tick",0.15); } }