AutoSong! + other minor fixes

master
William Toohey 10 years ago
parent cac6c63752
commit d47f30448e
  1. 1
      css/style.css
  2. 98
      js/HuesCore.js
  3. 6
      js/HuesSettings.js
  4. 21
      js/SoundManager.js

@ -258,6 +258,7 @@ label.settings-label:hover {
font-family: 'PetMe64Web'; font-family: 'PetMe64Web';
font-size: 7pt; font-size: 7pt;
padding: 3px; padding: 3px;
margin: -6px 0;
background: rgba(127,127,127, 0.5); background: rgba(127,127,127, 0.5);
border-color: rgb(0,0,0); border-color: rgb(0,0,0);
border-width: 1px; border-width: 1px;

@ -26,19 +26,16 @@ function HuesCore(defaults) {
// Bunch-o-initialisers // Bunch-o-initialisers
this.version = "0x01"; this.version = "0x01";
this.beatIndex = 0; this.beatIndex = 0;
this.beatLength=-1; this.beatLength = -1;
this.currentSong = null; this.currentSong = null;
this.currentImage = null; this.currentImage = null;
this.songIndex=-1; this.songIndex = -1;
this.colourIndex=0x3f; this.colourIndex = 0x3f;
this.imageIndex=-1; this.imageIndex = -1;
this.isFullAuto = true; this.isFullAuto = true;
this.invert = false; this.invert = false;
this.loopCount=0; this.loopCount = 0;
this.fadeOut=false; this.doBuildup = true;
this.fadeDirection=false;
this.loadedFiles=0;
this.doBuildup=true;
this.userInterface = null; this.userInterface = null;
var that = this; var that = this;
@ -54,7 +51,7 @@ function HuesCore(defaults) {
this.lastSongArray = []; this.lastSongArray = [];
this.lastImageArray = []; this.lastImageArray = [];
this.settings = new HuesSettings(defaults); this.settings = new HuesSettings(defaults);
//this.autoSong = this.settings.autosong; this.autoSong = localStorage["autoSong"];
this.resourceManager = new Resources(this); this.resourceManager = new Resources(this);
this.soundManager = new SoundManager(this); this.soundManager = new SoundManager(this);
if(!this.soundManager.canUse) { if(!this.soundManager.canUse) {
@ -181,6 +178,9 @@ HuesCore.prototype.animationLoop = function() {
var beat = this.getBeat(this.beatIndex); var beat = this.getBeat(this.beatIndex);
this.beater(beat); this.beater(beat);
} }
if(Math.floor(now / this.soundManager.loopLength) > this.loopCount) {
this.onLoop();
}
requestAnimationFrame(function() {that.animationLoop();}); requestAnimationFrame(function() {that.animationLoop();});
}; };
@ -230,6 +230,7 @@ HuesCore.prototype.setSong = function(index) {
if(this.currentSong == this.resourceManager.enabledSongs[index]) { if(this.currentSong == this.resourceManager.enabledSongs[index]) {
return; return;
} }
this.lastSongArray.push(index);
this.songIndex = index; this.songIndex = index;
this.currentSong = this.resourceManager.enabledSongs[this.songIndex]; this.currentSong = this.resourceManager.enabledSongs[this.songIndex];
if (this.currentSong === undefined) { if (this.currentSong === undefined) {
@ -284,37 +285,48 @@ HuesCore.prototype.randomSong = function() {
} else { } else {
console.log("Randoming a song!"); console.log("Randoming a song!");
this.setSong(index); this.setSong(index);
this.lastSongArray.push(index);
var noRepeat = Math.min(5, Math.floor((this.resourceManager.enabledSongs.length / 2))); var noRepeat = Math.min(5, Math.floor((this.resourceManager.enabledSongs.length / 2)));
while (this.lastSongArray.length > noRepeat && noRepeat >= 0) { while (this.lastSongArray.length > noRepeat && noRepeat >= 0) {
this.lastSongArray.shift(); this.lastSongArray.shift();
} }
} }
}; };
/*
HuesCore.prototype.onLoop = function() { HuesCore.prototype.onLoop = function() {
this.loopCount = this.loopCount + 1; this.loopCount++;
switch (this.settings.autosong) { switch (localStorage["autoSong"]) {
case "loop": case "loop":
console.log("Checking loops"); console.log("Checking loops");
if (this.loopCount >= this.settings.autosongDelay) { if (this.loopCount >= localStorage["autoSongDelay"]) {
this.startSongChangeFade(); this.doAutoSong();
} }
break; break;
case "time": case "time":
console.log("Checking times"); console.log("Checking times");
if (this.currentSong.sound && this.calculateSongLength(this.currentSong.sound) / 1000 * this.loopCount >= this.settings.autosongDelay * 60) { if (this.soundManager.loopLength * this.loopCount >= localStorage["autoSongDelay"] * 60) {
this.startSongChangeFade(); this.doAutoSong();
} }
break; break;
} }
} }
HuesCore.prototype.startSongChangeFade = function() { HuesCore.prototype.doAutoSong = function() {
this.fadeDirection = true; var func = null;
this.fadeOut = true; var that = this;
if(localStorage["autoSongShuffle"] == "on") {
func = this.randomSong;
} else {
func = this.nextSong;
}
if(localStorage["autoSongFadeout"] == "on") {
this.soundManager.fadeOut(function() {
func.call(that);
});
} else {
func.call(that);
}
} }
*/
HuesCore.prototype.songDataUpdated = function() { HuesCore.prototype.songDataUpdated = function() {
if (this.currentSong) { if (this.currentSong) {
this.beatLength = 0; this.beatLength = 0;
@ -538,46 +550,10 @@ HuesCore.prototype.toggleInvert = function() {
this.setInvert(!this.invert); this.setInvert(!this.invert);
} }
/*HuesCore.prototype.enterFrame = function() {
this.setTexts();
if (this.fadeOut) {
// 30fps frame locked, TODO
delta = this.fadeDirection ? -2 : 2;
if (this.soundChannel) {
fadeTo = Math.max(0, Math.min(this.currentVolume, soundManager.volume + delta));
this.soundManager.setVolume(fadeTo);
if (fadeTo == 0) {
this.fadeOut = false;
this.fadeDirection = false;
if (this.settings.autosongShuffle) {
this.randomSong();
} else {
this.nextSong();
}
}
}
}
}*/
HuesCore.prototype.respackLoaded = function() { HuesCore.prototype.respackLoaded = function() {
this.init(); this.init();
}; };
/*HuesCore.prototype.rightClickListener = function(event) {
switch (event) {
case flash.events.MouseEvent.RIGHT_CLICK:
this.toggleSettingsWindow();
break;
case flash.events.MouseEvent.MOUSE_WHEEL:
if (event.delta > 0) {
this.soundManager.increaseVolume();
} else {
this.soundManager.decreaseVolume();
}
break;
}
}*/
HuesCore.prototype.changeUI = function(index) { HuesCore.prototype.changeUI = function(index) {
if (index >= 0 && this.uiArray.length > index && this.userInterface != this.uiArray[index]) { if (index >= 0 && this.uiArray.length > index && this.userInterface != this.uiArray[index]) {
this.hideLists(); this.hideLists();
@ -647,11 +623,11 @@ HuesCore.prototype.settingsUpdated = function() {
} }
break; break;
} }
/*if (this.autoSong == "off" && !(this.settings.autosong == "off")) { if (this.autoSong == "off" && localStorage["autoSong"] != "off") {
console.log("Resetting loopCount since AutoSong was enabled"); console.log("Resetting loopCount since AutoSong was enabled");
this.loopCount = 0; this.loopCount = 0;
this.autoSong = this.settings.autosong; }
}*/ this.autoSong = localStorage["autoSong"];
}; };
HuesCore.prototype.enabledChanged = function() { HuesCore.prototype.enabledChanged = function() {

@ -55,6 +55,7 @@ HuesSettings.prototype.defaultSettings = {
autoSong: "off", autoSong: "off",
autoSongDelay: 5, // loops or minutes depending on autoSong value autoSongDelay: 5, // loops or minutes depending on autoSong value
autoSongShuffle: "on", autoSongShuffle: "on",
autoSongFadeout: "on",
volume: 0.7 volume: 0.7
}; };
@ -79,6 +80,7 @@ HuesSettings.prototype.settingsCategories = {
"Functionality" : [ "Functionality" : [
"autoSong", "autoSong",
"autoSongShuffle", "autoSongShuffle",
"autoSongFadeout",
"smartAlign" "smartAlign"
], ],
"Interface" : [ "Interface" : [
@ -169,6 +171,10 @@ HuesSettings.prototype.settingsOptions = {
autoSongShuffle : { autoSongShuffle : {
name : "AutoSong shuffle", name : "AutoSong shuffle",
options : ["off", "on"] options : ["off", "on"]
},
autoSongFadeout : {
name : "AutoSong fade out",
options : ["off", "on"]
} }
}; };

@ -109,6 +109,11 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
if(!song || (!song.sound)) { // null song if(!song || (!song.sound)) { // null song
return; return;
} }
// if there's a fadeout happening from AutoSong, kill it
this.gainNode.gain.cancelScheduledValues(0);
// Reset original volume
this.setVolume(this.lastVol);
this.loadBuffer(song, function() { this.loadBuffer(song, function() {
// To prevent race condition if you press "next" twice fast // To prevent race condition if you press "next" twice fast
@ -442,18 +447,24 @@ SoundManager.prototype.toggleMute = function() {
SoundManager.prototype.decreaseVolume = function() { SoundManager.prototype.decreaseVolume = function() {
this.setMute(false); this.setMute(false);
var val = Math.max(this.gainNode.gain.value - 0.1, 0); var val = Math.max(this.gainNode.gain.value - 0.1, 0);
this.gainNode.gain.value = val; this.setVolume(val);
this.core.userInterface.updateVolume(val);
}; };
SoundManager.prototype.increaseVolume = function() { SoundManager.prototype.increaseVolume = function() {
this.setMute(false); this.setMute(false);
var val = Math.min(this.gainNode.gain.value + 0.1, 1); var val = Math.min(this.gainNode.gain.value + 0.1, 1);
this.gainNode.gain.value = val; this.setVolume(val);
this.core.userInterface.updateVolume(val);
}; };
SoundManager.prototype.setVolume = function(vol) { SoundManager.prototype.setVolume = function(vol) {
this.gainNode.gain.value = vol; this.gainNode.gain.value = vol;
this.lastVol = vol;
this.core.userInterface.updateVolume(vol); this.core.userInterface.updateVolume(vol);
}; };
SoundManager.prototype.fadeOut = function(callback) {
// Firefox hackery
this.gainNode.gain.setValueAtTime(this.lastVol, this.context.currentTime);
this.gainNode.gain.exponentialRampToValueAtTime(0.01, this.context.currentTime + 2);
setTimeout(callback, 2000);
}

Loading…
Cancel
Save