-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.tsx
More file actions
216 lines (204 loc) · 6.87 KB
/
controls.tsx
File metadata and controls
216 lines (204 loc) · 6.87 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* Copyright 2019 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import React from 'react';
import { style } from 'typestyle';
import Button from '@material-ui/core/Button';
import FormControl from '@material-ui/core/FormControl';
import FormHelperText from '@material-ui/core/FormHelperText';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import ToggleButton from '@material-ui/lab/ToggleButton';
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
import {
PlayArrow,
Stop,
DeleteSweep,
Edit,
SelectAll,
Undo,
Redo,
CloudDownload,
} from '@material-ui/icons';
import { observer } from 'mobx-react';
import { generator, player, layout, editor, EditorTool, undo } from '../core';
import saveload from '../core/save-load';
import * as theme from '../core/theme';
import { Voice } from '../core/note';
import { KeySignatures } from './key-signatures';
import { Spacer } from './spacer';
import featureFlags from '../core/feature-flags';
interface State {
keyDialogOpen: boolean;
}
@observer
export class Controls extends React.Component<{}, State> {
state = {
keyDialogOpen: false,
};
render() {
const { baseline } = featureFlags;
const PADDING = 0;
const width = layout.editorWidth;
const controlsStyle = style({
width: width - 2 * PADDING,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
paddingLeft: PADDING,
paddingRight: PADDING,
margin: '20px 0 60px',
height: layout.controlsHeight,
});
const playDisabled = !player.isPlayerLoaded || editor.allNotes.length === 0;
const showPlay = !player.isPlaying;
const maskButtonDisabled = generator.candidateSequences.length > 1;
return (
<div className={controlsStyle}>
<div>
<Button
disabled={playDisabled}
variant="outlined"
color="primary"
onClick={() => player.togglePlay()}
>
{showPlay ? <PlayArrow /> : <Stop />}
</Button>
</div>
<div>
<Button
disabled={playDisabled}
variant="outlined"
color="primary"
onClick={() => saveload.saveMIDI()}
>
<CloudDownload/>
</Button>
</div>
<div>
<Button
disabled={!undo.canUndo}
variant="outlined"
color="primary"
onClick={() => undo.undo()}
>
{<Undo />}
</Button>
<Spacer />
<Button
disabled={!undo.canRedo}
variant="outlined"
color="primary"
onClick={() => undo.redo()}
>
{<Redo />}
</Button>
</div>
<ToggleButtonGroup
value={editor.selectedTool}
exclusive
onChange={(e, value: EditorTool) => {
if (value !== null) {
editor.selectTool(value);
}
}}
>
<ToggleButton value={EditorTool.DRAW}>
<Edit />
</ToggleButton>
{baseline ? null : (
<ToggleButton value={EditorTool.MASK} disabled={maskButtonDisabled}>
<SelectAll />
</ToggleButton>)}
<ToggleButton value={EditorTool.ERASE}>
<DeleteSweep />
</ToggleButton>
</ToggleButtonGroup>
<div>
<FormControl>
<Select
style={{ color: theme.VOICE_COLORS[editor.selectedVoice] }}
value={editor.selectedVoice}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
if (value !== null) {
editor.selectVoice(Number(value));
// If user changes voices, user very likely wants to start editing
editor.selectTool(EditorTool.DRAW, false /** logging */);
}
}}
autoWidth
>
<MenuItem
style={{ color: theme.COLOR_SOPRANO }}
value={Voice.SOPRANO}
>
Soprano
</MenuItem>
<MenuItem style={{ color: theme.COLOR_ALTO }} value={Voice.ALTO}>
Alto
</MenuItem>
<MenuItem
style={{ color: theme.COLOR_TENOR }}
value={Voice.TENOR}
>
Tenor
</MenuItem>
<MenuItem style={{ color: theme.COLOR_BASS }} value={Voice.BASS}>
Bass
</MenuItem>
</Select>
<FormHelperText style={{ width: 100 }}>Voice</FormHelperText>
</FormControl>
<Spacer width={10} />
<FormControl>
<Select
value={editor.quantizeStep}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
if (value !== null) {
editor.selectQuantization(Number(value));
// If user changes step size
// and they are in erase mode, user very likely wants to start editing
if (editor.selectedTool === EditorTool.ERASE) {
editor.selectTool(EditorTool.DRAW, false /** logging */);
}
// if they are in mask mode, they might want a more refined mask size
// in which case don't change it automatically
}
}}
autoWidth
>
<MenuItem value={1}>1/16</MenuItem>
<MenuItem value={2}>1/8</MenuItem>
<MenuItem value={4}>1/4</MenuItem>
<MenuItem value={8}>1/2</MenuItem>
</Select>
<FormHelperText style={{ width: 100 }}>Quantization</FormHelperText>
</FormControl>
</div>
<div>
<Button
onClick={() => this.setState({ keyDialogOpen: true })}
variant="outlined"
color="primary"
>
{editor.key} {editor.mode}
</Button>
</div>
<KeySignatures
isDialogOpen={this.state.keyDialogOpen}
onRequestClose={() => this.setState({ keyDialogOpen: false })}
/>
</div>
);
}
}