import { useState } from "react" import { useTranslation } from "react-i18next" import { Button } from "@/components/ui/button" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Slider } from "@/components/ui/slider" import { useModal } from "@/features/modals/services" import { MidiMapping } from "../../services/midi/midi-engine" export function MidiMappingEditorModal() { const { t } = useTranslation() const { modalData, closeModal } = useModal() const { mapping, onSave } = (modalData || {}) as { mapping?: MidiMapping onSave?: (updates: Partial) => void } const [min, setMin] = useState(mapping?.min ?? 0) const [max, setMax] = useState(mapping?.max ?? 1) const [curve, setCurve] = useState<"linear" | "exponential" | "logarithmic">(mapping?.curve ?? "linear") const handleSave = () => { if (onSave) { onSave({ min, max, curve, }) } closeModal() } if (!mapping) { return null } return (
{/* Mapping Info */}

{mapping.targetParameter}

{mapping.messageType.toUpperCase()} {mapping.controller !== undefined && ` CC${mapping.controller}`} {mapping.channel && ` CH${mapping.channel}`}

{/* Min Value */}
{min.toFixed(2)}
setMin(v)} min={0} max={1} step={0.01} className="w-full" />
{/* Max Value */}
{max.toFixed(2)}
setMax(v)} min={0} max={1} step={0.01} className="w-full" />
{/* Curve Type */}
{/* Curve Preview */}
{/* Grid */} {/* Curve */} {/* Min/Max indicators */}

{t("fairlightAudio.midi.mappingEditor.responseCurvePreview")}

) } function generateCurvePath(curve: string, min: number, max: number): string { const points: string[] = [] const steps = 50 for (let i = 0; i <= steps; i++) { const x = (i / steps) * 100 const t = i / steps let y: number switch (curve) { case "exponential": y = min + (max - min) * (t * t) break case "logarithmic": y = min + ((max - min) * Math.log(t + 1)) / Math.log(2) break default: // linear y = min + (max - min) * t } points.push(`${x},${100 - y * 100}`) } return `M ${points.join(" L ")}` }