@checksub_team/peaks_timeline 2.3.0-alpha.1 → 2.3.0-alpha.2
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 +232 -102
- package/src/components/line-group.js +1 -1
- package/src/components/line-indicator.js +59 -18
- package/src/components/mode-layer.js +19 -2
- package/src/components/source-group.js +121 -30
- package/src/components/sources-layer.js +17 -11
- package/src/components/waveform-shape.js +96 -100
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15085,7 +15085,7 @@ module.exports = function (SourceGroup, Utils, Konva) {
|
|
|
15085
15085
|
LineGroup.prototype.addSource = function (source, sourceGroup, sourcesAround) {
|
|
15086
15086
|
if (sourceGroup) {
|
|
15087
15087
|
this._sourcesGroup[source.id] = sourceGroup;
|
|
15088
|
-
if (!sourceGroup.
|
|
15088
|
+
if (!sourceGroup.isDragged()) {
|
|
15089
15089
|
if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
|
|
15090
15090
|
sourceGroup.moveTo(this._group);
|
|
15091
15091
|
}
|
|
@@ -16027,24 +16027,24 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16027
16027
|
]);
|
|
16028
16028
|
this.refreshIndicators();
|
|
16029
16029
|
};
|
|
16030
|
-
LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText) {
|
|
16030
|
+
LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText, defaultStyle = {}) {
|
|
16031
16031
|
const indicator = new Konva.Group();
|
|
16032
16032
|
let indicatorHeight = 0;
|
|
16033
16033
|
var self = this;
|
|
16034
16034
|
var textGroup, iconGroup, subTextGroup;
|
|
16035
16035
|
var textNode, iconNode, subTextNode;
|
|
16036
16036
|
if (text) {
|
|
16037
|
-
[textGroup, textNode] = this._createIndicatorText(text);
|
|
16037
|
+
[textGroup, textNode] = this._createIndicatorText(text, 'line-indicator-text', defaultStyle);
|
|
16038
16038
|
indicator.add(textGroup);
|
|
16039
16039
|
indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
|
|
16040
16040
|
}
|
|
16041
|
-
[iconGroup, iconNode] = this._createIndicatorIcon(type);
|
|
16041
|
+
[iconGroup, iconNode] = this._createIndicatorIcon(type, 'line-indicator-icon', defaultStyle);
|
|
16042
16042
|
iconGroup.y(indicatorHeight);
|
|
16043
16043
|
indicator.add(iconGroup);
|
|
16044
16044
|
indicatorHeight += iconGroup.getAttr('trueHeight');
|
|
16045
16045
|
if (subText) {
|
|
16046
16046
|
indicatorHeight += this._bottomPadding;
|
|
16047
|
-
[subTextGroup, subTextNode] = this._createIndicatorText(subText);
|
|
16047
|
+
[subTextGroup, subTextNode] = this._createIndicatorText(subText, 'line-indicator-subText', defaultStyle);
|
|
16048
16048
|
subTextGroup.y(indicatorHeight);
|
|
16049
16049
|
indicator.add(subTextGroup);
|
|
16050
16050
|
indicatorHeight += subTextGroup.getAttr('trueHeight');
|
|
@@ -16125,16 +16125,18 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16125
16125
|
indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
|
|
16126
16126
|
return indicator;
|
|
16127
16127
|
};
|
|
16128
|
-
LineIndicator.prototype._createIndicatorText = function (text) {
|
|
16128
|
+
LineIndicator.prototype._createIndicatorText = function (text, role, defaultStyle = {}) {
|
|
16129
|
+
defaultStyle = defaultStyle[role] || {};
|
|
16129
16130
|
const textGroup = new Konva.Group();
|
|
16130
16131
|
const textNode = new Konva.Text({
|
|
16131
16132
|
text: text,
|
|
16132
16133
|
fontSize: this._sizes.font,
|
|
16133
16134
|
fontFamily: this._peaks.options.lineIndicatorFont,
|
|
16134
|
-
fill: this._peaks.options.lineIndicatorTextColor,
|
|
16135
|
+
fill: defaultStyle.fill || this._peaks.options.lineIndicatorTextColor,
|
|
16135
16136
|
align: 'center',
|
|
16136
16137
|
width: this._width,
|
|
16137
|
-
listening: false
|
|
16138
|
+
listening: false,
|
|
16139
|
+
name: role
|
|
16138
16140
|
});
|
|
16139
16141
|
textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
|
|
16140
16142
|
textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
|
|
@@ -16155,7 +16157,8 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16155
16157
|
textNode
|
|
16156
16158
|
];
|
|
16157
16159
|
};
|
|
16158
|
-
LineIndicator.prototype._createIndicatorIcon = function (type) {
|
|
16160
|
+
LineIndicator.prototype._createIndicatorIcon = function (type, role, defaultStyle = {}) {
|
|
16161
|
+
defaultStyle = defaultStyle[role] || {};
|
|
16159
16162
|
type = this._types.includes(type) ? type : 'default';
|
|
16160
16163
|
const iconGroup = new Konva.Group();
|
|
16161
16164
|
var iconHeight = this._sizes.icon[type];
|
|
@@ -16165,21 +16168,23 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16165
16168
|
x: this._width / 2,
|
|
16166
16169
|
y: this._sizes.icon.default / 2,
|
|
16167
16170
|
radius: this._sizes.icon.default / 2,
|
|
16168
|
-
fill: this._peaks.options.lineIndicatorIconColor,
|
|
16171
|
+
fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
|
|
16169
16172
|
strokeWidth: 0,
|
|
16170
|
-
listening: false
|
|
16173
|
+
listening: false,
|
|
16174
|
+
name: role
|
|
16171
16175
|
});
|
|
16172
16176
|
} else {
|
|
16173
16177
|
iconNode = new Konva.Path({
|
|
16174
16178
|
x: (this._width - this._sizes.icon[type]) / 2,
|
|
16175
16179
|
y: 0,
|
|
16176
16180
|
data: SVGs[type].path,
|
|
16177
|
-
fill: this._peaks.options.lineIndicatorIconColor,
|
|
16181
|
+
fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
|
|
16178
16182
|
scale: {
|
|
16179
16183
|
x: this._sizes.icon[type] / SVGs[type].width,
|
|
16180
16184
|
y: this._sizes.icon[type] / SVGs[type].height
|
|
16181
16185
|
},
|
|
16182
|
-
listening: false
|
|
16186
|
+
listening: false,
|
|
16187
|
+
name: role
|
|
16183
16188
|
});
|
|
16184
16189
|
}
|
|
16185
16190
|
iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
|
|
@@ -16221,11 +16226,11 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16221
16226
|
this._peaks.logger('peaks.line-indicator.update(): line indicator not found: ' + line.id);
|
|
16222
16227
|
return;
|
|
16223
16228
|
}
|
|
16224
|
-
if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText) {
|
|
16229
|
+
if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText && indicatorData.subText === line.indicatorSubText) {
|
|
16225
16230
|
return;
|
|
16226
16231
|
}
|
|
16227
|
-
this.removeIndicator(line.id, true);
|
|
16228
|
-
var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText);
|
|
16232
|
+
const styleData = this.removeIndicator(line.id, true);
|
|
16233
|
+
var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText, styleData);
|
|
16229
16234
|
this._layer.add(indicator);
|
|
16230
16235
|
indicatorData.indicator = indicator;
|
|
16231
16236
|
indicatorData.type = line.indicatorType;
|
|
@@ -16233,17 +16238,40 @@ module.exports = function (Konva, SVGs, Invoker, Utils) {
|
|
|
16233
16238
|
indicatorData.subText = line.indicatorSubText;
|
|
16234
16239
|
this.batchDraw();
|
|
16235
16240
|
};
|
|
16241
|
+
LineIndicator.prototype._getStyleData = function (konvaItem) {
|
|
16242
|
+
if (!konvaItem) {
|
|
16243
|
+
return {};
|
|
16244
|
+
}
|
|
16245
|
+
var styleData = {};
|
|
16246
|
+
const name = konvaItem.name();
|
|
16247
|
+
if (name) {
|
|
16248
|
+
styleData[name] = { fill: konvaItem.fill() };
|
|
16249
|
+
}
|
|
16250
|
+
if (typeof konvaItem.getChildren === 'function') {
|
|
16251
|
+
const children = konvaItem.getChildren();
|
|
16252
|
+
if (children && children.length > 0) {
|
|
16253
|
+
children.forEach(function (child) {
|
|
16254
|
+
styleData = Object.assign(styleData, this._getStyleData(child));
|
|
16255
|
+
}.bind(this));
|
|
16256
|
+
}
|
|
16257
|
+
}
|
|
16258
|
+
return styleData;
|
|
16259
|
+
};
|
|
16236
16260
|
LineIndicator.prototype.removeIndicator = function (lineId, keepInList) {
|
|
16261
|
+
var styleData = {};
|
|
16237
16262
|
if (this._indicators[lineId]) {
|
|
16238
|
-
|
|
16239
|
-
this._indicators[lineId].indicator.destroy();
|
|
16240
|
-
}
|
|
16263
|
+
const indicator = this._indicators[lineId].indicator;
|
|
16241
16264
|
if (!keepInList) {
|
|
16242
16265
|
delete this._indicators[lineId];
|
|
16243
16266
|
} else {
|
|
16244
16267
|
this._indicators[lineId].indicator = null;
|
|
16268
|
+
styleData = this._getStyleData(indicator);
|
|
16269
|
+
}
|
|
16270
|
+
if (indicator) {
|
|
16271
|
+
indicator.destroy();
|
|
16245
16272
|
}
|
|
16246
16273
|
}
|
|
16274
|
+
return styleData;
|
|
16247
16275
|
};
|
|
16248
16276
|
LineIndicator.prototype.refreshIndicator = function (lineId) {
|
|
16249
16277
|
var anyChange = false;
|
|
@@ -16648,6 +16676,10 @@ module.exports = function (SourceGroup, Invoker, Source, Utils, Konva) {
|
|
|
16648
16676
|
};
|
|
16649
16677
|
ModeLayer.prototype._onMouseMoveInCutMode = function () {
|
|
16650
16678
|
var mousePosition = this._stage.getPointerPosition();
|
|
16679
|
+
if (!mousePosition) {
|
|
16680
|
+
return;
|
|
16681
|
+
}
|
|
16682
|
+
this._syncHoveredElementFromPointer();
|
|
16651
16683
|
mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
|
|
16652
16684
|
var cuttingPosition = mousePosition;
|
|
16653
16685
|
var hoveredElement = this._view.getHoveredElement();
|
|
@@ -16707,13 +16739,17 @@ module.exports = function (SourceGroup, Invoker, Source, Utils, Konva) {
|
|
|
16707
16739
|
while (node) {
|
|
16708
16740
|
if (node.attrs && node.attrs.sourceId) {
|
|
16709
16741
|
var sourceGroup = this._view.getSourceGroupById(node.attrs.sourceId);
|
|
16710
|
-
if (sourceGroup
|
|
16711
|
-
|
|
16742
|
+
if (sourceGroup) {
|
|
16743
|
+
this._view.setHoveredElement(sourceGroup);
|
|
16744
|
+
if (!sourceGroup.isHovered()) {
|
|
16745
|
+
sourceGroup.startHover();
|
|
16746
|
+
}
|
|
16712
16747
|
}
|
|
16713
16748
|
return;
|
|
16714
16749
|
}
|
|
16715
16750
|
node = node.getParent ? node.getParent() : null;
|
|
16716
16751
|
}
|
|
16752
|
+
this._view.setHoveredElement(null);
|
|
16717
16753
|
};
|
|
16718
16754
|
ModeLayer.prototype.setMode = function (mode) {
|
|
16719
16755
|
if (this._mode === mode) {
|
|
@@ -18115,7 +18151,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18115
18151
|
this._selected = this._source.selected;
|
|
18116
18152
|
this._hovered = false;
|
|
18117
18153
|
this._isDragged = false;
|
|
18118
|
-
this.
|
|
18154
|
+
this._isHandleDragged = false;
|
|
18119
18155
|
this._destroyed = false;
|
|
18120
18156
|
this._dragGhost = null;
|
|
18121
18157
|
this._drawScheduled = false;
|
|
@@ -18246,7 +18282,10 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18246
18282
|
return this._hovered;
|
|
18247
18283
|
};
|
|
18248
18284
|
SourceGroup.prototype.isActive = function () {
|
|
18249
|
-
return this._isDragged || this.
|
|
18285
|
+
return this._isDragged || this._isHandleDragged;
|
|
18286
|
+
};
|
|
18287
|
+
SourceGroup.prototype.isDragged = function () {
|
|
18288
|
+
return this._isDragged;
|
|
18250
18289
|
};
|
|
18251
18290
|
SourceGroup.prototype.addToContent = function (newChild) {
|
|
18252
18291
|
if (this._source.wrapped) {
|
|
@@ -18255,7 +18294,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18255
18294
|
this._unwrap.add(newChild);
|
|
18256
18295
|
}
|
|
18257
18296
|
};
|
|
18258
|
-
SourceGroup.prototype.
|
|
18297
|
+
SourceGroup.prototype._updateHandles = function () {
|
|
18259
18298
|
var handleWidth = Math.min(this._peaks.options.sourceHandleWidth, this._width / 2);
|
|
18260
18299
|
this._leftHandle.width(handleWidth);
|
|
18261
18300
|
this._rightHandle.width(handleWidth);
|
|
@@ -18291,7 +18330,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18291
18330
|
if (newTimeToPixelsScale !== this._currentTimeToPixelsScaleUsed) {
|
|
18292
18331
|
this._currentTimeToPixelsScaleUsed = newTimeToPixelsScale;
|
|
18293
18332
|
this._updateMarkers();
|
|
18294
|
-
this._rightHandle.x(this._width - this._rightHandle.width());
|
|
18295
18333
|
} else {
|
|
18296
18334
|
const newTitle = Utils.removeLineBreaks(this._source.getVisibleTitle());
|
|
18297
18335
|
if (this._wrappedTitle && this._wrappedTitle.text() !== newTitle) {
|
|
@@ -18301,6 +18339,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18301
18339
|
this._unwrap.add(this._createTitle(false));
|
|
18302
18340
|
}
|
|
18303
18341
|
}
|
|
18342
|
+
this._updateHandles();
|
|
18304
18343
|
this._updateVolumeSlider();
|
|
18305
18344
|
this._updateButtons();
|
|
18306
18345
|
this._updateLoadingOverlay();
|
|
@@ -18342,14 +18381,13 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18342
18381
|
start: this._source.startTime,
|
|
18343
18382
|
end: this._source.endTime
|
|
18344
18383
|
};
|
|
18345
|
-
this.
|
|
18384
|
+
this._isHandleDragged = true;
|
|
18346
18385
|
this._hideButtons();
|
|
18347
18386
|
};
|
|
18348
18387
|
SourceGroup.prototype._onHandleDragEnd = function () {
|
|
18349
|
-
this.
|
|
18388
|
+
this._isHandleDragged = false;
|
|
18350
18389
|
this._showButtons();
|
|
18351
|
-
this.
|
|
18352
|
-
this.prepareDragEnd();
|
|
18390
|
+
this._layer.processSourceUpdates([this._source]);
|
|
18353
18391
|
};
|
|
18354
18392
|
SourceGroup.prototype._addHandles = function (forceCreate) {
|
|
18355
18393
|
var self = this;
|
|
@@ -18443,9 +18481,8 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18443
18481
|
SourceGroup.prototype.drawSourceShape = function (ctx, shape, addBorderWidth, fill) {
|
|
18444
18482
|
var offset = addBorderWidth ? this._borderWidth : 0;
|
|
18445
18483
|
var radius = !Utils.isNullOrUndefined(this._source.borderRadius) ? this._source.borderRadius : Math.max(1, Math.min(this._width / 2, Math.min(CORNER_RADIUS, this._height / 2)));
|
|
18446
|
-
var
|
|
18447
|
-
var
|
|
18448
|
-
var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, actualX - this._view.getFrameOffset()));
|
|
18484
|
+
var x = Math.max(0, -(this._group.x() + 2 * radius));
|
|
18485
|
+
var width = Math.min(this._width - x, this._view.getWidth() + 4 * radius - Math.max(0, this._group.x()));
|
|
18449
18486
|
var xWidth = x + width;
|
|
18450
18487
|
if (width > 0) {
|
|
18451
18488
|
ctx.beginPath();
|
|
@@ -18463,7 +18500,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18463
18500
|
var backgroundColor;
|
|
18464
18501
|
if (this._selected) {
|
|
18465
18502
|
backgroundColor = this._source.selectedBackgroundColor;
|
|
18466
|
-
} else if (this._hovered) {
|
|
18503
|
+
} else if (this._hovered && this._view.getCurrentMode() !== 'cut') {
|
|
18467
18504
|
backgroundColor = this._source.hoverBackgroundColor;
|
|
18468
18505
|
} else {
|
|
18469
18506
|
backgroundColor = this._source.backgroundColor;
|
|
@@ -18809,12 +18846,14 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18809
18846
|
});
|
|
18810
18847
|
}
|
|
18811
18848
|
}
|
|
18849
|
+
var self = this;
|
|
18812
18850
|
var waveform = new WaveformShape({
|
|
18813
|
-
layer: this._layer,
|
|
18814
18851
|
view: this._view,
|
|
18815
|
-
|
|
18852
|
+
color: this._source.color,
|
|
18816
18853
|
height: preview.group.height(),
|
|
18817
|
-
|
|
18854
|
+
waveformDataFunc: function () {
|
|
18855
|
+
return self._createWaveformPointsIterator(url);
|
|
18856
|
+
}
|
|
18818
18857
|
});
|
|
18819
18858
|
preview.group.add(waveform);
|
|
18820
18859
|
this._addToUnwrap(preview.group);
|
|
@@ -18823,6 +18862,69 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
18823
18862
|
}
|
|
18824
18863
|
this._previewList.push(preview);
|
|
18825
18864
|
};
|
|
18865
|
+
SourceGroup.prototype._createWaveformPointsIterator = function (url) {
|
|
18866
|
+
var loaded = this._layer.getLoadedData(url + '-scaled');
|
|
18867
|
+
var waveformData = loaded && loaded.data;
|
|
18868
|
+
if (!waveformData) {
|
|
18869
|
+
return {
|
|
18870
|
+
next: function () {
|
|
18871
|
+
return { done: true };
|
|
18872
|
+
}
|
|
18873
|
+
};
|
|
18874
|
+
}
|
|
18875
|
+
var view = this._view;
|
|
18876
|
+
var source = this._source;
|
|
18877
|
+
var groupX = this._group && typeof this._group.x === 'function' ? this._group.x() : 0;
|
|
18878
|
+
var groupWidth = this._width;
|
|
18879
|
+
var viewWidth = view.getWidth();
|
|
18880
|
+
var startPixel = 0;
|
|
18881
|
+
var startOffset = 0;
|
|
18882
|
+
var endPixel = Math.min(viewWidth, waveformData.length);
|
|
18883
|
+
var targetSpeed = 1;
|
|
18884
|
+
if (source) {
|
|
18885
|
+
targetSpeed = source.targetSpeed || 1;
|
|
18886
|
+
var hiddenLeftPixels = Math.max(-groupX, 0);
|
|
18887
|
+
var hiddenRightPixels = Math.max(groupX + groupWidth - viewWidth, 0);
|
|
18888
|
+
startPixel = Math.floor((view.timeToPixels(source.mediaStartTime) + hiddenLeftPixels) * targetSpeed);
|
|
18889
|
+
startOffset = view.timeToPixels(source.mediaStartTime);
|
|
18890
|
+
endPixel = Math.min(Math.ceil((view.timeToPixels(source.mediaEndTime) - hiddenRightPixels) * targetSpeed), waveformData.length);
|
|
18891
|
+
}
|
|
18892
|
+
if (startPixel < 0) {
|
|
18893
|
+
startPixel = 0;
|
|
18894
|
+
}
|
|
18895
|
+
if (endPixel < startPixel) {
|
|
18896
|
+
endPixel = startPixel;
|
|
18897
|
+
}
|
|
18898
|
+
var channels = waveformData.channels;
|
|
18899
|
+
var channelData = new Array(channels);
|
|
18900
|
+
for (var c = 0; c < channels; c++) {
|
|
18901
|
+
channelData[c] = waveformData.channel(c);
|
|
18902
|
+
}
|
|
18903
|
+
var x = startPixel;
|
|
18904
|
+
return {
|
|
18905
|
+
next: function () {
|
|
18906
|
+
if (x >= endPixel) {
|
|
18907
|
+
return { done: true };
|
|
18908
|
+
}
|
|
18909
|
+
var min = new Array(channels);
|
|
18910
|
+
var max = new Array(channels);
|
|
18911
|
+
for (var i = 0; i < channels; i++) {
|
|
18912
|
+
min[i] = channelData[i].min_sample(x);
|
|
18913
|
+
max[i] = channelData[i].max_sample(x);
|
|
18914
|
+
}
|
|
18915
|
+
var value = {
|
|
18916
|
+
x: x / targetSpeed - startOffset + 0.5,
|
|
18917
|
+
min: min,
|
|
18918
|
+
max: max
|
|
18919
|
+
};
|
|
18920
|
+
x++;
|
|
18921
|
+
return {
|
|
18922
|
+
done: false,
|
|
18923
|
+
value: value
|
|
18924
|
+
};
|
|
18925
|
+
}
|
|
18926
|
+
};
|
|
18927
|
+
};
|
|
18826
18928
|
SourceGroup.prototype.getAudioPreview = function () {
|
|
18827
18929
|
return this._previewList.filter(function (preview) {
|
|
18828
18930
|
return preview.type === 'audio';
|
|
@@ -19479,18 +19581,21 @@ module.exports = function (WaveformBuilder, WaveformShape, Loader, Invoker, Util
|
|
|
19479
19581
|
});
|
|
19480
19582
|
volumeSliderGroup.add(volumeSliderRect);
|
|
19481
19583
|
volumeSliderGroup.add(volumeSliderLine);
|
|
19482
|
-
volumeSliderGroup.on('dragstart', function () {
|
|
19584
|
+
volumeSliderGroup.on('dragstart', function (evt) {
|
|
19585
|
+
evt.cancelBubble = true;
|
|
19483
19586
|
volumeText.visible(true);
|
|
19484
19587
|
self._peaks.emit('source.startVolumeChange', self._source);
|
|
19485
19588
|
});
|
|
19486
|
-
volumeSliderGroup.on('dragmove', function () {
|
|
19589
|
+
volumeSliderGroup.on('dragmove', function (evt) {
|
|
19590
|
+
evt.cancelBubble = true;
|
|
19487
19591
|
var volume = self._getVolumeFromY(volumeSliderGroup.y());
|
|
19488
19592
|
volumeText.text((volume * 100).toFixed(0) + '%');
|
|
19489
19593
|
self._source.volume = Math.max(self._source.volumeRange[0], Math.min(volume, self._source.volumeRange[1]));
|
|
19490
19594
|
self._peaks.emit('source.volumeChanged', self._source);
|
|
19491
19595
|
self._scheduleBatchDraw();
|
|
19492
19596
|
});
|
|
19493
|
-
volumeSliderGroup.on('dragend', function () {
|
|
19597
|
+
volumeSliderGroup.on('dragend', function (evt) {
|
|
19598
|
+
evt.cancelBubble = true;
|
|
19494
19599
|
volumeText.visible(false);
|
|
19495
19600
|
self._peaks.emit('source.endVolumeChange', self._source);
|
|
19496
19601
|
});
|
|
@@ -19621,19 +19726,19 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19621
19726
|
const frameEndTime = this._view.pixelsToTime(frameOffset + width);
|
|
19622
19727
|
var redraw = false;
|
|
19623
19728
|
var isSourceGroupHovered = false;
|
|
19624
|
-
var
|
|
19729
|
+
var isSourceGroupDragged = false;
|
|
19625
19730
|
if (sourceGroup) {
|
|
19626
19731
|
isSourceGroupHovered = sourceGroup.isHovered();
|
|
19627
|
-
|
|
19732
|
+
isSourceGroupDragged = sourceGroup.isDragged();
|
|
19628
19733
|
this._destroySourceGroup(source);
|
|
19629
19734
|
redraw = true;
|
|
19630
19735
|
}
|
|
19631
|
-
if (source.isVisible(frameStartTime, frameEndTime) ||
|
|
19736
|
+
if (source.isVisible(frameStartTime, frameEndTime) || isSourceGroupDragged) {
|
|
19632
19737
|
const newSourceGroup = this._addSourceGroup(source);
|
|
19633
19738
|
if (isSourceGroupHovered) {
|
|
19634
19739
|
newSourceGroup.startHover();
|
|
19635
19740
|
}
|
|
19636
|
-
if (
|
|
19741
|
+
if (isSourceGroupDragged) {
|
|
19637
19742
|
newSourceGroup.startDrag();
|
|
19638
19743
|
}
|
|
19639
19744
|
redraw = true;
|
|
@@ -19795,7 +19900,6 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19795
19900
|
const sourceGroup = self._sourcesGroup[source.id];
|
|
19796
19901
|
if (sourceGroup) {
|
|
19797
19902
|
sourceGroup.setDragging(false);
|
|
19798
|
-
sourceGroup.prepareDragEnd();
|
|
19799
19903
|
self._lineGroups.addSource(source, sourceGroup);
|
|
19800
19904
|
sourceGroup.y(0);
|
|
19801
19905
|
}
|
|
@@ -19803,9 +19907,7 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19803
19907
|
});
|
|
19804
19908
|
this._draggedElementId = null;
|
|
19805
19909
|
this.refresh();
|
|
19806
|
-
this.
|
|
19807
|
-
this._view.updateTimelineLength();
|
|
19808
|
-
this._peaks.emit('sources.updated', updatedSources);
|
|
19910
|
+
this.processSourceUpdates(updatedSources);
|
|
19809
19911
|
};
|
|
19810
19912
|
SourcesLayer.prototype.onSourcesGroupDrag = function (draggedElement) {
|
|
19811
19913
|
var pointerPos = this._view.getPointerPosition();
|
|
@@ -19875,6 +19977,11 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19875
19977
|
this.batchDraw();
|
|
19876
19978
|
}
|
|
19877
19979
|
};
|
|
19980
|
+
SourcesLayer.prototype.processSourceUpdates = function (updatedSources) {
|
|
19981
|
+
this._view.batchDrawSourcesLayer();
|
|
19982
|
+
this._view.updateTimelineLength();
|
|
19983
|
+
this._peaks.emit('sources.updated', updatedSources);
|
|
19984
|
+
};
|
|
19878
19985
|
SourcesLayer.prototype.findSources = function (startTime, endTime) {
|
|
19879
19986
|
var sources = this._peaks.sourceHandler.find(startTime, endTime);
|
|
19880
19987
|
var lineIds = this._lineGroups.getVisibleLines();
|
|
@@ -19985,7 +20092,9 @@ module.exports = function (SourceGroup, LineGroups, DataRetriever, Invoker, Util
|
|
|
19985
20092
|
for (var sourceId in this._sourcesGroup) {
|
|
19986
20093
|
if (Utils.objectHasProperty(this._sourcesGroup, sourceId)) {
|
|
19987
20094
|
var sourceGroup = this._sourcesGroup[sourceId];
|
|
19988
|
-
if (
|
|
20095
|
+
if (sourceGroup.isActive()) {
|
|
20096
|
+
sourceGroup.update();
|
|
20097
|
+
} else {
|
|
19989
20098
|
var source = this._sourcesGroup[sourceId].getSource();
|
|
19990
20099
|
if (!this._isSourceVisible(source, startTime, endTime)) {
|
|
19991
20100
|
this._destroySourceGroup(source);
|
|
@@ -20392,83 +20501,104 @@ module.exports = function (Utils, Konva) {
|
|
|
20392
20501
|
return height - Utils.clamp(height - scaledAmplitude, 0, height);
|
|
20393
20502
|
}
|
|
20394
20503
|
function WaveformShape(options) {
|
|
20395
|
-
const shape = new Konva.Shape({
|
|
20504
|
+
const shape = new Konva.Shape({
|
|
20505
|
+
fill: options.color,
|
|
20506
|
+
listening: false
|
|
20507
|
+
});
|
|
20396
20508
|
Object.assign(this, shape);
|
|
20397
|
-
this._layer = options.layer;
|
|
20398
20509
|
this._view = options.view;
|
|
20399
|
-
this._source = options.source;
|
|
20400
20510
|
this._height = options.height;
|
|
20401
|
-
this.
|
|
20402
|
-
this.sceneFunc(
|
|
20403
|
-
|
|
20511
|
+
this._waveformDataFunc = options.waveformDataFunc;
|
|
20512
|
+
this.sceneFunc(function (context) {
|
|
20513
|
+
var waveformPoints = this._waveformDataFunc ? this._waveformDataFunc() : null;
|
|
20514
|
+
this._sceneFunc(context, waveformPoints);
|
|
20515
|
+
});
|
|
20404
20516
|
}
|
|
20405
20517
|
WaveformShape.prototype = Object.create(Konva.Shape.prototype);
|
|
20406
|
-
WaveformShape.prototype._sceneFunc = function (context) {
|
|
20407
|
-
|
|
20408
|
-
|
|
20409
|
-
|
|
20410
|
-
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20518
|
+
WaveformShape.prototype._sceneFunc = function (context, waveformPoints) {
|
|
20519
|
+
if (!waveformPoints) {
|
|
20520
|
+
return;
|
|
20521
|
+
}
|
|
20522
|
+
var xPoints = [];
|
|
20523
|
+
var minByChannel = [];
|
|
20524
|
+
var maxByChannel = [];
|
|
20525
|
+
var channels = 0;
|
|
20526
|
+
this._forEachWaveformPoint(waveformPoints, function (point) {
|
|
20527
|
+
if (!point || !point.min || !point.max) {
|
|
20528
|
+
return;
|
|
20529
|
+
}
|
|
20530
|
+
if (channels === 0) {
|
|
20531
|
+
channels = point.min.length;
|
|
20532
|
+
for (var c = 0; c < channels; c++) {
|
|
20533
|
+
minByChannel[c] = [];
|
|
20534
|
+
maxByChannel[c] = [];
|
|
20535
|
+
}
|
|
20536
|
+
}
|
|
20537
|
+
xPoints.push(point.x);
|
|
20538
|
+
for (var i = 0; i < channels; i++) {
|
|
20539
|
+
minByChannel[i].push(point.min[i]);
|
|
20540
|
+
maxByChannel[i].push(point.max[i]);
|
|
20541
|
+
}
|
|
20542
|
+
});
|
|
20543
|
+
if (channels === 0 || xPoints.length === 0) {
|
|
20544
|
+
return;
|
|
20415
20545
|
}
|
|
20416
|
-
this.
|
|
20546
|
+
this._drawWaveformFromPoints(context, xPoints, minByChannel, maxByChannel, channels, this._height);
|
|
20417
20547
|
};
|
|
20418
|
-
WaveformShape.prototype.
|
|
20419
|
-
|
|
20548
|
+
WaveformShape.prototype._forEachWaveformPoint = function (waveformPoints, callback) {
|
|
20549
|
+
if (!waveformPoints) {
|
|
20550
|
+
return;
|
|
20551
|
+
}
|
|
20552
|
+
if (typeof waveformPoints.next === 'function') {
|
|
20553
|
+
while (true) {
|
|
20554
|
+
var result = waveformPoints.next();
|
|
20555
|
+
if (!result || result.done) {
|
|
20556
|
+
break;
|
|
20557
|
+
}
|
|
20558
|
+
callback(result.value);
|
|
20559
|
+
}
|
|
20560
|
+
return;
|
|
20561
|
+
}
|
|
20562
|
+
if (typeof Symbol !== 'undefined' && waveformPoints[Symbol.iterator]) {
|
|
20563
|
+
var iterator = waveformPoints[Symbol.iterator]();
|
|
20564
|
+
while (true) {
|
|
20565
|
+
var iterResult = iterator.next();
|
|
20566
|
+
if (iterResult.done) {
|
|
20567
|
+
break;
|
|
20568
|
+
}
|
|
20569
|
+
callback(iterResult.value);
|
|
20570
|
+
}
|
|
20571
|
+
return;
|
|
20572
|
+
}
|
|
20573
|
+
if (Array.isArray(waveformPoints)) {
|
|
20574
|
+
for (var i = 0; i < waveformPoints.length; i++) {
|
|
20575
|
+
callback(waveformPoints[i]);
|
|
20576
|
+
}
|
|
20577
|
+
}
|
|
20578
|
+
};
|
|
20579
|
+
WaveformShape.prototype._drawWaveformFromPoints = function (context, xPoints, minByChannel, maxByChannel, channels, height) {
|
|
20420
20580
|
var waveformTop = 0;
|
|
20421
20581
|
var waveformHeight = Math.floor(height / channels);
|
|
20422
20582
|
for (var i = 0; i < channels; i++) {
|
|
20423
20583
|
if (i === channels - 1) {
|
|
20424
20584
|
waveformHeight = height - (channels - 1) * waveformHeight;
|
|
20425
20585
|
}
|
|
20426
|
-
this.
|
|
20586
|
+
this._drawChannelFromPoints(context, xPoints, minByChannel[i], maxByChannel[i], waveformTop, waveformHeight);
|
|
20427
20587
|
waveformTop += waveformHeight;
|
|
20428
20588
|
}
|
|
20429
20589
|
};
|
|
20430
|
-
WaveformShape.prototype.
|
|
20431
|
-
var x, val;
|
|
20590
|
+
WaveformShape.prototype._drawChannelFromPoints = function (context, xPoints, minValues, maxValues, top, height) {
|
|
20432
20591
|
var amplitudeScale = this._view.getAmplitudeScale();
|
|
20433
20592
|
context.beginPath();
|
|
20434
|
-
for (
|
|
20435
|
-
|
|
20436
|
-
context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
|
|
20593
|
+
for (var i = 0; i < xPoints.length; i++) {
|
|
20594
|
+
context.lineTo(xPoints[i], top + scaleY(minValues[i], height, amplitudeScale) + 0.5);
|
|
20437
20595
|
}
|
|
20438
|
-
for (
|
|
20439
|
-
|
|
20440
|
-
context.lineTo(x / targetSpeed - startOffset + 0.5, top + scaleY(val, height, amplitudeScale) + 0.5);
|
|
20596
|
+
for (var j = xPoints.length - 1; j >= 0; j--) {
|
|
20597
|
+
context.lineTo(xPoints[j], top + scaleY(maxValues[j], height, amplitudeScale) + 0.5);
|
|
20441
20598
|
}
|
|
20442
20599
|
context.closePath();
|
|
20443
20600
|
context.fillShape(this);
|
|
20444
20601
|
};
|
|
20445
|
-
WaveformShape.prototype._waveformShapeHitFunc = function (context) {
|
|
20446
|
-
if (!this._source) {
|
|
20447
|
-
return;
|
|
20448
|
-
}
|
|
20449
|
-
var frameOffset = this._view.getFrameOffset();
|
|
20450
|
-
var viewWidth = this._view.getWidth();
|
|
20451
|
-
var startPixels = this._view.timeToPixels(this._source.startTime);
|
|
20452
|
-
var endPixels = this._view.timeToPixels(this._source.endTime);
|
|
20453
|
-
var offsetY = 10;
|
|
20454
|
-
var hitRectHeight = this._height;
|
|
20455
|
-
if (hitRectHeight < 0) {
|
|
20456
|
-
hitRectHeight = 0;
|
|
20457
|
-
}
|
|
20458
|
-
var hitRectLeft = startPixels - frameOffset;
|
|
20459
|
-
var hitRectWidth = endPixels - startPixels;
|
|
20460
|
-
if (hitRectLeft < 0) {
|
|
20461
|
-
hitRectWidth -= -hitRectLeft;
|
|
20462
|
-
hitRectLeft = 0;
|
|
20463
|
-
}
|
|
20464
|
-
if (hitRectLeft + hitRectWidth > viewWidth) {
|
|
20465
|
-
hitRectWidth -= hitRectLeft + hitRectWidth - viewWidth;
|
|
20466
|
-
}
|
|
20467
|
-
context.beginPath();
|
|
20468
|
-
context.rect(hitRectLeft, offsetY, hitRectWidth, hitRectHeight);
|
|
20469
|
-
context.closePath();
|
|
20470
|
-
context.fillStrokeShape(this);
|
|
20471
|
-
};
|
|
20472
20602
|
return WaveformShape;
|
|
20473
20603
|
}(_dereq_('../utils'), _dereq_('konva'));
|
|
20474
20604
|
},{"../utils":116,"konva":43}],107:[function(_dereq_,module,exports){
|
|
@@ -197,7 +197,7 @@ define([
|
|
|
197
197
|
this._sourcesGroup[source.id] = sourceGroup;
|
|
198
198
|
// Only move to this group if not currently being dragged
|
|
199
199
|
// (during drag, source stays in drag layer for z-order)
|
|
200
|
-
if (!sourceGroup.
|
|
200
|
+
if (!sourceGroup.isDragged()) {
|
|
201
201
|
if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
|
|
202
202
|
sourceGroup.moveTo(this._group);
|
|
203
203
|
}
|