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.22k stars 281 forks source link

Segment Dragging will out of waveform. #547

Open jason30704 opened 2 months ago

jason30704 commented 2 months ago

Hello, When enableSegmentDragging(true) is set, segment will not detect whether endTime is out of range.

https://github.com/user-attachments/assets/15087faf-98e3-427a-a49d-45e58f94c0c7

jason30704 commented 2 months ago

I'm not sure if this is an issue or not. I can achieve almost complete functionality by trying the method below.

image

However, overlay does not stop perfectly like startMarker and endMarker.

https://github.com/user-attachments/assets/089d9e47-e05a-4026-a1c0-683bb80640f6

chrisn commented 2 months ago

Yes, it's inconsistent. You can drag a segment so that it ends after the right edge of the waveform view, but dragging the segment marker is limited to the width of the waveform view.

chrisn commented 2 months ago

The code in Peaks.js that handles this is a bit complex, and takes into account the pixel position of the markers, not just their time position.

We could make the behaviour consistent (e.g, by allowing markers to be dragged beyond the visible window). But is this really a problem in practice?

jason30704 commented 2 months ago

Thanks for reply. From a user's perspective, I think it's strange that a segment would exceed the scope of a wave. In practice, there really isn’t much of a problem.

chrisn commented 2 months ago

So, there are three separate changes we could make:

  1. Allow point and segment handles to be dragged beyond the limit of the waveform view.
  2. Limit point and segment dragging to within the waveform duration.
  3. Limit point and segment times to within the waveform duration when calling peaks.points.add(), peaks.segments.add(), peaks.points.update(), and peaks.segments.update().

I'm hesitant about 2 and 3.