Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: RepresentationModule.addInitializer(function(options){ Daniel@0: Daniel@0: RepresentationModule.registerMaster({ Daniel@0: id: "view.collection._similarity", Daniel@0: inherit: "view._default", Daniel@0: Daniel@0: options: { Daniel@0: canHaveBase: true, Daniel@0: widthToHeightRatio: 1, Daniel@0: headerSuffixesForCompressorValues: { Daniel@0: "zlib": "normalised", Daniel@0: "zxd": "differential" Daniel@0: }, Daniel@0: }, Daniel@0: Daniel@0: defaultConfigParameterValues: { Daniel@0: measure: "euclidean", Daniel@0: simFeaturesIncludeChords: "1", Daniel@0: simFeaturesIncludeChromagram: "1", Daniel@0: simFeaturesIncludeMFCC: "1", Daniel@0: compressor: "zlib", Daniel@0: subsampling: "1" Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // housekeeping Daniel@0: Daniel@0: _listSimFeatures: function(viewConfig) { Daniel@0: var result = []; Daniel@0: if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeChords")) { Daniel@0: result.push("chords"); Daniel@0: } Daniel@0: if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeChromagram")) { Daniel@0: result.push("chromagram"); Daniel@0: } Daniel@0: if (this.getConfigPlannedParameterValueOrDefaultValue(viewConfig, "simFeaturesIncludeMFCC")) { Daniel@0: result.push("mfcc"); Daniel@0: } Daniel@0: return result; Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // config grid panel Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // config grid panel - prepare Daniel@0: Daniel@0: prepareConfigGridPanelMainArea: function(configGridPanelView) { Daniel@0: configGridPanelView._$mainArea.data("$measure", configGridPanelView._$mainArea.find(".cgpma__id_compressor")); Daniel@0: configGridPanelView._$mainArea.data("$subsampling", configGridPanelView._$mainArea.find(".cgpma__id_subsampling")); Daniel@0: Daniel@0: // Parent master's behaviour Daniel@0: RepresentationModule.getMasterById("view._default").prepareConfigGridPanelMainArea.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // config grid panel - sync Daniel@0: Daniel@0: syncConfigGridPanelMainArea: function(configGridPanelView, instant) { Daniel@0: var measure = this.getConfigPlannedParameterValueOrDefaultValue(configGridPanelView._cachedConfig, "measure").toLowerCase().trim(); Daniel@0: var toggleValue = measure == "compression"; Daniel@0: configGridPanelView._$mainArea.data("$measure").toggle(toggleValue); Daniel@0: configGridPanelView._$mainArea.data("$subsampling").toggle(toggleValue); Daniel@0: Daniel@0: // Parent master's behaviour Daniel@0: RepresentationModule.getMasterById("view._default").syncConfigGridPanelMainArea.apply(this, arguments); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // config grid header Daniel@0: Daniel@0: _generateHeaderLabelSuffix: function(headerView) { Daniel@0: var result = [" ("]; Daniel@0: Daniel@0: var simFeatures = this._listSimFeatures(headerView.options.config); Daniel@0: if (simFeatures) { Daniel@0: result.push("by "); Daniel@0: result.push(simFeatures.join(" + ")); Daniel@0: } else { Daniel@0: result.push("no characteristics"); Daniel@0: } Daniel@0: Daniel@0: var measure = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "measure", true); Daniel@0: if (measure == "euclidean") { Daniel@0: result.push("; euclidean measure"); Daniel@0: } else if (measure == "compression") { Daniel@0: var compressor = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "compressor", true); Daniel@0: var compressorLabel = this.options.headerSuffixesForCompressorValues[compressor]; Daniel@0: if (compressorLabel) { Daniel@0: result.push(_.str.sprintf("; %s compressor", compressorLabel)); Daniel@0: } else { Daniel@0: result.push("; unknown compressor"); Daniel@0: }; Daniel@0: var subsampling = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "subsampling", true); Daniel@0: if (subsampling) { Daniel@0: result.push("; subsampling"); Daniel@0: } Daniel@0: } else { Daniel@0: result.push("; unknown measure"); Daniel@0: } Daniel@0: result.push(")"); Daniel@0: return result.join(""); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // vis instance rendering Daniel@0: Daniel@0: calculateVisInstanceContentHeight: function(viewConfig, entityWidth) { Daniel@0: var representation = this.getConfigParameterValueOrDefaultValue(viewConfig, "representaton", true); Daniel@0: return entityWidth; Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // vis instance rendering - base Daniel@0: Daniel@0: _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) { Daniel@0: var measure = this.getConfigParameterValueOrDefaultValue(viewConfig, "measure", true); Daniel@0: var result = { Daniel@0: "sim_features": this._listSimFeatures(viewConfig).join(","), Daniel@0: "sim_type": measure, Daniel@0: "pid": "similarity" Daniel@0: }; Daniel@0: if (measure) { Daniel@0: result["sim_compressor"] = this.getConfigParameterValueOrDefaultValue(viewConfig, "compressor", true); Daniel@0: result["sim_downsample"] = this.getConfigParameterValueOrDefaultValue(viewConfig, "subsampling", true); Daniel@0: } Daniel@0: return result; Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) { Daniel@0: var viewConfig = visInstanceView.options.viewConfig; Daniel@0: Daniel@0: var options = {}; Daniel@0: options.comparisonMode = comparisonMode; Daniel@0: Daniel@0: options.measure = !!this.getConfigParameterValueOrDefaultValue(viewConfig, "measure", true); Daniel@0: Daniel@0: options.primaryColor = "#3182bd"; Daniel@0: options.secondaryColor = "#31a354"; Daniel@0: Daniel@0: var representation = this.getConfigParameterValueOrDefaultValue(viewConfig, "sequenceRepresentation", true); Daniel@0: App.GraphicsRenderingModule.render(this.id.split(".")[2], visInstanceView.$content, this._groupDataForGraphicsRendering(visInstanceView, "base"), options); Daniel@0: }, Daniel@0: Daniel@0: }); Daniel@0: }); Daniel@0: }, Logger);