wavesurfer.js 5.0.1 → 5.1.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.
- package/CHANGES.md +11 -1
- package/dist/plugin/wavesurfer.cursor.js +1 -1
- package/dist/plugin/wavesurfer.cursor.min.js +1 -1
- package/dist/plugin/wavesurfer.elan.js +1 -1
- package/dist/plugin/wavesurfer.elan.min.js +1 -1
- package/dist/plugin/wavesurfer.markers.js +16 -6
- package/dist/plugin/wavesurfer.markers.js.map +1 -1
- package/dist/plugin/wavesurfer.markers.min.js +2 -2
- package/dist/plugin/wavesurfer.markers.min.js.map +1 -1
- package/dist/plugin/wavesurfer.mediasession.js +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
- package/dist/plugin/wavesurfer.microphone.js +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js +1 -1
- package/dist/plugin/wavesurfer.minimap.js +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js +1 -1
- package/dist/plugin/wavesurfer.playhead.js +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js +1 -1
- package/dist/plugin/wavesurfer.regions.js +5 -3
- package/dist/plugin/wavesurfer.regions.js.map +1 -1
- package/dist/plugin/wavesurfer.regions.min.js +2 -2
- package/dist/plugin/wavesurfer.regions.min.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.js +66 -60
- package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.js +17 -5
- package/dist/plugin/wavesurfer.timeline.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js +2 -2
- package/dist/plugin/wavesurfer.timeline.min.js.map +1 -1
- package/dist/wavesurfer-html-init.js +1 -1
- package/dist/wavesurfer-html-init.min.js +1 -1
- package/dist/wavesurfer.js +2 -2
- package/dist/wavesurfer.min.js +2 -2
- package/package.json +15 -15
- package/src/plugin/markers/index.js +13 -5
- package/src/plugin/regions/region.js +2 -2
- package/src/plugin/spectrogram/index.js +65 -61
- package/src/plugin/timeline/index.js +20 -11
|
@@ -254,30 +254,32 @@ export default class SpectrogramPlugin {
|
|
|
254
254
|
const width = my.width;
|
|
255
255
|
const pixels = my.resample(frequenciesData);
|
|
256
256
|
const heightFactor = my.buffer ? 2 / my.buffer.numberOfChannels : 1;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
for (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
257
|
+
if (spectrCc) {
|
|
258
|
+
const imageData = spectrCc.createImageData(width, height);
|
|
259
|
+
let i;
|
|
260
|
+
let j;
|
|
261
|
+
let k;
|
|
262
|
+
|
|
263
|
+
for (i = 0; i < pixels.length; i++) {
|
|
264
|
+
for (j = 0; j < pixels[i].length; j++) {
|
|
265
|
+
const colorMap = my.colorMap[pixels[i][j]];
|
|
266
|
+
/* eslint-disable max-depth */
|
|
267
|
+
for (k = 0; k < heightFactor; k++) {
|
|
268
|
+
let y = height - j * heightFactor;
|
|
269
|
+
if (heightFactor === 2 && k === 1) {
|
|
270
|
+
y--;
|
|
271
|
+
}
|
|
272
|
+
const redIndex = y * (width * 4) + i * 4;
|
|
273
|
+
imageData.data[redIndex] = colorMap[0] * 255;
|
|
274
|
+
imageData.data[redIndex + 1] = colorMap[1] * 255;
|
|
275
|
+
imageData.data[redIndex + 2] = colorMap[2] * 255;
|
|
276
|
+
imageData.data[redIndex + 3] = colorMap[3] * 255;
|
|
270
277
|
}
|
|
271
|
-
|
|
272
|
-
imageData.data[redIndex] = colorMap[0] * 255;
|
|
273
|
-
imageData.data[redIndex + 1] = colorMap[1] * 255;
|
|
274
|
-
imageData.data[redIndex + 2] = colorMap[2] * 255;
|
|
275
|
-
imageData.data[redIndex + 3] = colorMap[3] * 255;
|
|
278
|
+
/* eslint-enable max-depth */
|
|
276
279
|
}
|
|
277
|
-
/* eslint-enable max-depth */
|
|
278
280
|
}
|
|
281
|
+
spectrCc.putImageData(imageData, 0, 0);
|
|
279
282
|
}
|
|
280
|
-
spectrCc.putImageData(imageData, 0, 0);
|
|
281
283
|
}
|
|
282
284
|
|
|
283
285
|
getFrequencies(callback) {
|
|
@@ -378,47 +380,49 @@ export default class SpectrogramPlugin {
|
|
|
378
380
|
this.labelsEl.height = this.height;
|
|
379
381
|
this.labelsEl.width = bgWidth;
|
|
380
382
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
383
|
+
if (ctx) {
|
|
384
|
+
// fill background
|
|
385
|
+
ctx.fillStyle = bgFill;
|
|
386
|
+
ctx.fillRect(0, 0, bgWidth, getMaxY);
|
|
387
|
+
ctx.fill();
|
|
388
|
+
let i;
|
|
389
|
+
|
|
390
|
+
// render labels
|
|
391
|
+
for (i = 0; i <= labelIndex; i++) {
|
|
392
|
+
ctx.textAlign = textAlign;
|
|
393
|
+
ctx.textBaseline = 'middle';
|
|
394
|
+
|
|
395
|
+
const freq = freqStart + step * i;
|
|
396
|
+
const index = Math.round(
|
|
397
|
+
(freq / (this.sampleRate / 2)) * this.fftSamples
|
|
398
|
+
);
|
|
399
|
+
const label = this.freqType(freq);
|
|
400
|
+
const units = this.unitType(freq);
|
|
401
|
+
const yLabelOffset = 2;
|
|
402
|
+
const x = 16;
|
|
403
|
+
let y;
|
|
404
|
+
|
|
405
|
+
if (i == 0) {
|
|
406
|
+
y = getMaxY + i - 10;
|
|
407
|
+
// unit label
|
|
408
|
+
ctx.fillStyle = textColorUnit;
|
|
409
|
+
ctx.font = fontSizeUnit + ' ' + fontType;
|
|
410
|
+
ctx.fillText(units, x + 24, y);
|
|
411
|
+
// freq label
|
|
412
|
+
ctx.fillStyle = textColorFreq;
|
|
413
|
+
ctx.font = fontSizeFreq + ' ' + fontType;
|
|
414
|
+
ctx.fillText(label, x, y);
|
|
415
|
+
} else {
|
|
416
|
+
y = getMaxY - i * 50 + yLabelOffset;
|
|
417
|
+
// unit label
|
|
418
|
+
ctx.fillStyle = textColorUnit;
|
|
419
|
+
ctx.font = fontSizeUnit + ' ' + fontType;
|
|
420
|
+
ctx.fillText(units, x + 24, y);
|
|
421
|
+
// freq label
|
|
422
|
+
ctx.fillStyle = textColorFreq;
|
|
423
|
+
ctx.font = fontSizeFreq + ' ' + fontType;
|
|
424
|
+
ctx.fillText(label, x, y);
|
|
425
|
+
}
|
|
422
426
|
}
|
|
423
427
|
}
|
|
424
428
|
}
|
|
@@ -434,7 +434,10 @@ export default class TimelinePlugin {
|
|
|
434
434
|
*/
|
|
435
435
|
setFillStyles(fillStyle) {
|
|
436
436
|
this.canvases.forEach(canvas => {
|
|
437
|
-
canvas.getContext('2d')
|
|
437
|
+
const context = canvas.getContext('2d');
|
|
438
|
+
if (context) {
|
|
439
|
+
context.fillStyle = fillStyle;
|
|
440
|
+
}
|
|
438
441
|
});
|
|
439
442
|
}
|
|
440
443
|
|
|
@@ -445,7 +448,10 @@ export default class TimelinePlugin {
|
|
|
445
448
|
*/
|
|
446
449
|
setFonts(font) {
|
|
447
450
|
this.canvases.forEach(canvas => {
|
|
448
|
-
canvas.getContext('2d')
|
|
451
|
+
const context = canvas.getContext('2d');
|
|
452
|
+
if (context) {
|
|
453
|
+
context.font = font;
|
|
454
|
+
}
|
|
449
455
|
});
|
|
450
456
|
}
|
|
451
457
|
|
|
@@ -471,14 +477,17 @@ export default class TimelinePlugin {
|
|
|
471
477
|
};
|
|
472
478
|
|
|
473
479
|
if (intersection.x1 < intersection.x2) {
|
|
474
|
-
canvas
|
|
475
|
-
.getContext('2d')
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
const context = canvas
|
|
481
|
+
.getContext('2d');
|
|
482
|
+
if (context) {
|
|
483
|
+
context
|
|
484
|
+
.fillRect(
|
|
485
|
+
intersection.x1 - leftOffset,
|
|
486
|
+
intersection.y1,
|
|
487
|
+
intersection.x2 - intersection.x1,
|
|
488
|
+
intersection.y2 - intersection.y1
|
|
489
|
+
);
|
|
490
|
+
}
|
|
482
491
|
}
|
|
483
492
|
});
|
|
484
493
|
}
|
|
@@ -502,7 +511,7 @@ export default class TimelinePlugin {
|
|
|
502
511
|
return;
|
|
503
512
|
}
|
|
504
513
|
|
|
505
|
-
if (xOffset + canvasWidth > x) {
|
|
514
|
+
if (xOffset + canvasWidth > x && context) {
|
|
506
515
|
textWidth = context.measureText(text).width;
|
|
507
516
|
context.fillText(text, x - xOffset, y);
|
|
508
517
|
}
|