Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
|
Daniel@0
|
4
|
Daniel@0
|
5 RepresentationModule.addInitializer(function(options){
|
Daniel@0
|
6
|
Daniel@0
|
7 RepresentationModule.registerMaster({
|
Daniel@0
|
8 id: "view.collection._similarity",
|
Daniel@0
|
9 inherit: "view._default",
|
Daniel@0
|
10
|
Daniel@0
|
11 options: {
|
Daniel@0
|
12 canHaveBase: true,
|
Daniel@0
|
13 widthToHeightRatio: 1,
|
Daniel@0
|
14 headerSuffixesForCompressorValues: {
|
Daniel@0
|
15 "zlib": "normalised",
|
Daniel@0
|
16 "zxd": "differential"
|
Daniel@0
|
17 },
|
Daniel@0
|
18 },
|
Daniel@0
|
19
|
Daniel@0
|
20 defaultConfigParameterValues: {
|
Daniel@0
|
21 measure: "euclidean",
|
Daniel@0
|
22 simFeaturesIncludeChords: "1",
|
Daniel@0
|
23 simFeaturesIncludeChromagram: "1",
|
Daniel@0
|
24 simFeaturesIncludeMFCC: "1",
|
Daniel@0
|
25 compressor: "zlib",
|
Daniel@0
|
26 subsampling: "1"
|
Daniel@0
|
27 },
|
Daniel@0
|
28
|
Daniel@0
|
29
|
Daniel@0
|
30 // =================================================================
|
Daniel@0
|
31 // housekeeping
|
Daniel@0
|
32
|
Daniel@0
|
33 _listSimFeatures: function(viewConfig) {
|
Daniel@0
|
34 var result = [];
|
Daniel@0
|
35 if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeChords")) {
|
Daniel@0
|
36 result.push("chords");
|
Daniel@0
|
37 }
|
Daniel@0
|
38 if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeChromagram")) {
|
Daniel@0
|
39 result.push("chromagram");
|
Daniel@0
|
40 }
|
Daniel@0
|
41 if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeMFCC")) {
|
Daniel@0
|
42 result.push("mfcc");
|
Daniel@0
|
43 }
|
Daniel@0
|
44 return result;
|
Daniel@0
|
45 },
|
Daniel@0
|
46
|
Daniel@0
|
47
|
Daniel@0
|
48 // =================================================================
|
Daniel@0
|
49 // config grid panel
|
Daniel@0
|
50
|
Daniel@0
|
51
|
Daniel@0
|
52 // -----------------------------------------------------------------
|
Daniel@0
|
53 // config grid panel - prepare
|
Daniel@0
|
54
|
Daniel@0
|
55 prepareConfigGridPanelMainArea: function(configGridPanelView) {
|
Daniel@0
|
56 configGridPanelView._$mainArea.data("$measure", configGridPanelView._$mainArea.find(".cgpma__id_compressor"));
|
Daniel@0
|
57 configGridPanelView._$mainArea.data("$subsampling", configGridPanelView._$mainArea.find(".cgpma__id_subsampling"));
|
Daniel@0
|
58
|
Daniel@0
|
59 // Parent master's behaviour
|
Daniel@0
|
60 RepresentationModule.getMasterById("view._default").prepareConfigGridPanelMainArea.apply(this, arguments);
|
Daniel@0
|
61 },
|
Daniel@0
|
62
|
Daniel@0
|
63
|
Daniel@0
|
64 // -----------------------------------------------------------------
|
Daniel@0
|
65 // config grid panel - sync
|
Daniel@0
|
66
|
Daniel@0
|
67 syncConfigGridPanelMainArea: function(configGridPanelView, instant) {
|
Daniel@0
|
68 var measure = this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "measure").toLowerCase().trim();
|
Daniel@0
|
69 var toggleValue = measure == "compression";
|
Daniel@0
|
70 configGridPanelView._$mainArea.data("$measure").toggle(toggleValue);
|
Daniel@0
|
71 configGridPanelView._$mainArea.data("$subsampling").toggle(toggleValue);
|
Daniel@0
|
72
|
Daniel@0
|
73 // Parent master's behaviour
|
Daniel@0
|
74 RepresentationModule.getMasterById("view._default").syncConfigGridPanelMainArea.apply(this, arguments);
|
Daniel@0
|
75 },
|
Daniel@0
|
76
|
Daniel@0
|
77
|
Daniel@0
|
78 // =================================================================
|
Daniel@0
|
79 // config grid header
|
Daniel@0
|
80
|
Daniel@0
|
81 _generateHeaderLabelSuffix: function(headerView) {
|
Daniel@0
|
82 var result = [" ("];
|
Daniel@0
|
83
|
Daniel@0
|
84 var simFeatures = this._listSimFeatures(headerView.options.config);
|
Daniel@0
|
85 if (simFeatures) {
|
Daniel@0
|
86 result.push("by ");
|
Daniel@0
|
87 result.push(simFeatures.join(" + "));
|
Daniel@0
|
88 } else {
|
Daniel@0
|
89 result.push("no characteristics");
|
Daniel@0
|
90 }
|
Daniel@0
|
91
|
Daniel@0
|
92 var measure = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "measure", true);
|
Daniel@0
|
93 if (measure == "euclidean") {
|
Daniel@0
|
94 result.push("; euclidean measure");
|
Daniel@0
|
95 } else if (measure == "compression") {
|
Daniel@0
|
96 var compressor = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "compressor", true);
|
Daniel@0
|
97 var compressorLabel = this.options.headerSuffixesForCompressorValues[compressor];
|
Daniel@0
|
98 if (compressorLabel) {
|
Daniel@0
|
99 result.push(_.str.sprintf("; %s compressor", compressorLabel));
|
Daniel@0
|
100 } else {
|
Daniel@0
|
101 result.push("; unknown compressor");
|
Daniel@0
|
102 };
|
Daniel@0
|
103 var subsampling = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "subsampling", true);
|
Daniel@0
|
104 if (subsampling) {
|
Daniel@0
|
105 result.push("; subsampling");
|
Daniel@0
|
106 }
|
Daniel@0
|
107 } else {
|
Daniel@0
|
108 result.push("; unknown measure");
|
Daniel@0
|
109 }
|
Daniel@0
|
110 result.push(")");
|
Daniel@0
|
111 return result.join("");
|
Daniel@0
|
112 },
|
Daniel@0
|
113
|
Daniel@0
|
114
|
Daniel@0
|
115 // =================================================================
|
Daniel@0
|
116 // vis instance rendering
|
Daniel@0
|
117
|
Daniel@0
|
118 calculateVisInstanceContentHeight: function(viewConfig, entityWidth) {
|
Daniel@0
|
119 var representation = this.getConfigParameterValueOrDefaultValue(viewConfig, "representaton", true);
|
Daniel@0
|
120 return entityWidth;
|
Daniel@0
|
121 },
|
Daniel@0
|
122
|
Daniel@0
|
123
|
Daniel@0
|
124 // -----------------------------------------------------------------
|
Daniel@0
|
125 // vis instance rendering - base
|
Daniel@0
|
126
|
Daniel@0
|
127 _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) {
|
Daniel@0
|
128 var measure = this.getConfigParameterValueOrDefaultValue(viewConfig, "measure", true);
|
Daniel@0
|
129 var result = {
|
Daniel@0
|
130 "sim_features": this._listSimFeatures(viewConfig).join(","),
|
Daniel@0
|
131 "sim_type": measure,
|
Daniel@0
|
132 "pid": "similarity"
|
Daniel@0
|
133 };
|
Daniel@0
|
134 if (measure) {
|
Daniel@0
|
135 result["sim_compressor"] = this.getConfigParameterValueOrDefaultValue(viewConfig, "compressor", true);
|
Daniel@0
|
136 result["sim_downsample"] = this.getConfigParameterValueOrDefaultValue(viewConfig, "subsampling", true);
|
Daniel@0
|
137 }
|
Daniel@0
|
138 return result;
|
Daniel@0
|
139 },
|
Daniel@0
|
140
|
Daniel@0
|
141
|
Daniel@0
|
142 _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) {
|
Daniel@0
|
143 var viewConfig = visInstanceView.options.viewConfig;
|
Daniel@0
|
144
|
Daniel@0
|
145 var options = {};
|
Daniel@0
|
146 options.comparisonMode = comparisonMode;
|
Daniel@0
|
147
|
Daniel@0
|
148 options.measure = !!this.getConfigParameterValueOrDefaultValue(viewConfig, "measure", true);
|
Daniel@0
|
149
|
Daniel@0
|
150 options.primaryColor = "#3182bd";
|
Daniel@0
|
151 options.secondaryColor = "#31a354";
|
Daniel@0
|
152
|
Daniel@0
|
153 var representation = this.getConfigParameterValueOrDefaultValue(viewConfig, "sequenceRepresentation", true);
|
Daniel@0
|
154 App.GraphicsRenderingModule.render(this.id.split(".")[2], visInstanceView.$content, this._groupDataForGraphicsRendering(visInstanceView, "base"), options);
|
Daniel@0
|
155 },
|
Daniel@0
|
156
|
Daniel@0
|
157 });
|
Daniel@0
|
158 });
|
Daniel@0
|
159 }, Logger);
|