diff options
author | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-08-05 04:08:01 -0700 |
---|---|---|
committer | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-08-05 04:08:01 -0700 |
commit | 4062563cdc4606d9513ab7f9d0524e92a6e90305 (patch) | |
tree | cdddf167d3506d89043c2c025c25d80546ca8f54 | |
parent | 2f12e2d6945c51eb7df961443fe5d06b10577659 (diff) |
made waveform resizable (still have progress bar bug)
-rw-r--r-- | src/client/views/nodes/AudioBox.scss | 4 | ||||
-rw-r--r-- | src/client/views/nodes/AudioBox.tsx | 90 | ||||
-rw-r--r-- | src/typings/index.d.ts | 4 | ||||
-rw-r--r-- | webpack.config.js | 62 |
4 files changed, 122 insertions, 38 deletions
diff --git a/src/client/views/nodes/AudioBox.scss b/src/client/views/nodes/AudioBox.scss index 9065966d7..306062ced 100644 --- a/src/client/views/nodes/AudioBox.scss +++ b/src/client/views/nodes/AudioBox.scss @@ -148,6 +148,7 @@ border: gray solid 1px; border-radius: 3px; z-index: 1000; + overflow: hidden; .audiobox-current { width: 1px; @@ -162,7 +163,8 @@ width: 100%; height: 100%; overflow: hidden; - z-index: 0; + z-index: -1000; + bottom: -30%; } .audiobox-linker, diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx index 0f142261d..682aaaeed 100644 --- a/src/client/views/nodes/AudioBox.tsx +++ b/src/client/views/nodes/AudioBox.tsx @@ -80,6 +80,8 @@ export class AudioBox extends ViewBoxAnnotatableComponent<FieldViewProps, AudioD private _isPointerDown = false; private _currMarker: any; + @observable private _height: number = NumCast(this.layoutDoc.height); + @observable private _finish: boolean = false; @observable private _dragging: boolean = false; @observable private _duration = 0; @observable private _rect: Array<any> = []; @@ -686,14 +688,92 @@ export class AudioBox extends ViewBoxAnnotatableComponent<FieldViewProps, AudioD @computed get height() { console.log(this.layoutDoc._height); if (this.layoutDoc._height) { - return 0.8 * this.layoutDoc._height + return 0.8 * NumCast(this.layoutDoc._height) } } + // waveform() { + // let wavesurfer: any; + // if (WaveSurfer) { + // this.path ? + // wavesurfer = WaveSurfer.create({ + // container: 'waveform', + // waveColor: "grey", + // progressColor: "blue" + // }) + // : + // wavesurfer = (null); + // } else { + // console.log("hi"); + // } + + // if (wavesurfer) { + // wavesurfer.on('ready', function () { + // wavesurfer.play(); + // }); + + // wavesurfer.load(this.path); + // console.log("hi"); + // } + // } + + @computed get waveform() { + return <Waveform + color={"blue"} + height={this._height} + barWidth={0.1} + pos={this.layoutDoc.currentTimecode} + duration={this.dataDoc.duration} + peaks={this._buckets.length === 100 ? this._buckets : undefined} + progressColor={"blue"} />; + } + + @action + update = () => { + if (this.layoutDoc._height) { + this._height = 0.8 * NumCast(this.layoutDoc._height); + console.log(document.getElementById("timeline")?.clientWidth); + let width = document.getElementById("timeline")?.clientWidth; + let canvas2 = document.getElementsByTagName("canvas")[0]; + if (canvas2) { + let oldWidth = canvas2.width; + let oldHeight = canvas2.height; + canvas2.style.height = `${this._height}`; + canvas2.style.width = `${width}`; + + let ratio1 = oldWidth / window.innerWidth; + let ratio2 = oldHeight / window.innerHeight; + let context = canvas2.getContext('2d'); + if (context) { + context.scale(ratio1, ratio2) + } + } + + let canvas1 = document.getElementsByTagName("canvas")[1]; + if (canvas1) { + let oldWidth = canvas1.width; + let oldHeight = canvas1.height; + canvas1.style.height = `${this._height}`; + canvas1.style.width = `${width}`; + + let ratio1 = oldWidth / window.innerWidth; + let ratio2 = oldHeight / window.innerHeight; + let context = canvas1.getContext('2d'); + if (context) { + context.scale(ratio1, ratio2) + + } + } + } + } + + render() { //trace(); const interactive = this.active() ? "-interactive" : ""; this.reset(); + this.update(); + // this.waveform(); return <div className={`audiobox-container`} onContextMenu={this.specificContextMenu} onClick={!this.path ? this.recordClick : undefined}> {!this.path ? <div className="audiobox-buttons"> @@ -755,15 +835,17 @@ export class AudioBox extends ViewBoxAnnotatableComponent<FieldViewProps, AudioD }}> <div className="waveform" id="waveform" style={{ height: `${100}%`, width: "100%", bottom: "0px" }}> {console.log(this.peaks)} - <Waveform + {/* <Waveform color={"#000000"} - height={this.height} + height={this._height} barWidth={0.1} pos={this.layoutDoc.currentTimecode} duration={this.dataDoc.duration} peaks={this._buckets.length === 100 ? this._buckets : undefined} - progressColor={"#0000ff"} /> + progressColor={"#0000ff"} /> */} + {this.waveform} + {/* {this.waveform} */} </div> {DocListCast(this.dataDoc[this.annotationKey]).map((m, i) => { // let text = Docs.Create.TextDocument("hello", { title: "label", _showSidebar: false, _autoHeight: false }); diff --git a/src/typings/index.d.ts b/src/typings/index.d.ts index ee2c25f8a..728dd51d3 100644 --- a/src/typings/index.d.ts +++ b/src/typings/index.d.ts @@ -6,8 +6,8 @@ declare module 'cors'; declare module 'webrtc-adapter'; declare module 'bezier-curve'; -declare module 'fit-curve' -declare module 'react-audio-waveform' +declare module 'fit-curve'; +declare module 'react-audio-waveform'; declare module '@react-pdf/renderer' { diff --git a/webpack.config.js b/webpack.config.js index a5fe6ad80..c973be1ed 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -66,42 +66,42 @@ module.exports = { }, module: { rules: [{ - test: [/\.tsx?$/], - use: [{ - loader: 'ts-loader', - options: { - transpileOnly: true - } - }] + test: [/\.tsx?$/], + use: [{ + loader: 'ts-loader', + options: { + transpileOnly: true + } + }] + }, + { + test: /\.scss|css$/, + use: [{ + loader: "style-loader" }, { - test: /\.scss|css$/, - use: [{ - loader: "style-loader" - }, - { - loader: "css-loader" - }, - { - loader: "sass-loader" - } - ] + loader: "css-loader" }, { - test: /\.(jpg|png|pdf)$/, - use: [{ - loader: 'file-loader' - }] - }, - { - test: /\.(png|jpg|gif)$/i, - use: [{ - loader: 'url-loader', - options: { - limit: 8192 - } - }] + loader: "sass-loader" } + ] + }, + { + test: /\.(jpg|png|pdf)$/, + use: [{ + loader: 'file-loader' + }] + }, + { + test: /\.(png|jpg|gif)$/i, + use: [{ + loader: 'url-loader', + options: { + limit: 8192 + } + }] + } ] }, plugins, |