bbc / peaks.js

JavaScript UI component for interacting with audio waveforms
https://waveform.prototyping.bbc.co.uk
GNU Lesser General Public License v3.0
3.16k stars 275 forks source link

Issue with dragend event #488

Closed vivekd95 closed 1 year ago

vivekd95 commented 1 year ago

Hi, I am trying to check when does your dragend and dragstart event fires. So, the dragend event is also fired when I drag the starting of segment, co-incide it with the previous segment and release it. Same is happening if I drag the ending of the segment, matching it with the next segment and releasing it. According to me, these events should not fire together like this. Also, when you drag and drop the segment then sometimes dragstart is getting fired sometime dragend. In this case, either both of them should get fired or neither of them should.

Screenshot 1: Zoomview with settings ss1

Screenshot 2: Dragging a segment's start and co-inciding it with the previous segment's end ss2

Screenshot 3: Screenshot of console showing both events getting fired (along the screenshot of code sample). ss4 ss3

Do correct me if I am mistaken. P.S- Tested it on v3.0.0-beta.8

chrisn commented 1 year ago

Hi @NinjaCoderDotCom, thanks for asking this question.

A segments.dragstart event is emitted when you start dragging a segment (either the whole segment, if you have "enable segment dragging" ticked, or the start or end of a segment). A segments.dragend event is emitted when you stop dragging.

Between the segments.dragstart and segments.dragend events, you will get segments.dragged event with each mouse movement.

These events are emitted for the segment you are dragging (the segment value in the event).

v3.0.0-beta.9 changes the behaviour when you have "compress" mode active. Now, when you drag a segment such that it moves an adjacent segment, you will get a segments.dragged event for both segments (the one you are dragging, and the adjacent segment).

I hope this makes sense. What problem are you having in your code?

vivekd95 commented 1 year ago

Hi @chrisn Thank you for helping me out regarding the both of events. I think through this explanation now most of my doubts and problems will be solved.

vivekd95 commented 1 year ago

Hi @chrisn I have one more doubt that how can I identify whether whole segment is being dragged or just start/end is being changed?

chrisn commented 1 year ago

The events currently don't give you that information, the events are the same when dragging the whole segment, and when just dragging the start or end. The startMarker flag in the event is always false when dragging the whole segment.

vivekd95 commented 1 year ago

@chrisn The startMarker flag is also false if you drag and drop the endtime of segment. I need something from which I can know that if I am dragging the whole segment or just resizing it by changing the starting and ending time.

chrisn commented 1 year ago

We can add an option to the events to indicate that, e.g.,

this._peaks.emit('segments.dragged', {
  segment: this._segment,
  startMarker: false,
  marker: true,
  evt: event.evt
});

where marker is true when resizing (i.e., either the start marker or end marker is being dragged) and false when dragging the whole segment.

vivekd95 commented 1 year ago

Yeah, that will be very good to identify between both events. When can we except the release of new version along with this change?

chrisn commented 1 year ago

Yes, v3.0.0-beta.10 is now available in npm.

chrisn commented 1 year ago

Is it OK it close this issue?