summaryrefslogtreecommitdiff
path: root/app/client/modules/pix2pixhd/views/sequence.editor.js
blob: 6a5da39444ee237d6c010c54f53969011106088f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Route, Link } from 'react-router-dom'

import { Loading, FileList, FileViewer } from '../../../common'

import actions from '../../../actions'

const initialState = {
  dir: '/',
  frameA: null,
  frameB: null,
  selection: null,
  loading: true
}

/*
  when the sequence editor loads,
    reset the selection
    reset the two frames
    set the two frames to the beginning and end of the video
  when mousing over the video
    ideally you would see a tiny thumbnail preview of the frame :)
    - click to start a selection, drag over, mouseup to end the selection
  this should update the start/end frame
  ...
  so there are two things you could do with this
  1) create an entirely new dataset
  2) add frames to an existing dataset
  ...
  method 1)
  - requires minimal setup, just a server script which..
     - creates the new sequence folder
     - symlinks the frames
     - runs build_dataset
     - create appropriate file object, using parent dataset's folder_id
     - enqueue initial training
       ---> we can then train on basic subsets, with more control, like we do already...
     - tell parent dataset thing the new sequence name
  ...
  method 2)
  - requires sequence editor to be aware of its own dataset
  - requires sequence editor to know whether a sequence is original or not
*/

class SequenceEditor extends Component {
  state = { ...initialState }

  constructor() {
    super()
    this.handleMouseDown = this.handleMouseDown.bind(this)
    this.handleMouseMove = this.handleMouseMove.bind(this)
    this.handleMouseEnter = this.handleMouseEnter.bind(this)
    this.handleMouseLeave = this.handleMouseLeave.bind(this)
    this.handleMouseUp = this.handleMouseUp.bind(this)
  }

  componentDidMount() {
    const { checkpoint } = this.props
    window.addEventListener('mousemove', this.handleMouseMove)
    window.addEventListener('mouseup', this.handleMouseUp)
    if (checkpoint && checkpoint.sequence) {
      console.log(checkpoint)
      const frameA = checkpoint.sequence[0]
      const frameB = checkpoint.sequence[checkpoint.sequence.length-1]
      this.setState({
        ...initialState,
        frameA,
        frameB,
      })
    }
  }

  componentDidUpdate(prevProps) {
    const { checkpoint } = this.props
    if (checkpoint !== prevProps.checkpoint) {
      console.log(checkpoint)
      const frameA = checkpoint.sequence[0]
      const frameB = checkpoint.sequence[checkpoint.sequence.length-1]
      this.setState({
        ...initialState,
        frameA,
        frameB,
      })
    }
  }

  componentWillUnmount(){
    window.removeEventListener('mouseup', this.handleMouseUp)
    window.removeEventListener('mousemove', this.handleMouseMove)
  }

  handleMouseDown(e) {
    this.setState({ dragging: true })
  }
  handleMouseMove(e) {
  }
  handleMouseEnter(e) {
  }
  handleMouseLeave(e) {
  }
  handleMouseUp(e) {
    this.setState({ dragging: false })
  }

  handlePick(file) {
    console.log(file)
    // this.setState({ dir, file: null, loading: true })
  }

  render() {
    const { app, checkpoint } = this.props
    const {
      loading,
      selection,
      frameA, frameB,
    } = this.state
    // console.log(this.props, this.state)
    const width = 200
    const path = "sequences/" + checkpoint.name
    return (
      <div className='sequenceEditor'>
        <div
          className='timeline'
          style={{ width }}
          mouseDown={this.handleSelectionStart}
          mouseEnter={this.handleMouseEnter}
          mouseLeave={this.handleMouseLeave}
        >
          {selection && <div className='selection' style={selection}></div>}
        </div>
        <FileViewer path={path} file={this.state.frameA} />
        <FileViewer path={path} file={this.state.frameB} />
      </div>
    )
  }
}

const mapStateToProps = state => ({
  app: state.system.app,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators({}, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(SequenceEditor)