Daniel@0
|
1 /* global Backbone */
|
Daniel@0
|
2 'use strict';
|
Daniel@0
|
3
|
Daniel@0
|
4 App.addInitializer(function(options){
|
Daniel@0
|
5 // http://stackoverflow.com/questions/19491336/get-url-parameter-jquery
|
Daniel@0
|
6 function getUrlParameter(sParam)
|
Daniel@0
|
7 {
|
Daniel@0
|
8 var sPageURL = window.location.search.substring(1);
|
Daniel@0
|
9 var sURLVariables = sPageURL.split('&');
|
Daniel@0
|
10 for (var i = 0; i < sURLVariables.length; i++)
|
Daniel@0
|
11 {
|
Daniel@0
|
12 var sParameterName = sURLVariables[i].split('=');
|
Daniel@0
|
13 if (sParameterName[0] == sParam)
|
Daniel@0
|
14 {
|
Daniel@0
|
15 return sParameterName.length == 2 ? sParameterName[1] : "";
|
Daniel@0
|
16 }
|
Daniel@0
|
17 }
|
Daniel@0
|
18 };
|
Daniel@0
|
19
|
Daniel@0
|
20 var screenshotParameterValue = getUrlParameter("screenshot");
|
Daniel@0
|
21 if (screenshotParameterValue === undefined) {
|
Daniel@0
|
22 return;
|
Daniel@0
|
23 }
|
Daniel@0
|
24
|
Daniel@0
|
25 console.log("Running in screenshot mode: " + screenshotParameterValue);
|
Daniel@0
|
26 App.options.vegaRenderer = "canvas";
|
Daniel@0
|
27 window.devicePixelRatio = 2;
|
Daniel@0
|
28
|
Daniel@0
|
29
|
Daniel@0
|
30 //
|
Daniel@0
|
31 var $html = $("html");
|
Daniel@0
|
32 $html.addClass("screenshot");
|
Daniel@0
|
33 var screenshotTypes = _.invert(screenshotParameterValue.replace(/%7C/g, "|").split("|"));
|
Daniel@0
|
34 _.each(_.keys(screenshotTypes), function(screenshotType) {
|
Daniel@0
|
35 $html.addClass("screenshot_" + screenshotType);
|
Daniel@0
|
36 var wh = screenshotType.split("x");
|
Daniel@0
|
37 if (wh.length == 2) {
|
Daniel@0
|
38 var w = parseInt(wh[0]);
|
Daniel@0
|
39 var h = parseInt(wh[1]);
|
Daniel@0
|
40 if (w && h) {
|
Daniel@0
|
41 $("body").css({
|
Daniel@0
|
42 "width": w,
|
Daniel@0
|
43 "height": h,
|
Daniel@0
|
44 });
|
Daniel@0
|
45 }
|
Daniel@0
|
46 }
|
Daniel@0
|
47 });
|
Daniel@0
|
48
|
Daniel@0
|
49 var intervalId = setInterval(function() {
|
Daniel@0
|
50 var ready = true;
|
Daniel@0
|
51 //
|
Daniel@0
|
52 // var $vegas = $(".vega");
|
Daniel@0
|
53 // if (!$vegas.length) {
|
Daniel@0
|
54 // return;
|
Daniel@0
|
55 // }
|
Daniel@0
|
56 // $vegas.each(function() {
|
Daniel@0
|
57 // var $this = $(this);
|
Daniel@0
|
58 // var tagName = $this.children().eq(0).prop("tagName").toLowerCase();
|
Daniel@0
|
59 // if (tagName !== "svg" && tagName !== "canvas") {
|
Daniel@0
|
60 // ready = false;
|
Daniel@0
|
61 // return false;
|
Daniel@0
|
62 // }
|
Daniel@0
|
63 // });
|
Daniel@0
|
64
|
Daniel@0
|
65 if (screenshotTypes["state_interface"]) {
|
Daniel@0
|
66
|
Daniel@0
|
67 }
|
Daniel@0
|
68
|
Daniel@0
|
69 if (ready) {
|
Daniel@0
|
70 if (screenshotTypes["state_interface"]) {
|
Daniel@0
|
71 //App.PlayerModule.$jPlayer.jPlayer("play", 42);
|
Daniel@0
|
72 //$(".player__slider-head_type_time").show();
|
Daniel@0
|
73 $(".player__slider-head_type_time")
|
Daniel@0
|
74 .show()
|
Daniel@0
|
75 .css("width", "100%");
|
Daniel@0
|
76 $(".player__time_type_before")
|
Daniel@0
|
77 .text("00:42");
|
Daniel@0
|
78 $(".player__time_type_after")
|
Daniel@0
|
79 .text("−01:59");
|
Daniel@0
|
80
|
Daniel@0
|
81 //$(".player__slider-head_type_time").show();
|
Daniel@0
|
82 }
|
Daniel@0
|
83
|
Daniel@0
|
84 if (screenshotTypes["state_flip"]) {
|
Daniel@0
|
85 var frame = 1;
|
Daniel@0
|
86 for (var i = 2; i < 7; i++) {
|
Daniel@0
|
87 if (screenshotTypes["frame_" + i]) {
|
Daniel@0
|
88 frame = i;
|
Daniel@0
|
89 }
|
Daniel@0
|
90 }
|
Daniel@0
|
91 if (frame >= 2 && frame <= 5) {
|
Daniel@0
|
92 App.context.get("state").set("musicRecordingsGridIsShown", true);
|
Daniel@0
|
93 setTimeout(function() {
|
Daniel@0
|
94 allDone();
|
Daniel@0
|
95 }, frame * 50);
|
Daniel@0
|
96 }
|
Daniel@0
|
97 return;
|
Daniel@0
|
98 }
|
Daniel@0
|
99
|
Daniel@0
|
100 allDone();
|
Daniel@0
|
101 }
|
Daniel@0
|
102 }, 5000);
|
Daniel@0
|
103
|
Daniel@0
|
104 var allDone = function() {
|
Daniel@0
|
105 window.status = "screenshot_ready";
|
Daniel@0
|
106 console.log("screenshot is ready");
|
Daniel@0
|
107 clearInterval(intervalId);
|
Daniel@0
|
108 }
|
Daniel@0
|
109
|
Daniel@0
|
110 //
|
Daniel@0
|
111 if (screenshotTypes["state_interface"]) {
|
Daniel@0
|
112 App.context.get("state").unserialize(JSON.parse('{"musicCollectionGrid":{"entityConfigs":[{"clientId":"cf1647","parameters":{"library":"bl","composer":"Mozart","year":"","performer":"","title":"Symphony; 41","collection":"","place":""},"plannedParameterUpdates":{}},{"clientId":"cf544","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf562","parameters":{"library":"bl","title":"Symphony; 40","year":"","composer":"Mozart","performer":"","place":"","collection":""},"plannedParameterUpdates":{"year":"1970-1979","title":"Sonata"}},{"clientId":"cf170","parameters":{"library":"charm","title":"","year":"","composer":"Mozart","performer":"","recordingURI":"http://dml.org/charm/2378"},"plannedParameterUpdates":{}},{"clientId":"cf224","parameters":{},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"custom17","parameters":{"kind":"list","limit":"10","offset":"6","sortBy":"label"},"plannedParameterUpdates":{}},{"clientId":"cf1783","parameters":{"kind":"tonic-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf780","parameters":{"kind":"key-relative-chord-seq","sequenceCount":"50","sequenceRepresentation":"parallel-coordinates","chordGrouppingIsByType":"1","guidesAreVisible":"1","recordingsInMajorModeAreIncluded":"1","recordingsInMinorModeAreIncluded":"1","chordTypesArePopularOnly":"","chordSequencesWithCyclesAreIncluded":"1","nIsIncluded":"","sequenceStepCount":"5"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf562","selectedViewConfigClientId":"cf780","entityWidth":260},"musicRecordingGrid":{"entityConfigs":[{"clientId":"cf204","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1LP0181227XX-0200V0"},"plannedParameterUpdates":{}},{"clientId":"cf209","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1LP0163217XX-0100V0"},"plannedParameterUpdates":{}},{"clientId":"cf214","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1CL0046563XX-0100V0"},"plannedParameterUpdates":{}},{"clientId":"cf219","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1LP0163226XX-0100V0"},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"def4","parameters":{"kind":"properties"},"plannedParameterUpdates":{}},{"clientId":"def5","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}}]}}'))
|
Daniel@0
|
113 App.play("http://dml.org/charm/2378");
|
Daniel@0
|
114 var $fakeMouse = $.bem.generateElement("screenshot", "fake-cursor");
|
Daniel@0
|
115 $fakeMouse.css({
|
Daniel@0
|
116 "left": 335,
|
Daniel@0
|
117 "top": 430,
|
Daniel@0
|
118 });
|
Daniel@0
|
119 $("body").append($fakeMouse);
|
Daniel@0
|
120
|
Daniel@0
|
121 $fakeMouse.on("mouseover", function(event){
|
Daniel@0
|
122 console.log("here", arguments, $fakeMouse);
|
Daniel@0
|
123 event.pageX = 335;
|
Daniel@0
|
124 event.pageY = 430;
|
Daniel@0
|
125 App.TooltipModule.update(event, "C# → 15", $fakeMouse);
|
Daniel@0
|
126
|
Daniel@0
|
127 });
|
Daniel@0
|
128 $fakeMouse.trigger("mouseover");
|
Daniel@0
|
129
|
Daniel@0
|
130 }
|
Daniel@0
|
131 var teaserEntityWidth = 200;
|
Daniel@0
|
132 if (screenshotTypes["state_teaser"]) {
|
Daniel@0
|
133 //App.context.get("state").unserialize(JSON.parse('{"musicCollectionGrid":{"entityConfigs":[{"clientId":"cf1647","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"uganda","place":""},"plannedParameterUpdates":{}},{"clientId":"cf544","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf1681","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"dinka","place":""},"plannedParameterUpdates":{}},{"clientId":"cf660","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf602","parameters":{"kind":"pair","comparisonMode":"direct"},"plannedParameterUpdates":{}},{"clientId":"cf718","parameters":{"library":"bl","composer":"schoenberg","year":"","performer":"","title":"","place":"","collection":""},"plannedParameterUpdates":{}},{"clientId":"cf480","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"symphony","place":"","collection":""},"plannedParameterUpdates":{}},{"clientId":"cf418","parameters":{"library":"bl","title":"piano","year":"","composer":"","performer":"","place":"","collection":""},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"custom16","parameters":{"kind":"list"},"plannedParameterUpdates":{}},{"clientId":"custom17","parameters":{"kind":"pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"custom18","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"cf1783","parameters":{"kind":"tuning-stats","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf1872","parameters":{"kind":"mean-tempo-curve","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf780","parameters":{"kind":"pitch-class-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf481","parameters":{"kind":"tempo-histogram","tempoMin":"30","tempoMax":"300","tempoNumBins":"50","tempoPeriod":"1","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf1961","parameters":{"kind":"tonic-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf1647","selectedViewConfigClientId":"","entityWidth":' + teaserEntityWidth + '},"musicRecordingGrid":{"entityConfigs":[],"viewConfigs":[{"clientId":"def4","parameters":{"kind":"properties"},"plannedParameterUpdates":{}},{"clientId":"def5","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}}]}}'))
|
Daniel@0
|
134 App.context.get("state").unserialize(JSON.parse('{"musicCollectionGrid":{"entityConfigs":[{"clientId":"cf1647","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"uganda","place":""},"plannedParameterUpdates":{}},{"clientId":"cf544","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf1681","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"dinka","place":""},"plannedParameterUpdates":{}},{"clientId":"cf660","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf602","parameters":{"kind":"pair","comparisonMode":"direct"},"plannedParameterUpdates":{}},{"clientId":"cf718","parameters":{"library":"bl","composer":"schoenberg","year":"","performer":"","title":"","place":"","collection":""},"plannedParameterUpdates":{}},{"clientId":"cf480","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"symphony","place":"","collection":""},"plannedParameterUpdates":{}},{"clientId":"cf418","parameters":{"library":"bl","title":"piano","year":"","composer":"","performer":"","place":"","collection":""},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"custom17","parameters":{"kind":"pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"custom18","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"cf1783","parameters":{"kind":"tuning-stats","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf780","parameters":{"kind":"pitch-class-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf481","parameters":{"kind":"tempo-histogram","tempoMin":"30","tempoMax":"300","tempoNumBins":"50","tempoPeriod":"1","widthToHeightRatio":"2"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf1647","entityWidth":200},"musicRecordingGrid":{"entityConfigs":[],"viewConfigs":[{"clientId":"def4","parameters":{"kind":"properties"},"plannedParameterUpdates":{}},{"clientId":"def5","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}}]}}'))
|
Daniel@0
|
135 }
|
Daniel@0
|
136 if (screenshotTypes["state_teaser-wo-piano"]) {
|
Daniel@0
|
137 App.context.get("state").unserialize(JSON.parse('{"musicCollectionGrid":{"entityConfigs":[{"clientId":"cf1647","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"uganda","place":""},"plannedParameterUpdates":{}},{"clientId":"cf544","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf1681","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"","collection":"dinka","place":""},"plannedParameterUpdates":{}},{"clientId":"cf660","parameters":{"kind":"pair","comparisonMode":"superposition"},"plannedParameterUpdates":{}},{"clientId":"cf602","parameters":{"kind":"pair","comparisonMode":"direct"},"plannedParameterUpdates":{}},{"clientId":"cf718","parameters":{"library":"bl","composer":"schoenberg","year":"","performer":"","title":"","place":"","collection":""},"plannedParameterUpdates":{}},{"clientId":"cf480","parameters":{"library":"bl","composer":"","year":"","performer":"","title":"symphony","place":"","collection":""},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"custom16","parameters":{"kind":"list"},"plannedParameterUpdates":{}},{"clientId":"custom17","parameters":{"kind":"pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"custom18","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"cf1783","parameters":{"kind":"tuning-stats","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf1872","parameters":{"kind":"mean-tempo-curve","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf780","parameters":{"kind":"pitch-class-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf481","parameters":{"kind":"tempo-histogram","tempoMin":"30","tempoMax":"300","tempoNumBins":"50","tempoPeriod":"1","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf1961","parameters":{"kind":"tonic-histogram","widthToHeightRatio":"2"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf1647","selectedViewConfigClientId":"","entityWidth":' + teaserEntityWidth + '},"musicRecordingGrid":{"entityConfigs":[],"viewConfigs":[{"clientId":"def4","parameters":{"kind":"properties"},"plannedParameterUpdates":{}},{"clientId":"def5","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}}]}}'));
|
Daniel@0
|
138 }
|
Daniel@0
|
139
|
Daniel@0
|
140 if (screenshotTypes["state_flip"]) {
|
Daniel@0
|
141 var musicRecordingsGridIsShown = screenshotTypes["frame_6"] ? true : false;
|
Daniel@0
|
142 App.context.get("state").unserialize(JSON.parse('{"musicRecordingsGridIsShown":' + musicRecordingsGridIsShown + ',"musicCollectionGrid":{"entityConfigs":[{"clientId":"cf1647","parameters":{"library":"charm","composer":"Mozart","year":"","performer":"","title":""},"plannedParameterUpdates":{}},{"clientId":"cf562","parameters":{"library":"charm","title":"","year":"","composer":"Haydn","performer":""},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"custom17","parameters":{"kind":"list","limit":"10","offset":"6","sortBy":"label"},"plannedParameterUpdates":{}},{"clientId":"cf1783","parameters":{"kind":"tempo-histogram","widthToHeightRatio":"2","tempoMin":"30","tempoMax":"300","tempoNumBins":"50","tempoPeriod":"1"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf1647","selectedViewConfigClientId":"cf1783","entityWidth":260},"musicRecordingGrid":{"entityConfigs":[{"clientId":"cf209","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1LP0163217XX-0100V0"},"plannedParameterUpdates":{}},{"clientId":"cf471","parameters":{"kind":"pair","comparisonMode":"direct"},"plannedParameterUpdates":{}},{"clientId":"cf219","parameters":{"recordingURI":"http://sounds.bl.uk/resource/026M-1LP0163226XX-0100V0"},"plannedParameterUpdates":{}}],"viewConfigs":[{"clientId":"def5","parameters":{"kind":"midi-pitch-histogram"},"plannedParameterUpdates":{}},{"clientId":"cf397","parameters":{"kind":"tempo-nonuniform","widthToHeightRatio":"2"},"plannedParameterUpdates":{}},{"clientId":"cf494","parameters":{"kind":"tempo-normalised","widthToHeightRatio":"2"},"plannedParameterUpdates":{}}],"selectedEntityConfigClientId":"cf471","selectedViewConfigClientId":"cf494","entityWidth":220}}'));
|
Daniel@0
|
143 }
|
Daniel@0
|
144
|
Daniel@0
|
145
|
Daniel@0
|
146
|
Daniel@0
|
147 var resizeIfNeededAfterADelay = function() {
|
Daniel@0
|
148 setInterval(function() {
|
Daniel@0
|
149 if (screenshotTypes["autosize_grid"] || screenshotTypes["autosize"]) {
|
Daniel@0
|
150 var $configGrid = $(".config-grid:visible");
|
Daniel@0
|
151 var $cellsSpace = $configGrid.find(".config-grid-cells__space");
|
Daniel@0
|
152 var maxX = 0;
|
Daniel@0
|
153 var maxY = 0;
|
Daniel@0
|
154 var $visInstances = $cellsSpace.find(".config-grid-cells__vis-instance");
|
Daniel@0
|
155 if (!$visInstances.length) {
|
Daniel@0
|
156 resizeIfNeededAfterADelay();
|
Daniel@0
|
157 return;
|
Daniel@0
|
158 }
|
Daniel@0
|
159 $visInstances.each(function() {
|
Daniel@0
|
160 var $visInstance = $(this);
|
Daniel@0
|
161 var position = $visInstance.position();
|
Daniel@0
|
162 var currentMaxX = position.left + $visInstance.width();
|
Daniel@0
|
163 var currentMaxY = position.top + $visInstance.height();
|
Daniel@0
|
164 if (currentMaxX > maxX) {
|
Daniel@0
|
165 maxX = currentMaxX;
|
Daniel@0
|
166 }
|
Daniel@0
|
167 if (currentMaxY > maxY) {
|
Daniel@0
|
168 maxY = currentMaxY;
|
Daniel@0
|
169 }
|
Daniel@0
|
170 });
|
Daniel@0
|
171 $cellsSpace.css({
|
Daniel@0
|
172 "padding-right": 0,
|
Daniel@0
|
173 "padding-bottom": 0,
|
Daniel@0
|
174 "width": maxX,
|
Daniel@0
|
175 "height": maxY,
|
Daniel@0
|
176 "overflow": "visible"
|
Daniel@0
|
177 });
|
Daniel@0
|
178
|
Daniel@0
|
179
|
Daniel@0
|
180
|
Daniel@0
|
181 if (screenshotTypes["autosize"]) {
|
Daniel@0
|
182 var $body = $("body");
|
Daniel@0
|
183 $body.width ($cellsSpace.offset().left + $cellsSpace.outerWidth());
|
Daniel@0
|
184 $body.height($cellsSpace.offset().top + $cellsSpace.outerHeight());
|
Daniel@0
|
185 // var $html = $("html");
|
Daniel@0
|
186 // $html.width ($cellsSpace.offset().left + $cellsSpace.outerWidth());
|
Daniel@0
|
187 // $html.height($cellsSpace.offset().top + $cellsSpace.outerHeight());
|
Daniel@0
|
188 }
|
Daniel@0
|
189
|
Daniel@0
|
190 // console.log("VIEWPORT" + document.documentElement.clientWidth + " / " + document.documentElement.clientWidth);
|
Daniel@0
|
191 // console.log("BODY" + $body.width() + " / " + $body.height() );
|
Daniel@0
|
192 };
|
Daniel@0
|
193 }, 100);
|
Daniel@0
|
194 };
|
Daniel@0
|
195 resizeIfNeededAfterADelay();
|
Daniel@0
|
196 $(window).resize(resizeIfNeededAfterADelay);
|
Daniel@0
|
197 });
|