-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
1447 lines (1260 loc) · 48.7 KB
/
Copy pathserver.py
File metadata and controls
1447 lines (1260 loc) · 48.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
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
#!/usr/bin/env python3
"""
Lumix S5 Camera Controller
────────────────────────────────────────────────────────────────────
- Flask web server → iPhone UI at http://<mac-ip>:5050
- Cubase transport → virtual MIDI port; lumix_transport.js binds notes to it directly (no manual Cubase mapping)
- Camera control → Lumix WiFi HTTP API (video_recstart / video_recstop)
────────────────────────────────────────────────────────────────────
Copy .env.example to .env and fill in your camera's IP, then run: python server.py
"""
from __future__ import annotations
import os
import re
import shutil
import threading
import time
import socket
import requests
from dotenv import load_dotenv
from flask import Flask, jsonify, request
load_dotenv()
# ─── CONFIG ─────────────────────────────────────────────────────────────────
# All of these can be overridden via .env (see .env.example) instead of
# editing this file directly — keeps machine-specific values (camera IP,
# OBS password, ...) out of source control.
CAMERA_IP = os.environ.get("CAMERA_IP", "192.168.1.100") # ← S5's IP address
PORT = int(os.environ.get("PORT", "5050")) # web server port
OBS_HOST = os.environ.get("OBS_HOST", "localhost") # OBS WebSocket host
OBS_PORT = int(os.environ.get("OBS_PORT", "4455")) # OBS WebSocket port (Tools → WebSocket Server Settings)
OBS_PASSWORD = os.environ.get("OBS_PASSWORD", "") # leave empty if no password set in OBS
MEDIA_DIR = os.path.expanduser(os.environ.get("MEDIA_DIR", "~/Movies/LumixSessions")) # where S5 clips are saved
OBS_RECORDING_DIR = os.path.expanduser(os.environ.get("OBS_RECORDING_DIR", "~/Movies")) # OBS's own output folder
# ────────────────────────────────────────────────────────────────────────────
app = Flask(__name__)
_lock = threading.Lock()
_recording = False
_armed = False # when True, Cubase play/stop triggers the camera
_cubase_playing = False # tracks Cubase transport state
_download_from_camera = False # WiFi download over the S5 is slow — off by default;
# use the SD card import flow instead when disabled
_sdcard_only_latest = True # SD import: only the most recent new clip by default
# ("record several takes, only the last matters"); unchecking
# imports every new clip found on the card
# Camera selection — which camera(s) to actually use for the *next* recording.
# At least one must stay True; enforced in the /camera/*/toggle endpoints.
_use_obs = True
_use_lumix = True
# Snapshot of the above, taken when a recording actually starts — record_stop()
# and the pipeline must use what was active for THIS take, not whatever the
# toggles happen to say by the time the take finishes.
_active_use_obs = True
_active_use_lumix = True
# ── Session / take tracking ──────────────────────────────────────────────────
_SESSION_NAME_FILE = os.path.join(MEDIA_DIR, ".last_session_name.txt")
def _load_session_name() -> str:
try:
with open(_SESSION_NAME_FILE) as f:
name = f.read().strip()
if name:
return name
except Exception:
pass
return "Session"
def _save_session_name(name: str):
try:
os.makedirs(MEDIA_DIR, exist_ok=True)
with open(_SESSION_NAME_FILE, "w") as f:
f.write(name)
except Exception as exc:
print(f"[session] ⚠ Could not persist session name: {exc}")
def _next_take_number(session_name: str) -> int:
"""
Highest existing "Take NN" folder under this session, so numbering
survives server restarts and stays correct per-session (switching
sessions picks up wherever that session's own folder state left off)
without needing a separate counter file that could drift from disk.
"""
session_dir = os.path.join(MEDIA_DIR, session_name)
highest = 0
try:
for entry in os.listdir(session_dir):
m = re.match(r"Take (\d+)$", entry)
if m:
highest = max(highest, int(m.group(1)))
except FileNotFoundError:
pass
return highest
_session_name = _load_session_name() # persists across server restarts; set via /session endpoint
_take_number = _next_take_number(_session_name)
# ── Post-production pipeline state ───────────────────────────────────────────
_pipeline = {
"state": "idle", # idle | downloading | decoding | resolve | done | error
"message": "",
"take": 0,
}
# ── Camera control ───────────────────────────────────────────────────────────
def _cam(value: str) -> bool:
"""Send a single command to the camera. Returns True on success."""
try:
resp = requests.get(
f"http://{CAMERA_IP}/cam.cgi",
params={"mode": "camcmd", "value": value},
timeout=3,
)
ok = "<result>ok</result>" in resp.text
if not ok:
print(f"[camera] ⚠ command '{value}' response: {resp.text.strip()}")
return ok
except requests.exceptions.ConnectionError:
print(f"[camera] ✗ Cannot reach {CAMERA_IP} — is the camera on the same WiFi?")
return False
except Exception as e:
print(f"[camera] ✗ {e}")
return False
# ── Camera battery / storage status (background-polled, cached) ──────────────
#
# Polled on a timer rather than fetched inside /status directly, so the
# iPhone UI's frequent polling never blocks on a camera HTTP round-trip —
# /status just reads whatever this thread last cached.
_CAMERA_STATE_POLL_INTERVAL = 15 # seconds
_camera_state = {"battery": None, "video_remaining_min": None, "reachable": False}
def _poll_camera_state():
while True:
try:
resp = requests.get(
f"http://{CAMERA_IP}/cam.cgi", params={"mode": "getstate"}, timeout=3
)
text = resp.text
batt = re.search(r"<batt>([^<]*)</batt>", text)
remain = re.search(r"<video_remaincapacity>([^<]*)</video_remaincapacity>", text)
_camera_state["battery"] = batt.group(1) if batt else None
_camera_state["video_remaining_min"] = int(remain.group(1)) if remain else None
_camera_state["reachable"] = True
except Exception:
_camera_state["reachable"] = False
time.sleep(_CAMERA_STATE_POLL_INTERVAL)
# ── Cubase transport control (virtual MIDI port) ─────────────────────────────
#
# HTTP isn't viable from inside a Cubase MIDI Remote script on this install —
# require('http') and require('child_process') both throw ("invalid module
# load callback return value"), confirmed by directly testing both. MIDI is
# the one thing guaranteed to work, so server.py creates a virtual port and
# lumix_transport.js binds these two notes to Transport Record/Stop
# directly in code (via mMidiBinding + makeValueBinding) — unlike the old
# Generic Remote setup, there's no manual per-note mapping step in
# Cubase's UI. Bound to mRecord, not mStart, so this actually arms +
# starts recording rather than just playback.
NOTE_RECORD = 20 # channel 1 (0-based: 0) — must match lumix_transport.js
NOTE_STOP = 21
_midi_out = None # rtmidi.MidiOut — Python's "out" is Cubase's "in"
_midi_in = None # rtmidi.MidiIn — unused for data, but Cubase's
# detectPortPair() needs a real in+out port pair to match
def _setup_virtual_midi_out():
global _midi_out, _midi_in
try:
import rtmidi
_midi_out = rtmidi.MidiOut()
_midi_out.open_virtual_port("Lumix Controller")
_midi_in = rtmidi.MidiIn()
_midi_in.open_virtual_port("Lumix Controller")
print("[midi] ✓ Virtual MIDI port 'Lumix Controller' created (in + out)")
except Exception as e:
print(f"[midi] ✗ Could not create virtual MIDI port: {e}")
print("[midi] Cubase transport control disabled; iPhone manual button still works.")
def _cubase_record():
if _midi_out is None:
return
try:
_midi_out.send_message([0x90, NOTE_RECORD, 0x7F]) # Note On
_midi_out.send_message([0x80, NOTE_RECORD, 0x00]) # Note Off
print("[cubase] ● record MIDI sent")
except Exception as e:
print(f"[cubase] ✗ record failed: {e}")
def _cubase_stop():
if _midi_out is None:
return
try:
_midi_out.send_message([0x90, NOTE_STOP, 0x7F]) # Note On
_midi_out.send_message([0x80, NOTE_STOP, 0x00]) # Note Off
print("[cubase] ■ stop MIDI sent")
except Exception as e:
print(f"[cubase] ✗ stop failed: {e}")
# Known real locations found on this machine for Cubase's MIDI Remote local
# scripts folder (varies by Cubase version/install — discovered via mdfind
# since neither matched the commonly-documented path). Copied, not
# symlinked — unlike Resolve's Scripts folder, Cubase's script scanner
# doesn't appear to pick up symlinked files (confirmed: it silently
# skipped one entirely rather than loading or erroring on it). So this
# needs a server restart to push edits, not live like the Resolve ones.
_CUBASE_SCRIPT_INSTALL_PATHS = [
os.path.expanduser("~/Cubase MIDI Remote/Driver Scripts/Local/lumix_transport.js"),
os.path.expanduser(
"~/Documents/Steinberg/Cubase/MIDI Remote/Driver Scripts/Local/lumix/transport/lumix_transport.js"
),
]
def install_cubase_script():
source_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "lumix_transport.js")
for dest_path in _CUBASE_SCRIPT_INSTALL_PATHS:
try:
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
if os.path.islink(dest_path) or os.path.exists(dest_path):
os.remove(dest_path)
shutil.copy2(source_path, dest_path)
print(f"[cubase] ✓ lumix_transport.js -> {dest_path}")
except Exception as exc:
print(f"[cubase] ⚠ Could not install script to {dest_path}: {exc}")
# ── OBS control ──────────────────────────────────────────────────────────────
_obs = None # obsws_python ReqClient, set up at startup
def _setup_obs():
global _obs
try:
import obsws_python as obs
_obs = obs.ReqClient(host=OBS_HOST, port=OBS_PORT, password=OBS_PASSWORD, timeout=3)
print(f"[obs] ✓ Connected to OBS WebSocket at {OBS_HOST}:{OBS_PORT}")
except Exception as e:
print(f"[obs] ✗ Could not connect to OBS: {e}")
print("[obs] Make sure OBS is running and WebSocket server is enabled.")
def _obs_is_connected() -> bool:
"""
Live liveness check, not just "was _obs set once at startup" — a
stale/dropped connection object stays non-None, so a real round-trip
call is the only way to know OBS is actually responding right now.
"""
if _obs is None:
return False
try:
_obs.get_version()
return True
except Exception:
return False
def _obs_start():
if _obs is None:
return
try:
_obs.start_record()
print("[obs] ▶ Recording started")
except Exception as e:
print(f"[obs] ✗ start_record failed: {e}")
def _obs_stop() -> str | None:
"""Stop OBS recording. Returns the output file path, or None."""
if _obs is None:
return None
try:
resp = _obs.stop_record()
path = getattr(resp, "output_path", None)
print(f"[obs] ■ Recording stopped → {path}")
return path
except Exception as e:
print(f"[obs] ✗ stop_record failed: {e}")
return None
RECORD_START_LTC_SETTLE_S = 3.0 # Cubase must be playing LTC before the camera/OBS
# start recording, or the first moment of the take has
# no valid timecode to decode
def record_start(trigger_cubase: bool = False) -> tuple[bool, str]:
"""Returns (ok, reason) — reason is only meaningful when ok is False."""
global _recording, _active_use_obs, _active_use_lumix
with _lock:
if _recording:
if trigger_cubase:
_cubase_record()
return True, "" # already recording, nothing to do
use_obs, use_lumix = _use_obs, _use_lumix
if not use_obs and not use_lumix:
return False, "Enable at least one camera (OBS or Lumix S5) before recording"
# Pre-flight: don't trigger Cubase or the camera at all if OBS won't
# actually produce a clip — a silent OBS failure previously left the
# UI reporting a successful take with no way to multicam-sync it.
# Skipped entirely when this take isn't using OBS at all.
if use_obs and not _obs_is_connected():
msg = "OBS not connected — recording aborted (no OBS clip would be produced)"
print(f"[obs] ✗ {msg}")
return False, msg
if trigger_cubase:
_cubase_record() # start Cubase (and its LTC generator) first...
time.sleep(RECORD_START_LTC_SETTLE_S) # ...and let it settle before the camera starts
if use_lumix:
_cam("recmode") # ensure camera is in record mode
ok = _cam("video_recstart")
if not ok:
return False, "Camera did not confirm recording start — check WiFi connection"
else:
ok = True
_active_use_obs, _active_use_lumix = use_obs, use_lumix
_recording = True
mode = "OBS + Lumix" if use_obs and use_lumix else ("OBS only" if use_obs else "Lumix only")
print(f"▶ REC started ({mode})")
if use_obs:
threading.Thread(target=_obs_start, daemon=True).start()
return True, ""
def record_stop(trigger_cubase: bool = False) -> bool:
global _recording, _take_number
with _lock:
if not _recording:
if trigger_cubase:
_cubase_stop()
return True # already stopped, nothing to do
use_obs, use_lumix = _active_use_obs, _active_use_lumix
ok = _cam("video_recstop") if use_lumix else True
if ok:
_recording = False
_take_number += 1
take_snap = _take_number
session_snap = _session_name
print(f"■ REC stopped — session '{session_snap}' take {take_snap}")
from resolve_helper import log_camera_usage
log_camera_usage(MEDIA_DIR, use_obs, use_lumix)
# Stop OBS and collect its output path, then run the full pipeline
def _stop_and_pipeline():
obs_path = _obs_stop() if use_obs else None
_run_pipeline(session_snap, take_snap, obs_path, use_obs, use_lumix)
threading.Thread(target=_stop_and_pipeline, daemon=True).start()
if trigger_cubase:
_cubase_stop()
return ok
# ── Post-production pipeline ─────────────────────────────────────────────────
def _set_pipeline(state: str, message: str):
_pipeline["state"] = state
_pipeline["message"] = message
print(f"[pipeline] [{state}] {message}")
def _run_pipeline(
session_name: str,
take_num: int,
obs_path: str | None,
use_obs: bool = True,
use_lumix: bool = True,
):
"""
Background thread: download Lumix clip, decode LTC on each clip actually
used for this take, then create the (multicam, or single-angle if only
one camera was used) take in DaVinci Resolve.
"""
from resolve_helper import decode_ltc, download_lumix_clip, build_fcpxml, open_in_resolve, mark_obs_consumed
_pipeline["take"] = take_num
if use_lumix and not _download_from_camera:
_set_pipeline(
"idle",
"S5 WiFi download disabled — insert the SD card and use IMPORT SD CARD",
)
return
session_dir = os.path.join(MEDIA_DIR, session_name, f"Take {take_num:02d}")
os.makedirs(session_dir, exist_ok=True)
clips = []
# ── OBS clip ─────────────────────────────────────────────────────────
if use_obs:
if obs_path and os.path.exists(obs_path):
clips.append({"path": obs_path, "label": "OBS", "timecode": None})
else:
print(f"[pipeline] ⚠ OBS file not found: {obs_path}")
# ── Lumix clip (WiFi download) ────────────────────────────────────────
if use_lumix:
_set_pipeline("downloading", "Downloading S5 footage over WiFi …")
def _lumix_progress(done, total):
if total:
pct = int(done / total * 100)
_set_pipeline("downloading", f"Downloading S5 footage … {pct}%")
lumix_path = download_lumix_clip(CAMERA_IP, session_dir, progress_cb=_lumix_progress)
if lumix_path:
clips.append({"path": lumix_path, "label": "Lumix S5", "timecode": None})
else:
_set_pipeline("error", "S5 download failed — check WiFi connection")
return
if not clips:
_set_pipeline("error", "No camera clips available for this take")
return
# ── Decode LTC from each clip ─────────────────────────────────────────
_set_pipeline("decoding", "Decoding LTC timecode …")
for clip in clips:
tc = decode_ltc(clip["path"])
clip["timecode"] = tc
status = tc if tc else "⚠ not found"
print(f"[pipeline] LTC {clip['label']}: {status}")
if not any(c["timecode"] for c in clips):
_set_pipeline("error", "LTC decode failed on all clips — check audio channel")
return
# ── Build FCPXML and open in DaVinci Resolve ──────────────────────────
_set_pipeline("resolve", "Building FCPXML timeline …")
fcpxml_path = build_fcpxml(session_name, take_num, clips, output_dir=session_dir)
if fcpxml_path:
open_in_resolve(fcpxml_path, session_name=session_name, media_dir=MEDIA_DIR)
if use_obs and obs_path:
mark_obs_consumed(MEDIA_DIR, obs_path)
_set_pipeline("done", f"Take {take_num:02d} ready — opening in Resolve ✓")
else:
_set_pipeline("error", "FCPXML generation failed — see terminal for details")
# ── iPhone web UI ────────────────────────────────────────────────────────────
_HTML = f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Lumix S5</title>
<style>
*, *::before, *::after {{ box-sizing: border-box; margin: 0; padding: 0; }}
body {{
background: #0d0d0d;
color: #fff;
font-family: -apple-system, 'Helvetica Neue', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding-bottom: 24px;
-webkit-tap-highlight-color: transparent;
user-select: none;
gap: 0;
}}
/* ── ARM button ── */
#arm-btn {{
border: 1.5px solid #2a2a2a;
background: transparent;
color: #333;
font-family: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 3px;
text-transform: uppercase;
padding: 10px 28px;
border-radius: 100px;
cursor: pointer;
margin-bottom: 14px;
transition: color .25s, border-color .25s, box-shadow .25s;
-webkit-appearance: none;
}}
#arm-btn:active {{ opacity: 0.6; }}
#arm-btn.armed {{
color: #ff9500;
border-color: #ff9500;
box-shadow: 0 0 18px rgba(255,149,0,0.25);
}}
#arm-label {{
font-size: 10px;
letter-spacing: 2px;
text-transform: uppercase;
color: #252525;
margin-bottom: 48px;
height: 14px;
transition: color .25s;
}}
#arm-label.armed {{
color: #7a4700;
}}
/* ── SD card import button ── */
#sdcard-btn {{
border: 1.5px solid #2a2a2a;
background: transparent;
color: #333;
font-family: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 2px;
text-transform: uppercase;
padding: 9px 22px;
border-radius: 100px;
cursor: pointer;
margin-top: 32px;
transition: color .25s, border-color .25s, box-shadow .25s;
-webkit-appearance: none;
}}
#sdcard-btn:active {{ opacity: 0.6; }}
#sdcard-btn.busy {{
color: #0a84ff;
border-color: #0a84ff;
box-shadow: 0 0 18px rgba(10,132,255,0.25);
}}
#sdcard-btn:disabled {{
opacity: 0.4;
cursor: default;
}}
/* ── Setup checklist (collapsible) ── */
#checklist-toggle {{
border: 1.5px solid #2a2a2a;
background: transparent;
color: #555;
font-family: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 2px;
text-transform: uppercase;
padding: 8px 20px;
border-radius: 100px;
cursor: pointer;
margin-bottom: 18px;
-webkit-appearance: none;
}}
#checklist-toggle:active {{ opacity: 0.6; }}
#checklist-toggle.open {{
color: #ff9500;
border-color: #ff9500;
}}
#checklist-panel {{
display: none;
width: 280px;
margin-bottom: 24px;
padding: 6px 4px;
border: 1.5px solid #1e1e1e;
border-radius: 14px;
}}
#checklist-panel.open {{ display: block; }}
.checklist-item {{
display: flex;
align-items: flex-start;
gap: 10px;
min-height: 44px;
padding: 6px 10px;
cursor: pointer;
user-select: none;
}}
.checklist-item input[type="checkbox"] {{
margin-top: 2px;
width: 18px;
height: 18px;
flex-shrink: 0;
accent-color: #ff9500;
cursor: pointer;
}}
.checklist-item span {{
font-size: 12px;
line-height: 1.5;
color: #999;
}}
.checklist-item input[type="checkbox"]:checked ~ span {{
color: #444;
text-decoration: line-through;
}}
/* ── Toggle rows (OBS, Lumix, download, sdcard only-latest, ...) ──
The whole row is the tap target (min. 44px tall, full label width),
not just the tiny native checkbox — much easier to hit on a phone. */
.toggle-row {{
display: flex;
align-items: center;
justify-content: space-between;
width: 240px;
min-height: 44px;
padding: 4px 2px;
cursor: pointer;
user-select: none;
}}
.toggle-row-label {{
font-size: 11px;
letter-spacing: 1.5px;
text-transform: uppercase;
color: #555;
}}
.toggle-input {{
position: absolute;
opacity: 0;
width: 0;
height: 0;
}}
.toggle-switch {{
position: relative;
flex-shrink: 0;
width: 46px;
height: 27px;
background: #232323;
border: 1px solid #2a2a2a;
border-radius: 100px;
transition: background .2s, border-color .2s;
}}
.toggle-switch::after {{
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 21px;
height: 21px;
background: #666;
border-radius: 50%;
transition: transform .2s, background .2s;
}}
.toggle-input:checked + .toggle-switch {{
background: rgba(10,132,255,0.25);
border-color: #0a84ff;
}}
.toggle-input:checked + .toggle-switch::after {{
transform: translateX(19px);
background: #0a84ff;
}}
/* ── Status ── */
#status-text {{
font-size: 11px;
font-weight: 600;
letter-spacing: 3px;
text-transform: uppercase;
color: #444;
height: 16px;
margin-bottom: 48px;
transition: color .3s;
}}
#status-text.rec {{
color: #ff3b30;
animation: blink 1s ease-in-out infinite;
}}
@keyframes blink {{ 0%, 100% {{ opacity: 1 }} 50% {{ opacity: 0.25 }} }}
/* ── Record button ── */
#btn-wrap {{
width: 200px;
height: 200px;
border-radius: 50%;
border: 3px solid #1a1a1a;
display: flex;
align-items: center;
justify-content: center;
transition: border-color .3s, box-shadow .3s;
}}
#btn-wrap.rec {{
border-color: rgba(255,59,48,0.3);
box-shadow: 0 0 60px rgba(255,59,48,0.12);
}}
#btn {{
width: 164px;
height: 164px;
border-radius: 50%;
border: none;
cursor: pointer;
background: #ff3b30;
position: relative;
transition: transform .12s, background .3s;
-webkit-appearance: none;
}}
#btn:active {{ transform: scale(0.91); }}
#btn.rec {{ background: #1c1c1e; }}
#btn::after {{
content: '';
display: block;
width: 58px;
height: 58px;
background: #fff;
border-radius: 50%;
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
transition: border-radius .25s, width .25s, height .25s, background .3s;
}}
#btn.rec::after {{
border-radius: 10px;
width: 52px;
height: 52px;
background: #ff3b30;
}}
#label {{
margin-top: 44px;
font-size: 12px;
color: #2a2a2a;
letter-spacing: 2px;
text-transform: uppercase;
transition: color .3s;
height: 16px;
}}
#label.rec {{ color: #555; }}
/* ── Session input ── */
#session-wrap {{
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 28px;
}}
#session-input {{
background: #1a1a1a;
border: 1.5px solid #2a2a2a;
color: #ccc;
font-family: inherit;
font-size: 13px;
letter-spacing: 1px;
padding: 8px 14px;
border-radius: 100px;
outline: none;
width: 180px;
text-align: center;
-webkit-appearance: none;
}}
#session-input:focus {{ border-color: #555; color: #fff; }}
#session-save {{
background: #1a1a1a;
border: 1.5px solid #2a2a2a;
color: #555;
font-family: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 2px;
padding: 8px 16px;
border-radius: 100px;
cursor: pointer;
-webkit-appearance: none;
}}
#session-save:active {{ opacity: 0.6; }}
#take-counter {{
font-size: 10px;
letter-spacing: 2px;
color: #2a2a2a;
margin-bottom: 10px;
height: 14px;
transition: color .3s;
}}
#take-counter.active {{ color: #444; }}
/* ── Pipeline status ── */
#pipeline-wrap {{
margin-top: 36px;
min-height: 52px;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
width: 260px;
}}
#pipeline-bar-bg {{
width: 100%;
height: 2px;
background: #1a1a1a;
border-radius: 2px;
overflow: hidden;
display: none;
}}
#pipeline-bar {{
height: 100%;
background: #ff9500;
border-radius: 2px;
width: 0%;
transition: width .5s;
}}
#pipeline-msg {{
font-size: 10px;
letter-spacing: 2px;
text-transform: uppercase;
color: #333;
text-align: center;
line-height: 1.6;
transition: color .3s;
}}
#pipeline-msg.active {{ color: #777; }}
#pipeline-msg.done {{ color: #30d158; }}
#pipeline-msg.error {{ color: #ff3b30; }}
#cam-addr {{
margin-top: 8px;
font-size: 10px;
color: #1e1e1e;
letter-spacing: 1px;
}}
#cam-status {{
margin-top: 28px;
font-size: 10px;
letter-spacing: 1px;
color: #444;
}}
#cam-status.warn {{ color: #ff9500; }}
</style>
</head>
<body>
<!-- Setup checklist -->
<button id="checklist-toggle" onclick="toggleChecklist()">☑ CHECKLIST</button>
<div id="checklist-panel">
<label class="checklist-item">
<input type="checkbox" data-checklist-id="0">
<span>1. LUMIX in den Videomodus stellen</span>
</label>
<label class="checklist-item">
<input type="checkbox" data-checklist-id="1">
<span>2. Brennweite und manuellen Fokus einstellen</span>
</label>
<label class="checklist-item">
<input type="checkbox" data-checklist-id="2">
<span>3. Mit dem WiFi-Netz verbinden</span>
</label>
<label class="checklist-item">
<input type="checkbox" data-checklist-id="3">
<span>4. Timecode-Kabel an den Mikrofoneingang anschließen</span>
</label>
<label class="checklist-item">
<input type="checkbox" data-checklist-id="4">
<span>5. In Cubase prüfen: Timecode-Kanal nicht gemutet, Pegel liegt an der Kamera an</span>
</label>
<label class="checklist-item">
<input type="checkbox" data-checklist-id="5">
<span>6. Richtiges MIDI-Eingabegerät in Cubase für Remote Control von der UI eingestellt</span>
</label>
</div>
<!-- Session name input -->
<div id="session-wrap">
<input id="session-input" type="text" placeholder="Session Name" maxlength="40"
onkeydown="if(event.key==='Enter'){{ saveSession(); this.blur(); }}">
<button id="session-save" onclick="saveSession()">SET</button>
</div>
<div id="take-counter">TAKE —</div>
<button id="arm-btn" onclick="toggleArm()">ARM</button>
<div id="arm-label">CUBASE SYNC OFF</div>
<div id="status-text">READY</div>
<div id="btn-wrap"><button id="btn" onclick="toggleRec()"></button></div>
<div id="label">TAP TO RECORD</div>
<button id="sdcard-btn" onclick="importSdCard()">IMPORT SD CARD</button>
<!-- Post-production pipeline status -->
<div id="pipeline-wrap">
<div id="pipeline-bar-bg"><div id="pipeline-bar"></div></div>
<div id="pipeline-msg"></div>
</div>
<label class="toggle-row">
<span class="toggle-row-label">Use OBS</span>
<input type="checkbox" class="toggle-input" id="obs-toggle" checked onchange="toggleUseObs()">
<span class="toggle-switch"></span>
</label>
<label class="toggle-row">
<span class="toggle-row-label">Use Lumix S5</span>
<input type="checkbox" class="toggle-input" id="lumix-toggle" checked onchange="toggleUseLumix()">
<span class="toggle-switch"></span>
</label>
<label class="toggle-row">
<span class="toggle-row-label">Download from S5 over WiFi</span>
<input type="checkbox" class="toggle-input" id="download-toggle" onchange="toggleDownload()">
<span class="toggle-switch"></span>
</label>
<label class="toggle-row">
<span class="toggle-row-label">Only latest take from SD card</span>
<input type="checkbox" class="toggle-input" id="sdcard-only-latest-toggle" checked onchange="toggleSdcardOnlyLatest()">
<span class="toggle-switch"></span>
</label>
<div id="cam-status"></div>
<div id="cam-addr">CAM {CAMERA_IP}</div>
<script>
let rec = false;
let armed = false;
let pipelineState = 'idle';
// ── Pipeline status steps → progress bar width ──────────────────────────────
const PIPELINE_STEPS = {{ idle:0, downloading:25, decoding:60, resolve:85, done:100, error:100 }};
// ── Setup checklist (collapsible, checked state persisted locally) ──────────
const CHECKLIST_STORAGE_KEY = 'lumix-checklist-checked';
function loadChecklistState() {{
let checked = [];
try {{ checked = JSON.parse(localStorage.getItem(CHECKLIST_STORAGE_KEY)) || []; }} catch(e) {{}}
document.querySelectorAll('.checklist-item input[type="checkbox"]').forEach(cb => {{
cb.checked = checked.includes(cb.dataset.checklistId);
}});
}}
function saveChecklistState() {{
const checked = Array.from(document.querySelectorAll('.checklist-item input[type="checkbox"]:checked'))
.map(cb => cb.dataset.checklistId);
localStorage.setItem(CHECKLIST_STORAGE_KEY, JSON.stringify(checked));
}}
function toggleChecklist() {{
document.getElementById('checklist-toggle').classList.toggle('open');
document.getElementById('checklist-panel').classList.toggle('open');
}}
document.querySelectorAll('.checklist-item input[type="checkbox"]').forEach(cb => {{
cb.addEventListener('change', saveChecklistState);
}});
loadChecklistState();
function applyArmed(a) {{
armed = a;
const ab = document.getElementById('arm-btn');
const alb = document.getElementById('arm-label');
if (a) {{
ab.classList.add('armed');
alb.textContent = 'CUBASE SYNC ON';
alb.classList.add('armed');
}} else {{
ab.classList.remove('armed');
alb.textContent = 'CUBASE SYNC OFF';
alb.classList.remove('armed');
}}
}}
function applyRec(r) {{
rec = r;
const btn = document.getElementById('btn');
const wrap = document.getElementById('btn-wrap');
const st = document.getElementById('status-text');
const lbl = document.getElementById('label');
if (r) {{
btn.classList.add('rec');
wrap.classList.add('rec');
st.textContent = '● REC';
st.classList.add('rec');
lbl.textContent = 'TAP TO STOP';
lbl.classList.add('rec');
}} else {{
btn.classList.remove('rec');
wrap.classList.remove('rec');
st.textContent = 'READY';
st.classList.remove('rec');