Splitting from #1572 because things seem to have gotten confusing.
Every time you load a new file the regions plugin adds new listeners. The effect is that if you load several files and then you create a single region you get several regions -- one for each file you've ever loaded.
https://jsbin.com/mutavib/edit?output
Expectation: Every time you load a new file the plugins should effectively reset themselves. Having loaded previous files should not cause multiple regions on the current file.
Note that in my opinion this is related to the open issue in #1572 in which the spectrogram plugin is creating multiple spectograms, one for each file that's been loaded in the past.
I think I figured this out locally.
enableDragSelection() creates an anonymous eventDown() function locally and then calls addEventListener() (https://github.com/katspaugh/wavesurfer.js/blob/master/src/plugin/regions.js#L754).
It seems that calling enableDragSelection() on each new file is necessary, so my assumption that this was like the regions bug and onReady() was getting called too many times is incorrect.
However, it looks like there might be an assumption that you can call addEventListener() multiple times without any adverse affect but that isn't true in this case.
My workaround fix was is to call wavesurfer.disableDragSelection(); before loading a new file.
I tried to make eventDown() a non-anonymous function but realized it was relying on _this8. So I think the long-term fix will be to unload eventDown() (and any other anonymous functions like onDown()), or to create actual functions out of them and use binding in addEventListener() which, now that I think about it, probably breaks the no-duplicates feature.
thanks for the test case. #1608 should fix this, can you test that PR @jamesshannon?
Most helpful comment
I think I figured this out locally.
enableDragSelection()creates an anonymouseventDown()function locally and then callsaddEventListener()(https://github.com/katspaugh/wavesurfer.js/blob/master/src/plugin/regions.js#L754).It seems that calling
enableDragSelection()on each new file is necessary, so my assumption that this was like the regions bug andonReady()was getting called too many times is incorrect.However, it looks like there might be an assumption that you can call
addEventListener()multiple times without any adverse affect but that isn't true in this case.My workaround fix was is to call
wavesurfer.disableDragSelection();before loading a new file.I tried to make
eventDown()a non-anonymous function but realized it was relying on_this8. So I think the long-term fix will be to unloadeventDown()(and any other anonymous functions likeonDown()), or to create actual functions out of them and use binding inaddEventListener()which, now that I think about it, probably breaks the no-duplicates feature.