From ae902b6f2a30ecc07bf1e2051be451f1caca1883 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 7 Jun 2018 10:53:59 +0200 Subject: rope in the pix2wav live script --- app/client/modules/pix2wav/views/pix2wav.live.js | 317 +++++++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 app/client/modules/pix2wav/views/pix2wav.live.js (limited to 'app/client/modules/pix2wav/views') diff --git a/app/client/modules/pix2wav/views/pix2wav.live.js b/app/client/modules/pix2wav/views/pix2wav.live.js new file mode 100644 index 0000000..2902bff --- /dev/null +++ b/app/client/modules/pix2wav/views/pix2wav.live.js @@ -0,0 +1,317 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import { + ParamGroup, Param, Player, + Slider, Select, Button, Loading +} from '../../../common/' + +import { startRecording, stopRecording, saveFrame } from '../../../live/player' + +import * as liveActions from '../../../live/live.actions' +import * as queueActions from '../../../queue/queue.actions' +import * as pix2wavTasks from '../pix2wav.tasks' +import * as pix2wavActions from '../pix2wav.actions' + +class Pix2WavLive extends Component { + constructor(props){ + super() + props.actions.pix2wav.load_directories() + props.actions.live.get_params() + this.changeCheckpoint = this.changeCheckpoint.bind(this) + this.changeEpoch = this.changeEpoch.bind(this) + this.changeSequence = this.changeSequence.bind(this) + this.seek = this.seek.bind(this) + this.togglePlaying = this.togglePlaying.bind(this) + this.toggleRecording = this.toggleRecording.bind(this) + } + componentWillUpdate(nextProps) { + if (nextProps.opt.checkpoint_name && nextProps.opt.checkpoint_name !== this.props.opt.checkpoint_name) { + this.props.actions.live.list_epochs('pix2wav', nextProps.opt.checkpoint_name) + } + } + changeCheckpoint(field, checkpoint_name){ + this.props.actions.live.load_epoch(checkpoint_name, 'latest') + } + changeEpoch(field, epoch_name){ + this.props.actions.live.load_epoch(this.props.opt.checkpoint_name, epoch_name) + } + changeSequence(field, sequence){ + console.log('got sequence', sequence) + this.props.actions.live.load_sequence(sequence) + } + seek(percentage){ + const frame = Math.floor(percentage * (parseInt(this.props.frame.sequence_len) || 1) + 1) + this.props.actions.live.seek(frame) + } + start(){ + // console.log(this.props) + const sequence = this.props.pix2wav.data.sequences[0].name + const checkpoint = this.props.pix2wav.data.checkpoints[0].name + console.log('starting up!', sequence, checkpoint) + this.props.actions.tasks.live_task(sequence, checkpoint) + } + interrupt(){ + this.props.actions.queue.stop_task('gpu') + } + togglePlaying(){ + if (this.props.opt.processing) { + this.props.actions.live.pause() + } else { + this.props.actions.live.play() + } + } + toggleRecording(){ + if (this.props.opt.recording){ + stopRecording() + this.props.actions.live.pause() + } else { + startRecording() + } + } + render(){ + // console.log(this.props) + if (this.props.pix2wav.loading) { + return + } + return ( +
+ +
+
+ + file.name)} + onChange={this.changeSequence} + /> + + + {this.renderRestartButton()} + + + +

{this.props.last_message}

+
+
+
+ + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+ ) + } + renderRestartButton(){ + if (this.props.runner.gpu.status === 'IDLE') { + return ( + + ) + } + if (this.props.runner.gpu.task.module !== 'pix2wav') { + return ( + + ) + } + if (! this.props.opt.processing) { + return ( +
+ + +
+ ) + } + return ( +
+ + +
+ ) + } +} +function timeInSeconds(n){ + return (n / 10).toFixed(1) + ' s.' +} +const mapStateToProps = state => ({ + last_message: state.live.last_message, + opt: state.live.opt, + frame: state.live.frame, + checkpoints: state.live.checkpoints, + epochs: state.live.epochs, + sequences: state.live.sequences, + runner: state.system.runner, + pix2wav: state.module.pix2wav, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: { + live: bindActionCreators(liveActions, dispatch), + queue: bindActionCreators(queueActions, dispatch), + pix2wav: bindActionCreators(pix2wavActions, dispatch), + tasks: bindActionCreators(pix2wavTasks, dispatch),s + } +}) + +export default connect(mapStateToProps, mapDispatchToProps)(Pix2WavLive) -- cgit v1.2.3-70-g09d2