source: main/trunk/model-sites-dev/multimodal-mdl/collect/js-dsp-my-ipod/script/hybrid-audio-player.js@ 28433

Last change on this file since 28433 was 28433, checked in by davidb, 11 years ago

Further collections to add to the set

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1
2Element.prototype.getElementWidth = function() {
3 if (typeof this.clip !== "undefined") {
4 return this.clip.width;
5 } else {
6 if (this.style.pixelWidth) {
7 return this.style.pixelWidth;
8 } else {
9 return this.offsetWidth;
10 }
11 }
12};
13
14Element.prototype.getElementHeight = function() {
15 if (typeof this.clip !== "undefined") {
16 return this.clip.height;
17 } else {
18 if (this.style.pixelHeight) {
19 return this.style.pixelHeight;
20 } else {
21 return this.offsetHeight;
22 }
23 }
24};
25
26
27function isDefined(v) {
28 return typeof v !== "undefined";
29}
30
31/* // ***** */
32/* Move above in to more general header file */
33
34
35// Useful shorthands
36var SVG_NS ="http://www.w3.org/2000/svg";
37var XLINK_NS = "http://www.w3.org/1999/xlink";
38
39
40var hasStructuredAudio = false;
41var hasChromaSelfSimMap = false;
42
43var allData = null;
44var yScaleSimImg = null;
45var caAlgorithm = null;
46var duration = null;
47
48
49// ******
50// * Frequency Player/Plotter part of Hybrid Player
51// ******
52
53function freqPlayerAudioPlay(event)
54{
55 console.info("Audio play pressed");
56
57 if (audioMode == "stopped") {
58 // Nolonger used (Firefox fails to fire this event on a fresh 'play' once an existing play has finished)
59
60 // take a fresh snapshot of the transform mode selected in the web page
61
62 //var transformMode = $('input:radio[name=visualization]:checked').val();
63 //chromaTransform.setTransformMode(transformMode);
64
65 }
66 audioMode = "playing";
67}
68
69function freqPlayerAudioPause()
70{
71 console.info("Audio pause pressed");
72 audioMode = "paused";
73
74 // if stoping dualPlay
75 leftSong.pause();
76 rightSong.pause();
77 baseSong.volume = 1.0;
78
79}
80
81function freqPlayerAudioEnded()
82{
83 console.info("Audio play/playlist ended");
84 console.log("reset freq plot called");
85
86 audioMode = "stopped";
87 needsRefresh = true;
88
89 frequencyPlotter.reset();
90
91}
92
93// ******
94// * Meandre (server-side) workflow part of Hybrid Player
95// ******
96//
97// Started when 'play' is pressed
98
99// (workflows now in their own folder '$httpCollection/script/meandre-workflow/*.js)
100// the global variable 'meandreWorkflows' stores which flows are available
101
102
103
104
105
106// ******
107// * Structured Audio (CAA) part of Hybrid Player
108// ******
109
110function caaInit()
111{
112 // duration information is now available
113 var audio = document.getElementById('rta-audio-element');
114 duration = audio.duration;
115
116 if (!isDefined(allData)) {
117 // degenerate case
118
119 var ground_truth = []; // empty ground truth
120
121 var numSegs = 4;
122 var gap = duration/numSegs;
123
124 var label = [ "a", "b" ];
125 var val = [ 0, 1];
126
127 var equal_spacing = [];
128 for (var i=0; i<numSegs; i++) {
129 equal_spacing.push( {o: i*gap, f: i*gap+gap, l: label[i%2], a: val[i%2] } );
130 }
131
132 allData = [ ground_truth, equal_spacing ];
133
134 caAlgorithm = 1;
135 hasStructuredAudio = true;
136 }
137
138 svgGTStructuredInit();
139 svgCAStructuredInit(caAlgorithm);
140 svgAudioDBInit();
141}
142
143
144allData = gs.documentMetadata["json.data"];
145
146// ****
147
148// The following is actually the XSLT page param
149// 'p.yScaleSimImg;, which presumably automatically generates
150// gs.cgiParams.yScaleSimImg (if present). Defaults to 0.5
151
152yScaleSimImg=gs.variables.cgiargYScaleSimImg || 0.5;
153
154caAlgorithm=gs.variables.cgiargCAAlgorithm;
155
156$(function() {
157
158 var audio = document.getElementById('rta-audio-element');
159 audio.addEventListener('loadedmetadata', caaInit, false);
160
161 audio.addEventListener('MozAudioAvailable', freqPlayerAudioAvailable, false);
162 audio.addEventListener('loadedmetadata', freqPlayerLoadedAudioMetadata, false);
163
164 audio.addEventListener('play', freqPlayerAudioPlay, false);
165 audio.addEventListener('pause', freqPlayerAudioPause, false);
166 audio.addEventListener('ended', freqPlayerAudioEnded, false);
167
168});
169
Note: See TracBrowser for help on using the repository browser.