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

Suggestion: To add new event which informs that zoomview's current bound have been changed. #548

Open vivekd95 opened 2 months ago

vivekd95 commented 2 months ago

Hi @chrisn

As you know, we can get the zoomview's current rendered start and end time stamps via functions getStartTime() and getEndTime(). We can add an event for zoomview that will be triggered on view change when time crosses the current view's end time stamp. Also, additional details like the time stamps for the previous view's lower and upper bounds, and the time stamps for the new view's lower and upper bounds will be beneficial.

What is your opinion?

chrisn commented 2 months ago

There is already an event that's used internally to sync the state between the overview and zoomview waveforms. I guess we could make this part of the documented API. It would fire whenever the zoomview start/end time changes, including when scrolling.

I probably wouldn't want to include the previous start/end times, just the new ones, as applications can keep track themselves if they need to.

The API would be something like:

peaks.on('zoomview.update', (event) => {
  console.log(event.startTime, event.endTime);
});

I might also consider deprecating the existing zoom.update event, and have a single event that fires when the view position or zoom level changes:

peaks.on('zoomview.update', (event) => {
  console.log(event.startTime, event.endTime, event.scale);
});
adamalexander commented 2 weeks ago

Can you release a [3.4.3] to include this change?