PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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