wavesurfer.js 6.5.2 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +16 -2
  2. package/dist/plugin/wavesurfer.cursor.js +1 -1
  3. package/dist/plugin/wavesurfer.cursor.min.js +1 -1
  4. package/dist/plugin/wavesurfer.elan.js +1 -1
  5. package/dist/plugin/wavesurfer.elan.min.js +1 -1
  6. package/dist/plugin/wavesurfer.markers.js +1 -1
  7. package/dist/plugin/wavesurfer.markers.min.js +1 -1
  8. package/dist/plugin/wavesurfer.mediasession.js +1 -1
  9. package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
  10. package/dist/plugin/wavesurfer.microphone.js +1 -1
  11. package/dist/plugin/wavesurfer.microphone.min.js +1 -1
  12. package/dist/plugin/wavesurfer.minimap.js +1 -1
  13. package/dist/plugin/wavesurfer.minimap.min.js +1 -1
  14. package/dist/plugin/wavesurfer.playhead.js +1 -1
  15. package/dist/plugin/wavesurfer.playhead.min.js +1 -1
  16. package/dist/plugin/wavesurfer.regions.js +1 -1
  17. package/dist/plugin/wavesurfer.regions.min.js +1 -1
  18. package/dist/plugin/wavesurfer.spectrogram.js +128 -34
  19. package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
  20. package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
  21. package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
  22. package/dist/plugin/wavesurfer.timeline.js +1 -1
  23. package/dist/plugin/wavesurfer.timeline.min.js +1 -1
  24. package/dist/wavesurfer-html-init.js +1 -1
  25. package/dist/wavesurfer-html-init.min.js +1 -1
  26. package/dist/wavesurfer.js +160 -6
  27. package/dist/wavesurfer.js.map +1 -1
  28. package/dist/wavesurfer.min.js +2 -2
  29. package/dist/wavesurfer.min.js.map +1 -1
  30. package/package.json +4 -3
  31. package/src/drawer.canvasentry.js +43 -0
  32. package/src/drawer.js +0 -4
  33. package/src/drawer.multicanvas.js +71 -1
  34. package/src/plugin/spectrogram/index.js +121 -30
  35. package/src/wavesurfer.js +33 -0
package/README.md CHANGED
@@ -124,8 +124,22 @@ If you want to use [the VS Code - Debugger for Chrome](https://github.com/Micros
124
124
  ## Editing documentation
125
125
  The homepage and documentation files are maintained in the [`gh-pages` branch](https://github.com/wavesurfer-js/wavesurfer.js/tree/gh-pages). Contributions to the documentation are especially welcome.
126
126
 
127
- ## Updating the NPM package
128
- When preparing a new release, update the version in the `package.json` and have it merged to master. The new version of the package will be published to NPM automatically via GitHub Actions.
127
+ ## Releasing a new version
128
+ To release a new version and publish it to NPM, follow the steps below.
129
+
130
+ Switch to the master branch and make sure it's up-to-date
131
+ ```
132
+ git checkout master
133
+ git fetch --all; git reset --hard origin/master
134
+ ```
135
+
136
+ Run the release script:
137
+ ```
138
+ yarn release
139
+ ```
140
+ This will update the version, generate a changelog, and push everything to a new branch called `release/X.X.X`.
141
+
142
+ A browser window will open to create a PR from this new branch to the master branch. Once the PR is approved and merged, an automated workflow will kick in and publish a release both on GitHub and NPM.
129
143
 
130
144
  ## Credits
131
145
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js cursor plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js cursor plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js cursor plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js cursor plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js elan plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js elan plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js elan plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js elan plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js markers plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js markers plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js markers plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js markers plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js mediasession plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js mediasession plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js mediasession plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js mediasession plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js microphone plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js microphone plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js microphone plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js microphone plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js minimap plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js minimap plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js minimap plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js minimap plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js playhead plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js playhead plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js playhead plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js playhead plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js regions plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js regions plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js regions plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js regions plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wavesurfer.js spectrogram plugin 6.5.2 (2023-03-12)
2
+ * wavesurfer.js spectrogram plugin 6.6.0 (2023-03-14)
3
3
  * https://wavesurfer-js.org
4
4
  * @license BSD-3-Clause
5
5
  */
@@ -284,6 +284,9 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
284
284
  this._onRender = function () {
285
285
  _this.render();
286
286
  };
287
+ this._onZoom = function () {
288
+ _this.stretchCanvases();
289
+ };
287
290
  this._onWrapperClick = function (e) {
288
291
  _this._wrapperClickHandler(e);
289
292
  };
@@ -320,15 +323,19 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
320
323
  _this.alpha = params.alpha;
321
324
  _this.splitChannels = params.splitChannels;
322
325
  _this.channels = _this.splitChannels ? ws.backend.buffer.numberOfChannels : 1;
326
+ _this.canvases = [];
327
+ _this.canvasesTimeouts = [];
328
+ _this.scrollLeftTracker = 0; //Tracks the desired scrollLeft value
323
329
 
324
330
  // Getting file's original samplerate is difficult(#1248).
325
331
  // So set 12kHz default to render like wavesurfer.js 5.x.
326
332
  _this.frequencyMin = params.frequencyMin || 0;
327
333
  _this.frequencyMax = params.frequencyMax || 12000;
328
334
  _this.createWrapper();
329
- _this.createCanvas();
335
+ _this.addCanvas();
330
336
  _this.render();
331
337
  drawer.wrapper.addEventListener('scroll', _this._onScroll);
338
+ ws.on('zoom', _this._onZoom);
332
339
  ws.on('redraw', _this._onRender);
333
340
  };
334
341
  }
@@ -404,15 +411,49 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
404
411
  var relX = 'offsetX' in event ? event.offsetX : event.layerX;
405
412
  this.fireEvent('click', relX / this.width || 0);
406
413
  }
414
+
415
+ /**
416
+ * Add a canvas to this.canvases
417
+ */
407
418
  }, {
408
- key: "createCanvas",
409
- value: function createCanvas() {
410
- var canvas = this.canvas = this.wrapper.appendChild(document.createElement('canvas'));
411
- this.spectrCc = canvas.getContext('2d');
419
+ key: "addCanvas",
420
+ value: function addCanvas() {
421
+ var canvas = this.wrapper.appendChild(document.createElement('canvas'));
412
422
  this.util.style(canvas, {
413
423
  position: 'absolute',
414
424
  zIndex: 4
415
425
  });
426
+ this.canvases.push(canvas);
427
+ this.canvasesTimeouts.push(null);
428
+ }
429
+
430
+ /**
431
+ * Remove a canvas from this.canvases
432
+ */
433
+ }, {
434
+ key: "removeCanvas",
435
+ value: function removeCanvas() {
436
+ //Stop drawing (if drawing)
437
+ clearTimeout(this.canvasesTimeouts[this.canvasesTimeouts.length - 1]);
438
+ var lastEntry = this.canvases[this.canvases.length - 1];
439
+ lastEntry.parentElement.removeChild(lastEntry);
440
+ this.canvases.pop();
441
+ this.canvasesTimeouts.pop();
442
+ }
443
+
444
+ /**
445
+ * Ensure the correct number of canvases for the size of the spectrogram
446
+ */
447
+ }, {
448
+ key: "updateCanvases",
449
+ value: function updateCanvases() {
450
+ var canvasesRequired = Math.ceil(this.width / 4000);
451
+ while (this.canvases.length < canvasesRequired) {
452
+ this.addCanvas();
453
+ }
454
+ while (this.canvases.length > canvasesRequired) {
455
+ this.removeCanvas();
456
+ }
416
457
  }
417
458
  }, {
418
459
  key: "render",
@@ -427,11 +468,14 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
427
468
  }, {
428
469
  key: "updateCanvasStyle",
429
470
  value: function updateCanvasStyle() {
430
- var width = Math.round(this.width / this.pixelRatio) + 'px';
431
- this.canvas.width = this.width;
432
- this.canvas.height = this.fftSamples / 2 * this.channels;
433
- this.canvas.style.width = width;
434
- this.canvas.style.height = this.height + 'px';
471
+ this.updateCanvases();
472
+ //width per canvas
473
+ for (var i = 0; i < this.canvases.length; i++) {
474
+ this.canvases[i].width = Math.round(this.width / this.canvases.length);
475
+ this.canvases[i].height = this.fftSamples / 2 * this.channels;
476
+ this.canvases[i].style.width = Math.round(this.canvases[i].width / this.pixelRatio) + 'px';
477
+ this.canvases[i].style.height = this.height + 'px';
478
+ }
435
479
  }
436
480
  }, {
437
481
  key: "drawSpectrogram",
@@ -441,23 +485,58 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
441
485
  // to [channel, sample, freq] format
442
486
  frequenciesData = [frequenciesData];
443
487
  }
444
- var spectrCc = my.spectrCc;
488
+ my.updateCanvasStyle();
489
+
490
+ //Stop canvases still being drawn
491
+ for (var i = 0; i < my.canvasesTimeouts.length; i++) {
492
+ clearTimeout(my.canvasesTimeouts[i]);
493
+ }
494
+ var view = [my.scrollLeftTracker, my.scrollLeftTracker + my.wrapper.clientWidth];
495
+ for (var canvasNum = 0; canvasNum < my.canvases.length; canvasNum++) {
496
+ var canvasLeft = canvasNum * Math.floor(my.width / my.canvases.length / my.pixelRatio);
497
+ var canvasRight = (canvasNum + 1) * Math.floor(my.width / my.canvases.length / my.pixelRatio);
498
+ var canvasBound = [canvasLeft, canvasRight];
499
+ my.canvases[canvasNum].style['left'] = canvasLeft + 'px';
500
+
501
+ //Optimise drawing for the view
502
+ var priority = 0;
503
+ if (canvasBound[0] > view[1]) {
504
+ //Canvas is to the right of view window
505
+ var distance = canvasBound[0] - view[1];
506
+ priority = Math.ceil(distance / (view[1] - view[0]));
507
+ } else if (canvasBound[1] < view[0]) {
508
+ //Canvas is to the left of the view window
509
+ var _distance = view[0] - canvasBound[1];
510
+ priority = Math.ceil(_distance / (view[1] - view[0]));
511
+ }
512
+
513
+ //delay = 25ms * number of viewport widths away the canvas is
514
+ my.canvasesTimeouts[canvasNum] = setTimeout(my.drawToCanvas, 25 * priority, frequenciesData, my, canvasNum);
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Draw spectrogram channel to a specific canvas
520
+ * @param {[Number, Number, Number]} frequenciesData spectrogram data in [channel, sample, freq] format
521
+ * @param {SpectrogramPlugin} my variable with 'this' in it
522
+ * @param {Number} canvasNum Canvas to draw to
523
+ */
524
+ }, {
525
+ key: "drawToCanvas",
526
+ value: function drawToCanvas(frequenciesData, my, canvasNum) {
445
527
  var height = my.fftSamples / 2;
446
- var width = my.width;
447
528
  var freqFrom = my.buffer.sampleRate / 2;
448
529
  var freqMin = my.frequencyMin;
449
530
  var freqMax = my.frequencyMax;
450
- if (!spectrCc) {
451
- return;
452
- }
453
- var _loop = function _loop(c) {
454
- // for each channel
455
- var pixels = my.resample(frequenciesData[c]);
456
- var imageData = new ImageData(width, height);
531
+ var _loop = function _loop(channel) {
532
+ //Get pixels from frequency data and apply to image
533
+ var relevantFreqs = frequenciesData[channel].slice(canvasNum * Math.round(frequenciesData[channel].length / my.canvases.length), (canvasNum + 1) * Math.round(frequenciesData[channel].length / my.canvases.length));
534
+ var pixels = my.resample(relevantFreqs);
535
+ var imageData = new ImageData(pixels.length, height);
457
536
  for (var i = 0; i < pixels.length; i++) {
458
537
  for (var j = 0; j < pixels[i].length; j++) {
459
538
  var colorMap = my.colorMap[pixels[i][j]];
460
- var redIndex = ((height - j) * width + i) * 4;
539
+ var redIndex = ((height - j) * imageData.width + i) * 4;
461
540
  imageData.data[redIndex] = colorMap[0] * 255;
462
541
  imageData.data[redIndex + 1] = colorMap[1] * 255;
463
542
  imageData.data[redIndex + 2] = colorMap[2] * 255;
@@ -465,21 +544,26 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
465
544
  }
466
545
  }
467
546
 
468
- // scale and stack spectrograms
547
+ //Draw image to canvas
469
548
  createImageBitmap(imageData).then(function (renderer) {
470
- return spectrCc.drawImage(renderer, 0, height * (1 - freqMax / freqFrom),
471
- // source x, y
472
- width, height * (freqMax - freqMin) / freqFrom,
473
- // source width, height
474
- 0, height * c,
475
- // destination x, y
476
- width, height // destination width, height
477
- );
549
+ if (my.canvases[canvasNum]) {
550
+ //Check canvas still exists after creating image
551
+ my.canvases[canvasNum].getContext('2d').drawImage(renderer, 0, height * (1 - freqMax / freqFrom),
552
+ // source x, y
553
+ imageData.width, height * (freqMax - freqMin) / freqFrom,
554
+ // source width, height
555
+ 0, height * channel,
556
+ // destination x, y
557
+ my.canvases[canvasNum].width, height // destination width, height
558
+ );
559
+ }
478
560
  });
479
561
  };
480
- for (var c = 0; c < frequenciesData.length; c++) {
481
- _loop(c);
562
+ for (var channel = 0; channel < frequenciesData.length; channel++) {
563
+ _loop(channel);
482
564
  }
565
+ //Drawing is finished
566
+ my.canvasesTimeouts[canvasNum] = null;
483
567
  }
484
568
  }, {
485
569
  key: "getFrequencies",
@@ -497,7 +581,7 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
497
581
  var frequencies = [];
498
582
  var noverlap = this.noverlap;
499
583
  if (!noverlap) {
500
- var uniqueSamplesPerPx = buffer.length / this.canvas.width;
584
+ var uniqueSamplesPerPx = buffer.length / this.width;
501
585
  noverlap = Math.max(0, Math.round(fftSamples - uniqueSamplesPerPx));
502
586
  }
503
587
  var fft = new _fft.default(fftSamples, sampleRate, this.windowFunc, this.alpha);
@@ -623,13 +707,14 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
623
707
  key: "updateScroll",
624
708
  value: function updateScroll(e) {
625
709
  if (this.wrapper) {
710
+ this.scrollLeftTracker = e.target.scrollLeft;
626
711
  this.wrapper.scrollLeft = e.target.scrollLeft;
627
712
  }
628
713
  }
629
714
  }, {
630
715
  key: "resample",
631
716
  value: function resample(oldMatrix) {
632
- var columnsNumber = this.width;
717
+ var columnsNumber = oldMatrix.length;
633
718
  var newMatrix = [];
634
719
  var oldPiece = 1 / oldMatrix.length;
635
720
  var newPiece = 1 / columnsNumber;
@@ -665,6 +750,15 @@ var SpectrogramPlugin = /*#__PURE__*/function () {
665
750
  }
666
751
  return newMatrix;
667
752
  }
753
+ }, {
754
+ key: "stretchCanvases",
755
+ value: function stretchCanvases() {
756
+ for (var i = 0; i < this.canvases.length; i++) {
757
+ this.canvases[i].style.width = Math.round(this.drawer.width / this.canvases.length / this.pixelRatio) + 'px';
758
+ var canvasLeft = i * Math.floor(this.drawer.width / this.canvases.length / this.pixelRatio);
759
+ this.canvases[i].style['left'] = canvasLeft + 'px';
760
+ }
761
+ }
668
762
  }], [{
669
763
  key: "create",
670
764
  value: