From f1acc0992acef679d29617692daa0e46fe083b18 Mon Sep 17 00:00:00 2001 From: Jorge Marcos Date: Wed, 9 Feb 2022 13:35:04 +0100 Subject: [PATCH] avoid search when input loses focus, remove unnecessary worker logs --- .../onsets/src/components/BrowseDisplayPanel.vue | 13 ++++++++++--- examples/demos/onsets/src/core/audio-worker.js | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/demos/onsets/src/components/BrowseDisplayPanel.vue b/examples/demos/onsets/src/components/BrowseDisplayPanel.vue index 5f4c30f..3878c3e 100644 --- a/examples/demos/onsets/src/components/BrowseDisplayPanel.vue +++ b/examples/demos/onsets/src/components/BrowseDisplayPanel.vue @@ -3,7 +3,7 @@
- @@ -55,11 +55,13 @@ export default { searchTerm: "", uploadLabel: null, showSearchFailureBanner: false, - showNoResultsFoundBanner: false + showNoResultsFoundBanner: false, + window: window } }, methods: { - searchFreesound (ev) { + searchFreesound () { + window.removeEventListener('keydown', this.searchOnEnter ); this.$root.$emit('bv::hide::tooltip'); const isSearchById = /#\d+$/.test(this.searchTerm); // match regex for # if (isSearchById) { @@ -118,6 +120,11 @@ export default { this.showFreesoundResults = false; this.showSearchFailureBanner = true; console.error("Freesound search failed", error); + }, + searchOnEnter (event) { + if (event.key == 'Enter') { + this.searchFreesound(); + } } }, created () { diff --git a/examples/demos/onsets/src/core/audio-worker.js b/examples/demos/onsets/src/core/audio-worker.js index 4408dd0..3331d77 100644 --- a/examples/demos/onsets/src/core/audio-worker.js +++ b/examples/demos/onsets/src/core/audio-worker.js @@ -36,7 +36,6 @@ onmessage = function listenToMainThread(msg) { log('received analyse cmd') // const signal = new Float32Array(msg.data.audio); self.signal = msg.data.audio; - log(self.signal); computeFFT(); self.onsetPositions = computeOnsets(); const slices = sliceAudio(); @@ -164,7 +163,6 @@ function computeOnsets () { function sliceAudio () { // onsets: seconds to samples const onsetSamplePositions = Array.from(self.onsetPositions.map( (pos) => Math.round(pos * self.params.sampleRate) )); - log(onsetSamplePositions); return onsetSamplePositions.map( (samp, index) => self.signal.slice(samp, onsetSamplePositions[index+1]) ); }