UNPKG

essentia.js

Version:

JavaScript library for music/audio analysis and processing, powered by Essentia WebAssembly

35 lines (32 loc) 5.47 kB
var EssentiaPlot=function(t){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,i)};function i(t,i){function o(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)} /** * @license * Copyright (C) 2006-2020 Music Technology Group - Universitat Pompeu Fabra * * This file is part of Essentia * * Essentia is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation (FSF), either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the Affero GNU General Public License * version 3 along with this program. If not, see http://www.gnu.org/licenses/ */var o={isPlotting:!1,startTimeIndex:0},r={title:"Melody Contour",plot_bgcolor:"transparent",paper_bgcolor:"#FCF7F7",autosize:!1,width:670,height:300,xaxis:{type:"time",title:"Time"},yaxis:{autorange:!1,range:[30,3e3],type:"linear",title:"Frequency (Hz)"}},a={title:"",plot_bgcolor:"transparent",paper_bgcolor:"#FCF7F7",autosize:!1,width:670,height:300,xaxis:{title:"Time",autorange:!0,time:"Time"},yaxis:{title:"Bands",range:null,type:"linear"}},n=function(){function t(t,e){void 0===e&&(e=o),this.Plotly=t,this.options=e,this.isPlotting=e.isPlotting,this.startTimeIndex=e.startTimeIndex}return t.prototype.makeLinearSpace=function(t,e,i){if(void 0===i&&(i=Math.max(Math.round(e-t)+1,1)),i<2)return 1===i?[t]:[];var o,r=Array(i);for(o=--i;o>=0;o--)r[o]=(o*e+(i-o)*t)/i;return r},t}(),s=function(t){function e(e,i,o){void 0===o&&(o=r);var a=t.call(this,e)||this;return a.Plotly=e,a.divId=i,a.plotLayout=o,a}return i(e,t),e.prototype.create=function(t,e,i,o){this.plotLayout.title=e;var r=this.makeLinearSpace(this.startTimeIndex,i/o,t.length);this.isPlotting?(r=this.makeLinearSpace(this.startTimeIndex,this.startTimeIndex+i/o,t.length),this.startTimeIndex=r[r.length-1],this.Plotly.extendTraces(this.divId,{x:[r],y:[t]},[0])):(this.Plotly.newPlot(this.divId,[{x:r,y:t,mode:"lines",line:{color:"#2B6FAC",width:2}}],this.plotLayout),this.isPlotting=!0,this.startTimeIndex=r[r.length-1])},e.prototype.destroy=function(){this.Plotly.deleteTraces(this.divId,0),this.isPlotting=!1,this.startTimeIndex=0},e}(n),l=function(t){function e(e,i,o,r){void 0===o&&(o="chroma"),void 0===r&&(r=a);var n=t.call(this,e)||this;if(n.Plotly=e,n.divId=i,n.plotType=o,n.plotLayout=r,"chroma"===o)n.yAxis=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];else{if("spectrogram"!==o)throw"Invalid value for argument 'plotType'. Should be either 'chroma' or 'spectrogram'";n.yAxis=null}return n}return i(e,t),e.prototype.create=function(t,e,i,o,r,a){if(void 0===a&&(a="Jet"),this.plotLayout.title=e,"spectrogram"===this.plotType){var n=t[0].length;this.plotLayout.yaxis.range=[0,n+1]}if(this.isPlotting){s=void 0,l=void 0;if(t[0].constructor!==Array&&t[0].constructor!==Float32Array)throw"Got 1D array as input, expect a 2D array...";1==t.length?(s=t,l=[this.startTimeIndex+r/o,this.startTimeIndex+i/o]):(s=t,l=this.makeLinearSpace(this.startTimeIndex,i/o,s.length)),this.startTimeIndex=l[l.length-1],this.Plotly.extendTraces(this.divId,{x:[l],z:[t]},[0])}else{var s=void 0,l=void 0;if(t[0].constructor!==Array&&t[0].constructor!==Float32Array)throw"Got 1D array as input, expect a 2D array...";1==t.length?(s=t,l=[this.startTimeIndex+r/o,this.startTimeIndex+i/o]):(s=t,l=this.makeLinearSpace(this.startTimeIndex,i/o,s.length));var h={x:l,y:this.yAxis,z:s,colorscale:a,type:"heatmap",transpose:!0};this.Plotly.newPlot(this.divId,[h],this.plotLayout),this.isPlotting=!0,this.startTimeIndex=l[l.length-1]}},e.prototype.destroy=function(){this.Plotly.deleteTraces(this.divId,0),this.isPlotting=!1,this.startTimeIndex=0},e}(n);return t.EssentiaPlot=n,t.LayoutChromaPlot={title:"",plot_bgcolor:"transparent",paper_bgcolor:"#FCF7F7",autosize:!1,width:670,height:300,xaxis:{autorange:!0,time:"Time",title:"Time"},yaxis:{title:"Pitch class",range:[0,11]}},t.LayoutMelodyContourPlot=r,t.LayoutSpectrogramPlot=a,t.PlotConfig=o,t.PlotHeatmap=l,t.PlotMelodyContour=s,Object.defineProperty(t,"__esModule",{value:!0}),t}({});