Repository navigation
Expand file tree
/
Copy pathsettings.html
More file actions
1317 lines (1221 loc) · 62.9 KB
/
Copy pathsettings.html
File metadata and controls
1317 lines (1221 loc) · 62.9 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
<!-- Stem Splitter settings — injected into the app Settings panel. Scoped under
.stem-splitter-settings. Nothing heavy loads until the user clicks Download. -->
<style>
/* Scoped to the plugin's settings root. Inlined on purpose: the plugin's
stylesheet (assets/plugin.css) is only loaded on the plugin SCREEN, not in the
app's Settings panel, so status styling has to live here. */
#ss-settings .ss-statusbar {
display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
margin: .5rem 0 .75rem;
}
#ss-settings .ss-chip {
display: inline-flex; align-items: center; gap: .35rem;
padding: .22rem .6rem; border-radius: 999px;
font-size: .78rem; font-weight: 600; line-height: 1.2;
border: 1px solid transparent; white-space: nowrap;
}
#ss-settings .ss-chip.ok { background: rgba(34,197,94,.16); color: #4ade80; border-color: rgba(34,197,94,.35); }
#ss-settings .ss-chip.warn { background: rgba(234,179,8,.16); color: #facc15; border-color: rgba(234,179,8,.35); }
#ss-settings .ss-chip.bad { background: rgba(239,68,68,.16); color: #f87171; border-color: rgba(239,68,68,.35); }
#ss-settings .ss-chip.info { background: rgba(59,130,246,.16); color: #93c5fd; border-color: rgba(59,130,246,.35); }
#ss-settings .ss-chip.off { background: rgba(148,163,184,.12); color: #94a3b8; border-color: rgba(148,163,184,.25); }
#ss-settings .ss-chip .dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
#ss-settings .ss-chip.live .dot { animation: ss-pulse 1.4s ease-in-out infinite; }
@keyframes ss-pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }
#ss-settings .ss-note { font-size: .78rem; color: #94a3b8; margin: .1rem 0 .6rem; }
#ss-settings .ss-note.warn { color: #facc15; }
/* Action buttons whose colour reflects state, not decoration. */
#ss-settings .ss-actionbtn {
border: 0; border-radius: 7px; padding: .45rem .85rem;
font-weight: 600; cursor: pointer; color: #fff;
display: inline-flex; align-items: center; gap: .4rem;
transition: background .15s ease, opacity .15s ease;
}
#ss-settings .ss-actionbtn .dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
#ss-settings .ss-actionbtn.green { background: #16a34a; } /* server up */
#ss-settings .ss-actionbtn.red { background: #b91c1c; } /* server down */
#ss-settings .ss-actionbtn.blue { background: #2563eb; }
#ss-settings .ss-actionbtn.grey { background: rgba(148,163,184,.2); color: #e2e8f0; }
#ss-settings .ss-actionbtn.amber { background: #a16207; }
/* The way through to the queue (#18). Sits directly under the title, because a user who lands in
Settings and can't get to their running jobs from here has to go hunting for them. */
#ss-settings .ss-queue-link {
display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
margin: .25rem 0 1rem 0;
}
#ss-settings .ss-queue-count {
min-width: 1.25rem; padding: 0 .35rem; border-radius: 999px;
background: #2563eb; color: #fff; font-size: .72rem; font-weight: 700;
text-align: center;
}
#ss-settings .ss-actionbtn[disabled] { opacity: .45; cursor: not-allowed; }
#ss-settings .ss-actionbtn.busy .dot { animation: ss-pulse 1.4s ease-in-out infinite; }
/* ── Section structure ────────────────────────────────────────────────────────
The three areas (engines / in-process engine / managed server) previously ran
together as bare <h3> text with nothing separating them. Give each a card and a
real header so it's obvious where one ends and the next begins. */
#ss-settings .ss-title {
font-size: 1.15rem; font-weight: 700; margin: 0 0 .25rem; color: #f1f5f9;
}
#ss-settings .ss-subtitle { color: #94a3b8; font-size: .82rem; margin: 0 0 1rem; }
#ss-settings .ss-section {
background: rgba(30, 41, 59, .45);
border: 1px solid rgba(148, 163, 184, .18);
border-radius: 10px;
padding: .9rem 1.05rem 1.05rem;
margin: 0 0 1rem;
}
#ss-settings .ss-section > h3 {
display: flex; align-items: center; gap: .55rem;
margin: 0 0 .75rem; padding-bottom: .55rem;
font-size: .92rem; font-weight: 700; letter-spacing: .01em; color: #e2e8f0;
border-bottom: 1px solid rgba(148, 163, 184, .15);
}
/* Accent bar keys each section to its colour. */
#ss-settings .ss-section > h3::before {
content: ''; width: 3px; height: 1.05rem; border-radius: 2px; flex: none;
background: var(--ss-accent, #3b82f6);
}
#ss-settings .ss-section.engines { --ss-accent: #3b82f6; }
#ss-settings .ss-section.local { --ss-accent: #a855f7; }
#ss-settings .ss-section.server { --ss-accent: #16a34a; }
#ss-settings .ss-section.docker { --ss-accent: #0ea5e9; }
#ss-settings .ss-section > h3 .ss-h-note {
margin-left: auto; font-size: .72rem; font-weight: 500; color: #94a3b8;
}
#ss-settings .ss-section p:first-of-type { margin-top: 0; }
/* Advanced: collapsed by default — these are escape hatches, not everyday knobs. */
#ss-settings .ss-adv {
margin-top: .9rem; border-top: 1px solid rgba(148,163,184,.15); padding-top: .6rem;
}
#ss-settings .ss-adv > summary {
cursor: pointer; font-size: .8rem; font-weight: 600; color: #94a3b8;
list-style: none; user-select: none;
}
#ss-settings .ss-adv > summary::-webkit-details-marker { display: none; }
#ss-settings .ss-adv > summary::before { content: '▸ '; }
#ss-settings .ss-adv[open] > summary::before { content: '▾ '; }
#ss-settings .ss-adv > summary:hover { color: #cbd5e1; }
#ss-settings .ss-adv .ss-adv-body { padding-top: .6rem; }
#ss-settings code.ss-mono {
font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
background: rgba(148,163,184,.12); padding: .1rem .35rem; border-radius: 4px;
}
</style>
<div class="stem-splitter-settings" id="ss-settings">
<h2 class="ss-title">Stem Splitter</h2>
<p class="ss-subtitle">Split stems and transcribe lyrics — using a server, or on this machine.</p>
<!-- The jobs run in the background and the queue is the only place their progress is visible.
Landing in Settings and having no way through to it is how "where did my split go?" starts,
so the way out is on the way in. (#18) -->
<div class="ss-queue-link">
<button class="ss-actionbtn grey" id="ss-open-queue">📋 Open the queue<span id="ss-queue-count" class="ss-queue-count" hidden></span></button>
<span class="ss-h-note">watch splits, transcriptions and re-aligns as they run</span>
</div>
<section class="ss-section engines">
<h3>Engines <span class="ss-h-note">which engine runs the work</span></h3>
<p class="ss-muted">Chooses <em>where</em> splitting and lyric transcription happen. Leave both on
<strong>Auto</strong> and it does the right thing: use the server below if it's running, otherwise
fall back to the in-app engine if you installed one.</p>
<p class="ss-note"><strong>“Server”</strong> = the managed local demucs server below whenever it's
running, otherwise whatever the app's <code>demucs_server_url</code> points at — so the same option
covers both. <strong>“In-app”</strong> = the models run inside the feedBack process itself.<br>
These settings apply to <em>both</em>: “Split model” is sent to the server <em>and</em> used by the
in-app audio-separator; “WhisperX model” is the one exception — only the in-app transcriber uses it,
the server has its own.</p>
<label for="ss-set-split">Split engine</label>
<select id="ss-set-split">
<option value="auto">Auto — server if running, else in-app</option>
<option value="remote">Server (managed local, or demucs_server_url)</option>
<option value="audio-separator">In-app — audio-separator (bs_roformer_sw)</option>
<option value="demucs">In-app — demucs (htdemucs_6s)</option>
</select>
<label for="ss-set-lyrics">Lyrics engine</label>
<select id="ss-set-lyrics">
<option value="auto">Auto — server if running, else in-app</option>
<option value="remote">Server (/align)</option>
<option value="local">In-app — whisperx</option>
</select>
<div class="row">
<div>
<label for="ss-set-remote-model" title="Sent to the server AND used by the in-app audio-separator engine">Split model (server + in-app)</label>
<input type="text" id="ss-set-remote-model" value="bs_roformer_sw">
</div>
<div>
<label for="ss-set-wx-model" title="Only the in-app whisperx uses this; the server has its own">WhisperX model (in-app only)</label>
<select id="ss-set-wx-model">
<option>tiny</option><option>base</option><option>small</option>
<option selected>medium</option><option>large-v2</option><option>large-v3</option>
</select>
</div>
<div>
<label for="ss-set-lang">Language (blank = auto)</label>
<input type="text" id="ss-set-lang" placeholder="en" style="width:5rem">
</div>
</div>
<div style="margin-top:1rem"><button class="ss-btn" id="ss-set-save" style="background:#2563eb;color:#fff;border:0;border-radius:7px;padding:.45rem .85rem;font-weight:600;cursor:pointer">Save</button>
<span id="ss-set-saved" class="ss-muted"></span></div>
</section>
<section class="ss-section server">
<h3>Local demucs server <span class="ss-h-note" id="ss-srv-saved">recommended — start here</span></h3>
<p class="ss-muted"><strong>The easiest way to get splitting working.</strong> Runs got-feedBack's real
demucs/whisperx server on this machine and manages it for you. <em>Install server + models</em> does
the whole setup in one click (dependencies, then the model weights) and starts it.</p>
<p class="ss-note">Once it's running, the plugin uses it automatically — nothing else to configure.
It can use your <strong>GPU</strong> (big speed-up: seconds instead of minutes), it runs in its own
process so it can't destabilise the app, and <em>Uninstall server</em> removes every byte it
downloaded. This is the only thing here that downloads anything; app startup never downloads and
is never blocked by it.</p>
<div class="ss-statusbar" id="ss-srv-chips"><span class="ss-chip off">Checking…</span></div>
<p class="ss-note" id="ss-srv-note"></p>
<div class="row">
<div>
<label for="ss-srv-port">Port</label>
<input type="text" id="ss-srv-port" value="7865" style="width:5.5rem">
</div>
<div>
<label for="ss-srv-device">Device</label>
<select id="ss-srv-device">
<option value="">Auto</option>
<option value="cpu">CPU</option>
<option value="cuda">CUDA (GPU)</option>
</select>
</div>
<div>
<label><input type="checkbox" id="ss-srv-autostart"> Start with the app</label>
<label><input type="checkbox" id="ss-srv-global"> Use for the whole app</label>
<label><input type="checkbox" id="ss-srv-gpu"> <span id="ss-srv-gpu-label">Use GPU (CUDA)</span></label>
</div>
</div>
<div class="row" style="margin-top:.6rem">
<button class="ss-actionbtn blue" id="ss-srv-install"><span id="ss-srv-install-label">Install server + models (~5 GB)</span></button>
<!-- One button. Its COLOUR is the server's state (red = down, green = up); its
LABEL is what clicking will do. -->
<button class="ss-actionbtn red" id="ss-srv-toggle"><i class="dot"></i><span id="ss-srv-toggle-label">Start server</span></button>
<button class="ss-actionbtn grey" id="ss-srv-test">Test status</button>
<button class="ss-actionbtn grey" id="ss-srv-update">Check for update</button>
<button class="ss-actionbtn grey" id="ss-srv-uninstall">Uninstall server</button>
</div>
<details class="ss-adv" id="ss-srv-adv">
<summary>Advanced — pin a server revision / CUDA build</summary>
<div class="ss-adv-body">
<p class="ss-note" style="margin-top:0">Only needed if you're testing a specific server revision,
or if the default CUDA build doesn't match your driver. Changing these takes effect on the
<strong>next install</strong> — use <em>Uninstall server</em>, then install again.</p>
<div class="row">
<div>
<label for="ss-srv-ref">Server revision (branch, tag or commit)</label>
<input type="text" id="ss-srv-ref" placeholder="main" style="width:16rem">
</div>
<div>
<label for="ss-srv-cuda">CUDA build</label>
<select id="ss-srv-cuda"></select>
</div>
</div>
<p class="ss-note" id="ss-srv-adv-note"></p>
</div>
</details>
<div id="ss-srv-progress" style="display:none;margin-top:.75rem">
<div class="ss-row" style="justify-content:space-between">
<strong id="ss-srv-phase" style="font-size:.85rem">Starting…</strong>
<span id="ss-srv-pct" class="ss-muted">0%</span>
</div>
<div class="ss-bar" style="width:100%;margin:.35rem 0"><i id="ss-srv-fill" style="width:0%"></i></div>
<pre class="ss-log" id="ss-srv-log" style="height:240px;max-height:240px;overflow:auto;margin:0;padding:.6rem;background:#0b1220;color:#94a3b8;border:1px solid rgba(148,163,184,.2);border-radius:6px;font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word"></pre>
</div>
</section>
<!-- Docker users. Hidden entirely unless we're in a container OR a daemon is reachable,
so the overwhelming majority (Electron, no Docker) never see a card that has nothing
to say to them. -->
<section class="ss-section docker" id="ss-dk-card" style="display:none">
<h3>Run the server as a Docker container <span class="ss-h-note" id="ss-dk-h-note"></span></h3>
<p class="ss-muted" id="ss-dk-intro">feedBack is running in a container, so it can't install the
server on your host — a container can't start a process outside itself. Instead, run the
server as its own container alongside this one.</p>
<div class="ss-row" style="gap:.4rem;flex-wrap:wrap;margin:.5rem 0">
<span id="ss-dk-chips"></span>
</div>
<!-- The recommended path: costs nothing, grants nobody root. -->
<div id="ss-dk-compose-wrap">
<p class="ss-note"><strong>Recommended.</strong> Add this service to the
<code>docker-compose.yml</code> you already have, then <code>docker compose up -d</code>.
Nothing else to configure — the plugin finds it automatically.</p>
<div class="ss-row" style="justify-content:space-between;align-items:center">
<span class="ss-muted" style="font-size:.78rem">compose service</span>
<button class="ss-btn" id="ss-dk-copy" type="button">Copy</button>
</div>
<pre class="ss-log" id="ss-dk-compose" style="max-height:210px;overflow:auto;margin:.35rem 0 0;padding:.6rem;background:#0b1220;color:#94a3b8;border:1px solid rgba(148,163,184,.2);border-radius:6px;font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre;word-break:normal"></pre>
</div>
<!-- The one-click path. Only appears if the socket is ALREADY exposed. We never ask the
user to mount it: it is root-equivalent on the host, and that is their call, not ours. -->
<div id="ss-dk-oneclick" style="display:none;margin-top:1rem;padding-top:.85rem;border-top:1px solid rgba(148,163,184,.18)">
<p class="ss-note"><strong>Or let feedBack do it.</strong> You've mounted the Docker socket, so
the plugin can pull the image and start the container for you — same result as the compose
snippet above, one click.</p>
<p class="ss-note warn" id="ss-dk-warn" style="display:none"></p>
<div class="ss-row" style="gap:.5rem;flex-wrap:wrap;margin-top:.5rem">
<button class="ss-btn" id="ss-dk-up">Start the server container</button>
<button class="ss-btn" id="ss-dk-down" style="display:none">Stop</button>
<button class="ss-btn" id="ss-dk-test">Test status</button>
<label class="ss-row" style="gap:.35rem;font-size:.82rem" id="ss-dk-gpu-wrap">
<input type="checkbox" id="ss-dk-gpu"> Use GPU
</label>
</div>
<p class="ss-note" id="ss-dk-gpu-note"></p>
<div id="ss-dk-progress" style="display:none;margin-top:.75rem">
<div class="ss-row" style="justify-content:space-between">
<strong id="ss-dk-phase" style="font-size:.85rem">Working…</strong>
<span id="ss-dk-pct" class="ss-muted">0%</span>
</div>
<div class="ss-bar" style="width:100%;margin:.35rem 0"><i id="ss-dk-fill" style="width:0%"></i></div>
<pre class="ss-log" id="ss-dk-log" style="height:200px;max-height:200px;overflow:auto;margin:0;padding:.6rem;background:#0b1220;color:#94a3b8;border:1px solid rgba(148,163,184,.2);border-radius:6px;font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word"></pre>
</div>
</div>
</section>
<section class="ss-section local">
<h3>Local engine <span class="ss-h-note">alternative — no server</span></h3>
<p class="ss-muted">Runs the models <strong>inside the feedBack process</strong> instead of talking to
a server. You don't need this if you're using the server above — it's a separate, second download.</p>
<p class="ss-note">Worth knowing: it's <strong>CPU-only</strong> (no CUDA install path, so it's slower
than the server on an NVIDIA machine), it loads multi-GB models into the app's own process, and its
weights land in the shared <code>~/.cache</code> — so <em>Uninstall</em> can't reclaim them all.
Prefer the server unless you specifically want to avoid running one.</p>
<div class="ss-statusbar" id="ss-engine-chips"><span class="ss-chip off">Checking…</span></div>
<p class="ss-note" id="ss-engine-note"></p>
<div class="row">
<button class="ss-btn" id="ss-dl-all" style="background:#2563eb;color:#fff;border:0;border-radius:7px;padding:.45rem .85rem;font-weight:600;cursor:pointer">Download local engine + models (~2 GB+)</button>
<button class="ss-btn" id="ss-dl-as" style="background:rgba(148,163,184,.2);color:#e2e8f0;border:0;border-radius:7px;padding:.45rem .85rem;cursor:pointer">audio-separator only</button>
<button class="ss-btn" id="ss-dl-demucs" style="background:rgba(148,163,184,.2);color:#e2e8f0;border:0;border-radius:7px;padding:.45rem .85rem;cursor:pointer">demucs only</button>
<button class="ss-btn" id="ss-dl-wx" style="background:rgba(148,163,184,.2);color:#e2e8f0;border:0;border-radius:7px;padding:.45rem .85rem;cursor:pointer">whisperx only</button>
<button class="ss-btn" id="ss-uninstall" style="background:#b91c1c;color:#fff;border:0;border-radius:7px;padding:.45rem .85rem;cursor:pointer">Uninstall</button>
</div>
<div id="ss-install-progress" style="display:none;margin-top:.75rem">
<div class="ss-row" style="justify-content:space-between">
<strong id="ss-install-phase" style="font-size:.85rem">Starting…</strong>
<span id="ss-install-pct" class="ss-muted">0%</span>
</div>
<div class="ss-bar" style="width:100%;margin:.35rem 0"><i id="ss-install-fill" style="width:0%"></i></div>
<pre class="ss-log" id="ss-install-log" style="height:240px;max-height:240px;overflow:auto;margin:0;padding:.6rem;background:#0b1220;color:#94a3b8;border:1px solid rgba(148,163,184,.2);border-radius:6px;font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word"></pre>
</div>
</section>
</div>
<script>
(function () {
'use strict';
if (window.__stemSplitterSettingsLoaded) return;
window.__stemSplitterSettingsLoaded = true;
var API = '/api/plugins/stem_splitter';
function $(id) { return document.getElementById(id); }
function j(path, opts) { return fetch(API + path, opts).then(function (r) { return r.json(); }); }
function loadConfig() {
j('/config').then(function (cfg) {
var s = cfg.settings || {};
$('ss-set-split').value = s.split_engine || 'auto';
$('ss-set-lyrics').value = s.lyrics_engine || 'auto';
$('ss-set-remote-model').value = s.remote_model || 'bs_roformer_sw';
$('ss-set-wx-model').value = s.whisperx_model || 'medium';
$('ss-set-lang').value = s.language || '';
$('ss-srv-port').value = s.local_server_port || 7865;
$('ss-srv-device').value = s.local_server_device || '';
$('ss-srv-autostart').checked = !!s.local_server_autostart;
$('ss-srv-global').checked = !!s.local_server_use_globally;
if (s.local_server_gpu !== null && typeof s.local_server_gpu !== 'undefined') {
$('ss-srv-gpu').checked = !!s.local_server_gpu;
gpuTouched = true;
}
$('ss-srv-ref').value = s.local_server_ref || '';
advCudaWanted = s.local_server_cuda_tag || '';
// /config carries only the cheap install map now; the full status
// (with the expensive cache-size walk) comes from /engine_status.
renderStatus(null);
}).catch(function () {});
loadServerStatus();
}
function esc(s) {
return String(s == null ? '' : s).replace(/[&<>"]/g, function (c) {
return { '&': '&', '<': '<', '>': '>', '"': '"' }[c];
});
}
// tone: ok | warn | bad | info | off. `live` adds a pulsing dot.
function chip(label, tone, opts) {
opts = opts || {};
return '<span class="ss-chip ' + tone + (opts.live ? ' live' : '') + '"'
+ (opts.title ? ' title="' + esc(opts.title) + '"' : '') + '>'
+ (opts.dot ? '<i class="dot"></i>' : '') + esc(label) + '</span>';
}
function gb(bytes) { return ((bytes || 0) / 1e9).toFixed(2) + ' GB'; }
function renderStatus(st) {
if (!st) { j('/engine_status').then(renderStatus); return; }
var inst = st.installed || {};
var chips = Object.keys(inst).map(function (k) {
return inst[k] ? chip(k + ' ✓', 'ok') : chip(k + ' —', 'off');
});
var onDisk = (st.engine_bytes || 0) + (st.models_bytes || 0);
chips.push(chip(gb(onDisk) + ' on disk', onDisk ? 'info' : 'off'));
$('ss-engine-chips').innerHTML = chips.join('');
// The app pins TORCH_HOME/HF_HOME to the shared ~/.cache dirs, so some weights
// land there rather than in our models dir. Say so — Uninstall won't reclaim them.
var note = $('ss-engine-note');
if (st.external_cache_bytes) {
note.textContent = '⚠ ' + gb(st.external_cache_bytes)
+ ' of model weights also live in shared caches and are NOT removed by Uninstall — '
+ (st.external_caches || []).map(function (c) { return c.path; }).join(', ');
note.className = 'ss-note warn';
} else {
note.textContent = '';
note.className = 'ss-note';
}
}
function save() {
var body = {
split_engine: $('ss-set-split').value,
lyrics_engine: $('ss-set-lyrics').value,
remote_model: $('ss-set-remote-model').value,
whisperx_model: $('ss-set-wx-model').value,
language: $('ss-set-lang').value,
};
// The server card saves itself (see saveServerSettings) - don't duplicate its keys here.
j('/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
.then(function () { $('ss-set-saved').textContent = 'Saved.'; setTimeout(function () { $('ss-set-saved').textContent = ''; }, 2000); });
}
var MAX_LOG_LINES = 500;
function appendLog(log, line) {
// Keep only the last N lines so a long pip run can't balloon the DOM; the
// fixed-height box scrolls, and we pin to the bottom unless the user has
// scrolled up to read back.
var atBottom = log.scrollTop + log.clientHeight >= log.scrollHeight - 4;
var lines = log.textContent ? log.textContent.split('\n') : [];
lines.push(line);
if (lines.length > MAX_LOG_LINES) lines = lines.slice(lines.length - MAX_LOG_LINES);
log.textContent = lines.join('\n');
if (atBottom) log.scrollTop = log.scrollHeight;
}
function setBar(pct, phase) {
$('ss-install-fill').style.width = Math.round((pct || 0) * 100) + '%';
$('ss-install-pct').textContent = Math.round((pct || 0) * 100) + '%';
if (phase) $('ss-install-phase').textContent = phase;
}
// Lock every engine action while an install or uninstall is in flight so the
// user can't start a download over a running uninstall (or vice-versa) and race
// pip/rmtree on the same engine dir.
var ENGINE_BTNS = ['ss-dl-all', 'ss-dl-as', 'ss-dl-demucs', 'ss-dl-wx', 'ss-uninstall'];
function setEngineButtons(disabled) {
ENGINE_BTNS.forEach(function (id) { var el = $(id); if (el) el.disabled = disabled; });
}
function install(which) {
$('ss-install-progress').style.display = 'block';
$('ss-install-log').textContent = 'Starting download of ' + which + '…\n';
setBar(0.02, 'Starting');
setEngineButtons(true); // re-enabled on install_done / install_error over the WS
connectWS();
j('/install_engine', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ which: which }) })
.catch(function (err) {
appendLog($('ss-install-log'), '✗ install request failed: ' + err);
setBar(0, 'Failed'); setEngineButtons(false);
});
}
// Render bar/phase from a persisted install state carried in the WS snapshot.
// This is how a reconnected page recovers a "Done" (or "Failed") that finished
// while the socket was down.
function renderInstall(st) {
if (!st) return;
$('ss-install-progress').style.display = 'block';
setBar(st.pct, st.phase || (st.active ? 'Installing' : 'Done'));
if (st.error) appendLog($('ss-install-log'), '✗ ' + st.error);
setEngineButtons(!!st.active); // keep buttons locked if an install is still running
}
// Snapshot recovery for a server op that was still running while the page was away.
function renderServerOp(st) {
if (!st) return;
// The managed server and the Docker sidecar share ONE op mutex and one event stream,
// so the SNAPSHOT has to be routed by op exactly as the live events are. Without this,
// reloading the page mid-pull draws the container's progress into the local-server
// card — a bar moving in a section the user never touched.
if (isDk(st.op)) {
$('ss-dk-progress').style.display = 'block';
setDkBar(st.pct, st.phase || (st.active ? 'Working…' : 'Done'));
if (st.error) appendLog($('ss-dk-log'), '✗ ' + st.error);
setDkButtons(!!st.active);
return;
}
$('ss-srv-progress').style.display = 'block';
// A snapshot is authoritative for whatever operation is live NOW (this fires on reconnect,
// possibly into a different op than the one whose floor we're carrying), so it resets.
setSrvBar(st.pct, st.phase || (st.active ? st.op : 'Done'), true);
if (st.error) appendLog($('ss-srv-log'), '✗ ' + st.error);
setServerButtons(!!st.active);
}
var ws = null;
function connectWS() {
if (ws) return;
var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(proto + '//' + location.host + API + '/events');
ws.onmessage = function (ev) {
var m; try { m = JSON.parse(ev.data); } catch (e) { return; }
var log = $('ss-install-log');
if (m.type === 'jobs') {
renderQueueCount(m); // jobs started/finished anywhere, incl. here
if (m.install) renderInstall(m.install); // snapshot recovery
if (m.server) renderServerOp(m.server);
} else if (m.type === 'server') {
// The managed server and the Docker sidecar share one op mutex and one event
// stream, so route by op — otherwise a container pull would draw its progress
// into the local-server card.
if (isDk(m.op)) {
$('ss-dk-progress').style.display = 'block';
if (m.line) appendLog($('ss-dk-log'), m.line);
setDkBar(m.pct, m.phase);
setDkButtons(true);
} else {
$('ss-srv-progress').style.display = 'block';
if (m.line) appendLog($('ss-srv-log'), m.line);
setSrvBar(m.pct, m.phase);
setServerButtons(true);
}
} else if (m.type === 'server_done') {
if (isDk(m.op)) {
appendLog($('ss-dk-log'), '✓ the demucs container is running.');
setDkBar(1, 'Running');
setDkButtons(false);
loadDocker();
} else {
appendLog($('ss-srv-log'), '✓ ' + m.op + ' done.');
setSrvBar(1, 'Done', true);
setServerButtons(false);
if (m.status) renderServerStatus(m.status); else loadServerStatus();
}
} else if (m.type === 'server_error') {
if (isDk(m.op)) {
appendLog($('ss-dk-log'), '✗ ' + m.error);
setDkBar(0, 'Failed');
setDkButtons(false);
loadDocker();
} else {
appendLog($('ss-srv-log'), '✗ ' + m.error);
setSrvBar(0, 'Failed', true);
setServerButtons(false);
loadServerStatus();
}
} else if (m.type === 'install') {
$('ss-install-progress').style.display = 'block';
if (m.line) appendLog(log, m.line);
setBar(m.pct, m.phase);
} else if (m.type === 'install_done') {
appendLog(log, '✓ Done.'); setBar(1, 'Done'); renderStatus(m.status); setEngineButtons(false);
} else if (m.type === 'install_error') {
appendLog(log, '✗ ' + m.error); setBar(m.pct || 0, 'Failed'); setEngineButtons(false);
}
};
ws.onclose = function () { ws = null; setTimeout(connectWS, 2000); };
ws.onerror = function () { try { ws.close(); } catch (e) {} };
}
$('ss-open-queue').addEventListener('click', openQueue);
refreshQueueCount();
$('ss-set-save').addEventListener('click', save);
$('ss-dl-all').addEventListener('click', function () { install('all'); });
$('ss-dl-as').addEventListener('click', function () { install('audio-separator'); });
$('ss-dl-demucs').addEventListener('click', function () { install('demucs'); });
$('ss-dl-wx').addEventListener('click', function () { install('whisperx'); });
$('ss-uninstall').addEventListener('click', function () {
setEngineButtons(true);
j('/uninstall_engine', { method: 'POST' }).then(function (st) {
renderStatus(st);
var u = st && st.uninstall;
if (u) {
$('ss-install-progress').style.display = 'block';
var phase, done;
if (u.removed) { phase = 'Removed'; done = 1; }
else if (u.pending) { phase = 'Restart required'; done = 0; }
else { phase = 'Uninstall incomplete'; done = 0; } // removed:false, pending:false
$('ss-install-phase').textContent = phase;
setBar(done, phase);
$('ss-install-log').textContent = u.message + '\n';
}
}).catch(function (err) {
$('ss-install-progress').style.display = 'block';
$('ss-install-phase').textContent = 'Uninstall failed';
setBar(0, 'Uninstall failed');
$('ss-install-log').textContent = 'Uninstall request failed: ' + err + '\n';
}).finally(function () { setEngineButtons(false); });
});
// ── managed demucs server ──────────────────────────────────────────────────
// These controls sit in their own card, away from the Engines "Save" button, so a
// user reasonably expects them to stick on their own. They used to be dropped on
// reload unless you happened to press a Save button in a different section.
var srvSaveTimer = null;
var SRV_FIELDS = ['ss-srv-autostart', 'ss-srv-global', 'ss-srv-gpu',
'ss-srv-port', 'ss-srv-device', 'ss-srv-ref', 'ss-srv-cuda'];
function saveServerSettings() {
// POST /config merges only the keys present, so a partial body is safe.
var body = {
local_server_port: parseInt($('ss-srv-port').value, 10) || 7865,
local_server_device: $('ss-srv-device').value,
local_server_autostart: $('ss-srv-autostart').checked,
local_server_use_globally: $('ss-srv-global').checked,
local_server_ref: $('ss-srv-ref').value.trim(),
local_server_cuda_tag: $('ss-srv-cuda').value,
};
// local_server_gpu is TRI-state: null means "auto-detect at install time", and
// renderServerStatus pre-checks the box for a detected GPU without the user asking.
// Sending the checkbox unconditionally would launder that hint into an explicit
// `true` the first time ANY other field on this card is touched, permanently
// disabling auto-detection. Only send it once the user has actually set it.
if (gpuTouched) body.local_server_gpu = $('ss-srv-gpu').checked;
return j('/config', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}).then(function () {
var el = $('ss-srv-saved');
if (!el) return;
var prev = el.textContent;
el.textContent = 'Saved ✓';
setTimeout(function () { el.textContent = prev; }, 1500);
}).catch(function () {});
}
function queueServerSave() {
if (srvSaveTimer) clearTimeout(srvSaveTimer);
srvSaveTimer = setTimeout(function () { srvSaveTimer = null; saveServerSettings(); }, 400);
}
SRV_FIELDS.forEach(function (id) {
var el = $(id);
if (!el) return;
el.addEventListener('change', queueServerSave);
if (el.tagName === 'INPUT' && el.type === 'text') el.addEventListener('input', queueServerSave);
});
var SERVER_BTNS = ['ss-srv-install', 'ss-srv-toggle', 'ss-srv-test', 'ss-srv-update',
'ss-srv-uninstall'];
var serverManageable = true; // false when the backend says it can't manage a server here
var serverBusy = false; // an install/start/stop/prepare is in flight
function setServerButtons(disabled) {
serverBusy = !!disabled;
var d = disabled || !serverManageable; // never re-enable an unsupported section
SERVER_BTNS.forEach(function (id) { var el = $(id); if (el) el.disabled = d; });
}
// The bar never runs backwards WITHIN an operation.
//
// The UI seeds a percentage for a step it is about to take (10% "Checking", 20% "Updating"),
// and then the server's own stream legitimately opens lower — update_server() emits 0.05 for
// "Stopping the server" when one is running. So the bar jumped forward and then back, which
// reads as the operation restarting. Enforcing it here rather than hand-tuning the seeds is
// the difference between fixing this and fixing it again the next time a step is inserted.
//
// `reset` starts a new operation (or reports a terminal state): that's the one time the bar
// is allowed to move down.
var _srvBarMax = 0;
// Settings -> queue. The queue's own header has a Settings button; this is that door from the
// other side, because a user who has just configured a server wants to watch it work.
// How many jobs are actually in flight. A bare "Open the queue" button tells you nothing about
// whether there is anything IN it; "3 running" is the difference between a link and an answer.
function renderQueueCount(snap) {
var el = $('ss-queue-count');
if (!el) return;
var live = ((snap && snap.jobs) || []).filter(function (job) {
return job.status === 'running' || job.status === 'queued';
}).length;
el.hidden = !live;
el.textContent = live || '';
}
// One fetch for the initial paint; after that the badge rides the SAME `jobs` snapshots the
// WebSocket already delivers to this page (see ws.onmessage). A count that is only correct at
// the moment the panel opened is a count you cannot trust — and this page can sit open for the
// whole length of a job, which is exactly when someone is watching it.
function refreshQueueCount() {
j('/jobs')
.then(renderQueueCount)
.catch(function () { /* the button still works; only the badge is missing */ });
}
function openQueue() {
var fb = window.feedBack;
if (fb && fb.navigate) fb.navigate('plugin-stem_splitter');
else if (window.showScreen) window.showScreen('plugin-stem_splitter');
}
function setSrvBar(pct, phase, reset) {
var p = pct || 0;
if (reset) _srvBarMax = p;
else if (p < _srvBarMax) p = _srvBarMax;
else _srvBarMax = p;
$('ss-srv-fill').style.width = Math.round(p * 100) + '%';
$('ss-srv-pct').textContent = Math.round(p * 100) + '%';
if (phase) $('ss-srv-phase').textContent = phase;
}
function srvLog(line) { $('ss-srv-progress').style.display = 'block'; appendLog($('ss-srv-log'), line); }
var lastServerStatus = null;
var gpuTouched = false; // did the user set the GPU box themselves?
var advCudaWanted = ''; // saved CUDA override, applied once the options exist
// Advanced is rendered from the backend's defaults, so the UI never hardcodes the
// ref or the list of CUDA builds.
function renderAdvanced(st) {
var sel = $('ss-srv-cuda'), note = $('ss-srv-adv-note');
if (!sel || !st || !st.defaults) return;
var d = st.defaults;
if (!sel.options.length) {
var opts = ['<option value="">Default (' + esc(d.cuda_tag) + ')</option>'];
(d.cuda_tags || []).forEach(function (t) {
opts.push('<option value="' + esc(t) + '">' + esc(t) + '</option>');
});
sel.innerHTML = opts.join('');
sel.value = advCudaWanted || '';
}
$('ss-srv-ref').placeholder = d.ref || 'main';
// Show what's actually on disk, so "pinned" isn't a claim you have to trust.
var bits = [];
var src = st.source || {}, inst = st.install_info || {};
if (src.commit) {
bits.push('installed: ' + esc(d.repo) + ' @ ' + esc(String(src.ref || '')) +
' (' + esc(String(src.commit).slice(0, 8)) + ')');
}
if (inst.torch) bits.push('torch: ' + esc(inst.torch));
note.innerHTML = bits.length
? bits.join(' · ')
: 'Nothing installed yet — these apply to the next install.';
}
// The toggle's colour tracks the SERVER's state (red = down, green = up); its label
// says what a click will do. Previously Start was always green and Stop always grey,
// so the controls told you nothing about what was actually happening.
function setBtnTone(id, tone) {
var el = $(id);
if (!el) return;
el.classList.remove('green', 'red', 'blue', 'grey', 'amber', 'busy');
el.classList.add(tone);
}
// The setup button reflects what's still MISSING, rather than just disabling itself
// once the deps exist: installing the dependencies without the model weights leaves a
// server that starts but can't split, and that half-state needs a way forward.
function renderInstallBtn(st) {
var btn = $('ss-srv-install'), label = $('ss-srv-install-label');
if (!btn || !label) return;
if (!st) { btn.disabled = true; return; }
// Only offer the GPU build when there's actually an NVIDIA card to use it, and
// default it on in that case - a CPU install on a GPU box is minutes vs seconds.
var gpuBox = $('ss-srv-gpu'), gpuLabel = $('ss-srv-gpu-label');
var g = st.gpu_detected;
if (g) {
gpuBox.disabled = false;
gpuLabel.textContent = 'Use GPU (CUDA) - ' + g.name;
if (!gpuTouched && !st.installed) gpuBox.checked = true;
} else {
gpuBox.disabled = true;
gpuBox.checked = false;
gpuLabel.textContent = 'Use GPU (CUDA) - no NVIDIA GPU detected';
}
// A GPU box running a CPU-only install: offer the rebuild rather than greying out.
if (st.installed && g && !st.gpu_build && gpuBox.checked) {
setBtnTone('ss-srv-install', 'amber');
label.textContent = 'Reinstall with GPU (~5.5 GB)';
btn.disabled = serverBusy || !serverManageable;
btn.title = 'torch is the CPU-only build; rebuild it against CUDA to use ' + g.name;
return;
}
if (!st.installed) {
setBtnTone('ss-srv-install', 'blue');
label.textContent = 'Install server + models (~5 GB)';
btn.disabled = serverBusy || !serverManageable;
} else if (!st.models_downloaded) {
setBtnTone('ss-srv-install', 'amber');
label.textContent = 'Download models (~2 GB)'; // deps are there; finish the job
btn.disabled = serverBusy || !serverManageable;
} else {
setBtnTone('ss-srv-install', 'grey');
label.textContent = 'Installed ✓';
btn.disabled = true; // nothing left to do
btn.title = 'Server and models are installed. Use Uninstall server to remove them.';
}
}
function renderToggle(st) {
var label = $('ss-srv-toggle-label');
if (!st || !st.installed) {
setBtnTone('ss-srv-toggle', 'grey');
label.textContent = 'Not installed';
$('ss-srv-toggle').disabled = true;
return;
}
$('ss-srv-toggle').disabled = serverBusy || !serverManageable;
if (st.running) {
setBtnTone('ss-srv-toggle', 'green');
label.textContent = 'Running — click to stop';
} else {
setBtnTone('ss-srv-toggle', 'red');
label.textContent = 'Stopped — click to start';
}
}
var WARMUP_TONE = { ready: 'ok', skipped: 'ok', downloading: 'warn',
pending: 'off', failed: 'bad', evicted: 'off' };
// The server's warmup keys are NOT our models_present keys. It reports the default separator
// as `demucs` (the backend treats that as an alias for bs_roformer_sw — see _model_ready) and
// names the aligner differently again. A raw present[k] lookup misses, leaving the chip on
// "downloading" for a file sitting right there — which is the exact bug the loading-vs-
// downloading change exists to fix, reintroduced through a key mismatch.
var PRESENT_KEY = {
demucs: 'bs_roformer_sw',
bs_roformer_sw: 'bs_roformer_sw',
whisperx: 'whisperx',
whisperx_aligners: 'whisperx_aligners',
aligner: 'whisperx_aligners',
align: 'whisperx_aligners',
};
// An unmapped key falls back to the key itself rather than guessing.
function isPresent(present, key) {
return !!present[PRESENT_KEY[key] || key];
}
function renderServerStatus(st) {
lastServerStatus = st || null;
var bar = $('ss-srv-chips'), note = $('ss-srv-note');
if (!st) { bar.innerHTML = chip('Status unavailable', 'bad'); return; }
// Deployments where a managed server can't work (no pip, read-only config dir):
// disable the section and say why, rather than letting the user start an install
// that cannot succeed.
if (st.manageable === false) {
serverManageable = false;
bar.innerHTML = chip('Unavailable here', 'bad', { dot: true });
renderToggle(null);
renderInstallBtn(null);
note.textContent = st.manage_reason || '';
note.className = 'ss-note warn';
setServerButtons(true);
return;
}
serverManageable = true;
var chips = [];
if (!st.installed) {
chips.push(chip('Not installed', 'off', { dot: true }));
} else if (st.running) {
chips.push(chip('Running · :' + st.port, 'ok', { dot: true, live: true }));
var h = st.health || {};
if (h.device) chips.push(chip(h.device.toUpperCase() + (h.gpu ? ' · GPU' : ''),
h.gpu ? 'ok' : 'info'));
} else {
chips.push(chip('Installed · stopped', 'warn', { dot: true }));
}
chips.push(st.models_downloaded ? chip('Models downloaded', 'ok')
: chip('Models not downloaded', 'warn'));
// The case worth shouting about: a GPU is sitting right there, but the install
// built CPU-only torch, so every split runs at CPU speed for no reason.
var g = st.gpu_detected;
if (st.installed && g && !st.gpu_build) {
chips.push(chip('CPU-only build - GPU idle', 'warn',
{ title: g.name + ' detected. Reinstall with GPU to use it.' }));
} else if (st.installed && st.gpu_build) {
chips.push(chip('GPU build' + (g ? ' - ' + g.name : ''), 'ok'));
} else if (!st.installed && g) {
chips.push(chip('GPU available - ' + g.name, 'info'));
}
if (st.running && st.models_ready) chips.push(chip('Warm · ready to split', 'ok'));
// Per-model warmup detail (pending / downloading / ready / failed).
var wu = (st.health || {}).warmup || {};
var present = st.models_present || {};
Object.keys(wu).forEach(function (k) {
var v = wu[k];
if (typeof v !== 'string') return;
// The server says "downloading" while it warms a model — even when it is only loading
// a cached file from disk into VRAM. Shown verbatim, that tells the user their weights
// are being re-fetched when nothing is crossing the wire, which is exactly how a
// 1-second RAM load gets reported as a bug. If we can see the file, say "loading".
var label = v, tone = WARMUP_TONE[v] || 'off';
if (v === 'downloading' && isPresent(present, k)) {
label = 'loading';
tone = 'info';
}
var busy = (v === 'downloading');
chips.push(chip(k + ': ' + label, tone, { live: busy, dot: busy }));
});
if (st.disk_bytes) chips.push(chip(gb(st.disk_bytes) + ' on disk', 'info'));
bar.innerHTML = chips.join('');
renderToggle(st);
renderInstallBtn(st);
renderAdvanced(st);
var notes = [];
if (st.advisory) notes.push('⚠ ' + st.advisory);
if (st.source && st.source.commit) {
notes.push('source: ' + st.source.ref + ' @ ' + String(st.source.commit).slice(0, 8));
}
note.textContent = notes.join(' ');
note.className = st.advisory ? 'ss-note warn' : 'ss-note';
syncGlobalUrl(st);
}
function loadServerStatus() {
return j('/server_status').then(renderServerStatus).catch(function () {});
}
// Poll while the server is up but not yet warm, so the per-model warmup chips
// tick from pending -> downloading -> ready on their own. Idle otherwise (and
// stops entirely once everything is ready) so we're not hammering /health.
setInterval(function () {
var st = lastServerStatus;
if (!serverManageable || !st) return;
var busy = st.running && !st.models_ready;
if (busy) loadServerStatus();
}, 5000);
// "Use for the whole app": mirror the running local URL into the app's own
// demucs_server_url via the app's writer (it holds the settings lock + does an
// atomic write; a plugin-side config.json write would race it).
function appSettings(body) {
return fetch('/api/settings', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}).then(function (r) { return r.json(); });
}
// What we last wrote into the app's demucs_server_url, PERSISTED.
//
// It has to survive a reload. The clear-on-untoggle path may only clear a value it
// knows it wrote (otherwise it would clobber a remote URL the user set), and an
// in-memory-only record forced it to guess "the server's current url" instead. That
// guess is wrong precisely when it matters: the port is user-configurable, so after
// changing it (or reinstalling on a different port) the CURRENT url no longer equals
// the one we wrote, and the stale value would be left pointing the whole app at a
// server that is no longer there — with no way to clear it from the UI.
var SYNCED_KEY = 'stem_splitter.global_url';
function loadSyncedUrl() {
try { return window.localStorage.getItem(SYNCED_KEY) || null; } catch (e) { return null; }
}
function saveSyncedUrl(url) {
try {
if (url) window.localStorage.setItem(SYNCED_KEY, url);
else window.localStorage.removeItem(SYNCED_KEY);
} catch (e) { /* private mode / quota - degrades to in-memory only */ }
}
var lastSyncedUrl = loadSyncedUrl(); // what we last wrote, so a poll doesn't rewrite it
function syncGlobalUrl(st) {
if (!st) return;
// Turning the toggle OFF has to UNDO the write, not just stop making new ones —
// bailing out here left the whole app still pointed at our local server.
if (!$('ss-srv-global').checked) return clearGlobalUrl(st);
if (st.running && st.url) {
// renderServerStatus runs on every poll (every 5s while models warm), so writing
// unconditionally meant hammering the app's settings file - and its lock - with
// an identical value. Only write on an actual change.
if (st.url === lastSyncedUrl) return;
// The url CHANGED (e.g. the user moved the port) while we own the global setting:
// clear the old one first, or it leaks — nothing else remembers it.
if (lastSyncedUrl) clearGlobalUrl(st, lastSyncedUrl);
lastSyncedUrl = st.url;
saveSyncedUrl(st.url);
clearedUrl = null;
appSettings({ demucs_server_url: st.url }).catch(function () {
lastSyncedUrl = null; saveSyncedUrl(null);
});
} else {
clearGlobalUrl(st);
}
}
// Clear the app-level demucs_server_url — but ONLY if it still points at the URL WE
// wrote, so we never clobber a remote URL the user set in the meantime.
var clearedUrl = null; // don't re-clear the same URL on every 5s poll
function clearGlobalUrl(st, explicitUrl) {
// Prefer the persisted record of what we actually wrote. Fall back to the server's
// current url only when we have no record at all (first run, or localStorage
// unavailable) — it is a guess, and a wrong one once the port has changed.
var mine = explicitUrl || lastSyncedUrl || loadSyncedUrl() || (st && st.url) || null;
if (!mine || mine === clearedUrl) return;
if (!explicitUrl) { lastSyncedUrl = null; saveSyncedUrl(null); }
clearedUrl = mine;
fetch('/api/settings').then(function (r) { return r.json(); }).then(function (cur) {
if (cur && cur.demucs_server_url === mine) appSettings({ demucs_server_url: '' });
}).catch(function () {});
}
function serverOpBody(path, label, body) {
setServerButtons(true);
$('ss-srv-progress').style.display = 'block';
$('ss-srv-log').textContent = label + '…\n';
setSrvBar(0.02, label, true);
connectWS();
return j(path, { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body || {}) })
.then(function (res) {
if (res && res.ok === false && res.busy) {
srvLog('… ' + res.message);
setSrvBar(0, 'Busy: ' + res.busy, true);
setServerButtons(false);
}
return res;