/flash/src/editor/remix.js

http://echo-nest-remix.googlecode.com/ · JavaScript · 67 lines · 57 code · 9 blank · 1 comment · 7 complexity · cd7459c1bbbbaee79e7021c001725b13 MD5 · raw file

  1. var Remix = {
  2. init: function() {
  3. swfobject.embedSWF('player.swf', 'swf', '400', '120', '9.0.0');
  4. this._remixJsElt = document.getElementById('remixJs');
  5. this._progressElt = document.getElementById('progress');
  6. // add selection and sorting functions to global scope
  7. extend(window, selection);
  8. extend(window, sorting);
  9. },
  10. __init: function() {
  11. this._swf = document.getElementById('swf');
  12. },
  13. __setAnalysis: function(analysis) {
  14. this.analysis = new AudioAnalysis(analysis);
  15. },
  16. __remix: function() {
  17. try {
  18. eval(this._remixJsElt.value);
  19. }
  20. catch(e) {
  21. alert(e);
  22. return;
  23. }
  24. if (remix == null) {
  25. alert('remix function not found!');
  26. return;
  27. }
  28. try {
  29. var aqs = remix(this.analysis);
  30. if (!aqs) {
  31. alert('remix must return an array of audio quanta');
  32. return;
  33. }
  34. if (aqs.length == 0) {
  35. alert('remix must return at least one audio quantum');
  36. return;
  37. }
  38. this.sampleRanges = [];
  39. remixDuration = 0;
  40. for (var i = 0; i < aqs.length; i++) {
  41. var aq = aqs[i];
  42. if (aq.end <= aq.start) {
  43. alert('end position ' + i + ' is not after start position');
  44. return;
  45. }
  46. remixDuration += aq.end - aq.start;
  47. this.sampleRanges.push(aq.start, aq.end);
  48. }
  49. this._swf.setRemixString(this.sampleRanges.join(','))
  50. }
  51. catch (e) {
  52. alert(e);
  53. }
  54. },
  55. __setProgress: function(progress) {
  56. this._progressElt.style.width = 100 * progress + '%';
  57. }
  58. };