Skip to content

Commit 89366b0

Browse files
authored
Feat: splitChannels (#2796)
* Feat: splitChannels * Refactor rendering * Update tests * Timeout contexts * Fix color usage in the record plugin * Fix test
1 parent fe0ffdb commit 89366b0

16 files changed

+308
-181
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,26 @@ See [this example](https://wavesurfer.pages.dev/examples/#styling.js) for play a
9292
Most options, events, and methods are similar to those in previous versions.
9393

9494
### Notable differences
95-
* The `backend` option is removed – HTML5 audio (or video) is the only playback mechanism. However, you can still connect wavesurfer to Web Audio via `MediaElementSourceNode`. See this [example](https://wavesurfer.pages.dev/examples/#webaudio.js).
95+
* The `backend` option is removed – [HTML5 audio (or video) is the only playback mechanism](https://github.com/katspaugh/wavesurfer.js/discussions/2762#discussioncomment-5669347). However, you can still connect wavesurfer to Web Audio via `MediaElementSourceNode`. See this [example](https://wavesurfer.pages.dev/examples/#webaudio.js).
9696
* The Markers plugin is removed – use the Regions plugin with just a `startTime`.
9797
* No Microphone plugn – superseded by the new Record plugin with more features.
9898
* No Cursor and Playhead plugins yet – to be done.
9999

100+
### Removed options
101+
* `backend`, `audioContext`, `closeAudioContext', 'audioScriptProcessor` – there's no Web Audio backend, so no AudioContext
102+
* `autoCenterImmediately``autoCenter` is now always immediate unless the audio is playing
103+
* `backgroundColor`, `hideCursor` – this can be easily set via CSS
104+
* `mediaType`, `mediaControls` – you should instead pass an entire media element in the `media` option. [Example](https://wavesurfer-js.org/examples/#video.js).
105+
* `normalize` – peaks are normalized to -1..1 by default
106+
* `partialRender` – done by default
107+
* `pixelRatio``window.devicePixelRatio` is used by default
108+
* `renderer` – there's just one renderer for now, so no need for this option
109+
* `responsive` – responsiveness is enabled by default
110+
* `scrollParent` – the container will scroll if `minPxPerSec` is set to a higher value
111+
* `skipLength` – there's no `skipForward` and `skipBackward` methods anymore
112+
* `splitChannelsOptions` – you should now use `splitChannels` to pass the channel options. Pass `height: 0` to hide a channel. See [this example](https://wavesurfer-js.org/examples/#split-channels.js).
113+
* `xhr`, `drawingContextAttributes`, `maxCanvasWidth`, `forceDecode` – removed to reduce code complexity
114+
100115
### Removed methods
101116
* `getFilters`, `setFilter` – as there's no Web Audio "backend"
102117
* `drawBuffer` – to redraw the waveform, use `setOptions` instead and pass new rendering options

cypress/e2e/basic.cy.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ describe('WaveSurfer', () => {
2727

2828
it('should load an audio file without errors', () => {
2929
cy.window().then((win) => {
30-
expect(win.wavesurfer.getDuration()).to.equal(21.773878)
30+
expect(win.wavesurfer.getDuration().toFixed(2)).to.equal('21.77')
3131

3232
win.wavesurfer.load('../../examples/audio/audio.wav')
3333

3434
return new Promise((resolve) => {
3535
win.wavesurfer.once('ready', () => {
36-
expect(win.wavesurfer.getDuration()).to.equal(26.386688)
36+
expect(win.wavesurfer.getDuration().toFixed(2)).to.equal('26.39')
3737
resolve()
3838
})
3939
})
@@ -101,7 +101,6 @@ describe('WaveSurfer', () => {
101101

102102
it('should scroll on seek if zoomed in', () => {
103103
cy.window().then((win) => {
104-
const initialWidth = win.wavesurfer.getWrapper().clientWidth
105104
win.wavesurfer.zoom(300)
106105
const zoomedWidth = win.wavesurfer.getWrapper().clientWidth
107106
win.wavesurfer.zoom(600)

cypress/e2e/options.cy.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ describe('WaveSurfer', () => {
105105
win.wavesurfer = win.WaveSurfer.create({
106106
container: id,
107107
url: '../../examples/audio/demo.wav',
108-
waveColor: [
109-
"rgb(200, 165, 49)",
110-
"rgb(211, 194, 138)",
111-
"rgb(205, 124, 49)",
112-
"rgb(205, 98, 49)",
113-
],
108+
waveColor: ['rgb(200, 165, 49)', 'rgb(211, 194, 138)', 'rgb(205, 124, 49)', 'rgb(205, 98, 49)'],
114109
progressColor: 'rgba(0, 0, 0, 0.25)',
115110
cursorColor: 'blue',
116111
})
@@ -258,6 +253,53 @@ describe('WaveSurfer', () => {
258253
})
259254
})
260255

256+
it('should split channels', () => {
257+
cy.window().then((win) => {
258+
return new Promise((resolve) => {
259+
win.wavesurfer = win.WaveSurfer.create({
260+
container: id,
261+
url: '../../examples/audio/stereo.mp3',
262+
splitChannels: true,
263+
waveColor: 'rgb(200, 0, 200)',
264+
progressColor: 'rgb(100, 0, 100)',
265+
})
266+
267+
win.wavesurfer.once('ready', () => {
268+
win.wavesurfer.setTime(2)
269+
cy.wait(100)
270+
cy.get(id).matchImageSnapshot('split-channels')
271+
resolve()
272+
})
273+
})
274+
})
275+
})
276+
277+
it('should split channels with options', () => {
278+
cy.window().then((win) => {
279+
return new Promise((resolve) => {
280+
win.wavesurfer = win.WaveSurfer.create({
281+
container: id,
282+
url: '../../examples/audio/stereo.mp3',
283+
splitChannels: [
284+
{
285+
waveColor: 'rgb(200, 0, 200)',
286+
progressColor: 'rgb(100, 0, 100)',
287+
},
288+
{
289+
waveColor: 'rgb(0, 200, 200)',
290+
progressColor: 'rgb(0, 100, 100)',
291+
},
292+
],
293+
})
294+
295+
win.wavesurfer.once('ready', () => {
296+
cy.get(id).matchImageSnapshot('split-channels-options')
297+
resolve()
298+
})
299+
})
300+
})
301+
})
302+
261303
it('should use plugins with Regions', () => {
262304
cy.window().then((win) => {
263305
return new Promise((resolve) => {
0 Bytes
Loading

cypress/snapshots/bars.snap.png

28 Bytes
Loading
22.5 KB
Loading
14.7 KB
Loading
14.6 KB
Loading

examples/all-options.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const options = {
1212
container: 'body',
1313
/** The height of the waveform in pixels */
1414
height: 128,
15+
/** Render each audio channel as a separate waveform */
16+
splitChannels: false,
1517
/** The color of the waveform */
1618
waveColor: '#ff4e00',
1719
/** The color of the progress mask */

examples/multitrack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ multitrack.on('intro-end-change', ({ id, endTime }) => {
121121
multitrack.on('drop', ({ id }) => {
122122
multitrack.addTrack({
123123
id,
124-
url: '/examples/demo.wav',
124+
url: '/examples/audio/demo.wav',
125125
startPosition: 0,
126126
draggable: true,
127127
options: {

0 commit comments

Comments
 (0)