@checksub_team/peaks_timeline 2.0.0-alpha.14 → 2.0.0-alpha.16
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/package.json +1 -1
- package/peaks.js +256 -146
- package/src/components/axis.js +5 -5
- package/src/components/default-segment-marker.js +13 -4
- package/src/components/line-groups.js +36 -0
- package/src/components/line-indicator.js +65 -8
- package/src/components/mode-layer.js +7 -7
- package/src/components/playhead-layer.js +2 -2
- package/src/components/segment-shape.js +2 -2
- package/src/components/segments-group.js +1 -1
- package/src/components/source-group.js +126 -99
- package/src/components/sources-layer.js +12 -12
- package/src/components/waveform-builder.js +34 -17
- package/src/view.js +6 -6
package/peaks.js
CHANGED
|
@@ -14446,16 +14446,16 @@ module.exports = function (Utils, Konva) {
|
|
|
14446
14446
|
Axis.prototype._onPlayheadMoved = function (playheadX, playheadWidth) {
|
|
14447
14447
|
this._maskStart = playheadX + this._view.getFrameOffset();
|
|
14448
14448
|
this._maskEnd = playheadX + this._view.getFrameOffset() + playheadWidth;
|
|
14449
|
-
this._frontLayer.
|
|
14449
|
+
this._frontLayer.batchDraw();
|
|
14450
14450
|
};
|
|
14451
14451
|
Axis.prototype._onPlayheadHidden = function () {
|
|
14452
14452
|
this._maskStart = null;
|
|
14453
14453
|
this._maskEnd = null;
|
|
14454
|
-
this._frontLayer.
|
|
14454
|
+
this._frontLayer.batchDraw();
|
|
14455
14455
|
};
|
|
14456
|
-
Axis.prototype.
|
|
14457
|
-
this._backLayer.
|
|
14458
|
-
this._frontLayer.
|
|
14456
|
+
Axis.prototype.batchDraw = function () {
|
|
14457
|
+
this._backLayer.batchDraw();
|
|
14458
|
+
this._frontLayer.batchDraw();
|
|
14459
14459
|
};
|
|
14460
14460
|
Axis.prototype.addBackToStage = function (stage) {
|
|
14461
14461
|
stage.add(this._backLayer);
|
|
@@ -14710,11 +14710,11 @@ module.exports = function (Utils, Konva) {
|
|
|
14710
14710
|
if (self._options.draggable) {
|
|
14711
14711
|
group.on('dragstart', function () {
|
|
14712
14712
|
self._label.show();
|
|
14713
|
-
self.
|
|
14713
|
+
self._batchDraw();
|
|
14714
14714
|
});
|
|
14715
14715
|
group.on('dragend', function () {
|
|
14716
14716
|
self._label.hide();
|
|
14717
|
-
self.
|
|
14717
|
+
self._batchDraw();
|
|
14718
14718
|
});
|
|
14719
14719
|
}
|
|
14720
14720
|
if (self._handle) {
|
|
@@ -14722,12 +14722,12 @@ module.exports = function (Utils, Konva) {
|
|
|
14722
14722
|
self._options.view.setCursor('ew-resize');
|
|
14723
14723
|
self._label.show();
|
|
14724
14724
|
self._group.moveToTop();
|
|
14725
|
-
self._options.view.
|
|
14725
|
+
self._options.view.batchDrawSourcesLayer();
|
|
14726
14726
|
});
|
|
14727
14727
|
self._handle.on('mouseout touchend', function () {
|
|
14728
14728
|
self._options.view.setCursor('default');
|
|
14729
14729
|
self._label.hide();
|
|
14730
|
-
self._options.view.
|
|
14730
|
+
self._options.view.batchDrawSourcesLayer();
|
|
14731
14731
|
});
|
|
14732
14732
|
}
|
|
14733
14733
|
};
|
|
@@ -14745,6 +14745,13 @@ module.exports = function (Utils, Konva) {
|
|
|
14745
14745
|
DefaultSegmentMarker.prototype.timeUpdated = function (time) {
|
|
14746
14746
|
this._label.setText(Utils.formatTime(time, false));
|
|
14747
14747
|
};
|
|
14748
|
+
DefaultSegmentMarker.prototype._batchDraw = function () {
|
|
14749
|
+
const group = this._options.group;
|
|
14750
|
+
const layer = group && group.getLayer && group.getLayer();
|
|
14751
|
+
if (layer && typeof layer.batchDraw === 'function') {
|
|
14752
|
+
layer.batchDraw();
|
|
14753
|
+
}
|
|
14754
|
+
};
|
|
14748
14755
|
return DefaultSegmentMarker;
|
|
14749
14756
|
}(_dereq_('../utils'), _dereq_('konva'));
|
|
14750
14757
|
},{"../utils":116,"konva":43}],90:[function(_dereq_,module,exports){
|
|
@@ -15325,6 +15332,7 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
|
|
|
15325
15332
|
this._peaks.on('main.allowInteractions', this.allowInteractions.bind(this));
|
|
15326
15333
|
this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
|
|
15327
15334
|
this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
|
|
15335
|
+
this._peaks.on('lineIndicator.drag', this._onIndicatorDrag.bind(this));
|
|
15328
15336
|
}
|
|
15329
15337
|
LineGroups.prototype.fitToView = function () {
|
|
15330
15338
|
this._lineIndicator.fitToView();
|
|
@@ -15692,6 +15700,30 @@ module.exports = function (SegmentsGroup, LineGroup, LineIndicator, Utils) {
|
|
|
15692
15700
|
this.refreshLineYs();
|
|
15693
15701
|
return line.id;
|
|
15694
15702
|
};
|
|
15703
|
+
LineGroups.prototype._onIndicatorDrag = function (lineId, y) {
|
|
15704
|
+
const lineGroup = this._lineGroupsById[lineId];
|
|
15705
|
+
if (!lineGroup) {
|
|
15706
|
+
return;
|
|
15707
|
+
}
|
|
15708
|
+
const positions = this.getLinesUnderY(y);
|
|
15709
|
+
if (positions[0] !== positions[1] || positions[0] === lineGroup.getPosition()) {
|
|
15710
|
+
return;
|
|
15711
|
+
}
|
|
15712
|
+
const targetPos = positions[0];
|
|
15713
|
+
const targetLineGroup = this._lineGroupsByPosition[targetPos];
|
|
15714
|
+
const targetCenterY = targetLineGroup.y() + targetLineGroup.lineHeight() / 2;
|
|
15715
|
+
const movingDown = targetPos > lineGroup.getPosition();
|
|
15716
|
+
if (movingDown && y < targetCenterY || !movingDown && y > targetCenterY) {
|
|
15717
|
+
return;
|
|
15718
|
+
}
|
|
15719
|
+
if (targetPos === lineGroup.getPosition() + 1) {
|
|
15720
|
+
this._setLinePosition(targetLineGroup.getId(), lineGroup.getPosition());
|
|
15721
|
+
} else {
|
|
15722
|
+
this._setLinePosition(lineId, targetPos);
|
|
15723
|
+
}
|
|
15724
|
+
this.refreshLineYs();
|
|
15725
|
+
this._peaks.emit('line.moved', lineGroup.getLine());
|
|
15726
|
+
};
|
|
15695
15727
|
LineGroups.prototype.updateSegments = function (frameStartTime, frameEndTime) {
|
|
15696
15728
|
for (var lineId in this._segmentsGroups) {
|
|
15697
15729
|
if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
|
|
@@ -15775,7 +15807,12 @@ module.exports = function (Konva, SVGs, Utils) {
|
|
|
15775
15807
|
listening: false
|
|
15776
15808
|
});
|
|
15777
15809
|
this._layer.add(this._separatingLine);
|
|
15778
|
-
this._layer.
|
|
15810
|
+
this._layer.batchDraw();
|
|
15811
|
+
this._isDragging = false;
|
|
15812
|
+
this._dragLineId = null;
|
|
15813
|
+
this._dragContainerRect = null;
|
|
15814
|
+
this._onWindowMove = this._onWindowMove.bind(this);
|
|
15815
|
+
this._onWindowUp = this._onWindowUp.bind(this);
|
|
15779
15816
|
}
|
|
15780
15817
|
LineIndicator.prototype.fitToView = function () {
|
|
15781
15818
|
this._height = this._view.getHeight();
|
|
@@ -15855,19 +15892,30 @@ module.exports = function (Konva, SVGs, Utils) {
|
|
|
15855
15892
|
indicator.getChildren().forEach(function (child) {
|
|
15856
15893
|
child.fill(child.getAttr('selectedColor'));
|
|
15857
15894
|
});
|
|
15858
|
-
self.
|
|
15895
|
+
self.batchDraw();
|
|
15859
15896
|
self._stage.container().style.cursor = 'pointer';
|
|
15860
15897
|
});
|
|
15861
15898
|
indicator.on('mouseout', function () {
|
|
15862
15899
|
indicator.getChildren().forEach(function (child) {
|
|
15863
15900
|
child.fill(child.getAttr('defaultColor'));
|
|
15864
15901
|
});
|
|
15865
|
-
self.
|
|
15866
|
-
self.
|
|
15902
|
+
self.batchDraw();
|
|
15903
|
+
if (!self._isDragging) {
|
|
15904
|
+
self._stage.container().style.cursor = 'default';
|
|
15905
|
+
}
|
|
15867
15906
|
});
|
|
15868
15907
|
indicator.on('click', function (e) {
|
|
15869
15908
|
self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
|
|
15870
15909
|
});
|
|
15910
|
+
indicator.on('mousedown touchstart', function () {
|
|
15911
|
+
self._dragLineId = lineGroup.getId();
|
|
15912
|
+
self._dragContainerRect = self._stage.getContainer().getBoundingClientRect();
|
|
15913
|
+
window.addEventListener('mousemove', self._onWindowMove, false);
|
|
15914
|
+
window.addEventListener('touchmove', self._onWindowMove, false);
|
|
15915
|
+
window.addEventListener('mouseup', self._onWindowUp, false);
|
|
15916
|
+
window.addEventListener('touchend', self._onWindowUp, false);
|
|
15917
|
+
window.addEventListener('blur', self._onWindowUp, false);
|
|
15918
|
+
});
|
|
15871
15919
|
return indicator;
|
|
15872
15920
|
};
|
|
15873
15921
|
LineIndicator.prototype.addIndicator = function (lineGroup) {
|
|
@@ -15897,7 +15945,7 @@ module.exports = function (Konva, SVGs, Utils) {
|
|
|
15897
15945
|
indicatorData.indicator = indicator;
|
|
15898
15946
|
indicatorData.type = line.indicatorType;
|
|
15899
15947
|
indicatorData.text = line.indicatorText;
|
|
15900
|
-
this.
|
|
15948
|
+
this.batchDraw();
|
|
15901
15949
|
};
|
|
15902
15950
|
LineIndicator.prototype.removeIndicator = function (lineId, keepInList) {
|
|
15903
15951
|
if (this._indicators[lineId]) {
|
|
@@ -15946,12 +15994,39 @@ module.exports = function (Konva, SVGs, Utils) {
|
|
|
15946
15994
|
}
|
|
15947
15995
|
}
|
|
15948
15996
|
if (anyChange) {
|
|
15949
|
-
this.
|
|
15997
|
+
this.batchDraw();
|
|
15950
15998
|
}
|
|
15951
15999
|
return anyChange;
|
|
15952
16000
|
};
|
|
15953
|
-
LineIndicator.prototype.
|
|
15954
|
-
this._layer.
|
|
16001
|
+
LineIndicator.prototype.batchDraw = function () {
|
|
16002
|
+
this._layer.batchDraw();
|
|
16003
|
+
};
|
|
16004
|
+
LineIndicator.prototype._onWindowMove = function (event) {
|
|
16005
|
+
if (!this._dragContainerRect) {
|
|
16006
|
+
return;
|
|
16007
|
+
}
|
|
16008
|
+
if (!this._isDragging) {
|
|
16009
|
+
this._stage.container().style.cursor = 'grabbing';
|
|
16010
|
+
}
|
|
16011
|
+
var clientY;
|
|
16012
|
+
if (event.type === 'touchmove') {
|
|
16013
|
+
clientY = Math.floor(event.changedTouches[0].clientY);
|
|
16014
|
+
} else {
|
|
16015
|
+
clientY = event.clientY;
|
|
16016
|
+
}
|
|
16017
|
+
const relY = clientY - this._dragContainerRect.top;
|
|
16018
|
+
this._peaks.emit('lineIndicator.drag', this._dragLineId, relY);
|
|
16019
|
+
};
|
|
16020
|
+
LineIndicator.prototype._onWindowUp = function () {
|
|
16021
|
+
window.removeEventListener('mousemove', this._onWindowMove, false);
|
|
16022
|
+
window.removeEventListener('touchmove', this._onWindowMove, false);
|
|
16023
|
+
window.removeEventListener('mouseup', this._onWindowUp, false);
|
|
16024
|
+
window.removeEventListener('touchend', this._onWindowUp, false);
|
|
16025
|
+
window.removeEventListener('blur', this._onWindowUp, false);
|
|
16026
|
+
this._isDragging = false;
|
|
16027
|
+
this._dragLineId = null;
|
|
16028
|
+
this._dragContainerRect = null;
|
|
16029
|
+
this._stage.container().style.cursor = 'pointer';
|
|
15955
16030
|
};
|
|
15956
16031
|
return LineIndicator;
|
|
15957
16032
|
}(_dereq_('konva'), _dereq_('./svgs'), _dereq_('../utils'));
|
|
@@ -16198,7 +16273,7 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16198
16273
|
}
|
|
16199
16274
|
} else {
|
|
16200
16275
|
this.deselectDifference([], true);
|
|
16201
|
-
this._view.
|
|
16276
|
+
this._view.batchDrawSourcesLayer();
|
|
16202
16277
|
}
|
|
16203
16278
|
};
|
|
16204
16279
|
ModeLayer.prototype._onKeyboardDelete = function () {
|
|
@@ -16219,7 +16294,7 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16219
16294
|
};
|
|
16220
16295
|
ModeLayer.prototype._onMouseEnterInCutMode = function () {
|
|
16221
16296
|
this._cutGroup.visible(true);
|
|
16222
|
-
this._layer.
|
|
16297
|
+
this._layer.batchDraw();
|
|
16223
16298
|
};
|
|
16224
16299
|
ModeLayer.prototype._updateCursorTime = function (position) {
|
|
16225
16300
|
var hoveredElement = this._view.getHoveredElement();
|
|
@@ -16291,11 +16366,11 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16291
16366
|
}
|
|
16292
16367
|
this._updateCursorTime(cuttingPosition);
|
|
16293
16368
|
this._updateCuttingLine(cuttingPosition);
|
|
16294
|
-
this._layer.
|
|
16369
|
+
this._layer.batchDraw();
|
|
16295
16370
|
};
|
|
16296
16371
|
ModeLayer.prototype._onMouseLeaveInCutMode = function () {
|
|
16297
16372
|
this._cutGroup.visible(false);
|
|
16298
|
-
this._layer.
|
|
16373
|
+
this._layer.batchDraw();
|
|
16299
16374
|
};
|
|
16300
16375
|
ModeLayer.prototype._onMouseClickInCutMode = function () {
|
|
16301
16376
|
var mousePosition = this._stage.getPointerPosition();
|
|
@@ -16324,7 +16399,7 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16324
16399
|
this._view.setHoveredElement(null);
|
|
16325
16400
|
this._updateCursorTime(cuttingPosition);
|
|
16326
16401
|
this._updateCuttingLine(cuttingPosition);
|
|
16327
|
-
this._layer.
|
|
16402
|
+
this._layer.batchDraw();
|
|
16328
16403
|
}
|
|
16329
16404
|
}
|
|
16330
16405
|
};
|
|
@@ -16381,8 +16456,8 @@ module.exports = function (SourceGroup, Source, Utils, Konva) {
|
|
|
16381
16456
|
return;
|
|
16382
16457
|
}
|
|
16383
16458
|
this._mode = mode;
|
|
16384
|
-
this._layer.
|
|
16385
|
-
this._view.
|
|
16459
|
+
this._layer.batchDraw();
|
|
16460
|
+
this._view.batchDrawSourcesLayer();
|
|
16386
16461
|
};
|
|
16387
16462
|
ModeLayer.prototype.getCurrentMode = function () {
|
|
16388
16463
|
return this._mode;
|
|
@@ -16641,7 +16716,7 @@ module.exports = function (Utils, Konva) {
|
|
|
16641
16716
|
}
|
|
16642
16717
|
}
|
|
16643
16718
|
this._time = time;
|
|
16644
|
-
this._playheadLayer.
|
|
16719
|
+
this._playheadLayer.batchDraw();
|
|
16645
16720
|
};
|
|
16646
16721
|
PlayheadLayer.prototype.getPlayheadOffset = function () {
|
|
16647
16722
|
return this._playheadPixel - this._view.getFrameOffset();
|
|
@@ -16665,7 +16740,7 @@ module.exports = function (Utils, Konva) {
|
|
|
16665
16740
|
}
|
|
16666
16741
|
}
|
|
16667
16742
|
if (updated) {
|
|
16668
|
-
this._playheadLayer.
|
|
16743
|
+
this._playheadLayer.batchDraw();
|
|
16669
16744
|
}
|
|
16670
16745
|
};
|
|
16671
16746
|
return PlayheadLayer;
|
|
@@ -17041,7 +17116,7 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17041
17116
|
0.65,
|
|
17042
17117
|
this._segment.warningColor
|
|
17043
17118
|
]);
|
|
17044
|
-
this._view.
|
|
17119
|
+
this._view.batchDrawSourcesLayer();
|
|
17045
17120
|
this._peaks.emit('segments.mouseenter', this._segment);
|
|
17046
17121
|
};
|
|
17047
17122
|
SegmentShape.prototype._onMouseLeave = function () {
|
|
@@ -17055,7 +17130,7 @@ module.exports = function (Konva, SegmentMarker, Utils) {
|
|
|
17055
17130
|
0.65,
|
|
17056
17131
|
this._segment.warningColor
|
|
17057
17132
|
]);
|
|
17058
|
-
this._view.
|
|
17133
|
+
this._view.batchDrawSourcesLayer();
|
|
17059
17134
|
this._peaks.emit('segments.mouseleave', this._segment);
|
|
17060
17135
|
};
|
|
17061
17136
|
SegmentShape.prototype._onClick = function () {
|
|
@@ -17356,7 +17431,7 @@ module.exports = function (SegmentShape, Utils, Konva) {
|
|
|
17356
17431
|
return visibleSegments;
|
|
17357
17432
|
};
|
|
17358
17433
|
SegmentsGroup.prototype._draw = function () {
|
|
17359
|
-
this._view.
|
|
17434
|
+
this._view.batchDrawSourcesLayer();
|
|
17360
17435
|
};
|
|
17361
17436
|
SegmentsGroup.prototype._updateSegment = function (segment) {
|
|
17362
17437
|
var segmentShape = this._findOrAddSegmentShape(segment);
|
|
@@ -17654,6 +17729,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
17654
17729
|
var SPACING_BETWEEN_PREVIEWS = 1.5;
|
|
17655
17730
|
var CORNER_RADIUS = 8;
|
|
17656
17731
|
var INDICATOR_RADIUS = 4;
|
|
17732
|
+
var PREVIEW_CREATE_CHUNK = 8;
|
|
17657
17733
|
function SourceGroup(source, peaks, layer, view) {
|
|
17658
17734
|
this._source = source;
|
|
17659
17735
|
this._peaks = peaks;
|
|
@@ -17673,6 +17749,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
17673
17749
|
this._hovered = false;
|
|
17674
17750
|
this._isDragged = false;
|
|
17675
17751
|
this._previewList = [];
|
|
17752
|
+
this._previewBuildQueue = new Set();
|
|
17676
17753
|
this._markersGroup = this._createMarkers();
|
|
17677
17754
|
this._group = new Konva.Group({
|
|
17678
17755
|
x: this._x,
|
|
@@ -17730,14 +17807,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
17730
17807
|
if (!this._source.loading) {
|
|
17731
17808
|
this._showButtons();
|
|
17732
17809
|
}
|
|
17733
|
-
this.
|
|
17810
|
+
this._batchDraw();
|
|
17734
17811
|
};
|
|
17735
17812
|
SourceGroup.prototype._onHoverEnd = function () {
|
|
17736
17813
|
this._hovered = false;
|
|
17737
17814
|
this._manualHover = false;
|
|
17738
17815
|
this._view.setHoveredElement(null);
|
|
17739
17816
|
this._hideButtons();
|
|
17740
|
-
this.
|
|
17817
|
+
this._batchDraw();
|
|
17741
17818
|
};
|
|
17742
17819
|
SourceGroup.prototype._onDragStart = function (element) {
|
|
17743
17820
|
this._isDragged = true;
|
|
@@ -17786,7 +17863,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
17786
17863
|
const {start, end} = this._initialTimes;
|
|
17787
17864
|
this._view.updateWithAutoScroll(function () {
|
|
17788
17865
|
if (this._layer.manageSourceMovements([this._source], leftHandle ? start + diff + timeOffsetDiff : null, leftHandle ? null : end + diff + timeOffsetDiff)) {
|
|
17789
|
-
this._layer.
|
|
17866
|
+
this._layer.batchDraw();
|
|
17790
17867
|
}
|
|
17791
17868
|
}.bind(this));
|
|
17792
17869
|
return {
|
|
@@ -18258,64 +18335,40 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
18258
18335
|
if (err) {
|
|
18259
18336
|
throw err;
|
|
18260
18337
|
}
|
|
18261
|
-
originalWaveformData.
|
|
18262
|
-
if (originalWaveformData.
|
|
18263
|
-
|
|
18264
|
-
|
|
18265
|
-
|
|
18266
|
-
} else {
|
|
18267
|
-
self._minScale = originalWaveformData.scale;
|
|
18268
|
-
}
|
|
18269
|
-
self._view.setTimeToPixelsMaxZoom(originalWaveformData.sample_rate / self._minScale);
|
|
18338
|
+
var newScale = originalWaveformData.sample_rate / self._view.getTimeToPixelsMaxZoom();
|
|
18339
|
+
if (newScale > originalWaveformData.scale) {
|
|
18340
|
+
self._minScale = newScale;
|
|
18341
|
+
} else {
|
|
18342
|
+
self._minScale = originalWaveformData.scale;
|
|
18270
18343
|
}
|
|
18344
|
+
self._view.setTimeToPixelsMaxZoom(originalWaveformData.sample_rate / self._minScale);
|
|
18271
18345
|
self._layer.setLoadedData(url, originalWaveformData);
|
|
18272
18346
|
self._layer.setLoadedData(url + '-scaled', {
|
|
18273
18347
|
data: originalWaveformData,
|
|
18274
18348
|
scale: originalWaveformData.sample_rate / self._minScale
|
|
18275
18349
|
});
|
|
18276
18350
|
preview.loaded = true;
|
|
18277
|
-
self._createAudioPreview(preview,
|
|
18351
|
+
self._createAudioPreview(preview, redraw);
|
|
18278
18352
|
});
|
|
18279
18353
|
} else {
|
|
18280
18354
|
preview.loaded = true;
|
|
18281
|
-
this._createAudioPreview(preview,
|
|
18282
|
-
}
|
|
18283
|
-
};
|
|
18284
|
-
SourceGroup.prototype._hasAudio = function (waveformData) {
|
|
18285
|
-
var channels = waveformData.channels;
|
|
18286
|
-
var channel, someIsNotZero = false;
|
|
18287
|
-
for (var i = 0; i < channels; i++) {
|
|
18288
|
-
channel = waveformData.channel(i);
|
|
18289
|
-
someIsNotZero = channel.min_array().some(function (item) {
|
|
18290
|
-
return item !== 0;
|
|
18291
|
-
});
|
|
18292
|
-
if (!someIsNotZero) {
|
|
18293
|
-
someIsNotZero = channel.max_array().some(function (item) {
|
|
18294
|
-
return item !== 0;
|
|
18295
|
-
});
|
|
18296
|
-
}
|
|
18297
|
-
if (someIsNotZero) {
|
|
18298
|
-
break;
|
|
18299
|
-
}
|
|
18355
|
+
this._createAudioPreview(preview, redraw);
|
|
18300
18356
|
}
|
|
18301
|
-
return someIsNotZero;
|
|
18302
18357
|
};
|
|
18303
|
-
SourceGroup.prototype._createAudioPreview = function (preview,
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
this._layer.rescale(true);
|
|
18316
|
-
}
|
|
18317
|
-
this._previewList.push(preview);
|
|
18358
|
+
SourceGroup.prototype._createAudioPreview = function (preview, redraw) {
|
|
18359
|
+
var waveform = new WaveformShape({
|
|
18360
|
+
layer: this._layer,
|
|
18361
|
+
view: this._view,
|
|
18362
|
+
source: this._source,
|
|
18363
|
+
height: preview.group.height(),
|
|
18364
|
+
url: preview.url
|
|
18365
|
+
});
|
|
18366
|
+
preview.group.add(waveform);
|
|
18367
|
+
this._addToUnwrap(preview.group);
|
|
18368
|
+
if (redraw) {
|
|
18369
|
+
this._layer.rescale(true);
|
|
18318
18370
|
}
|
|
18371
|
+
this._previewList.push(preview);
|
|
18319
18372
|
};
|
|
18320
18373
|
SourceGroup.prototype.getAudioPreview = function () {
|
|
18321
18374
|
return this._previewList.filter(function (preview) {
|
|
@@ -18382,31 +18435,81 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
18382
18435
|
} else {
|
|
18383
18436
|
imageNumber = 0;
|
|
18384
18437
|
}
|
|
18385
|
-
|
|
18386
|
-
var i = 0;
|
|
18387
|
-
for (i = 0; i < imageNumber; i++) {
|
|
18388
|
-
if (imageList.length > i) {
|
|
18389
|
-
imageList[i].visible(true);
|
|
18390
|
-
} else {
|
|
18391
|
-
var imagePreview = new Konva.Image({
|
|
18392
|
-
x: preview.imageData.borderSpacing + i * interImageSpacing,
|
|
18393
|
-
y: preview.imageData.borderSpacing,
|
|
18394
|
-
image: preview.imageData.image,
|
|
18395
|
-
width: preview.imageData.width,
|
|
18396
|
-
height: preview.imageData.height,
|
|
18397
|
-
listening: false,
|
|
18398
|
-
visible: true
|
|
18399
|
-
});
|
|
18400
|
-
preview.group.add(imagePreview);
|
|
18401
|
-
}
|
|
18402
|
-
}
|
|
18403
|
-
for (i = imageNumber; i < imageList.length; i++) {
|
|
18404
|
-
imageList[i].visible(false);
|
|
18405
|
-
}
|
|
18438
|
+
self._ensureImagePreviewCount(preview, imageNumber, interImageSpacing);
|
|
18406
18439
|
}
|
|
18407
18440
|
}
|
|
18408
18441
|
});
|
|
18409
18442
|
};
|
|
18443
|
+
SourceGroup.prototype._batchDraw = function () {
|
|
18444
|
+
var layer = this._group && this._group.getLayer && this._group.getLayer();
|
|
18445
|
+
if (layer && typeof layer.batchDraw === 'function') {
|
|
18446
|
+
layer.batchDraw();
|
|
18447
|
+
}
|
|
18448
|
+
};
|
|
18449
|
+
SourceGroup.prototype._scheduleIdle = function (fn) {
|
|
18450
|
+
if (typeof window !== 'undefined' && window.requestIdleCallback) {
|
|
18451
|
+
return window.requestIdleCallback(fn, { timeout: 50 });
|
|
18452
|
+
}
|
|
18453
|
+
if (typeof window !== 'undefined' && window.requestAnimationFrame) {
|
|
18454
|
+
return window.requestAnimationFrame(function () {
|
|
18455
|
+
fn({
|
|
18456
|
+
timeRemaining: function () {
|
|
18457
|
+
return 0;
|
|
18458
|
+
},
|
|
18459
|
+
didTimeout: true
|
|
18460
|
+
});
|
|
18461
|
+
});
|
|
18462
|
+
}
|
|
18463
|
+
return setTimeout(function () {
|
|
18464
|
+
fn({
|
|
18465
|
+
timeRemaining: function () {
|
|
18466
|
+
return 0;
|
|
18467
|
+
},
|
|
18468
|
+
didTimeout: true
|
|
18469
|
+
});
|
|
18470
|
+
}, 0);
|
|
18471
|
+
};
|
|
18472
|
+
SourceGroup.prototype._ensureImagePreviewCount = function (preview, targetCount, interImageSpacing) {
|
|
18473
|
+
var imageList = preview.group.getChildren();
|
|
18474
|
+
var currentCount = imageList.length;
|
|
18475
|
+
for (var i = 0; i < Math.min(currentCount, targetCount); i++) {
|
|
18476
|
+
imageList[i].visible(true);
|
|
18477
|
+
}
|
|
18478
|
+
for (var j = targetCount; j < currentCount; j++) {
|
|
18479
|
+
imageList[j].visible(false);
|
|
18480
|
+
}
|
|
18481
|
+
if (currentCount >= targetCount || this._previewBuildQueue.has(preview)) {
|
|
18482
|
+
this._batchDraw();
|
|
18483
|
+
return;
|
|
18484
|
+
}
|
|
18485
|
+
this._previewBuildQueue.add(preview);
|
|
18486
|
+
var self = this;
|
|
18487
|
+
var nextIndex = currentCount;
|
|
18488
|
+
function buildChunk() {
|
|
18489
|
+
var added = 0;
|
|
18490
|
+
while (nextIndex < targetCount && added < PREVIEW_CREATE_CHUNK) {
|
|
18491
|
+
var imagePreview = new Konva.Image({
|
|
18492
|
+
x: preview.imageData.borderSpacing + nextIndex * interImageSpacing,
|
|
18493
|
+
y: preview.imageData.borderSpacing,
|
|
18494
|
+
image: preview.imageData.image,
|
|
18495
|
+
width: preview.imageData.width,
|
|
18496
|
+
height: preview.imageData.height,
|
|
18497
|
+
listening: false,
|
|
18498
|
+
visible: true
|
|
18499
|
+
});
|
|
18500
|
+
preview.group.add(imagePreview);
|
|
18501
|
+
nextIndex += 1;
|
|
18502
|
+
added += 1;
|
|
18503
|
+
}
|
|
18504
|
+
self._batchDraw();
|
|
18505
|
+
if (nextIndex < targetCount) {
|
|
18506
|
+
self._scheduleIdle(buildChunk);
|
|
18507
|
+
} else {
|
|
18508
|
+
self._previewBuildQueue.delete(preview);
|
|
18509
|
+
}
|
|
18510
|
+
}
|
|
18511
|
+
this._scheduleIdle(buildChunk);
|
|
18512
|
+
};
|
|
18410
18513
|
SourceGroup.prototype._createImagePreview = function (preview, image, redraw) {
|
|
18411
18514
|
preview.imageData = {
|
|
18412
18515
|
image: image,
|
|
@@ -18423,22 +18526,15 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
18423
18526
|
preview.imageData.height = preview.imageData.referenceHeight - 2 * preview.imageData.borderSpacing;
|
|
18424
18527
|
preview.imageData.width = preview.imageData.height * preview.imageData.dimRatio;
|
|
18425
18528
|
preview.imageData.imageSpacing = preview.imageData.width * SPACING_BETWEEN_PREVIEWS;
|
|
18426
|
-
var currentX = preview.imageData.borderSpacing;
|
|
18427
|
-
while (currentX < this._width) {
|
|
18428
|
-
var imagePreview = new Konva.Image({
|
|
18429
|
-
x: currentX,
|
|
18430
|
-
y: preview.imageData.borderSpacing,
|
|
18431
|
-
image: image,
|
|
18432
|
-
width: preview.imageData.width,
|
|
18433
|
-
height: preview.imageData.height,
|
|
18434
|
-
listening: false
|
|
18435
|
-
});
|
|
18436
|
-
preview.group.add(imagePreview);
|
|
18437
|
-
currentX += preview.imageData.width + preview.imageData.imageSpacing;
|
|
18438
|
-
}
|
|
18439
18529
|
this._addToUnwrap(preview.group);
|
|
18530
|
+
var interImageSpacing = preview.imageData.width + preview.imageData.imageSpacing;
|
|
18531
|
+
var targetCount = 0;
|
|
18532
|
+
if (this._width > preview.imageData.borderSpacing) {
|
|
18533
|
+
targetCount = Math.trunc((this._width - preview.imageData.borderSpacing) / interImageSpacing) + 1;
|
|
18534
|
+
}
|
|
18535
|
+
this._ensureImagePreviewCount(preview, targetCount, interImageSpacing);
|
|
18440
18536
|
if (redraw) {
|
|
18441
|
-
this.
|
|
18537
|
+
this._batchDraw();
|
|
18442
18538
|
}
|
|
18443
18539
|
this._previewList.push(preview);
|
|
18444
18540
|
};
|
|
@@ -18881,7 +18977,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Utils, Konva)
|
|
|
18881
18977
|
volumeText.text((volume * 100).toFixed(0) + '%');
|
|
18882
18978
|
self._source.volume = Math.max(self._source.volumeRange[0], Math.min(volume, self._source.volumeRange[1]));
|
|
18883
18979
|
self._peaks.emit('source.volumeChanged', self._source);
|
|
18884
|
-
self.
|
|
18980
|
+
self._batchDraw();
|
|
18885
18981
|
});
|
|
18886
18982
|
volumeSliderGroup.on('dragend', function () {
|
|
18887
18983
|
volumeText.visible(false);
|
|
@@ -19016,7 +19112,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19016
19112
|
sourceGroup.setSelected();
|
|
19017
19113
|
}
|
|
19018
19114
|
}.bind(this));
|
|
19019
|
-
this.
|
|
19115
|
+
this.batchDraw();
|
|
19020
19116
|
};
|
|
19021
19117
|
SourcesLayer.prototype._onSourcesAdd = function (sources) {
|
|
19022
19118
|
var self = this;
|
|
@@ -19036,21 +19132,21 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19036
19132
|
self._removeSource(source);
|
|
19037
19133
|
});
|
|
19038
19134
|
this._view.updateTimelineLength();
|
|
19039
|
-
this._layer.
|
|
19135
|
+
this._layer.batchDraw();
|
|
19040
19136
|
};
|
|
19041
19137
|
SourcesLayer.prototype._onSourcesShow = function (sources) {
|
|
19042
19138
|
var self = this;
|
|
19043
19139
|
sources.forEach(function (source) {
|
|
19044
19140
|
self._sourcesGroup[source.id].setWrapping(false, true);
|
|
19045
19141
|
});
|
|
19046
|
-
this._layer.
|
|
19142
|
+
this._layer.batchDraw();
|
|
19047
19143
|
};
|
|
19048
19144
|
SourcesLayer.prototype._onSourcesHide = function (sources) {
|
|
19049
19145
|
var self = this;
|
|
19050
19146
|
sources.forEach(function (source) {
|
|
19051
19147
|
self._sourcesGroup[source.id].setWrapping(true, true);
|
|
19052
19148
|
});
|
|
19053
|
-
this._layer.
|
|
19149
|
+
this._layer.batchDraw();
|
|
19054
19150
|
};
|
|
19055
19151
|
SourcesLayer.prototype._onDataRetrieved = function (data, source, url) {
|
|
19056
19152
|
if (data) {
|
|
@@ -19079,7 +19175,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19079
19175
|
SourcesLayer.prototype._onSegmentsShow = function (segmentsGroupId, lineId) {
|
|
19080
19176
|
this._lineGroups.addSegments(segmentsGroupId, lineId);
|
|
19081
19177
|
this._view.updateTimelineLength();
|
|
19082
|
-
this._layer.
|
|
19178
|
+
this._layer.batchDraw();
|
|
19083
19179
|
};
|
|
19084
19180
|
SourcesLayer.prototype._createSourceGroup = function (source) {
|
|
19085
19181
|
return new SourceGroup(source, this._peaks, this, this._view);
|
|
@@ -19097,7 +19193,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19097
19193
|
var sourceGroup = this._sourcesGroup[source.id];
|
|
19098
19194
|
if (sourceGroup) {
|
|
19099
19195
|
sourceGroup.createIndicators();
|
|
19100
|
-
this._layer.
|
|
19196
|
+
this._layer.batchDraw();
|
|
19101
19197
|
}
|
|
19102
19198
|
};
|
|
19103
19199
|
SourcesLayer.prototype.updateSources = function (startTime, endTime) {
|
|
@@ -19107,7 +19203,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19107
19203
|
sources.forEach(this._updateSource.bind(this));
|
|
19108
19204
|
count += this._removeInvisibleSources(startTime, endTime);
|
|
19109
19205
|
if (count > 0) {
|
|
19110
|
-
this._layer.
|
|
19206
|
+
this._layer.batchDraw();
|
|
19111
19207
|
}
|
|
19112
19208
|
};
|
|
19113
19209
|
SourcesLayer.prototype.onSourcesGroupDragStart = function (element) {
|
|
@@ -19144,7 +19240,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19144
19240
|
return source;
|
|
19145
19241
|
}.bind(this));
|
|
19146
19242
|
this._draggedElementId = null;
|
|
19147
|
-
this._view.
|
|
19243
|
+
this._view.batchDrawSourcesLayer();
|
|
19148
19244
|
this._view.updateTimelineLength();
|
|
19149
19245
|
this._peaks.emit('sources.updated', updatedSources);
|
|
19150
19246
|
};
|
|
@@ -19167,7 +19263,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19167
19263
|
}
|
|
19168
19264
|
const shouldRedraw = this.manageSourceMovements(this._draggedElements, initialStartTime + timeOffsetDiff + timeDiff, initialEndTime + timeOffsetDiff + timeDiff, orderable, mousePosX, mousePosY);
|
|
19169
19265
|
if (shouldRedraw) {
|
|
19170
|
-
this.
|
|
19266
|
+
this.batchDraw();
|
|
19171
19267
|
}
|
|
19172
19268
|
};
|
|
19173
19269
|
SourcesLayer.prototype.findSources = function (startTime, endTime) {
|
|
@@ -19292,8 +19388,8 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19292
19388
|
SourcesLayer.prototype.setVisible = function (visible) {
|
|
19293
19389
|
this._layer.setVisible(visible);
|
|
19294
19390
|
};
|
|
19295
|
-
SourcesLayer.prototype.
|
|
19296
|
-
this._layer.
|
|
19391
|
+
SourcesLayer.prototype.batchDraw = function () {
|
|
19392
|
+
this._layer.batchDraw();
|
|
19297
19393
|
};
|
|
19298
19394
|
SourcesLayer.prototype.listening = function (bool) {
|
|
19299
19395
|
this._layer.listening(bool);
|
|
@@ -19335,7 +19431,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19335
19431
|
});
|
|
19336
19432
|
}
|
|
19337
19433
|
}
|
|
19338
|
-
this._layer.
|
|
19434
|
+
this._layer.batchDraw();
|
|
19339
19435
|
};
|
|
19340
19436
|
SourcesLayer.prototype._shouldResampleAudio = function (audioUrl, urls) {
|
|
19341
19437
|
return this._loadedData[audioUrl + '-scaled'] && !urls.includes(audioUrl) && this._loadedData[audioUrl + '-scaled'].scale !== this._view.getTimeToPixelsScale();
|
|
@@ -19399,6 +19495,12 @@ module.exports = function () {
|
|
|
19399
19495
|
module.exports = function (WaveformData, Utils) {
|
|
19400
19496
|
'use strict';
|
|
19401
19497
|
var isXhr2 = 'withCredentials' in new XMLHttpRequest();
|
|
19498
|
+
function scheduleIdle(fn) {
|
|
19499
|
+
if (typeof window !== 'undefined' && window.requestIdleCallback) {
|
|
19500
|
+
return window.requestIdleCallback(fn, { timeout: 80 });
|
|
19501
|
+
}
|
|
19502
|
+
return setTimeout(fn, 0);
|
|
19503
|
+
}
|
|
19402
19504
|
function WaveformBuilder(peaks) {
|
|
19403
19505
|
this._peaks = peaks;
|
|
19404
19506
|
}
|
|
@@ -19463,12 +19565,18 @@ module.exports = function (WaveformData, Utils) {
|
|
|
19463
19565
|
callback(new Error('Unable to fetch remote data. HTTP status ' + this.status));
|
|
19464
19566
|
return;
|
|
19465
19567
|
}
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19471
|
-
|
|
19568
|
+
scheduleIdle(function () {
|
|
19569
|
+
try {
|
|
19570
|
+
var waveformData = WaveformData.create(event.target.response);
|
|
19571
|
+
if (waveformData.channels !== 1 && waveformData.channels !== 2) {
|
|
19572
|
+
callback(new Error('Peaks.init(): Only mono or stereo waveforms are currently supported'));
|
|
19573
|
+
return;
|
|
19574
|
+
}
|
|
19575
|
+
callback(null, waveformData);
|
|
19576
|
+
} catch (err) {
|
|
19577
|
+
callback(err);
|
|
19578
|
+
}
|
|
19579
|
+
});
|
|
19472
19580
|
}, function () {
|
|
19473
19581
|
callback(new Error('XHR Failed'));
|
|
19474
19582
|
});
|
|
@@ -19492,16 +19600,18 @@ module.exports = function (WaveformData, Utils) {
|
|
|
19492
19600
|
callback(new Error('Peaks.init(): Unable to determine a compatible waveformData format'));
|
|
19493
19601
|
return;
|
|
19494
19602
|
}
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19603
|
+
scheduleIdle(function () {
|
|
19604
|
+
try {
|
|
19605
|
+
var createdWaveformData = WaveformData.create(data);
|
|
19606
|
+
if (createdWaveformData.channels !== 1 && createdWaveformData.channels !== 2) {
|
|
19607
|
+
callback(new Error('Peaks.init(): Only mono or stereo waveforms are currently supported'));
|
|
19608
|
+
return;
|
|
19609
|
+
}
|
|
19610
|
+
callback(null, createdWaveformData);
|
|
19611
|
+
} catch (err) {
|
|
19612
|
+
callback(err);
|
|
19500
19613
|
}
|
|
19501
|
-
|
|
19502
|
-
} catch (err) {
|
|
19503
|
-
callback(err);
|
|
19504
|
-
}
|
|
19614
|
+
});
|
|
19505
19615
|
};
|
|
19506
19616
|
WaveformBuilder.prototype._buildWaveformDataUsingWebAudio = function (options, callback) {
|
|
19507
19617
|
var self = this;
|
|
@@ -22359,11 +22469,11 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22359
22469
|
View.prototype.overrideInteractions = function (areInteractionsAllowed) {
|
|
22360
22470
|
this._playheadLayer.listening(areInteractionsAllowed);
|
|
22361
22471
|
this._sourcesLayer.stopDrag();
|
|
22362
|
-
this._sourcesLayer.
|
|
22472
|
+
this._sourcesLayer.batchDraw();
|
|
22363
22473
|
};
|
|
22364
22474
|
View.prototype.allowInteractions = function () {
|
|
22365
22475
|
this._sourcesLayer.stopDrag();
|
|
22366
|
-
this._sourcesLayer.
|
|
22476
|
+
this._sourcesLayer.batchDraw();
|
|
22367
22477
|
};
|
|
22368
22478
|
View.prototype.getSelectedElements = function () {
|
|
22369
22479
|
return this._modeLayer.getSelectedElements();
|
|
@@ -22392,8 +22502,8 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22392
22502
|
View.prototype.isFocused = function () {
|
|
22393
22503
|
return this._isFocused;
|
|
22394
22504
|
};
|
|
22395
|
-
View.prototype.
|
|
22396
|
-
this._sourcesLayer.
|
|
22505
|
+
View.prototype.batchDrawSourcesLayer = function () {
|
|
22506
|
+
this._sourcesLayer.batchDraw();
|
|
22397
22507
|
};
|
|
22398
22508
|
View.prototype.refresh = function () {
|
|
22399
22509
|
this._sourcesLayer.refresh();
|
|
@@ -22618,7 +22728,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22618
22728
|
this.setFrameOffset(frameOffset);
|
|
22619
22729
|
const playheadPixel = this._playheadLayer.getPlayheadPixel();
|
|
22620
22730
|
this._playheadLayer.updatePlayheadTime(this.pixelsToTime(playheadPixel));
|
|
22621
|
-
this._axis.
|
|
22731
|
+
this._axis.batchDraw();
|
|
22622
22732
|
}
|
|
22623
22733
|
const frameStartTime = this.pixelsToTime(this._frameOffset);
|
|
22624
22734
|
const frameEndTime = this.pixelsToTime(this._frameOffset + this._width);
|
|
@@ -22672,7 +22782,7 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
22672
22782
|
this._sourcesLayer.fitToView();
|
|
22673
22783
|
this._playheadLayer.fitToView();
|
|
22674
22784
|
this.updateTimeline(this._frameOffset);
|
|
22675
|
-
this._stage.
|
|
22785
|
+
this._stage.batchDraw();
|
|
22676
22786
|
}
|
|
22677
22787
|
};
|
|
22678
22788
|
View.prototype.getFullHeight = function () {
|