summaryrefslogtreecommitdiff
path: root/app/client/modules/biggan/views/biggan.live.js
blob: e24d449c58fbbc25317efd01053acc53c5d1cbea (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import {
  ParamGroup, Param, Player, Group,
  Slider, SelectGroup, Select, TextInput, Button, Loading
} from '../../../common/'

import { startRecording, stopRecording, saveFrame, toggleFPS } from '../../../live/player'

import * as liveActions from '../../../live/live.actions'
import * as queueActions from '../../../queue/queue.actions'
import * as bigganTasks from '../biggan.tasks'
import * as bigganActions from '../biggan.actions'
import BigGANCategoryList from './biggan.categoryList.js'
import BigGANEncodingList from './biggan.encodingList.js'
import { frameTimestamp } from '../../../util'

class BigGANLive extends Component {
  constructor(props) {
    super()
    props.actions.live.get_params()
  }
  start(){
    // console.log(this.props.opt)
    console.log('starting up!')
    this.props.actions.tasks.live_task({
      // folder_id: this.props.biggan.data.resultsFolder.id,
    })
  }
  interrupt(){
    this.props.actions.queue.stop_task('gpu')
  }
  render() {
    const { biggan, actions, last_message } = this.props
    // console.log(actions)
    // if (biggan.loading) {
    //   return <Loading progress={biggan.progress} />
    // }
    return (
      <div className='app live biggan centered'>
        <div className='row'>
          <div className='column'>
            <Player width={512} height={512} square fullscreen={this.props.fullscreen} />
          </div>
          <div className='params column audioParams'>
            <div className='spacer'>
              {last_message}
            </div>

            <Group title="Player">
              {this.renderRestartButton()}
            </Group>

            <Group title={"Latent"}>
              <Button
                title={"Shuffle"}
                onClick={() => actions.live.send_command('switch', 'latent')}
              >{"Latent"}</Button>
              <Slider live
                name='latent_speed'
                title={"Update Speed"}
                min={1} max={250} type='int'
              />
              <Slider live
                name='truncation'
                title={"Truncation"}
                min={0.0001} max={4} type='float'
              />
            </Group>

            <Group title={"Label"}>
              <Slider live
                name='num_classes'
                title={"Classes to mix"}
                min={1} max={10} type='int'
              />
              <Button
                title={"Shuffle"}
                onClick={() => actions.live.send_command('switch', 'label')}
              >{"Label"}</Button>
              <Slider live
                name='label_speed'
                title={"Mix Speed"}
                min={1} max={250} type='int'
              />
            </Group>

            <Group title={"Orbit"}>
              <Slider live
                name='orbit_speed'
                title={"Orbit speed"}
                min={-250} max={250} type='int'
              />
              <Slider live
                name='orbit_radius'
                title={"Radius"}
                min={0} max={1.0} type='float'
              />
              <Button
                title={"Shuffle"}
                onClick={() => actions.live.send_command('switch', 'orbit_noise')}
              >{"Spin"}</Button>
              <Slider live
                name='orbit_noise_speed'
                title={"Shuffle Speed"}
                min={1} max={250} type='int'
              />
            </Group>

            <Group title={"Saturation"}>
              <Slider live
                name='abs_zoom'
                title={"Amount"}
                min={0} max={4} type='float'
              />
              <Slider live
                name='abs_mix_n'
                title={"Saturation mix"}
                min={0} max={1} type='float'
              />
            </Group>
          </div>
          <div className='params column'>
            <BigGANCategoryList />
          </div>
          <div className='params column'>
            <BigGANEncodingList />
          </div>
        </div>
      </div>
    )
  }
  renderRestartButton(){
    // console.log(this.props.runner.gpu)
    const { i18n } = this.props
    if (this.props.runner.gpu.status === 'IDLE') {
      return (
        <Button
          title={i18n.gpu.idle}
          onClick={() => this.start()}
        >{i18n.gpu.start}</Button>
      )
    }
    if (this.props.runner.gpu.task.module !== 'biggan') {
      return (
        <Button
          title={i18n.gpu.busy}
          onClick={() => this.interrupt()}
        >{i18n.gpu.interrupt}</Button>
      )
    }
    // if (! this.props.opt.processing) {
    //   return (
    //     <div>
    //       <Button
    //         title={i18n.gpu.not_processing}
    //         onClick={this.togglePlaying}
    //       >{i18n.gpu.restart}</Button>
    //       <Button
    //         title={i18n.gpu.busy}
    //         onClick={() => this.interrupt()}
    //       >{i18n.gpu.interrupt}</Button>
    //     </div>
    //   )
    // }
    return (
      <div>
        <Button
          title={i18n.gpu.busy}
          onClick={() => this.interrupt()}
        >{i18n.gpu.stop}</Button>
      </div>
    )
  }
}


const mapStateToProps = state => ({
  fullscreen: state.live.fullscreen,
  opt: state.live.opt,
  last_message: state.live.last_message,
  runner: state.system.runner,
  i18n: state.system.i18n.strings,
  biggan: state.module.biggan,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: {
    live: bindActionCreators(liveActions, dispatch),
    queue: bindActionCreators(queueActions, dispatch),
    biggan: bindActionCreators(bigganActions, dispatch),
    tasks: bindActionCreators(bigganTasks, dispatch),
  }
})

export default connect(mapStateToProps, mapDispatchToProps)(BigGANLive)