/flash/echo-nest-flash-api/examples/javascript/index.html

http://echo-nest-remix.googlecode.com/ · HTML · 156 lines · 134 code · 22 blank · 0 comment · 0 complexity · b196c6e2c17446a6939e3be5763f02fd MD5 · raw file

  1. <html>
  2. <head>
  3. <title>remix</title>
  4. <script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js" type="text/javascript"></script>
  5. <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script>
  6. <style type="text/css">
  7. body {
  8. font-family: helvetica, arial, sans-serif;
  9. font-size: 14px;
  10. margin: 20px 40px 0 40px;
  11. }
  12. #progress-wrapper {
  13. position: absolute;
  14. top: 0px;
  15. left: 0px;
  16. width: 100%;
  17. height: 20px;
  18. background-color: #222222;
  19. }
  20. #progress {
  21. height: 100%;
  22. background-color: #00aeef;
  23. width: 50%;
  24. }
  25. h1 {
  26. position: relative;
  27. font-size: 110px;
  28. margin-top: 40px;
  29. margin-bottom: 40px;
  30. }
  31. #left {
  32. width: 400px;
  33. float: left;
  34. margin-right: 20px;
  35. }
  36. img {
  37. border: none;
  38. }
  39. a {
  40. color: #000000;
  41. }
  42. a:hover {
  43. background-color: #222222;
  44. color: #ffffff;
  45. }
  46. textarea {
  47. border: 8px solid #eeeeee;
  48. padding: 6px;
  49. font-family: monospace;
  50. font-size: 14px;
  51. outline: none;
  52. }
  53. </style>
  54. <script type="text/javascript">
  55. var Remix = {
  56. __init: function() {
  57. this._swf = document.getElementById('swf');
  58. },
  59. __setAnalysis: function(analysis) {
  60. this.analysis = analysis;
  61. },
  62. __remix: function() {
  63. try {
  64. eval($('remixJs').value);
  65. }
  66. catch(e) {
  67. alert(e);
  68. return;
  69. }
  70. if (remix == null) {
  71. alert('remix function not found!');
  72. return;
  73. }
  74. try {
  75. var sampleRanges = remix(this.analysis);
  76. this._swf.setRemixJson(Object.toJSON(sampleRanges))
  77. }
  78. catch (e) {
  79. alert(e);
  80. }
  81. },
  82. __setProgress: function(progress) {
  83. $('progress').style.width = 100 * progress + '%';
  84. },
  85. _scriptLoaded: function() {
  86. if (remix) {
  87. $('remixJs').value = remix;
  88. }
  89. else {
  90. alert('Remix function not found in script.');
  91. }
  92. },
  93. _loadScript: function() {
  94. remix = null;
  95. document.write('<script src="' + location.hash.substring(1) + '" onload="Remix._scriptLoaded();"><' + '/script>');
  96. }
  97. };
  98. </script>
  99. </head>
  100. <body>
  101. <div id="progress-wrapper"><div id="progress" style="width: 0%;"></div></div>
  102. <h1>Remix</h1>
  103. <div id="left">
  104. <div id="swf"></div>
  105. <p>Edit songs with JavaScript and <a href="http://echonest.com">The Echo Nest</a>.</p>
  106. <p>Created by <a href="http://ryanberdeen.com">Ryan Berdeen</a>.</p>
  107. <p>Bugs, feedback, etc: <a href="mailto:remix@ryanberdeen.com">remix@ryanberdeen.com</a></p>
  108. <div id="credit"><a href="http://echonest.com"><img src="http://the.echonest.com/media/images/logos/140x50_lt.gif" alt="Powered By The Echo Nest"></a></div>
  109. </div>
  110. <textarea id="remixJs" rows="20" cols="60">function remix (analysis) {
  111. var bars = analysis.bars;
  112. var beats = analysis.beats;
  113. var beatIndex = 0;
  114. var samples = [];
  115. for (var i = 0; i < bars.length; i++) {
  116. while (beatIndex < beats.length - 1 &&
  117. beats[beatIndex].value != bars[i].value) {
  118. beatIndex++;
  119. }
  120. samples.push(
  121. beats[beatIndex].value,
  122. beats[beatIndex + 1].value
  123. );
  124. }
  125. return samples;
  126. }</textarea>
  127. <script type="text/javascript">
  128. swfobject.embedSWF('player.swf', 'swf', '400', '120', '9.0.0');
  129. if (location.hash) {
  130. Remix._loadScript();
  131. }
  132. </script>
  133. </body>
  134. </html>