failsafes and more notification sounds

This commit is contained in:
MathMan05 2024-06-21 22:22:20 -05:00
parent ae43fd497a
commit 95f6bc202d
4 changed files with 78 additions and 11 deletions

View file

@ -1,5 +1,5 @@
class voice{
constructor(wave,freq){
constructor(wave,freq,volume=1){
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
this.info={wave:wave,freq:freq}
this.playing=false;
@ -8,6 +8,9 @@ class voice{
this.audioCtx.sampleRate,
this.audioCtx.sampleRate,
);
this.gainNode = this.audioCtx.createGain();
this.gainNode.gain.value=volume;
this.gainNode.connect(this.audioCtx.destination);
this.buffer=this.myArrayBuffer.getChannelData(0);
this.source = this.audioCtx.createBufferSource();
this.source.buffer = this.myArrayBuffer;
@ -37,6 +40,9 @@ class voice{
}
waveFucnion(){
if(typeof this.wave === 'function'){
return this.wave;
}
switch(this.wave){
case "sin":
return (t,freq)=>{
@ -68,7 +74,7 @@ class voice{
if(this.playing){
return;
}
this.source.connect(this.audioCtx.destination);
this.source.connect(this.gainNode);
this.playing=true;
}
@ -78,4 +84,52 @@ class voice{
this.playing=false;
}
}
static noises(noise){
switch(noise){
case "three":{
const voicy=new voice("sin",800);
voicy.play();
setTimeout(_=>{voicy.freq=1000},50);
setTimeout(_=>{voicy.freq=1300},100);
setTimeout(_=>{voicy.stop()},150);
break;
}
case "zip":{
const voicy=new voice((t,freq)=>{
return Math.sin(((t+2)**(Math.cos(t*4)))*Math.PI*2*freq);
},700);
voicy.play();
setTimeout(_=>{voicy.stop()},150);
break;
}
case "square":{
const voicy=new voice("square",600,.4);
voicy.play()
setTimeout(_=>{voicy.freq=800},50);
setTimeout(_=>{voicy.freq=1000},100);
setTimeout(_=>{voicy.stop()},150);
break;
}
case "beep":{
const voicy=new voice("sin",800);
voicy.play();
setTimeout(_=>{voicy.stop()},50);
setTimeout(_=>{voicy.play();},100);
setTimeout(_=>{voicy.stop()},150);
break;
}
}
}
static get sounds(){
return ["three","zip","square","beep"];
}
static setNotificationSound(sound){
let userinfos=JSON.parse(localStorage.getItem("userinfos"));
userinfos.preferances.notisound=sound;
localStorage.setItem("userinfos",JSON.stringify(userinfos));
}
static getNotificationSound(){
let userinfos=JSON.parse(localStorage.getItem("userinfos"));
return userinfos.preferances.notisound;
}
}

View file

@ -509,13 +509,7 @@ class channel{
return message.author.username+" > "+this.owner.properties.name+" > "+this.name;
}
notify(message){
{
const voicy=new voice("sin",800);
voicy.play()
setTimeout(_=>{voicy.freq=1000},50);
setTimeout(_=>{voicy.freq=1300},100);
setTimeout(_=>{voicy.stop()},150);
}
voice.noises(voice.getNotificationSound());
if (!("Notification" in window)) {
} else if (Notification.permission === "granted") {

View file

@ -459,7 +459,11 @@ function genusersettings(){
["select","Theme:",["Dark","Light","WHITE"],e=>{
localStorage.setItem("theme",["Dark","Light","WHITE"][e.target.selectedIndex]);
setTheme();
},["Dark","Light","WHITE"].indexOf(localStorage.getItem("theme"))]
},["Dark","Light","WHITE"].indexOf(localStorage.getItem("theme"))],
["select","Notification sound:",voice.sounds,e=>{
voice.setNotificationSound(voice.sounds[e.target.selectedIndex]);
voice.noises(voice.sounds[e.target.selectedIndex]);
},voice.sounds.indexOf(voice.getNotificationSound())]
],
["vdiv",
["html",hypothetcialprofie]

View file

@ -19,7 +19,7 @@ function getBulkInfo(){
return JSON.parse(localStorage.getItem("userinfos"));
}
function setDefaults(){
let userinfos=localStorage.getItem("userinfos");
let userinfos=JSON.parse(localStorage.getItem("userinfos"));
if(!userinfos){
localStorage.setItem("userinfos",JSON.stringify({
currentuser:null,
@ -28,9 +28,24 @@ function setDefaults(){
{
theme:"Dark",
notifcations:false,
notisound:"three",
},
}));
}
if(userinfos.users===undefined){
userinfos.users={};
}
if(userinfos.preferances===undefined){
userinfos.preferances={
theme:"Dark",
notifcations:false,
notisound:"three",
}
}
if(userinfos.preferances&&(userinfos.preferances.notisound===undefined)){
userinfos.preferances.notisound="three";
}
localStorage.setItem("userinfos",JSON.stringify(userinfos));
}
setDefaults();
class specialuser{