Last active
August 29, 2015 13:57
-
-
Save nulltask/9719258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var music = new Music(data); | |
setInterval(function() { | |
var res = music.next(); | |
if (res.bars.length + res.beats.length + res.tatums.length + res.sections.length + res.segments.length) { | |
console.log(res); | |
} | |
}); | |
function Music(data) { | |
this.data = data; | |
} | |
Music.prototype.next = function() { | |
if (!this.start) { | |
this.start = new Date(); | |
} | |
var now = new Date(); | |
var time = (now - this.start) / 1000; | |
var res = {}; | |
['bars', 'beats', 'tatums', 'sections', 'segments'].forEach(function(key) { | |
res[key] = []; | |
this.data[key] = this.data[key].filter(function(el, i) { | |
if (el.start <= time) { | |
res[key].push(el); | |
return false; | |
} | |
return true; | |
}); | |
}, this); | |
return res; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment