diff options
Diffstat (limited to 'src/client/views/nodes/audio')
-rw-r--r-- | src/client/views/nodes/audio/AudioWaveform.tsx | 8 | ||||
-rw-r--r-- | src/client/views/nodes/audio/WaveCanvas.tsx | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/client/views/nodes/audio/AudioWaveform.tsx b/src/client/views/nodes/audio/AudioWaveform.tsx index 7fd799952..2d1d3d7db 100644 --- a/src/client/views/nodes/audio/AudioWaveform.tsx +++ b/src/client/views/nodes/audio/AudioWaveform.tsx @@ -7,8 +7,8 @@ import { List } from '../../../../fields/List'; import { listSpec } from '../../../../fields/Schema'; import { Cast } from '../../../../fields/Types'; import { numberRange } from '../../../../Utils'; +import { Colors } from '../../global/globalEnums'; import { ObservableReactComponent } from '../../ObservableReactComponent'; -import { Colors } from './../../global/globalEnums'; import './AudioWaveform.scss'; import { WaveCanvas } from './WaveCanvas'; @@ -62,7 +62,7 @@ export class AudioWaveform extends ObservableReactComponent<AudioWaveformProps> return NumListCast(this._props.layoutDoc[this.audioBucketField(this.clipStart, this.clipEnd, this.zoomFactor)]); } - audioBucketField = (start: number, end: number, zoomFactor: number) => this._props.fieldKey + '_audioBuckets/' + '/' + start.toFixed(2).replace('.', '_') + '/' + end.toFixed(2).replace('.', '_') + '/' + zoomFactor * 10; + audioBucketField = (start: number, end: number, zoomFactor: number) => this._props.fieldKey + '_audioBuckets//' + start.toFixed(2).replace('.', '_') + '/' + end.toFixed(2).replace('.', '_') + '/' + zoomFactor * 10; componentWillUnmount() { this._disposer?.(); @@ -72,7 +72,7 @@ export class AudioWaveform extends ObservableReactComponent<AudioWaveformProps> this._disposer = reaction( () => ({ clipStart: this.clipStart, clipEnd: this.clipEnd, fieldKey: this.audioBucketField(this.clipStart, this.clipEnd, this.zoomFactor), zoomFactor: this._props.zoomFactor }), ({ clipStart, clipEnd, fieldKey, zoomFactor }) => { - if (!this._props.layoutDoc[fieldKey] && this._props.layoutDoc.layout_fieldKey != 'layout_icon') { + if (!this._props.layoutDoc[fieldKey] && this._props.layoutDoc.layout_fieldKey !== 'layout_icon') { // setting these values here serves as a "lock" to prevent multiple attempts to create the waveform at nerly the same time. const waveform = Cast(this._props.layoutDoc[this.audioBucketField(0, this._props.rawDuration, 1)], listSpec('number')); this._props.layoutDoc[fieldKey] = waveform && new List<number>(waveform.slice((clipStart / this._props.rawDuration) * waveform.length, (clipEnd / this._props.rawDuration) * waveform.length)); @@ -109,7 +109,7 @@ export class AudioWaveform extends ObservableReactComponent<AudioWaveformProps> progressColor={Colors.MEDIUM_BLUE_ALT} progress={this._props.progress ?? 1} barWidth={200 / this.audioBuckets.length} - //gradientColors={this._props.gradientColors} + // gradientColors={this._props.gradientColors} peaks={this.audioBuckets} width={(this._props.PanelWidth ?? 0) * window.devicePixelRatio} height={this.waveHeight * window.devicePixelRatio} diff --git a/src/client/views/nodes/audio/WaveCanvas.tsx b/src/client/views/nodes/audio/WaveCanvas.tsx index d3f5669a2..eacda2d42 100644 --- a/src/client/views/nodes/audio/WaveCanvas.tsx +++ b/src/client/views/nodes/audio/WaveCanvas.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react/require-default-props */ import React from 'react'; interface WaveCanvasProps { @@ -14,7 +15,7 @@ interface WaveCanvasProps { export class WaveCanvas extends React.Component<WaveCanvasProps> { // If the first value of peaks is negative, addToIndices will be 1 - posPeaks = (peaks: number[], addToIndices: number) => peaks.filter((_, index) => (index + addToIndices) % 2 == 0); + posPeaks = (peaks: number[], addToIndices: number) => peaks.filter((_, index) => (index + addToIndices) % 2 === 0); drawBars = (waveCanvasCtx: CanvasRenderingContext2D, width: number, halfH: number, peaks: number[]) => { // Bar wave draws the bottom only as a reflection of the top, @@ -47,6 +48,7 @@ export class WaveCanvas extends React.Component<WaveCanvasProps> { // A half-pixel offset makes lines crisp const $ = 0.5 / this.props.pixelRatio; + // eslint-disable-next-line no-bitwise const length = ~~(allPeaks.length / 2); // ~~ is Math.floor for positive numbers. const scale = width / length; @@ -55,14 +57,14 @@ export class WaveCanvas extends React.Component<WaveCanvasProps> { waveCanvasCtx.beginPath(); waveCanvasCtx.moveTo($, halfH); - for (var i = 0; i < length; i++) { - var h = Math.round((allPeaks[2 * i] / absmax) * halfH); + for (let i = 0; i < length; i++) { + const h = Math.round((allPeaks[2 * i] / absmax) * halfH); waveCanvasCtx.lineTo(i * scale + $, halfH - h); } // Draw the bottom edge going backwards, to make a single closed hull to fill. - for (var i = length - 1; i >= 0; i--) { - var h = Math.round((allPeaks[2 * i + 1] / absmax) * halfH); + for (let i = length - 1; i >= 0; i--) { + const h = Math.round((allPeaks[2 * i + 1] / absmax) * halfH); waveCanvasCtx.lineTo(i * scale + $, halfH - h); } |