Buildup and Loop beat lengths can now be separate

master
William Toohey 10 years ago
parent 2d7e6b1de1
commit 07e6e26d7f
  1. 4
      src/js/HuesCanvas.js
  2. 62
      src/js/HuesCore.js
  3. 3
      src/js/SoundManager.js

@ -349,8 +349,8 @@ HuesCanvas.prototype.syncAnim = function() {
} }
var index = this.core.beatIndex; var index = this.core.beatIndex;
// When animation has more frames than song has beats, or part thereof // When animation has more frames than song has beats, or part thereof
if(this.lastBeat && this.core.beatLength) { if(this.lastBeat && this.core.getBeatLength()) {
var interp = (this.audio.currentTime - this.lastBeat) / this.core.beatLength; var interp = (this.audio.currentTime - this.lastBeat) / this.core.getBeatLength();
index += Math.min(interp, 1); index += Math.min(interp, 1);
} }
// This loops A-OK because the core's beatIndex never rolls over for a new loop // This loops A-OK because the core's beatIndex never rolls over for a new loop

@ -31,12 +31,18 @@ function HuesCore(defaults) {
// Bunch-o-initialisers // Bunch-o-initialisers
this.version = "0x0B"; this.version = "0x0B";
this.beatIndex = 0; this.beatIndex = 0;
this.beatLength = -1;
// How long a beat lasts for in each section
this.buildLength = -1;
this.loopLength = -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;
@ -282,8 +288,8 @@ HuesCore.prototype.animationLoop = function() {
this.currentSong.buildupPlayed = true; this.currentSong.buildupPlayed = true;
} }
} }
for(var beatTime = this.beatIndex * this.beatLength; beatTime < now; for(var beatTime = this.beatIndex * this.getBeatLength(); beatTime < now;
beatTime = ++this.beatIndex * this.beatLength) { beatTime = ++this.beatIndex * this.getBeatLength()) {
var beat = this.getBeat(this.beatIndex); var beat = this.getBeat(this.beatIndex);
this.beater(beat); this.beater(beat);
} }
@ -291,7 +297,7 @@ HuesCore.prototype.animationLoop = function() {
}; };
HuesCore.prototype.recalcBeatIndex = function() { HuesCore.prototype.recalcBeatIndex = function() {
this.beatIndex = Math.floor(this.soundManager.currentTime() / this.beatLength); this.beatIndex = Math.floor(this.soundManager.currentTime() / this.getBeatLength());
}; };
HuesCore.prototype.getBeatIndex = function() { HuesCore.prototype.getBeatIndex = function() {
@ -386,31 +392,46 @@ HuesCore.prototype.setSong = function(index) {
}; };
HuesCore.prototype.updateBeatLength = function() { HuesCore.prototype.updateBeatLength = function() {
//if(this.soundManager.currentTime() < 0) { this.loopLength = this.soundManager.loopLength / this.currentSong.rhythm.length;
// this.beatLength = this.soundManager.loopStart / this.currentSong.buildupRhythm.length; if(this.currentSong.buildup) {
//} else { this.buildLength = this.soundManager.buildLength / this.currentSong.buildupRhythm.length;
this.beatLength = this.soundManager.loopLength / this.currentSong.rhythm.length; } else {
//} this.buildLength = -1;
}
}
HuesCore.prototype.getBeatLength = function() {
if(this.beatIndex < 0) {
return this.buildLength;
} else {
return this.loopLength;
}
} }
HuesCore.prototype.fillBuildup = function() { HuesCore.prototype.fillBuildup = function() {
this.updateBeatLength();
if (!this.currentSong.buildupRhythm) { if (!this.currentSong.buildupRhythm) {
this.currentSong.buildupRhythm = ""; this.currentSong.buildupRhythm = ".";
} }
// update loop length for flash style filling
this.updateBeatLength();
if(this.currentSong.buildup) { if(this.currentSong.buildup) {
var buildBeats = Math.floor(this.soundManager.buildLength / this.beatLength); // TODO CHECK IF OLD OR NEW BEHAVIOUR
if(buildBeats < 1) { if(true) {
buildBeats = 1; console.log("Flash behaviour - filling buildup");
} var buildBeats = Math.floor(this.soundManager.buildLength / this.loopLength);
if (this.currentSong.buildupRhythm.length < buildBeats) { if(buildBeats < 1) {
console.log("Filling buildup beatmap"); buildBeats = 1;
}
while (this.currentSong.buildupRhythm.length < buildBeats) { while (this.currentSong.buildupRhythm.length < buildBeats) {
this.currentSong.buildupRhythm = this.currentSong.buildupRhythm + "."; this.currentSong.buildupRhythm = this.currentSong.buildupRhythm + ".";
} }
} else {
console.log("New behaviour - separate build/loop lengths");
} }
console.log("Buildup length:", buildBeats); console.log("Buildup length:", buildBeats);
} }
// update with a beatmap of possibly different length
this.updateBeatLength();
if(this.doBuildup) { if(this.doBuildup) {
this.beatIndex = -this.currentSong.buildupRhythm.length; this.beatIndex = -this.currentSong.buildupRhythm.length;
} else { } else {
@ -484,11 +505,8 @@ HuesCore.prototype.doAutoSong = function() {
HuesCore.prototype.songDataUpdated = function() { HuesCore.prototype.songDataUpdated = function() {
if (this.currentSong) { if (this.currentSong) {
this.beatLength = 0;
this.callEventListeners("newsong", this.currentSong); this.callEventListeners("newsong", this.currentSong);
this.callEventListeners("newimage", this.currentImage); this.callEventListeners("newimage", this.currentImage);
} else {
this.beatLength = -1;
} }
}; };
@ -609,7 +627,7 @@ HuesCore.prototype.beater = function(beat) {
this.renderer.doBlackout(true); this.renderer.doBlackout(true);
break; break;
case '|': case '|':
this.renderer.doShortBlackout(this.beatLength); this.renderer.doShortBlackout(this.getBeatLength());
this.randomColour(); this.randomColour();
break; break;
case ':': case ':':
@ -637,7 +655,7 @@ HuesCore.prototype.beater = function(beat) {
break; break;
} }
} }
this.renderer.doColourFade((fadeLen * this.beatLength) / this.soundManager.playbackRate); this.renderer.doColourFade((fadeLen * this.getBeatLength()) / this.soundManager.playbackRate);
this.randomColour(true); this.randomColour(true);
break; break;
case 'I': case 'I':

@ -175,6 +175,8 @@ SoundManager.prototype.playSong = function(song, playBuild, forcePlay) {
} }
return this.context.resume(); return this.context.resume();
}).then(() => {
this.playing = true;
}).catch(error => { }).catch(error => {
// Just to ignore it if the song was invalid // Just to ignore it if the song was invalid
// Log it in case it's something weird // Log it in case it's something weird
@ -241,7 +243,6 @@ SoundManager.prototype.seek = function(time) {
} }
this.startTime = this.context.currentTime - (time / this.playbackRate); this.startTime = this.context.currentTime - (time / this.playbackRate);
this.playing = true;
this.core.recalcBeatIndex(); this.core.recalcBeatIndex();
} }

Loading…
Cancel
Save