LogicMachine Forum
play beep on specific plan - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: play beep on specific plan (/showthread.php?tid=2305)



play beep on specific plan - 3r1ck - 25.10.2019

Hello colleagues, my idea is to be able to reproduce a beep (notification sound) on a specific plan, with a group address. when its state is 1, it reproduces the sound, the problem is what reproduces on all pages and must be in one



Adjunto el código javascript

Code:
$(function(){    var context= new AudioContext();   function jsNota(frecuencia){         var o= context.createOscillator();         g=context.createGain();         o.connect(g);         o.type="sine";         o.frequency.value=frecuencia;         g.connect(context.destination);         o.start(0);         g.gain.exponentialRampToValueAtTime(0.00001,context.currentTime +1.5);     } grp.listen('1/1/1', function(object, state) {     if (state == 'value' && object.value ) {       jsNota(1174.659, function() {       });     }   }, true);     });

Gracias


RE: play beep on specific plan - Erwin van der Zwart - 25.10.2019

Hi,

Just add a extra condition:
Code:
if (currentPlanId == 1){   //your code }
Here is also a code i use if the sound must be repeated until the object is false
Code:
$(function(){   var locked;   var ctx = new(window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext || window.msAudioContext);   var Beeping;     function beep(duration, freq, vol, cb) {     var osc = ctx.createOscillator();     osc.frequency.value = freq;     var volumeNode = ctx.createGain();     volumeNode.gain.value = (vol/1000);     osc.connect(volumeNode);     volumeNode.connect(ctx.destination);         osc.start ? osc.start(0) : osc.noteOn(0);     setTimeout(function () {     osc.disconnect();     if (typeof cb == "function") {      cb();     }    }, duration);   }     /* beep each time value is true note that 3rd listen parameter must be set to true to execute the callback each time new value arrives otherwise callback is executed only when value changes */   function startbeep(){     var ChromeDelay = 0;     if (document.hidden && !!window.chrome){       ChromeDelay = 1500;     }     setTimeout(function(){       if (!locked) {         locked = true;         // duration , freq         beep(300, 1500, 50, function() {           locked = false;         });       }     }, ChromeDelay);   }    // Function to start beep interval   function StartBeepTimer(){     // Jump to correct page     //showPlan(3);     // Set delay timer to start after x seconds     setTimeout(function(){       // Start feedback polling every second       if (!Beeping) {         // Run once to bypass the first delay         startbeep();         Beeping = setInterval(function(){ startbeep(); }, 2000);       }     }, 50); // Set higher value then 50 for extra delay after stop and start beep   }   // Function to stop beep interval   function StopBeepTimer(){     // Stop feedback polling every second     if (Beeping) {       clearInterval(Beeping);     }     Beeping = null;   }     // Creta elistener to start audio beep   grp.listen('21/0/1', function(object, state) {     if (state == 'value' && object.value ) {        StartBeepTimer();     } else if( state == 'value' && object.value == false){         StopBeepTimer();     }   }, true);    });
BR,

Erwin


RE: play beep on specific plan - 3r1ck - 25.10.2019

thank you very much Erwin, worked perfectly