diff options
author | Nicolas Bornand <nicolas74@gmail.com> | 2014-05-10 18:57:48 +0200 |
---|---|---|
committer | Nicolas Bornand <nicolas74@gmail.com> | 2014-05-10 18:57:48 +0200 |
commit | 1f582e8112896c0d1f5c50946f2d462a76e28051 (patch) | |
tree | abeb2c62c511ecdb45ab85f02c71dfd5cb8be9f9 | |
parent | 2361138c1ebd43d16f3a67a18b302bdb267901fc (diff) | |
download | playGraph-1f582e8112896c0d1f5c50946f2d462a76e28051.tar.gz playGraph-1f582e8112896c0d1f5c50946f2d462a76e28051.tar.bz2 playGraph-1f582e8112896c0d1f5c50946f2d462a76e28051.zip |
add array clone in computePlaylist()
-rw-r--r-- | app/js/services.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/app/js/services.js b/app/js/services.js index 15b1e09..142254d 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -11,8 +11,9 @@ app.service('pathService', function() { }, computePlaylist: function(songList, constrainList, duration) { //compute distances from the constrain path + var songListCopy = songList.slice(0); var maxDistOverall = Number.MIN_VALUE; - angular.forEach(songList, function(song){ + angular.forEach(songListCopy, function(song){ song.minDist = Number.MAX_VALUE; for(var i=0; i<constrainList.length;i++){ var point = constrainList[i]; @@ -29,17 +30,17 @@ app.service('pathService', function() { }); //select the songs var selection = []; - while(duration > 0 && songList.length > 0){ + while(duration > 0 && songListCopy.length > 0){ //randomly select one song - var index = Math.floor(Math.random()*songList.length); - var song = songList[index]; + var index = Math.floor(Math.random()*songListCopy.length); + var song = songListCopy[index]; var tuneParameter = 2; var ratio = song.minDist/(maxDistOverall*tuneParameter); console.log(ratio); //favor the ones closer to the path var weight = 1 - ratio*ratio; if(Math.random() < weight){ - songList.splice(index, 1); + songListCopy.splice(index, 1); selection.push(song); } duration -= 10; |