-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranscriberPanel.qml
More file actions
1034 lines (930 loc) · 34.3 KB
/
Copy pathTranscriberPanel.qml
File metadata and controls
1034 lines (930 loc) · 34.3 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Muse.Ui
import Muse.UiComponents
// Dockable panel: transport toolbar + waveform. Receives the state pushed
// by MUTranscriber.qml (updateStatus/setWaveform/onFileLoaded/
// setRecentFiles) and drives the backend via the functions exposed on
// `mscore`.
Item {
id: root
property var mscore: null
property string errorText: ""
property real duration: 0
property real serverPosition: 0
property real displayPosition: 0
property bool playing: false
property real loopA: -1
property real loopB: -1
property int volume: 100
property real rate: 1.0
property real pendingRate: -1 // -1 = no speed change awaiting backend confirmation
property real pitchSemitones: 0
property bool pitchPending: false
property real pendingSemitones: 0 // only meaningful while pitchPending is true
property bool eqPanelOpen: false
property bool recomputing: false
property real recomputeRemainingS: -1 // -1 = no estimate available yet
property var waveformData: null
property var zoomedWaveformData: null
property var recentFiles: []
property string currentFileName: ""
property string currentFilePath: "" // full path, to detect reloading the exact same file
property var markers: []
property int nextMarkerId: 1
property int nextMarkerNumber: 1
// Non-null {id, position} while a marker is being dragged in MarkerRuler -
// lets WaveformView draw that marker's guide line at its live position
// without `markers` itself changing until the drag is released.
property var liveMarkerDrag: null
// Suppresses the metaTag persistence hooks below (onMarkersChanged,
// onLoopAChanged/onLoopBChanged) while a saved session is being restored
// on load - otherwise the transient markers=[]/loopA=loopB=-1 reset that
// happens on every file load (see onFileLoaded) would overwrite the
// metaTag with an empty state before the restore even runs.
property bool suppressPersist: false
readonly property real minZoom: 1.0
readonly property real maxZoom: 50.0
property real mainZoom: 1.0
property real mainViewCenter: 0
readonly property real mainVisibleDuration: (root.duration > 0 && root.mainZoom > 0)
? Math.min(root.duration, root.duration / root.mainZoom) : root.duration
readonly property real mainViewStart: Math.max(0, Math.min(root.mainViewCenter - root.mainVisibleDuration / 2, root.duration - root.mainVisibleDuration))
readonly property real mainViewEnd: root.mainViewStart + root.mainVisibleDuration
// +20 over the previous 200 to cover MarkerRuler's height, so the
// waveform's default visual size doesn't shrink to make room for it.
implicitHeight: 220
// If the playback position leaves the currently zoomed window (e.g. Stop
// jumping back to 0, or free playback outrunning a very zoomed-in view),
// recenter the view on it - otherwise the cursor stays invisible in the
// main waveform until a manual navigation.
onDisplayPositionChanged: {
if (root.duration <= 0) return
if (root.displayPosition < root.mainViewStart || root.displayPosition > root.mainViewEnd) {
root.mainViewCenter = root.displayPosition
}
}
// Changes the zoom while keeping `anchorTime` at the same relative
// position in the view (the +/- buttons keep the current playback
// position clearly visible regardless of zoom level).
function requestZoom(newZoom, anchorTime) {
var clampedZoom = Math.max(root.minZoom, Math.min(root.maxZoom, newZoom))
// Already at min/max (e.g. a wheel that keeps turning past the limit):
// don't recompute/refetch anything, otherwise tiny floating-point
// drifts on every call would keep re-triggering the fetch in a loop
// and make the +/- buttons flash for nothing.
if (Math.abs(clampedZoom - root.mainZoom) < 1e-9) return
var oldVisible = root.mainVisibleDuration
var frac = oldVisible > 0 ? (anchorTime - root.mainViewStart) / oldVisible : 0.5
root.mainZoom = clampedZoom
var newVisible = root.mainVisibleDuration
root.mainViewCenter = (anchorTime - frac * newVisible) + newVisible / 2
}
// Regular step in percentage (not multiplicative: 100/140/196... was
// irregular) - anchored on the current playback position so the cursor
// stays visible even after several successive zooms.
function zoomByPercent(deltaPercent) {
var currentPercent = Math.round(root.mainZoom * 100)
root.requestZoom((currentPercent + deltaPercent) / 100, root.displayPosition)
}
function zoomIn() { root.zoomByPercent(10) }
function zoomOut() { root.zoomByPercent(-10) }
// Recomputes the high-resolution slice shown by the main view every time
// the visible window changes (debounced so it doesn't hammer the backend
// during a continuous zoom). The Flask backend is threaded=True, so
// several requests can fire in parallel during continuous scrolling and
// finish out of order - this guarantees only one request is in flight at
// a time; any request that comes in while one is running is merged and
// re-fired (for the most recent view) right after, instead of stacking
// up as concurrent requests.
property bool waveformFetchBusy: false
property bool waveformFetchDirty: false
Timer {
id: zoomFetchDebounce
interval: 50
repeat: false
onTriggered: root.triggerWaveformFetch()
}
function triggerWaveformFetch() {
if (!root.mscore || root.duration <= 0) return
if (root.waveformFetchBusy) {
root.waveformFetchDirty = true
return
}
root.waveformFetchBusy = true
root.waveformFetchDirty = false
root.mscore.fetchWaveformRange(root.mainViewStart, root.mainViewEnd, function(wf) {
root.zoomedWaveformData = wf
root.waveformFetchBusy = false
if (root.waveformFetchDirty) {
root.triggerWaveformFetch()
}
})
}
onMainViewStartChanged: zoomFetchDebounce.restart()
onMainViewEndChanged: zoomFetchDebounce.restart()
function formatTime(t) {
if (t === undefined || t === null || isNaN(t)) t = 0
var m = Math.floor(t / 60)
var s = t - m * 60
return m.toString().padStart(2, '0') + ":" + s.toFixed(2).padStart(5, '0')
}
property var recentMenuModel: {
if (!root.recentFiles || root.recentFiles.length === 0) {
return [{ id: "none", title: "No recent files", enabled: false }]
}
var model = []
for (var i = 0; i < root.recentFiles.length; i++) {
model.push({ id: String(i), title: basename(root.recentFiles[i]) })
}
// An item with no `title` renders as a separator line (see
// StyledMenu.qml's isSeparator check) - no title needed for it here.
model.push({ id: "separator" })
model.push({ id: "clear", title: "Clear Recent Files" })
return model
}
function basename(path) {
if (!path) return ""
var parts = path.split("/")
return parts[parts.length - 1]
}
function handleRecentFile(itemId) {
if (itemId === "none" || itemId === "separator") return
if (itemId === "clear") {
if (root.mscore) root.mscore.clearRecentFiles()
return
}
var idx = parseInt(itemId)
if (isNaN(idx) || !root.recentFiles[idx]) return
if (root.mscore) root.mscore.loadFile(root.recentFiles[idx])
}
// Called by MUTranscriber.qml on every /status poll (and after /load, /speed)
function updateStatus(status) {
playing = status.playing
duration = status.duration_s || 0
serverPosition = status.position_s || 0
displayPosition = serverPosition
loopA = (status.loop_a_s !== null && status.loop_a_s !== undefined) ? status.loop_a_s : -1
loopB = (status.loop_b_s !== null && status.loop_b_s !== undefined) ? status.loop_b_s : -1
if (status.volume !== undefined) volume = status.volume
if (status.rate !== undefined) {
// Ignore a stale polled rate while a speed change we just requested
// (via a preset button) hasn't been confirmed yet - otherwise the
// 150ms status poller keeps clobbering the optimistic value back to
// the old rate for as long as the backend's time-stretch takes (can
// be a few seconds on a long track), producing a flash-then-revert.
if (root.pendingRate < 0 || Math.abs(status.rate - root.pendingRate) < 0.005) {
rate = status.rate
pendingRate = -1
}
}
if (status.pitch_semitones !== undefined) {
// Same stale-poll guard as rate, for the same reason - pitch-shift
// is just as slow a recompute as time-stretch.
if (!root.pitchPending || Math.abs(status.pitch_semitones - root.pendingSemitones) < 0.005) {
pitchSemitones = status.pitch_semitones
pitchPending = false
}
}
recomputing = !!status.recomputing
recomputeRemainingS = (status.recompute_remaining_s !== undefined && status.recompute_remaining_s !== null)
? status.recompute_remaining_s : -1
errorText = status.error || ""
}
function onFileLoaded(resp, filePath) {
// Reloading the exact same file already open this session (e.g. the
// user picks it again from Recent Files) isn't a file change - keep the
// existing markers/loop instead of wiping them, since currentFilePath
// starts empty on first load, so the very first load of a session
// always falls into the "different file" branch below. Captured before
// updateStatus() below overwrites loopA/loopB with the backend's
// post-load response (see the restore a few lines down).
var sameFile = filePath !== "" && filePath === root.currentFilePath
var prevLoopA = root.loopA
var prevLoopB = root.loopB
// The backend's /load always clears the loop server-side first, even
// when reloading the same file - suppress persistence for that
// transient "no loop" state so it's never written to the metaTag
// (and never leaves a window where the score is momentarily saved
// without a loop it actually still has).
if (sameFile) root.suppressPersist = true
updateStatus(resp)
mainZoom = 1.0
mainViewCenter = 0
currentFileName = basename(filePath)
currentFilePath = filePath
if (!sameFile) {
// A new audio file invalidates any previous marker positions (they're
// timestamps into the old file's timeline) - restoreMarkers() below
// overrides this reset when reopening the same file's saved session.
// Counters reset BEFORE markers: onMarkersChanged fires synchronously
// on the next line and persists {nextId, nextNumber, items} together -
// resetting markers first would persist the old counters alongside the
// freshly emptied array.
nextMarkerId = 1
nextMarkerNumber = 1
markers = []
return
}
if ((prevLoopA >= 0 || prevLoopB >= 0) && root.mscore) {
root.mscore.setLoop(prevLoopA >= 0 ? prevLoopA : undefined, prevLoopB >= 0 ? prevLoopB : undefined)
}
Qt.callLater(function() { root.suppressPersist = false })
}
function setWaveform(wf) {
waveformData = wf
}
// `atPosition` defaults to the playback cursor (the M button's behavior);
// MarkerRuler's double-click-on-empty-space passes the clicked time instead.
function addMarker(atPosition) {
var pos = (atPosition !== undefined) ? atPosition : root.displayPosition
var marker = { id: root.nextMarkerId, position: pos, text: "#" + root.nextMarkerNumber }
root.nextMarkerId = root.nextMarkerId + 1
root.nextMarkerNumber = root.nextMarkerNumber + 1
root.markers = root.markers.concat([marker])
}
function updateMarkerText(id, text) {
root.markers = root.markers.map(function(m) {
return m.id === id ? { id: m.id, position: m.position, text: text } : m
})
}
function updateMarkerPosition(id, pos) {
root.markers = root.markers.map(function(m) {
return m.id === id ? { id: m.id, position: pos, text: m.text } : m
})
}
function deleteMarker(id) {
root.markers = root.markers.filter(function(m) { return m.id !== id })
}
// Called by MUTranscriber.qml when reopening a score whose saved session
// matches the file that was just (re)loaded.
function restoreMarkers(state) {
root.nextMarkerId = state.nextId || 1
root.nextMarkerNumber = state.nextNumber || 1
root.markers = state.items || []
}
function persistMarkers() {
if (root.suppressPersist) return
if (root.mscore) root.mscore.saveMarkers({ nextId: root.nextMarkerId, nextNumber: root.nextMarkerNumber, items: root.markers })
}
function persistLoopAB() {
if (root.suppressPersist) return
if (root.mscore) root.mscore.saveLoopAB(root.loopA, root.loopB)
}
// Called by MUTranscriber.qml's resetSession(), only after the user
// explicitly confirmed in resetConfirmPopup below. Mirrors every property
// declared above back to its startup default - suppressPersist avoids
// re-writing the metaTags MUTranscriber.qml just cleared directly.
function resetLocalState() {
root.suppressPersist = true
errorText = ""
duration = 0
serverPosition = 0
displayPosition = 0
playing = false
loopA = -1
loopB = -1
volume = 100
rate = 1.0
pendingRate = -1
pitchSemitones = 0
pitchPending = false
pendingSemitones = 0
eqPanelOpen = false
recomputing = false
recomputeRemainingS = -1
waveformData = null
zoomedWaveformData = null
currentFileName = ""
currentFilePath = ""
nextMarkerId = 1
nextMarkerNumber = 1
markers = []
mainZoom = 1.0
mainViewCenter = 0
Qt.callLater(function() { root.suppressPersist = false })
}
onMarkersChanged: root.persistMarkers()
onLoopAChanged: root.persistLoopAB()
onLoopBChanged: root.persistLoopAB()
function setRecentFiles(list) {
recentFiles = list || []
}
// Local cursor interpolation between two server polls (hard resync on
// updateStatus), for a smooth display without hammering /status.
Timer {
interval: 40
running: root.playing
repeat: true
onTriggered: {
var next = root.displayPosition + 0.04 * root.rate
// loopA/loopB are independent and can be set in either chronological
// order (see WaveformView) - min/max here mirrors the backend's own
// loop_lo/loop_hi, so this local prediction wraps at the same point
// the actual audio callback does.
if (root.loopA >= 0 && root.loopB >= 0 && next >= Math.max(root.loopA, root.loopB)) {
next = Math.min(root.loopA, root.loopB)
} else if (root.duration > 0 && next > root.duration) {
next = root.duration
}
root.displayPosition = next
}
}
ColumnLayout {
anchors.fill: parent
anchors.topMargin: 0
anchors.leftMargin: 8
anchors.rightMargin: 8
anchors.bottomMargin: 8
spacing: 6
Item {
id: toolbar
Layout.fillWidth: true
Layout.preferredHeight: 46
// The 6 transport buttons + the timer are wrapped in a single
// container (transportGroup): the timer is positioned above the
// buttons INSIDE this container, so it's centered on them by
// construction. Load/Speed/Volume anchor to the edges of this
// container (never to an element anchored deeper inside it -
// anchors.horizontalCenter only works between parent/child or direct
// siblings, otherwise QML raises "Cannot anchor to an item that
// isn't a parent or sibling").
Item {
id: transportGroup
anchors.top: parent.top
anchors.topMargin: 0
anchors.horizontalCenter: parent.horizontalCenter
width: transportRow.width
height: timeLabel.height + transportRow.height
Text {
id: timeLabel
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 10
color: "#dddddd"
text: formatTime(root.displayPosition) + " / " + formatTime(root.duration)
}
Row {
id: transportRow
anchors.top: timeLabel.bottom
anchors.topMargin: 2
anchors.horizontalCenter: parent.horizontalCenter
spacing: 4
FlatButton {
text: "M"
toolTipTitle: "Add marker"
enabled: root.duration > 0
width: 26
onClicked: root.addMarker()
}
FlatButton {
icon: IconCode.REWIND_START_FILL
toolTipTitle: "Go to start"
enabled: root.duration > 0
onClicked: {
root.mscore.seek(0)
root.displayPosition = 0
}
}
FlatButton {
icon: IconCode.REPEAT_START
toolTipTitle: "Go to loop start"
enabled: root.loopA >= 0 || root.loopB >= 0
onClicked: {
// The loop's actual start is whichever marker is earlier -
// loopA/loopB are independent and may have been set in
// either order (see WaveformView), so this isn't always A.
var target = (root.loopA >= 0 && root.loopB >= 0)
? Math.min(root.loopA, root.loopB)
: Math.max(root.loopA, root.loopB)
root.mscore.seek(target)
root.displayPosition = target
}
}
FlatButton {
icon: root.playing ? IconCode.PAUSE_FILL : IconCode.PLAY_FILL
toolTipTitle: root.playing ? "Pause" : "Play"
enabled: root.duration > 0
onClicked: {
if (root.playing) {
root.mscore.pause()
} else {
root.mscore.play(root.displayPosition)
}
}
}
FlatButton {
icon: IconCode.STOP_FILL
toolTipTitle: "Stop"
enabled: root.duration > 0
onClicked: {
root.mscore.pause()
root.mscore.seek(0)
root.displayPosition = 0
}
}
FlatButton {
text: "A"
toolTipTitle: "Set loop start (A)"
enabled: root.duration > 0
accentButton: root.loopA >= 0
width: 26
onClicked: {
if (root.loopA >= 0) {
root.mscore.setLoop(null, undefined)
} else {
root.mscore.setLoop(root.displayPosition, undefined)
}
}
}
FlatButton {
text: "B"
toolTipTitle: "Set loop end (B)"
enabled: root.duration > 0
accentButton: root.loopB >= 0
width: 26
onClicked: {
if (root.loopB >= 0) {
root.mscore.setLoop(undefined, null)
} else {
root.mscore.setLoop(undefined, root.displayPosition)
}
}
}
FlatButton {
icon: IconCode.LOOP
accentButton: root.loopA >= 0 && root.loopB >= 0
toolTipTitle: "Clear loop"
enabled: root.loopA >= 0 || root.loopB >= 0
onClicked: root.mscore.clearLoop()
}
}
}
Row {
id: loadGroup
anchors.right: transportGroup.left
anchors.rightMargin: 4
anchors.bottom: transportGroup.bottom
spacing: 0
FlatButton {
text: "⟲"
width: 28
textFont.pixelSize: 30
toolTipTitle: "Reset MUTranscriber for this score"
onClicked: resetConfirmPopup.open()
}
Item { width: 4 }
FlatButton {
icon: IconCode.OPEN_FILE
accentButton: true
toolTipTitle: "Load audio file"
onClicked: root.mscore && root.mscore.openFileDialog()
}
MenuButton {
icon: IconCode.SMALL_ARROW_DOWN
accentButton: true
toolTipTitle: "Recent files"
menuModel: root.recentMenuModel
onHandleMenuItem: function(itemId) { root.handleRecentFile(itemId) }
}
}
PitchSlider {
id: pitchSlider
anchors.right: loadGroup.left
anchors.rightMargin: 12
anchors.bottom: transportGroup.bottom
enabled: root.duration > 0 && !root.recomputing
mscore: root.mscore
semitones: root.pitchSemitones
onCommitted: function(s) {
root.pitchPending = true
root.pendingSemitones = s
root.pitchSemitones = s
}
}
SpeedDial {
id: speedDial
anchors.right: pitchSlider.left
anchors.rightMargin: 12
anchors.bottom: transportGroup.bottom
enabled: root.duration > 0 && !root.recomputing
mscore: root.mscore
rate: root.rate
onCommitted: function(r) {
root.pendingRate = r
root.rate = r
}
}
FlatButton {
id: eqButton
anchors.right: speedPresets.left
anchors.rightMargin: 12
anchors.bottom: transportGroup.bottom
icon: IconCode.MIXER
accentButton: root.eqPanelOpen
toolTipTitle: "Equalizer"
enabled: root.duration > 0
onClicked: root.eqPanelOpen = !root.eqPanelOpen
}
Row {
id: speedPresets
anchors.right: speedDial.left
anchors.rightMargin: 8
anchors.bottom: transportGroup.bottom
spacing: 4
FlatButton {
text: "0.50x"
width: 36
textFont.pixelSize: 9
toolTipTitle: "Set speed to 50%"
enabled: root.duration > 0 && !root.recomputing
accentButton: Math.abs(root.rate - 0.50) < 0.005
onClicked: {
root.pendingRate = 0.50
root.rate = 0.50
root.mscore.setSpeed(0.50)
}
}
FlatButton {
text: "0.65x"
width: 36
textFont.pixelSize: 9
toolTipTitle: "Set speed to 65%"
enabled: root.duration > 0 && !root.recomputing
accentButton: Math.abs(root.rate - 0.65) < 0.005
onClicked: {
root.pendingRate = 0.65
root.rate = 0.65
root.mscore.setSpeed(0.65)
}
}
FlatButton {
text: "0.80x"
width: 36
textFont.pixelSize: 9
toolTipTitle: "Set speed to 80%"
enabled: root.duration > 0 && !root.recomputing
accentButton: Math.abs(root.rate - 0.80) < 0.005
onClicked: {
root.pendingRate = 0.80
root.rate = 0.80
root.mscore.setSpeed(0.80)
}
}
}
VolumeSlider {
id: volumeSlider
anchors.left: transportGroup.right
anchors.leftMargin: 12
anchors.bottom: transportGroup.bottom
mscore: root.mscore
volume: root.volume
}
Row {
id: zoomGroup
anchors.left: volumeSlider.right
anchors.leftMargin: 12
anchors.bottom: transportGroup.bottom
spacing: 4
// FlatButton doesn't forward pressed/released signals (see its own
// source code comment about this), so a held-down press can't be
// detected on it - custom button here instead, to be able to
// repeat the zoom step while the button stays pressed.
Item {
id: zoomOutBtn
width: 22
height: 22
anchors.verticalCenter: parent.verticalCenter
property bool zoomEnabled: root.duration > 0 && root.mainZoom > root.minZoom
ToolTip.visible: zoomOutArea.containsMouse
ToolTip.text: "Zoom out"
ToolTip.delay: 500
Rectangle {
anchors.fill: parent
radius: 3
color: zoomOutArea.pressed ? "#3a3a3a" : (zoomOutArea.containsMouse ? "#333333" : "transparent")
}
Text {
anchors.centerIn: parent
text: "−"
font.pixelSize: 16
font.bold: true
color: zoomOutBtn.zoomEnabled ? "#dddddd" : "#666666"
}
Timer {
id: zoomOutRepeat
interval: 100
repeat: true
onTriggered: { zoomOutArea.repeated = true; root.zoomByPercent(-5) }
}
MouseArea {
id: zoomOutArea
property bool repeated: false
anchors.fill: parent
hoverEnabled: true
enabled: zoomOutBtn.zoomEnabled
onPressed: { repeated = false; zoomInput.focus = false; zoomOutRepeat.start() }
onReleased: zoomOutRepeat.stop()
onCanceled: zoomOutRepeat.stop()
onClicked: if (!repeated) root.zoomOut()
}
}
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: 1
Text {
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 9
color: "#bbbbbb"
text: "Zoom"
}
TextField {
id: zoomInput
implicitWidth: 46
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 11
color: "#dddddd"
selectByMouse: true
enabled: root.duration > 0
background: Rectangle { color: "#2a2a2a"; border.color: "#3a3a3a"; radius: 2 }
function syncFromZoom() {
if (!activeFocus) text = Math.round(root.mainZoom * 100) + "%"
}
function commitEdit() {
var parsed = parseInt(text.replace("%", ""), 10)
if (!isNaN(parsed)) {
root.requestZoom(parsed / 100, root.displayPosition)
}
}
Component.onCompleted: syncFromZoom()
// MuseScore intercepts Return/Enter/Escape at key-press time
// before they reach this field - handling them on key-release
// instead gets through.
Keys.onReleased: function(event) {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
commitEdit()
focus = false
event.accepted = true
} else if (event.key === Qt.Key_Escape) {
focus = false
event.accepted = true
} else if (event.key === Qt.Key_Space) {
event.accepted = true
}
}
onActiveFocusChanged: {
if (activeFocus) {
text = text.replace("%", "")
selectAll()
} else {
// Escape (no commitEdit before losing focus) falls back here
// and resets the text to the current zoom value, never
// modified if nothing was committed.
syncFromZoom()
}
}
}
}
Item {
id: zoomInBtn
width: 22
height: 22
anchors.verticalCenter: parent.verticalCenter
property bool zoomEnabled: root.duration > 0 && root.mainZoom < root.maxZoom
ToolTip.visible: zoomInArea.containsMouse
ToolTip.text: "Zoom in"
ToolTip.delay: 500
Rectangle {
anchors.fill: parent
radius: 3
color: zoomInArea.pressed ? "#3a3a3a" : (zoomInArea.containsMouse ? "#333333" : "transparent")
}
Text {
anchors.centerIn: parent
text: "+"
font.pixelSize: 16
font.bold: true
color: zoomInBtn.zoomEnabled ? "#dddddd" : "#666666"
}
Timer {
id: zoomInRepeat
interval: 100
repeat: true
onTriggered: { zoomInArea.repeated = true; root.zoomByPercent(5) }
}
MouseArea {
id: zoomInArea
property bool repeated: false
anchors.fill: parent
hoverEnabled: true
enabled: zoomInBtn.zoomEnabled
onPressed: { repeated = false; zoomInput.focus = false; zoomInRepeat.start() }
onReleased: zoomInRepeat.stop()
onCanceled: zoomInRepeat.stop()
onClicked: if (!repeated) root.zoomIn()
}
}
}
Connections {
target: root
function onMainZoomChanged() { zoomInput.syncFromZoom() }
}
Row {
id: zoomPresets
anchors.left: zoomGroup.right
anchors.leftMargin: 8
anchors.bottom: transportGroup.bottom
spacing: 4
FlatButton {
text: "100%"
width: 34
textFont.pixelSize: 9
toolTipTitle: "Zoom to 100%"
enabled: root.duration > 0
accentButton: Math.abs(root.mainZoom - 1.0) < 0.01
onClicked: root.requestZoom(1.0, root.displayPosition)
}
FlatButton {
text: "250%"
width: 34
textFont.pixelSize: 9
toolTipTitle: "Zoom to 250%"
enabled: root.duration > 0
accentButton: Math.abs(root.mainZoom - 2.5) < 0.01
onClicked: root.requestZoom(2.5, root.displayPosition)
}
FlatButton {
text: "500%"
width: 34
textFont.pixelSize: 9
toolTipTitle: "Zoom to 500%"
enabled: root.duration > 0
accentButton: Math.abs(root.mainZoom - 5.0) < 0.01
onClicked: root.requestZoom(5.0, root.displayPosition)
}
FlatButton {
text: "750%"
width: 34
textFont.pixelSize: 9
toolTipTitle: "Zoom to 750%"
enabled: root.duration > 0
accentButton: Math.abs(root.mainZoom - 7.5) < 0.01
onClicked: root.requestZoom(7.5, root.displayPosition)
}
}
}
Text {
visible: root.errorText !== ""
text: root.errorText
color: "#ff5252"
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
MarkerRuler {
id: markerRuler
Layout.fillWidth: true
Layout.preferredHeight: 20
markers: root.markers
duration: root.duration
zoomLevel: root.mainZoom
viewCenter: root.mainViewCenter
onMarkerMoved: function(id, newPosition) { root.updateMarkerPosition(id, newPosition) }
onEditCommitted: function(id, newText) { root.updateMarkerText(id, newText) }
onDeleteRequested: function(id) { root.deleteMarker(id) }
onAddMarkerRequested: function(position) { root.addMarker(position) }
onMarkerDragging: function(id, position) { root.liveMarkerDrag = { id: id, position: position } }
onMarkerDragEnded: function(id) { root.liveMarkerDrag = null }
}
// Plain, non-clipping wrapper: WaveformView itself sets clip:true (so
// the canvas/handles never draw past its own edges), which would also
// hard-clip the EQ overlay if it happened to be taller than the
// waveform's current height. EQPanel is a sibling here instead, so it
// overlays on top without being subject to WaveformView's clip.
Item {
Layout.fillWidth: true
Layout.fillHeight: true
WaveformView {
id: waveformView
anchors.fill: parent
mscore: root.mscore
duration: root.duration
position: root.displayPosition
loopA: root.loopA
loopB: root.loopB
fileName: root.currentFileName
version: root.mscore ? root.mscore.version : ""
waveformData: root.zoomedWaveformData
zoomLevel: root.mainZoom
viewCenter: root.mainViewCenter
markers: root.markers
liveMarkerDrag: root.liveMarkerDrag
}
EQPanel {
anchors.centerIn: parent
mscore: root.mscore
visible: root.eqPanelOpen
onCloseRequested: root.eqPanelOpen = false
}
// Time-stretching and/or pitch-shifting the whole track (see
// _apply_transform_change in server.py) takes real wall-clock time
// proportional to its length - without this, clicking a speed/pitch
// control looks like nothing happened for a few seconds.
// recomputeRemainingS is a rolling estimate calibrated from the last
// completed recompute this session, so it's absent (spinner only,
// no ETA text) the very first time.
Item {
visible: root.recomputing
anchors.centerIn: parent
width: stretchColumn.implicitWidth + 32
height: stretchColumn.implicitHeight + 24
z: 90
Rectangle {
anchors.fill: parent
radius: 6
color: "#262626"
border.color: "#3a3a3a"
border.width: 1
}
Column {
id: stretchColumn
anchors.centerIn: parent
spacing: 6
BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: root.recomputing
width: 28
height: 28
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "Applying speed/pitch change…"
font.pixelSize: 10
color: "#dddddd"
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
visible: root.recomputeRemainingS >= 0
text: "~" + root.recomputeRemainingS.toFixed(1) + "s remaining"
font.pixelSize: 9
color: "#999999"
}
}
}
}
WaveformOverview {
Layout.fillWidth: true
Layout.preferredHeight: 36
duration: root.duration
position: root.displayPosition
viewStart: root.mainViewStart
viewEnd: root.mainViewEnd
waveformData: root.waveformData
markers: root.markers
liveMarkerDrag: root.liveMarkerDrag
onSeekRequested: function(t) {
if (!root.mscore) return
root.mscore.seek(t)
root.displayPosition = t
root.mainViewCenter = t
}
}
}
// Confirmation required before resetSession() runs - clearing the
// metaTags bypasses setMetaTag's usual lack of undo support anyway (see
// MUTranscriber.qml), so there's no Ctrl+Z safety net for this one.
Popup {
id: resetConfirmPopup
modal: true
focus: true
x: (root.width - width) / 2