/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
- <html>
- <head>
- <title>remix</title>
- <script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js" type="text/javascript"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script>
- <style type="text/css">
- body {
- font-family: helvetica, arial, sans-serif;
- font-size: 14px;
- margin: 20px 40px 0 40px;
- }
- #progress-wrapper {
- position: absolute;
- top: 0px;
- left: 0px;
- width: 100%;
- height: 20px;
- background-color: #222222;
- }
- #progress {
- height: 100%;
- background-color: #00aeef;
- width: 50%;
- }
- h1 {
- position: relative;
- font-size: 110px;
- margin-top: 40px;
- margin-bottom: 40px;
- }
- #left {
- width: 400px;
- float: left;
- margin-right: 20px;
- }
- img {
- border: none;
- }
- a {
- color: #000000;
- }
- a:hover {
- background-color: #222222;
- color: #ffffff;
- }
- textarea {
- border: 8px solid #eeeeee;
- padding: 6px;
- font-family: monospace;
- font-size: 14px;
- outline: none;
- }
- </style>
- <script type="text/javascript">
- var Remix = {
- __init: function() {
- this._swf = document.getElementById('swf');
- },
- __setAnalysis: function(analysis) {
- this.analysis = analysis;
- },
- __remix: function() {
- try {
- eval($('remixJs').value);
- }
- catch(e) {
- alert(e);
- return;
- }
- if (remix == null) {
- alert('remix function not found!');
- return;
- }
- try {
- var sampleRanges = remix(this.analysis);
- this._swf.setRemixJson(Object.toJSON(sampleRanges))
- }
- catch (e) {
- alert(e);
- }
- },
- __setProgress: function(progress) {
- $('progress').style.width = 100 * progress + '%';
- },
- _scriptLoaded: function() {
- if (remix) {
- $('remixJs').value = remix;
- }
- else {
- alert('Remix function not found in script.');
- }
- },
- _loadScript: function() {
- remix = null;
- document.write('<script src="' + location.hash.substring(1) + '" onload="Remix._scriptLoaded();"><' + '/script>');
- }
- };
- </script>
- </head>
- <body>
- <div id="progress-wrapper"><div id="progress" style="width: 0%;"></div></div>
- <h1>Remix</h1>
- <div id="left">
- <div id="swf"></div>
- <p>Edit songs with JavaScript and <a href="http://echonest.com">The Echo Nest</a>.</p>
- <p>Created by <a href="http://ryanberdeen.com">Ryan Berdeen</a>.</p>
- <p>Bugs, feedback, etc: <a href="mailto:remix@ryanberdeen.com">remix@ryanberdeen.com</a></p>
- <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>
- </div>
- <textarea id="remixJs" rows="20" cols="60">function remix (analysis) {
- var bars = analysis.bars;
- var beats = analysis.beats;
- var beatIndex = 0;
- var samples = [];
- for (var i = 0; i < bars.length; i++) {
- while (beatIndex < beats.length - 1 &&
- beats[beatIndex].value != bars[i].value) {
- beatIndex++;
- }
- samples.push(
- beats[beatIndex].value,
- beats[beatIndex + 1].value
- );
- }
- return samples;
- }</textarea>
- <script type="text/javascript">
- swfobject.embedSWF('player.swf', 'swf', '400', '120', '9.0.0');
- if (location.hash) {
- Remix._loadScript();
- }
- </script>
- </body>
- </html>