Skip to content

Commit

Permalink
fix: Lower synth volume to an acceptable value
Browse files Browse the repository at this point in the history
Also only change volume if synth is enabled
  • Loading branch information
awsdcrafting committed Feb 4, 2024
1 parent 7ec8bcf commit cb405d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
37 changes: 32 additions & 5 deletions src/bongocat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {parseSong as parseSongBongo} from "./modules/bongo.js";
import {experimentalFeatures} from "./experimental/bongox.js";
import {extensionFeatures, experimentalFeatures} from "./experimental/bongox.js";

// ====================================================== //
// ================== type definitions ================== //
Expand Down Expand Up @@ -47,6 +47,8 @@ var githubUrls = ["https://raw.githubusercontent.com/jvpeek/twitch-bongocat/mast
var stackMode = false;
var maxSongLength = 90_000; //90 secs
var defaultNotation = "bongo";
var disableExperiments = false;
var disableExtensions = false;

var currentSong = null;
var volume = 1.0;
Expand All @@ -57,7 +59,7 @@ var audioContext;
var mainGainNode;
var oscillatorNode;
var synthStarted = false;
var synthDampening = 0.75;
var synthDampening = 0.1;

// ====================================================== //
// ================== notation handlers ================= //
Expand All @@ -76,7 +78,10 @@ notations["bongo+"] = parseSongBongo;
function setVolume(volumeParam)
{
volume = Math.min(1.0, Math.max(0, Number(volumeParam)));
mainGainNode.gain.value = volume * synthDampening;
if (mainGainNode)
{
mainGainNode.gain.value = volume * synthDampening;
}
}

function setMaxSongLength(maxSongLengthParam)
Expand Down Expand Up @@ -176,6 +181,10 @@ function prepareSynth(type)

function playSynthSound(frequency, time)
{
if (!audioContext || !mainGainNode || !oscillatorNode)
{
return;
}
if (!synthStarted)
{
oscillatorNode.start();
Expand All @@ -188,6 +197,10 @@ function playSynthSound(frequency, time)

function muteSynth(time)
{
if (!mainGainNode)
{
return;
}
mainGainNode.gain.setValueAtTime(0, time);
}

Expand Down Expand Up @@ -355,7 +368,11 @@ function checkQueue()
{
var song = getFromQueue();
let handler = notations[song.notation];
if (song.experimental)
if (song.extension && !disableExtensions)
{
handler = extensionFeatures[song.notation] || handler;
}
if (song.experimental && !disableExperiments)
{
handler = experimentalFeatures[song.notation] || handler;
}
Expand Down Expand Up @@ -554,7 +571,7 @@ function bongox(args)
let experiment = args.arg.slice(0, split);
let notes = args.arg.slice(split + 1);
let username = args.tags.username;
let song = {performer: args.tags.username, notes: notes, notation: experiment, "experimental": true};
let song = {performer: args.tags.username, notes: notes, notation: experiment, "experimental": true, "extension": true};
addToQueue(song);
//experimentalFeatures[experiment]?.(notes, username)
}
Expand Down Expand Up @@ -644,6 +661,16 @@ if (params.get("stackMode"))
stackMode = true;
}

if (params.get("disableExperiments"))
{
disableExperiments = true;
}

if (params.get("disableExtensions"))
{
disableExtensions = true;
}

let maxSongLengthParam = params.get("maxSongLength");
if (maxSongLengthParam && !isNaN(Number(maxSongLengthParam)))
{
Expand Down
3 changes: 2 additions & 1 deletion src/experimental/bongox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

let experimentalFeatures = {};
let extensionFeatures = {};


function createNoteTable()
Expand Down Expand Up @@ -261,4 +262,4 @@ function rtttl(song)
experimentalFeatures["rtttl"] = rtttl;
experimentalFeatures["rttl"] = rtttl;

export {experimentalFeatures};
export {extensionFeatures, experimentalFeatures};

0 comments on commit cb405d7

Please sign in to comment.