Skip to content

Instantly share code, notes, and snippets.

@nulltask
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nulltask/9719258 to your computer and use it in GitHub Desktop.
Save nulltask/9719258 to your computer and use it in GitHub Desktop.
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