Display negative time/beat, better intToHex

master
William Toohey 10 years ago
parent ab3ed8af1f
commit a7f2eef0a7
  1. 12
      src/js/HuesCore.js
  2. 45
      src/js/HuesUI.js
  3. 9
      src/js/SoundManager.js

@ -52,8 +52,8 @@ function HuesCore(defaults) {
this.eventListeners = {
/* callback time(hundredths)
*
* When the song time is updated - 0 for buildup, integer 10ths
* of a second otherwise
* When the song time is updated - negative for buildup
* Returns a floating point number denoting seconds
*/
time : [],
/* callback blurUpdate(xPercent, yPercent)
@ -280,14 +280,10 @@ HuesCore.prototype.animationLoop = function() {
}
this.updateVisualiser();
let now = this.soundManager.currentTime();
if(now < 0) {
this.callEventListeners("time", 0);
} else {
this.callEventListeners("time", this.soundManager.displayableTime());
if(this.doBuildup) {
this.callEventListeners("time", this.soundManager.clampedTime());
if(now >= 0 && this.doBuildup) {
this.currentSong.buildupPlayed = true;
}
}
for(let beatTime = this.beatIndex * this.getBeatLength(); beatTime < now;
beatTime = ++this.beatIndex * this.getBeatLength()) {
let beat = this.getBeat(this.beatIndex);

@ -242,30 +242,22 @@ HuesUI.prototype.newColour = function(colour) {
HuesUI.prototype.blurUpdated = function(x, y) {
x = Math.floor(x * 0xFF);
y = Math.floor(y * 0xFF);
this.xBlur.textContent = "X=" + this.intToHex2(x);
this.yBlur.textContent = "Y=" + this.intToHex2(y);
this.xBlur.textContent = "X=" + this.intToHex(x, 2);
this.yBlur.textContent = "Y=" + this.intToHex(y, 2);
};
HuesUI.prototype.updateTime = function(time) {
time = Math.floor(time * 1000);
this.timer.textContent = "T=" + this.intToHex5(time);
this.timer.textContent = "T=" + this.intToHex(time, 5);
};
HuesUI.prototype.intToHex2 = function(num) {
return '$0x' + ("00"+num.toString(16)).slice(-2);
};
HuesUI.prototype.intToHex3 = function(num) {
return '$0x' + ("000"+num.toString(16)).slice(-3);
};
HuesUI.prototype.intToHex4 = function(num) {
return '$0x' + ("0000"+num.toString(16)).slice(-4);
};
HuesUI.prototype.intToHex5 = function(num) {
return '$0x' + ("00000"+num.toString(16)).slice(-5);
};
HuesUI.prototype.intToHex = function(num, pad) {
let str = Math.abs(num).toString(16);
while (str.length < pad)
str = "0" + str;
let prefix = num < 0 ? "-" : "$";
return prefix + "0x" + str;
}
/*
Individual UIs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -416,16 +408,13 @@ RetroUI.prototype.newImage = function(image) {
RetroUI.prototype.newColour = function(colour) {
HuesUI.prototype.newColour.call(this, colour);
this.colourIndex.textContent = "C=" + this.intToHex2(this.core.colourIndex);
this.colourIndex.textContent = "C=" + this.intToHex(this.core.colourIndex, 2);
};
RetroUI.prototype.beat = function(beats, index) {
let rest = beats.slice(1);
this.beatBar.textContent = ">>" + rest;
if(index < 0) {
index = 0;
}
this.beatCount.textContent = "B=" + this.intToHex4(index);
this.beatCount.textContent = "B=" + this.intToHex(index, 4);
};
RetroUI.prototype.resize = function() {
@ -487,10 +476,7 @@ WeedUI.prototype.beat = function(beats, index) {
this.beatLeft.textContent = rest;
this.beatRight.textContent = rest;
if(index < 0) {
index = 0;
}
this.beatCount.textContent = "B=" + this.intToHex4(index);
this.beatCount.textContent = "B=" + this.intToHex(index, 4);
if(["x", "o", "X", "O"].indexOf(beats[0]) != -1) {
let beatCenter = document.createElement("div");
@ -753,10 +739,7 @@ ModernUI.prototype.beat = function(beats, index) {
span.textContent = this.currentBeat;
this.beatCenter.appendChild(span);
}
if(index < 0) {
index = 0;
}
this.beatCount.textContent = "B=" + this.intToHex4(index);
this.beatCount.textContent = "B=" + this.intToHex(index, 4);
};
ModernUI.prototype.resize = function() {

@ -296,15 +296,6 @@ SoundManager.prototype.clampedTime = function() {
return time;
};
SoundManager.prototype.displayableTime = function() {
let time = this.clampedTime();
if(time < 0) {
return 0;
} else {
return time;
}
};
SoundManager.prototype.loadSong = function(song) {
if(song._loadPromise) {
// Someone went forward then immediately back then forward again

Loading…
Cancel
Save