Files
gui-video-clipper/src/lib/components/TransportControls.svelte

209 lines
4.5 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { session } from '$lib/stores/videoSession.svelte';
import { markInPoint, markOutPoint } from '$lib/stores/clips.svelte';
import { formatTime } from '$lib/utils/time';
import {
jumpKeyframe,
runTransportAction,
seekBy,
stepFrame,
togglePlayPause,
setVolume,
setMuted,
getVolume,
getMuted,
type TransportKeyAction,
} from '$lib/transport/playback';
let hasKeyframes = $derived(session.keyframePositions.length > 0);
let volume = $state(1);
let isMuted = $state(false);
function toggleMute() {
isMuted = !isMuted;
setMuted(isMuted);
}
function handleVolumeChange(e: Event) {
const val = parseFloat((e.target as HTMLInputElement).value);
volume = val;
if (val > 0 && isMuted) {
isMuted = false;
}
setVolume(val);
if (val > 0) {
setMuted(false);
}
}
export function handleKeyAction(action: TransportKeyAction) {
runTransportAction(action, markInPoint, markOutPoint);
}
</script>
<div class="transport-controls">
<div class="buttons">
<button
onclick={() => jumpKeyframe(-1)}
disabled={!hasKeyframes}
title="Previous keyframe (Shift+,)"
type="button"
>
◄K
</button>
<button onclick={() => seekBy(-5)} title="Seek back 5s (←)" type="button">-5s</button>
<button onclick={() => seekBy(-1)} title="Seek back 1s (Shift+←)" type="button">-1s</button>
<button onclick={() => stepFrame(-1)} title="Previous frame (,)" type="button">◄|</button>
<button onclick={togglePlayPause} title="Play/Pause (Space / K)" type="button">
{session.isPlaying ? '❚❚' : '▶'}
</button>
<button onclick={() => stepFrame(1)} title="Next frame (.)" type="button">|►</button>
<button onclick={() => seekBy(1)} title="Seek forward 1s (Shift+→)" type="button">+1s</button>
<button onclick={() => seekBy(5)} title="Seek forward 5s (→)" type="button">+5s</button>
<button
onclick={() => jumpKeyframe(1)}
disabled={!hasKeyframes}
title="Next keyframe (Shift+.)"
type="button"
>
K►
</button>
</div>
<div class="time-display">
<span class="current">{formatTime(session.currentTime)}</span>
<span class="separator">/</span>
<span class="total">{formatTime(session.duration)}</span>
</div>
<div class="volume-controls">
<button
class="vol-btn"
onclick={toggleMute}
title={isMuted ? 'Unmute' : 'Mute'}
type="button"
>
{#if isMuted || volume === 0}
🔇
{:else if volume < 0.5}
🔉
{:else}
🔊
{/if}
</button>
<input
type="range"
class="vol-slider"
min="0"
max="1"
step="0.05"
value={isMuted ? 0 : volume}
oninput={handleVolumeChange}
/>
</div>
<div class="mark-buttons">
<button
class="mark-btn"
onclick={() => markInPoint(session.currentTime)}
title="Set in-point (I)"
type="button"
>
I
</button>
<button
class="mark-btn"
onclick={() => markOutPoint(session.currentTime)}
title="Set out-point (O)"
type="button"
>
O
</button>
</div>
</div>
<style>
.transport-controls {
display: flex;
align-items: center;
padding: 8px 12px;
background: var(--bg-secondary);
border-top: 1px solid var(--border);
border-bottom: 1px solid var(--border);
gap: 16px;
}
.buttons {
display: flex;
gap: 4px;
flex-wrap: wrap;
}
.buttons button {
font-size: 13px;
padding: 4px 8px;
min-width: 32px;
}
.time-display {
font-family: var(--font-mono);
font-size: 14px;
}
.current {
color: var(--text-primary);
}
.separator {
color: var(--text-muted);
margin: 0 4px;
}
.total {
color: var(--text-secondary);
}
.volume-controls {
display: flex;
align-items: center;
gap: 4px;
}
.vol-btn {
background: var(--bg-tertiary);
border: 1px solid var(--border);
border-radius: 4px;
padding: 3px 6px;
font-size: 14px;
cursor: pointer;
line-height: 1;
color: var(--text-secondary);
}
.vol-btn:hover {
color: var(--text-primary);
}
.vol-slider {
width: 80px;
height: 4px;
accent-color: #89b4fa;
cursor: pointer;
}
.mark-buttons {
margin-left: auto;
display: flex;
gap: 4px;
}
.mark-btn {
font-weight: 700;
font-size: 14px;
padding: 4px 12px;
background: var(--bg-tertiary);
border: 1px solid var(--border);
}
</style>