import { h, Component } from 'preact' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { ParamGroup, Player, Slider, Select, Button, Loading } from '../../../common/' import { startRecording, stopRecording, saveFrame } from '../../../live/player' import * as liveActions from '../../../live/live.actions' import * as pix2pixTasks from '../pix2pix.tasks' import * as pix2pixActions from '../pix2pix.actions' class Pix2PixLive extends Component { constructor(props){ super() if (! props.pix2pix || ! props.pix2pix.data) { props.pix2pixActions.load_directories() } props.actions.get_params() props.actions.list_checkpoints('pix2pix') props.actions.list_sequences('pix2pix') 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.list_epochs('pix2pix', nextProps.opt.checkpoint_name) } } changeCheckpoint(checkpoint_name){ this.props.actions.load_epoch(checkpoint_name, 'latest') } changeEpoch(epoch_name){ this.props.actions.load_epoch(this.props.opt.checkpoint_name, epoch_name) } changeSequence(sequence){ console.log('got sequence', sequence) this.props.actions.load_sequence(sequence) } seek(percentage){ const frame = Math.floor(percentage * (parseInt(this.props.frame.sequence_len) || 1) + 1) this.props.actions.seek(frame) } start(){ // console.log(this.props) const sequence = this.props.pix2pix.data.sequences[0].name const checkpoint = this.props.pix2pix.data.checkpoints[0].name console.log('starting up!', sequence, checkpoint) this.props.pix2pixTasks.live_task(sequence, checkpoint) } interrupt(){ // } togglePlaying(){ console.log('are we..........', this.props.opt.processing) if (this.props.opt.processing) { this.props.actions.pause() } else { this.props.actions.play() } } toggleRecording(){ if (this.props.opt.recording){ stopRecording() this.props.actions.pause() } else { startRecording() } } render(){ // console.log(this.props) if (this.props.pix2pix.loading) { return } return (
file.name)} onChange={this.changeSequence} /> {this.renderRestartButton()}
) } renderRestartButton(){ if (this.props.runner.gpu.status === 'IDLE') { return ( ) } if (this.props.runner.gpu.task.module !== 'pix2pix') { return ( ) } if (! this.props.opt.processing) { return ( ) } return ( ) } } function timeInSeconds(n){ return (n / 10).toFixed(1) + ' s.' } const mapStateToProps = state => ({ opt: state.live.opt, frame: state.live.frame, checkpoints: state.live.checkpoints, epochs: state.live.epochs, sequences: state.live.sequences, runner: state.system.runner, pix2pix: state.module.pix2pix, }) const mapDispatchToProps = (dispatch, ownProps) => ({ actions: bindActionCreators(liveActions, dispatch), pix2pixActions: bindActionCreators(pix2pixActions, dispatch), pix2pixTasks: bindActionCreators(pix2pixTasks, dispatch),s }) export default connect(mapStateToProps, mapDispatchToProps)(Pix2PixLive)