Skip to content

Commit

Permalink
avoid search when input loses focus, remove unnecessary worker logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarcosfer committed Feb 9, 2022
1 parent 2ed353d commit f1acc09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 10 additions & 3 deletions examples/demos/onsets/src/components/BrowseDisplayPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div id="audio-search-upload" class="my-2 mx-0 row justify-content-between">
<div class="px-0 col-5">
<b-input-group>
<b-form-input v-model="searchTerm" placeholder="Search Freesound.org" @change="searchFreesound"
<b-form-input v-model="searchTerm" placeholder="Search Freesound.org" @input="window.addEventListener('keydown', searchOnEnter)"
v-b-tooltip.focus.bottom title="Prepend a number with # to search by Freesound ID"></b-form-input>
<b-input-group-append>
<b-button variant="light" class="px-4" @click="searchFreesound">
Expand Down Expand Up @@ -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 #<id_number>
if (isSearchById) {
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 0 additions & 2 deletions examples/demos/onsets/src/core/audio-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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]) );
}

Expand Down

0 comments on commit f1acc09

Please sign in to comment.