-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathLateNightBpmTapEditor.qml
More file actions
329 lines (289 loc) · 9.7 KB
/
Copy pathLateNightBpmTapEditor.qml
File metadata and controls
329 lines (289 loc) · 9.7 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
pragma ComponentBehavior: Bound
import QtQuick
import Mixxx 1.0 as Mixxx
import "../LateNightTheme"
Item {
id: root
required property string group
property string mode: "listen"
property real originalEditValue: 0
property bool editingBpm: true
readonly property bool listenHovered: listenArea.containsMouse
readonly property int hoverLeaveTimeout: 2000
readonly property int inactiveTimeout: 5000
readonly property int tapModeClickGuardTimeout: 350
readonly property real bpmStepSize: 1.0
readonly property real rateStepSize: 0.01
readonly property bool trackLoaded: trackLoadedProxy.value > 0
function switchMode(newMode) {
hideTimer.stop();
if (!root.trackLoaded) {
newMode = "listen";
}
root.mode = newMode;
if (newMode === "select") {
hideTimer.stop();
} else if (newMode === "edit") {
startEditMode();
} else if (newMode === "tap") {
tapClickGuardTimer.restart();
hideTimer.stop();
} else if (newMode === "listen") {
editInput.text = "";
editInput.focus = false;
}
}
function handleTapClick(mouse) {
if (tapClickGuardTimer.running) {
return;
}
root.tapControl(mouse.button === Qt.RightButton ? bpmTapProxy : tempoTapProxy);
}
function tapControl(control) {
hideTimer.interval = root.inactiveTimeout;
hideTimer.restart();
control.value = 1;
control.value = 0;
}
function startEditMode() {
root.editingBpm = fileBpmProxy.value !== 0;
if (root.editingBpm) {
root.originalEditValue = bpmProxy.value;
editInput.text = root.originalEditValue.toFixed(2);
} else {
root.originalEditValue = rateRatioProxy.value * 100;
editInput.text = root.originalEditValue.toFixed(2);
}
editInput.forceActiveFocus();
editInput.selectAll();
}
function applyStep(steps) {
if (root.editingBpm) {
const newBpm = Math.max(1, Math.min(fileBpmProxy.value * 4, bpmProxy.value + steps * root.bpmStepSize));
bpmProxy.value = newBpm;
editInput.text = newBpm.toFixed(2);
root.originalEditValue = newBpm;
} else {
const newRateRatio = Math.max(0.01, Math.min(4.0, rateRatioProxy.value + steps * root.rateStepSize));
rateRatioProxy.value = newRateRatio;
editInput.text = (newRateRatio * 100).toFixed(2);
root.originalEditValue = newRateRatio * 100;
}
editInput.selectAll();
}
function applyEditValueAndQuit() {
const input = editInput.text.trim();
if (input.length === 0) {
switchMode("listen");
return;
}
const parsedValue = Number(input);
if (!Number.isFinite(parsedValue)) {
switchMode("listen");
return;
}
if (parsedValue !== root.originalEditValue) {
if (root.editingBpm) {
bpmProxy.value = Math.max(1, Math.min(fileBpmProxy.value * 4, parsedValue));
} else {
rateRatioProxy.value = Math.max(0.01, Math.min(4.0, parsedValue / 100));
}
}
switchMode("listen");
}
Mixxx.ControlProxy {
id: tempoTapProxy
group: root.group
key: "tempo_tap"
}
Mixxx.ControlProxy {
id: bpmTapProxy
group: root.group
key: "bpm_tap"
}
Mixxx.ControlProxy {
id: trackLoadedProxy
group: root.group
key: "track_loaded"
}
Mixxx.ControlProxy {
id: bpmProxy
group: root.group
key: "bpm"
}
Mixxx.ControlProxy {
id: fileBpmProxy
group: root.group
key: "file_bpm"
}
Mixxx.ControlProxy {
id: rateRatioProxy
group: root.group
key: "rate_ratio"
}
onTrackLoadedChanged: {
if (!root.trackLoaded) {
root.switchMode("listen");
}
}
Timer {
id: hideTimer
interval: root.hoverLeaveTimeout
repeat: false
onTriggered: root.switchMode("listen")
}
Timer {
id: tapClickGuardTimer
interval: root.tapModeClickGuardTimeout
repeat: false
}
MouseArea {
id: listenArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton
visible: root.mode === "listen"
onClicked: root.switchMode("select")
onDoubleClicked: function(mouse) {
root.switchMode(mouse.x < width / 2 ? "tap" : "edit");
}
}
Row {
anchors.fill: parent
visible: root.mode === "select"
Rectangle {
width: parent.width / 2
height: parent.height
color: LateNightTheme.bpmTapEditorSelectBackgroundColor
border.width: 1
border.color: LateNightTheme.bpmTapEditorSelectBorderColor
Image {
anchors.centerIn: parent
source: LateNightTheme.assetDeckBpmSelectTapButton
fillMode: Image.PreserveAspectFit
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: hideTimer.stop()
onExited: {
hideTimer.interval = root.hoverLeaveTimeout;
hideTimer.restart();
}
onClicked: root.switchMode("tap")
onDoubleClicked: root.switchMode("tap")
}
}
Rectangle {
width: parent.width / 2
height: parent.height
color: LateNightTheme.bpmTapEditorSelectBackgroundColor
border.width: 1
border.color: LateNightTheme.bpmTapEditorSelectBorderColor
Image {
anchors.centerIn: parent
source: LateNightTheme.assetDeckBpmSelectEditButton
fillMode: Image.PreserveAspectFit
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: hideTimer.stop()
onExited: {
hideTimer.interval = root.hoverLeaveTimeout;
hideTimer.restart();
}
onClicked: root.switchMode("edit")
onDoubleClicked: root.switchMode("edit")
}
}
}
Rectangle {
anchors.fill: parent
visible: root.mode === "tap"
color: LateNightTheme.bpmTapEditorBackgroundColor
border.width: 1
border.color: tapArea.pressed ? LateNightTheme.bpmTapEditorEditBorderColor : LateNightTheme.bpmTapEditorSelectBorderColor
radius: 1
MouseArea {
id: tapArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onEntered: hideTimer.stop()
onExited: {
hideTimer.interval = root.hoverLeaveTimeout;
hideTimer.restart();
}
onClicked: function(mouse) { root.handleTapClick(mouse); }
onDoubleClicked: function(mouse) { mouse.accepted = true; }
}
}
Rectangle {
anchors.fill: parent
visible: root.mode === "edit"
color: LateNightTheme.bpmTapEditorBackgroundColor
border.width: 1
border.color: LateNightTheme.bpmTapEditorEditBorderColor
radius: 2
TextInput {
id: editInput
x: 1
y: 1
width: parent.width - 2
height: parent.height - 17
color: LateNightTheme.textColor
selectedTextColor: LateNightTheme.deckActiveButtonTextColor
selectionColor: LateNightTheme.textColor
font.family: "Open Sans"
font.pixelSize: 14
font.weight: Font.Medium
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
onActiveFocusChanged: {
if (!activeFocus && root.mode === "edit") {
root.switchMode("listen");
}
}
Keys.onReturnPressed: root.applyEditValueAndQuit()
Keys.onEnterPressed: root.applyEditValueAndQuit()
Keys.onEscapePressed: root.switchMode("listen")
}
Rectangle {
x: 0
y: parent.height - 16
width: parent.width / 2
height: 16
color: LateNightTheme.bpmTapEditorButtonColor
Image {
anchors.centerIn: parent
source: decreaseArea.pressed ? LateNightTheme.assetDeckBpmSpinboxMinusPressedButton : LateNightTheme.assetDeckBpmSpinboxMinusButton
fillMode: Image.PreserveAspectFit
}
MouseArea {
id: decreaseArea
anchors.fill: parent
onClicked: root.applyStep(-1)
}
}
Rectangle {
x: parent.width / 2
y: parent.height - 16
width: parent.width / 2
height: 16
color: LateNightTheme.bpmTapEditorButtonColor
Image {
anchors.centerIn: parent
source: increaseArea.pressed ? LateNightTheme.assetDeckBpmSpinboxPlusPressedButton : LateNightTheme.assetDeckBpmSpinboxPlusButton
fillMode: Image.PreserveAspectFit
}
MouseArea {
id: increaseArea
anchors.fill: parent
onClicked: root.applyStep(1)
}
}
}
}