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.2k stars 279 forks source link

Question: customization of waveform #371

Open LukaMoria opened 3 years ago

LukaMoria commented 3 years ago

Earlier I used wavesurfer for customization waveform drawing with params like: barWidth : 2px and barGap :1px. I wanna to customize draw of full waveform. Can I do it with peaks.js?

LukaMoria commented 3 years ago

@chrisn any idea about it? Example: generating with customization by wavesurfer image the same track generated by peaks.js image

chrisn commented 3 years ago

We don't currently have a way for user customisation (apart from waveform colour) but I'm very much open to making it more configurable. This could be either by adding more options, or defining an extension API where you could fully take over how the rendering is done, similar to how we allow marker customisation (see https://github.com/bbc/peaks.js/blob/master/customizing.md).

In your use case, do you simply want a bar style display, as in your example, or do you want full control?

Related issues: https://github.com/bbc/peaks.js/issues/214, https://github.com/bbc/peaks.js/issues/193

BKnightSHiFi commented 3 years ago

We are working on this same thing in our app. The design is to use the bar style waveform that fills with color as the track progresses but this is not possible with peaks. I've only found wavesurfer to do this and would love to avoid having to pull it in just for this waveform styling.

noaLeibman commented 3 years ago

@chrisn I have another question about customization, hope you wouldn't mind:)

Is it possible to define the length (duration) of the view? For example I would like to create a Peaks instance with an audio file that's 3 seconds long, while the view would show 10 seconds (of course the remaining 7 seconds would be with no sound).

chrisn commented 3 years ago

Does the setZoom() method do what you need? I recommend trying out the demo pages, in particular the zoomable-waveform demo, which uses setZoom().

tidoni commented 3 years ago

Is there a way to change the background color of a segment? Or some other way to show that two segments overlap?

If there isn't at the moment, could this also be add to the options or the extension API?!

chrisn commented 3 years ago

If there isn't at the moment, could this also be add to the options or the extension API?!

At the moment, there isn't. Can you provide an example image of the effect you want to see?

tidoni commented 3 years ago

I just took the sample image from the git root and added some color.

peaks_mod

Maybe this could be done, simply by adding a background-color setting to the segments.

  segments: [{
    startTime: 4,
    endTime: 14,
    editable: false,
    color: "blue",
    labelText: "Mic open"
  },
  {
    startTime: 4,
    endTime: 8,
    editable: false,
    background-color: "red",
    labelText: "Jingle"
  },
  {
    startTime: 15,
    endTime: 17,
    editable: false,
    background-color: "red",
    labelText: "Jingle"
  },
  {
    startTime: 29,
    endTime: 33,
    editable: false,
    color: "violett",
    labelText: "Mic open"
  }],