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

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

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

Loading…
Cancel
Save