From 24a47dfa9d25c943bf1b51a1daf87140f76b3fbb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 6 Jun 2018 03:38:41 +0200 Subject: displaying these gray ass thumbnails --- .../modules/pix2wav/views/spectrogram.upload.js | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 app/client/modules/pix2wav/views/spectrogram.upload.js (limited to 'app/client/modules/pix2wav/views/spectrogram.upload.js') diff --git a/app/client/modules/pix2wav/views/spectrogram.upload.js b/app/client/modules/pix2wav/views/spectrogram.upload.js new file mode 100644 index 0000000..a0a2708 --- /dev/null +++ b/app/client/modules/pix2wav/views/spectrogram.upload.js @@ -0,0 +1,132 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import moment from 'moment' +import util from '../../../util' + +import * as pix2wavActions from '../pix2wav.actions' +import * as pix2wavTasks from '../pix2wav.tasks' + +import { + Loading, Progress, + Group, Param, FileUpload, TextInput, Button +} from '../../../common' + +import * as wav2pixActions from '../../../audio/wav2pix' + +import pix2wavModule from '../pix2wav.module' + +class SpectrogramUpload extends Component { + constructor(props){ + super(props) + this.state = { + file: null, + name: "", + frames: [], + } + const audioElement = document.createElement('audio') + audioElement.addEventListener('loadedmetadata', () => { + this.setState({ duration: audioElement.duration }) + }) + this.audioElement = audioElement + } + pickFile(file){ + let name = file.name.split('.')[0] + .replace(/\s+/g, '_') + .replace(/-/g, '_') + .replace(/_+/g, '_') + this.setState({ file, name }) + this.audioElement.src = URL.createObjectURL(file) + console.log(file.size) + if (file.size < 2 << 20) { + console.log('booooooooo') + this.props.wav2pix.renderFrames(file, {}) + .then(frames => { + console.log(frames) + this.setState({ + ...this.state, frames + }) + }) + } + console.log(file) + // get info on the file... size, etc + } + buildZip(){ + const { file } = this.state + + } + render(){ + // loading={pix2wav.loading} + // progress={pix2wav.progress} + // id={pix2wav.folder_id} + // module={pix2wavModule} + // data={pix2wav.data} + // folder={folder} + const { file, frames } = this.state + return ( +
+
+ +

+ {"Convert your sounds into spectrograms. "} + {"Sound files can be WAV, MP3, AIFF, or FLAC. "} + 2 minutes max. +

+ this.pickFile(file)} + /> + this.setState({ name: e.target.value })} + value={this.state.name} + /> + + + {file && this.renderMetadata(file)} +
+
+
{ this.canvases = c }} id='pix2wav_canvases' /> +
+ ) + } + renderMetadata(file){ + const { duration } = this.state + const size = util.hush_size(file.size) + return ( +
+ {file.size > 2 << 20 && +

+ Careful, your file is larger than 2 MB. +

} + {file.name} + {file.type} + {size[1]} + {moment(file.lastModifiedDate).format("YYYY-MM-DD h:mm a")} + {Math.floor(duration) + ' s.'} +
+ {this.props.pix2wav.status} +
+ ) + } + componentDidUpdate(){ + const canvases = (this.state.frames || []).map(c => { + this.canvases.append(c.canvas) + }) + } +} + +const mapStateToProps = state => ({ + pix2wav: state.module.pix2wav, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(pix2wavActions, dispatch), + remote: bindActionCreators(pix2wavTasks, dispatch), + wav2pix: bindActionCreators(wav2pixActions, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(SpectrogramUpload) -- cgit v1.2.3-70-g09d2