/** * Copyright (c) 2023 Amphion. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ // === init data === // load data from config.js let config; const loadConfig = (data) => { config = data; // ==== Init Display ==== currentMode = Object.keys(config.pathData)[0]; currentShowingPic = config.picTypes[3]; initAlert(); initSelect("mode_id", Object.keys(config.pathData), 0); refreshOptions(); initSelect("pic_id", config.picTypes, 3, -1); // drawStepMap(baseLink + "/data/mp_all/step_encoder_output.csv"); updatePlayIcon(playMode) updateHistogram(); resetDisplay(true, true, false); defaultConfig(); } const updateHistogram = () => { drawHistogram(config.histogramData.filter((e) => e.type === "high"), "#histogram", 128, "Metrics", "Score", "left"); drawHistogram(config.histogramData.filter((e) => e.type === "low"), "#histogram2", 158, "", "Log score", "right"); } const defaultConfig = () => { // get userMode from url query const urlParams = new URLSearchParams(window.location.search); if (urlParams.has('mode')) userMode = urlParams.get('mode'); if (["basic", "advanced"].indexOf(userMode) === -1) userMode = "advanced"; setTimeout(() => { preloading(); initInterface(); }, 1000) if (localStorage.getItem('GUIDED') === 'true') return; localStorage.setItem('GUIDED', 'true'); const driver = window.driver.js.driver; const driverObj = driver({ showProgress: true, steps: [ { element: '#performance', popover: { title: 'Model Performance', description: 'Check the metrics of the model. Click rectangular to filter the best performance case.' } }, { element: '#control_panel', popover: { title: 'Control Panel', description: 'Config mode and select data here.' } }, { element: '#step_axis', popover: { title: 'Select Steps', description: 'Drag it to see the forming process of voice. Mel Spectrogram for selected steps displays on middle-top. Steps will be highlighted in left map correspondingly.' } }, { element: '#step_preview', popover: { title: 'Preview Mel Spectrogram', description: 'Drap the "Step Axis" to select a step. Drag on graph to zoom in. Click right button to reset or click a step to pin for comparison.' } }, { element: '#touch_map', popover: { title: 'Step Map', description: 'Click steps and add them to comparison area in the right.', }, }, ...(userMode === "basic" ? [ { element: '#display1_-1', popover: { title: 'Step Comparison Matrix', description: 'You can add more steps to matrix by click in left step map. Click color cell to compare two steps.' } }, ] : [ { element: '#display_10', popover: { title: 'Step Detail', description: 'You can choose up to 3 steps. Close it by click second right-top button.' } }, { element: '#mel_10', popover: { title: 'Step\'s Mel Spectrogram', description: 'Drag to zoom in. Reset by click first right-top button.', }, } ]) ] }); driverObj.drive(); } const initConfig = (path) => { fetch(path).then(response => response.json()).then(data => loadConfig(data)).catch((e) => { console.error(e); alert("Failed to load config file. Please check your network and try again.") }); } // === shortcut === const $$ = (id) => document.getElementById(id) // === init symbol === const circleD3 = d3.symbol(); const triangleD3 = d3.symbol().type(d3.symbolTriangle); const refreshIcon = ''; const closeIcon = '' const loadingDiv = `
Loading...
`; // === init global variable === let SVG; let isAlertShown = false; let targetSingers = [], sourceSongs, sourceSingers; let displaySteps = []; let currentMode, currentSong, currentTargetSinger, currentSinger; let currentShowingPic = null; let enableReference = true; let hidePitch = false; let showFrequency = [0, 100]; let hideLowFrequency = false; let userMode = "advanced"; // basic or advanced let downloadingLock = []; let availableMode = ["Step Comparison"]; // default display mode before choose user mode let gridComparison = []; // save the step in grid comparison, up to 2 allowed let gridSelected = []; // save the selected step in grid comparison, no upper limit, but only 2 will be shown let usedColorList = []; let charts = []; let darkMode = false; let zoomStart, zoomEnd; let playMode = false; let currentCard const $mel = $$("mel_card_container") const $range = $$("range") let dropdowns = [] let currentHistogram = []; let highlightStep, resetStep, hoverStep; let changeVideoTimer = []; let compareNum = 0; let lastDownload; let hoveredStep = [] let lineChangeInterval; let slow_mode_count = 0; let jumpStep = 5; const stepOpacity = 0.8; const stepStrokeWidth = 0.8; const metricsColors = [ "#4075b0", "#ee8830", "#509e3d", "#a87d9f", "#967762" ]; let samplingSteps = false; let sampledSteps = []; let samplingNum = 100;