aboutsummaryrefslogtreecommitdiff
path: root/app/js/services.js
diff options
context:
space:
mode:
authorNicolas Bornand <nicolas74@gmail.com>2014-05-12 22:37:15 +0200
committerNicolas Bornand <nicolas74@gmail.com>2014-05-12 22:37:15 +0200
commit90f4cdfdc901131530e38579fbb99c8dd32411fa (patch)
tree0dd7cafdc865da1b50f3cf206bf5268914aac43a /app/js/services.js
parent3efc7a211a76fa2fbd092b281951b5f9a0438bee (diff)
downloadplayGraph-90f4cdfdc901131530e38579fbb99c8dd32411fa.tar.gz
playGraph-90f4cdfdc901131530e38579fbb99c8dd32411fa.tar.bz2
playGraph-90f4cdfdc901131530e38579fbb99c8dd32411fa.zip
improve path computations speedHEADmaster
Diffstat (limited to 'app/js/services.js')
-rw-r--r--app/js/services.js39
1 files changed, 36 insertions, 3 deletions
diff --git a/app/js/services.js b/app/js/services.js
index d18e923..8dbd1b2 100644
--- a/app/js/services.js
+++ b/app/js/services.js
@@ -9,7 +9,7 @@ app.service('pathService', function() {
var dy = point1.y - point2.y;
return Math.sqrt(dx * dx + dy * dy);
},
- computePlaylist: function(songList, line, duration) {
+ computePlaylistOld: function(songList, line, duration) {
//compute distances from the constrain path
console.log('length', line.length);
@@ -29,7 +29,39 @@ app.service('pathService', function() {
});
});
return selection;
- }
+ },
+ computePlaylist:function(songList, line, duration) {
+ //compute distances from the constrain path
+
+ var threshold = 60;
+ for(var i=songList.length-1; i>0; i--){
+ songList[i].selected = false;
+ };
+ var songCopy = songList.slice(0);
+ songCopy.sort(function(a,b){return a.x-b.x;});
+
+ var selection = [];
+ for(var i=line.length-1; i>0; i--) {
+ var point = line[i];
+ var min = line[i].x-threshold;
+ var max = line[i].x+threshold;
+ var j=songCopy.length-1;
+ while(songCopy[j].x > max && j > 0){
+ j--;
+ }
+ while(songCopy[j].x > min && j > 0){
+ var song = songCopy[j];
+ var d = self.dist(song, point);
+ if (d < threshold) {
+ songCopy.splice(j,1);
+ selection.push(song);
+ song.selected = true;
+ }
+ j--;
+ };
+ };
+ return selection;
+ }
};
return self;
});
@@ -39,12 +71,13 @@ app.service('musicPlayer', function() {
startSongWithDuration: function(id, duration)
{
$('#ytplayer').attr('src', 'https://www.youtube.com/embed/' + id + '?autoplay=1&modestbranding=1');
- self.musicTimer = setInterval(changeSong, duration * 1000);
+ self.musicTimer = setInterval(self.changeSong, duration * 1000);
},
changeSong: function()
{
clearInterval(self.musicTimer);
}
};
+
return self;
});