import { useMemo } from "react" import { useTranslation } from "react-i18next" import { AutomationEngine, AutomationMode } from "../../services/automation-engine" import { AutomationLaneComponent } from "./automation-lane" import { AutomationPanel } from "./automation-panel" interface AutomationViewProps { automationEngine: AutomationEngine currentTime: number pixelsPerSecond?: number laneHeight?: number totalWidth?: number } export function AutomationView({ automationEngine, currentTime, pixelsPerSecond = 50, laneHeight = 60, totalWidth = 2000, }: AutomationViewProps) { const { t } = useTranslation() const state = automationEngine.getState() const visibleLanes = useMemo(() => Array.from(state.lanes.values()).filter((lane) => lane.isVisible), [state.lanes]) const handleModeChange = (mode: AutomationMode) => { automationEngine.setMode(mode) } const handleStartRecording = () => { automationEngine.startRecording() } const handleStopRecording = () => { automationEngine.stopRecording() } const handleAddLane = (channelId: string, parameterId: string) => { const lane = automationEngine.createLane(channelId, parameterId) automationEngine.toggleLaneVisibility(lane.id) } const handleClearLane = (laneId: string) => { const lane = state.lanes.get(laneId) if (lane) { // Оставляем только первую точку const firstPoint = lane.points[0] if (firstPoint) { lane.points = [firstPoint] } } } const handlePointsChange = (laneId: string, points: any[]) => { const lane = state.lanes.get(laneId) if (lane) { lane.points = points } } const handleVisibilityToggle = (laneId: string) => { automationEngine.toggleLaneVisibility(laneId) } return (
{/* Automation Panel */} {/* Time Ruler */}
{/* Track header space */}
{/* Time markers */}
{Array.from({ length: Math.ceil(totalWidth / pixelsPerSecond) }).map((_, i) => (
{i}s
))} {/* Current time indicator */}
{/* Automation Lanes */}
{visibleLanes.length === 0 ? (

{t("fairlightAudio.automationView.noLanesVisible")}

{t("fairlightAudio.automationView.addLanePrompt")}

) : (
{visibleLanes.map((lane) => ( handlePointsChange(lane.id, points)} onVisibilityToggle={() => handleVisibilityToggle(lane.id)} /> ))}
)}
{/* Status Info */}
{t("fairlightAudio.automationView.status.automation")} {state.mode} •{" "} {t("fairlightAudio.automationView.status.lanes")} {state.lanes.size}{" "} {t("fairlightAudio.automationView.status.total")}, {visibleLanes.length}{" "} {t("fairlightAudio.automationView.status.visible")} • {t("fairlightAudio.automationView.status.time")}{" "} {currentTime.toFixed(2)}s{state.isRecording && ` • ${t("fairlightAudio.automationView.status.recording")}`}
) }