Create professional demos and 3D mockups in seconds, directly in your browser
feat: add sound card and library components with audio rendering capabilities
CristianOlivera13fe0981b8181
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsxindex d7e02fa..f6aecc8 100644--- a/app/[locale]/(editor)/editor/page.tsx+++ b/app/[locale]/(editor)/editor/page.tsx@@ -1095,12 +1095,12 @@ export default function Editor() {}}, [canvasElements, updateCanvasElement]);- const MAX_AUDIO_TRACKS = 5;+ const MAX_AUDIO_TRACKS = 8;// Audio handlersconst handleAudioUpload = useCallback(async (file: File) => {try {if (audioTracks.length >= MAX_AUDIO_TRACKS) {- alert(`Máximo ${MAX_AUDIO_TRACKS} pistas de audio permitidas.`);+ alert(`Maximum of ${MAX_AUDIO_TRACKS} audio tracks allowed.`);return;}@@ -1171,7 +1171,7 @@ export default function Editor() {if (!audio) return;if (audioTracks.length >= MAX_AUDIO_TRACKS) {- alert(`Máximo ${MAX_AUDIO_TRACKS} pistas de audio permitidas.`);+ alert(`Maximum of ${MAX_AUDIO_TRACKS} audio tracks allowed.`);return;}@@ -3097,6 +3097,8 @@ export default function Editor() {onUpdateMockupMotionFragment={handleUpdateMockupMotionFragment}onSelectMockupMotionFragment={handleSelectMockupMotionFragment}onDeleteMockupMotionFragment={handleDeleteMockupMotionFragment}+ selectedAudioTrackId={selectedAudioTrackId}+ setSelectedAudioTrackId={handleSelectAudioTrack}/></Suspense></motion.div>diff --git a/app/components/ui/editor/AudioFragmentTrackItem.tsx b/app/components/ui/editor/AudioFragmentTrackItem.tsxindex cb9b2f1..70f92d9 100644--- a/app/components/ui/editor/AudioFragmentTrackItem.tsx+++ b/app/components/ui/editor/AudioFragmentTrackItem.tsx@@ -4,258 +4,237 @@ import { motion, useMotionValue } from "framer-motion";import { AudioFragmentTrackItemProps, MIN_FRAGMENT_DURATION, MIN_VISUAL_WIDTH_PX } from "@/types/audio.types";export function AudioFragmentTrackItem({- track,- audio,- isSelected,- contentWidth,- videoDuration,- contentDuration,- otherTracks,- onSelect,- onUpdate,- onDragStateChange,- onMouseEnter,- onMouseLeave,- speed = 1,+ track, audio, isSelected, contentWidth, videoDuration, contentDuration,+ otherTracks, onSelect, onUpdate, onDragStateChange, onMouseEnter, onMouseLeave,+ speed = 1,+ lane = 0,+ laneHeight = 55,+ laneCount = 1,}: AudioFragmentTrackItemProps) {- const [isDragging, setIsDragging] = useState(false);- const [isResizing, setIsResizing] = useState<'start' | 'end' | null>(null);- const containerRef = useRef<HTMLDivElement>(null);- const fragmentX = useMotionValue(0);- const fragmentWidth = useMotionValue(0);-- const timeToPixels = useCallback((time: number) => {- return (time / videoDuration) * contentWidth;- }, [videoDuration, contentWidth]);-- const pixelsToTime = useCallback((pixels: number) => {- return (pixels / contentWidth) * videoDuration;- }, [contentWidth, videoDuration]);-- const initialLeft = timeToPixels(track.startTime);- const initialWidth = timeToPixels(track.duration);- const visualWidth = Math.max(initialWidth, MIN_VISUAL_WIDTH_PX);-- useEffect(() => {- if (!isDragging && !isResizing) {- fragmentX.set(initialLeft);- fragmentWidth.set(visualWidth);- }- }, [initialLeft, visualWidth, isDragging, isResizing, fragmentX, fragmentWidth]);-- const boundaries = useMemo(() => {- const sorted = [...otherTracks]- .filter(t => t.id !== track.id)- .sort((a, b) => a.startTime - b.startTime);-- let minStart = 0;- let maxEnd = contentDuration ?? videoDuration;-- for (const other of sorted) {- const otherEnd = other.startTime + other.duration;- const trackEnd = track.startTime + track.duration;-- if (otherEnd <= track.startTime) {- minStart = Math.max(minStart, otherEnd);- }- if (other.startTime >= trackEnd) {- maxEnd = Math.min(maxEnd, other.startTime);- break;- }- }- return { minStart, maxEnd };- }, [otherTracks, track.id, track.startTime, track.duration, videoDuration, contentDuration]);-- const handleDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {- if (contentWidth === 0 || videoDuration === 0) return;- const currentX = fragmentX.get();- let newX = currentX + info.delta.x;- const minX = timeToPixels(boundaries.minStart);- const maxX = timeToPixels(boundaries.maxEnd - track.duration);- newX = Math.max(minX, Math.min(maxX, newX));- fragmentX.set(newX);- }, [contentWidth, videoDuration, fragmentX, track.duration, boundaries, timeToPixels]);-- const handleDragStart = useCallback(() => {- setIsDragging(true);- onDragStateChange?.(true);- }, [onDragStateChange]);-- const handleDragEnd = useCallback(() => {- setIsDragging(false);- onDragStateChange?.(false);- const newStartTime = pixelsToTime(fragmentX.get());- onUpdate({- startTime: Math.max(0, Math.min((contentDuration ?? videoDuration) - track.duration, newStartTime)),- });- }, [fragmentX, pixelsToTime, track.duration, videoDuration, contentDuration, onUpdate, onDragStateChange]);-- const handleResizeStartDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {- if (contentWidth === 0 || videoDuration === 0) return;- const currentX = fragmentX.get();- const currentWidth = fragmentWidth.get();- let newX = currentX + info.delta.x;- let newWidth = currentWidth - info.delta.x;- const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);-- if (newWidth < minWidth) {- newWidth = minWidth;- newX = currentX + currentWidth - minWidth;- }-- const minX = timeToPixels(boundaries.minStart);- if (newX < minX) {- newWidth = newWidth - (minX - newX);- newX = minX;- }-- if (audio) {- const maxWidth = timeToPixels(audio.duration);- if (newWidth > maxWidth) {- const diff = newWidth - maxWidth;- newX = newX + diff;- newWidth = maxWidth;- }- }- fragmentX.set(newX);- fragmentWidth.set(newWidth);- }, [contentWidth, videoDuration, fragmentX, fragmentWidth, boundaries, timeToPixels, audio]);-- const handleResizeEndDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {- if (contentWidth === 0 || videoDuration === 0) return;- const currentX = fragmentX.get();- const currentWidth = fragmentWidth.get();- let newWidth = currentWidth + info.delta.x;- const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);-- newWidth = Math.max(minWidth, newWidth);- const maxWidth = timeToPixels(boundaries.maxEnd) - currentX;- newWidth = Math.min(newWidth, maxWidth);-- if (audio) {- newWidth = Math.min(newWidth, timeToPixels(audio.duration));- }- fragmentWidth.set(newWidth);- }, [contentWidth, videoDuration, fragmentWidth, fragmentX, boundaries, timeToPixels, audio]);-- const handleResizeStart = useCallback((handle: 'start' | 'end') => {- setIsResizing(handle);- onDragStateChange?.(true);- }, [onDragStateChange]);-- const handleResizeEnd = useCallback(() => {- setIsResizing(null);- onDragStateChange?.(false);- const newStartTime = pixelsToTime(fragmentX.get());- const newDuration = pixelsToTime(fragmentWidth.get());-- onUpdate({- startTime: Math.max(0, newStartTime),- duration: Math.min(audio?.duration ?? contentDuration ?? videoDuration, newDuration),- });- }, [fragmentX, fragmentWidth, pixelsToTime, audio, videoDuration, contentDuration, onUpdate, onDragStateChange]);-- const isInteracting = isDragging || isResizing !== null;-- return (- <motion.div- ref={containerRef}- className={`absolute h-[95%] top-[5%] rounded-md flex items-center border transition-shadow select-none focus:outline-none- ${isSelected || isInteracting- ? 'bg-violet-500/30 border-violet-400/70 shadow-[0_0_10px_rgba(139,92,246,0.3)] z-10'- : 'bg-violet-600/20 border-violet-500/35 hover:border-violet-500/60'- } ${isDragging ? 'cursor-grabbing' : 'cursor-grab'}`}- style={{- x: fragmentX,- width: fragmentWidth,- background: isSelected || isInteracting- ? 'linear-gradient(180deg, rgba(139, 92, 246, 0.5) 0%, rgba(109, 40, 217, 0.4) 100%)'- : 'linear-gradient(180deg, rgba(124, 58, 237, 0.2) 0%, rgba(91, 33, 182, 0.15) 100%)',- boxShadow: isSelected || isInteracting- ? 'inset 0 1px 0 rgba(255,255,255,0.3), 0 0 10px rgba(139,92,246,0.3)'- : 'inset 0 1px 0 rgba(255,255,255,0.1)'- }}- drag="x"- dragConstraints={{ left: 0, right: contentWidth / speed }}- dragElastic={0}- dragMomentum={false}- onDrag={handleDrag}- onDragStart={handleDragStart}- onDragEnd={handleDragEnd}- onClick={(e) => {- e.stopPropagation();- onSelect();- }}- onMouseEnter={onMouseEnter}- onMouseLeave={onMouseLeave}- whileTap={{ scale: 0.98 }}- role="slider"- aria-valuemin={0}- aria-valuemax={contentDuration ?? videoDuration}- aria-valuenow={track.startTime}- aria-label={`Audio fragment ${(track.duration / speed).toFixed(1)}s`}- tabIndex={0}- >- <motion.div- className="absolute left-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"- drag="x"- dragConstraints={{ left: 0, right: 0 }}- dragElastic={0}- dragMomentum={false}- onDrag={handleResizeStartDrag}- onDragStart={() => handleResizeStart('start')}- onDragEnd={handleResizeEnd}- onClick={(e) => e.stopPropagation()}- role="slider"- aria-label="Resize start"- aria-valuemin={0}- aria-valuemax={contentDuration ?? videoDuration}- aria-valuenow={track.startTime}- tabIndex={0}- >- <div- className={`w-1 h-6 rounded-full transition-all ${- isResizing === 'start'- ? 'bg-violet-300 scale-110'- : 'bg-violet-400/60 group-hover/resize:bg-violet-300'- }`}- />- </motion.div>-- <div className="flex-1 flex flex-col items-center justify-center pointer-events-none overflow-hidden px-2">- <span className={`text-[11px] truncate ${isSelected || isInteracting ? 'text-violet-200' : 'text-violet-300/70'}`}>- Audio- </span>- <span className={`text-[9px] truncate ${isSelected || isInteracting ? 'text-violet-300/70' : 'text-violet-400/45'}`}>- {(track.duration / speed).toFixed(1)}s- </span>- </div>-- <motion.div- className="absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"- drag="x"- dragConstraints={{ left: 0, right: 0 }}- dragElastic={0}- dragMomentum={false}- onDrag={handleResizeEndDrag}- onDragStart={() => handleResizeStart('end')}- onDragEnd={handleResizeEnd}- onClick={(e) => e.stopPropagation()}- role="slider"- aria-label="Resize end"- aria-valuemin={0}- aria-valuemax={contentDuration ?? videoDuration}- aria-valuenow={track.startTime + track.duration}- tabIndex={0}- >- <div- className={`w-1 h-6 rounded-full transition-all ${- isResizing === 'end'- ? 'bg-violet-300 scale-110'- : 'bg-violet-400/60 group-hover/resize:bg-violet-300'- }`}- />- </motion.div>- </motion.div>- );+ const [isDragging, setIsDragging] = useState(false);+ const [isResizing, setIsResizing] = useState<'start' | 'end' | null>(null);+ const containerRef = useRef<HTMLDivElement>(null);+ const fragmentX = useMotionValue(0);+ const fragmentY = useMotionValue(0);+ const fragmentWidth = useMotionValue(0);++ const topOffset = lane * laneHeight + laneHeight * 0.05;+ const itemHeight = laneHeight * 0.9;+ const maxLaneY = Math.max(0, laneCount - 1) * laneHeight + laneHeight * 0.05;++ const timeToPixels = useCallback((time: number) => (time / videoDuration) * contentWidth, [videoDuration, contentWidth]);+ const pixelsToTime = useCallback((pixels: number) => (pixels / contentWidth) * videoDuration, [contentWidth, videoDuration]);++ const initialLeft = timeToPixels(track.startTime);+ const initialWidth = timeToPixels(track.duration);+ const visualWidth = Math.max(initialWidth, MIN_VISUAL_WIDTH_PX);++ useEffect(() => {+ if (!isDragging && !isResizing) {+ fragmentX.set(initialLeft);+ fragmentWidth.set(visualWidth);+ fragmentY.set(topOffset);+ }+ }, [initialLeft, visualWidth, topOffset, isDragging, isResizing, fragmentX, fragmentWidth, fragmentY]);++ const boundaries = useMemo(() => {+ const sorted = [...otherTracks]+ .filter(t => t.id !== track.id)+ .sort((a, b) => a.startTime - b.startTime);+ let minStart = 0;+ let maxEnd = contentDuration ?? videoDuration;+ for (const other of sorted) {+ const otherEnd = other.startTime + other.duration;+ const trackEnd = track.startTime + track.duration;+ if (otherEnd <= track.startTime) {+ minStart = Math.max(minStart, otherEnd);+ }+ if (other.startTime >= trackEnd) {+ maxEnd = Math.min(maxEnd, other.startTime);+ break;+ }+ }+ return { minStart, maxEnd };+ }, [otherTracks, track.id, track.startTime, track.duration, videoDuration, contentDuration]);++ const handleDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number; y: number } }) => {+ if (contentWidth === 0 || videoDuration === 0) return;++ const currentX = fragmentX.get();+ let newX = currentX + info.delta.x;+ const minX = timeToPixels(boundaries.minStart);+ const maxX = timeToPixels(boundaries.maxEnd - track.duration);+ newX = Math.max(minX, Math.min(maxX, newX));+ fragmentX.set(newX);++ const currentY = fragmentY.get();+ const newY = Math.max(laneHeight * 0.05, Math.min(maxLaneY, currentY + info.delta.y));+ fragmentY.set(newY);+ }, [contentWidth, videoDuration, fragmentX, fragmentY, track.duration, boundaries, timeToPixels, maxLaneY, laneHeight]);++ const handleDragStart = useCallback(() => {+ setIsDragging(true);+ onDragStateChange?.(true);+ }, [onDragStateChange]);++ const handleDragEnd = useCallback(() => {+ setIsDragging(false);+ onDragStateChange?.(false);+ const newStartTime = pixelsToTime(fragmentX.get());+ const newLane = Math.max(0, Math.round((fragmentY.get() - laneHeight * 0.05) / laneHeight));+ onUpdate({+ startTime: Math.max(0, Math.min((contentDuration ?? videoDuration) - track.duration, newStartTime)),+ lane: newLane,+ });+ }, [fragmentX, fragmentY, pixelsToTime, track.duration, videoDuration, contentDuration, onUpdate, onDragStateChange, laneHeight]);++ const handleResizeStartDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {+ if (contentWidth === 0 || videoDuration === 0) return;+ const currentX = fragmentX.get();+ const currentWidth = fragmentWidth.get();+ let newX = currentX + info.delta.x;+ let newWidth = currentWidth - info.delta.x;+ const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);+ if (newWidth < minWidth) {+ newWidth = minWidth;+ newX = currentX + currentWidth - minWidth;+ }+ const minX = timeToPixels(boundaries.minStart);+ if (newX < minX) {+ newWidth = newWidth - (minX - newX);+ newX = minX;+ }+ if (audio) {+ const maxWidth = timeToPixels(audio.duration);+ if (newWidth > maxWidth) {+ const diff = newWidth - maxWidth;+ newX = newX + diff;+ newWidth = maxWidth;+ }+ }+ fragmentX.set(newX);+ fragmentWidth.set(newWidth);+ }, [contentWidth, videoDuration, fragmentX, fragmentWidth, boundaries, timeToPixels, audio]);++ const handleResizeEndDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {+ if (contentWidth === 0 || videoDuration === 0) return;+ const currentX = fragmentX.get();+ const currentWidth = fragmentWidth.get();+ let newWidth = currentWidth + info.delta.x;+ const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);+ newWidth = Math.max(minWidth, newWidth);+ const maxWidth = timeToPixels(boundaries.maxEnd) - currentX;+ newWidth = Math.min(newWidth, maxWidth);+ if (audio) {+ newWidth = Math.min(newWidth, timeToPixels(audio.duration));+ }+ fragmentWidth.set(newWidth);+ }, [contentWidth, videoDuration, fragmentWidth, fragmentX, boundaries, timeToPixels, audio]);++ const handleResizeStart = useCallback((handle: 'start' | 'end') => {+ setIsResizing(handle);+ onDragStateChange?.(true);+ }, [onDragStateChange]);++ const handleResizeEnd = useCallback(() => {+ setIsResizing(null);+ onDragStateChange?.(false);+ const newStartTime = pixelsToTime(fragmentX.get());+ const newDuration = pixelsToTime(fragmentWidth.get());+ onUpdate({+ startTime: Math.max(0, newStartTime),+ duration: Math.min(audio?.duration ?? contentDuration ?? videoDuration, newDuration),+ });+ }, [fragmentX, fragmentWidth, pixelsToTime, audio, videoDuration, contentDuration, onUpdate, onDragStateChange]);++ const isInteracting = isDragging || isResizing !== null;++ return (+ <motion.div+ ref={containerRef}+ className={`absolute rounded-md flex items-center border transition-shadow select-none focus:outline-none ${+ isSelected || isInteracting+ ? 'bg-violet-500/30 border-violet-400/70 shadow-[0_0_10px_rgba(139,92,246,0.3)] z-10'+ : 'bg-violet-600/20 border-violet-500/35 hover:border-violet-500/60'+ } ${isDragging ? 'cursor-grabbing' : 'cursor-grab'}`}+ style={{+ x: fragmentX,+ y: fragmentY,+ width: fragmentWidth,+ height: itemHeight,+ background: isSelected || isInteracting+ ? 'linear-gradient(180deg, rgba(139, 92, 246, 0.5) 0%, rgba(109, 40, 217, 0.4) 100%)'+ : 'linear-gradient(180deg, rgba(124, 58, 237, 0.2) 0%, rgba(91, 33, 182, 0.15) 100%)',+ boxShadow: isSelected || isInteracting+ ? 'inset 0 1px 0 rgba(255,255,255,0.3), 0 0 10px rgba(139,92,246,0.3)'+ : 'inset 0 1px 0 rgba(255,255,255,0.1)'+ }}+ drag+ dragConstraints={{ left: 0, right: contentWidth / speed, top: laneHeight * 0.05, bottom: maxLaneY }}+ dragElastic={0}+ dragMomentum={false}+ onDrag={handleDrag}+ onDragStart={handleDragStart}+ onDragEnd={handleDragEnd}+ onClick={(e) => { e.stopPropagation(); onSelect(); }}+ onMouseEnter={onMouseEnter}+ onMouseLeave={onMouseLeave}+ whileTap={{ scale: 0.98 }}+ role="slider"+ aria-valuemin={0}+ aria-valuemax={contentDuration ?? videoDuration}+ aria-valuenow={track.startTime}+ aria-label={`Audio fragment ${(track.duration / speed).toFixed(1)}s`}+ tabIndex={0}+ >+ <motion.div+ className="absolute left-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"+ drag="x"+ dragConstraints={{ left: 0, right: 0 }}+ dragElastic={0}+ dragMomentum={false}+ onDrag={handleResizeStartDrag}+ onDragStart={() => handleResizeStart('start')}+ onDragEnd={handleResizeEnd}+ onClick={(e) => e.stopPropagation()}+ role="slider"+ aria-label="Resize start"+ aria-valuemin={0}+ aria-valuemax={contentDuration ?? videoDuration}+ aria-valuenow={track.startTime}+ tabIndex={0}+ >+ <div className={`w-1 h-6 rounded-full transition-all ${isResizing === 'start' ? 'bg-violet-300 scale-110' : 'bg-violet-400/60 group-hover/resize:bg-violet-300'}`} />+ </motion.div>++ <div className="flex-1 flex flex-col items-center justify-center pointer-events-none overflow-hidden px-2">+ <span className={`text-[11px] truncate ${isSelected || isInteracting ? 'text-violet-200' : 'text-violet-300/70'}`}>+ Audio+ </span>+ <span className={`text-[9px] truncate ${isSelected || isInteracting ? 'text-violet-300/70' : 'text-violet-400/45'}`}>+ {(track.duration / speed).toFixed(1)}s+ </span>+ </div>++ <motion.div+ className="absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"+ drag="x"+ dragConstraints={{ left: 0, right: 0 }}+ dragElastic={0}+ dragMomentum={false}+ onDrag={handleResizeEndDrag}+ onDragStart={() => handleResizeStart('end')}+ onDragEnd={handleResizeEnd}+ onClick={(e) => e.stopPropagation()}+ role="slider"+ aria-label="Resize end"+ aria-valuemin={0}+ aria-valuemax={contentDuration ?? videoDuration}+ aria-valuenow={track.startTime + track.duration}+ tabIndex={0}+ >+ <div className={`w-1 h-6 rounded-full transition-all ${isResizing === 'end' ? 'bg-violet-300 scale-110' : 'bg-violet-400/60 group-hover/resize:bg-violet-300'}`} />+ </motion.div>+ </motion.div>+ );}\ No newline at end of filediff --git a/app/components/ui/editor/AudioMenu.tsx b/app/components/ui/editor/AudioMenu.tsxindex e3ad59b..7a87664 100644--- a/app/components/ui/editor/AudioMenu.tsx+++ b/app/components/ui/editor/AudioMenu.tsx@@ -1,13 +1,14 @@"use client";-import { Icon } from "@iconify/react";-import { useCallback, useRef, useState } from "react";+import { useCallback, useRef, useState, useEffect } from "react";import type { AudioMenuProps, AudioTrack } from "@/types/audio.types";import { AudioTrimModal } from "./AudioTrimModal";import { Button } from "@/components/ui/button";import { TooltipAction } from "@/components/ui/tooltip-action";import { TrackVolumeSlider } from "@/components/ui/TrackVolumeSlider";import { useTranslations } from "next-intl";+import { renderSoundToFile, type SoundName } from "@/lib/sounds";+import { SoundLibrary } from "@/components/ui/SoundLibrary";export function AudioMenu({audioTracks,@@ -16,82 +17,80 @@ export function AudioMenu({onAudioUpload,onUpdateAudioTrack,onDeleteAudioTrack,+ selectedAudioTrackId,+ onSelectAudioTrack,}: AudioMenuProps) {const t = useTranslations("audioMenu");const fileInputRef = useRef<HTMLInputElement>(null);- const [selectedTrackId, setSelectedTrackId] = useState<string | null>(null);const [trimModalOpen, setTrimModalOpen] = useState(false);const [trimModalTrack, setTrimModalTrack] = useState<AudioTrack | null>(null);+ const trackRefs = useRef<Map<string, HTMLDivElement>>(new Map());+ useEffect(() => {+ if (!selectedAudioTrackId) return;+ trackRefs.current.get(selectedAudioTrackId)?.scrollIntoView({ behavior: "smooth", block: "nearest" });+ }, [selectedAudioTrackId]);+const handleFileSelect = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {const file = e.target.files?.[0];if (!file) return;-- const SUPPORTED_AUDIO_FORMATS = [- 'audio/mpeg', 'audio/mp3', 'audio/wav', 'audio/wave',- 'audio/x-wav', 'audio/ogg', 'audio/aac', 'audio/m4a', 'audio/x-m4a'- ];-- if (!SUPPORTED_AUDIO_FORMATS.includes(file.type) &&- !['.mp3', '.wav', '.ogg', '.aac', '.m4a'].some(ext => file.name.toLowerCase().endsWith(ext))) {- alert("Formato de audio no soportado. Por favor usa MP3, WAV, OGG, AAC o M4A.");+ const SUPPORTED_AUDIO_FORMATS = ['audio/mpeg', 'audio/mp3', 'audio/wav', 'audio/wave', 'audio/x-wav', 'audio/ogg', 'audio/aac', 'audio/m4a', 'audio/x-m4a'];+ if (!SUPPORTED_AUDIO_FORMATS.includes(file.type) && !['.mp3', '.wav', '.ogg', '.aac', '.m4a'].some(ext => file.name.toLowerCase().endsWith(ext))) {+ alert("Unsupported audio format. Please use MP3, WAV, OGG, AAC, or M4A.");return;}-const MAX_AUDIO_FILE_SIZE = 10 * 1024 * 1024;if (file.size > MAX_AUDIO_FILE_SIZE) {- alert("El archivo es demasiado grande. El tamaño máximo es 10MB.");+ alert("The file is too large. The maximum size allowed is 10MB.");return;}-onAudioUpload(file);-- if (fileInputRef.current) {- fileInputRef.current.value = "";- }+ if (fileInputRef.current) fileInputRef.current.value = "";}, [onAudioUpload]);- const formatDuration = (seconds: number) => {- const mins = Math.floor(seconds / 60);- const secs = Math.floor(seconds % 60);- return `${mins}:${secs.toString().padStart(2, '0')}`;- };-const [isDragOver, setIsDragOver] = useState(false);-- const handleDragOver = useCallback((e: React.DragEvent) => {- e.preventDefault();- setIsDragOver(true);- }, []);-- const handleDragLeave = useCallback((e: React.DragEvent) => {- e.preventDefault();- setIsDragOver(false);- }, []);-+ const handleDragOver = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragOver(true); }, []);+ const handleDragLeave = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragOver(false); }, []);const handleDrop = useCallback((e: React.DragEvent) => {e.preventDefault();setIsDragOver(false);const file = e.dataTransfer.files?.[0];if (!file) return;-- const SUPPORTED_AUDIO_FORMATS = [- 'audio/mpeg', 'audio/mp3', 'audio/wav', 'audio/wave',- 'audio/x-wav', 'audio/ogg', 'audio/aac', 'audio/m4a', 'audio/x-m4a'- ];- if (!SUPPORTED_AUDIO_FORMATS.includes(file.type) &&- !['.mp3', '.wav', '.ogg', '.aac', '.m4a'].some(ext => file.name.toLowerCase().endsWith(ext))) {- alert("Formato de audio no soportado. Por favor usa MP3, WAV, OGG, AAC o M4A.");+ const SUPPORTED_AUDIO_FORMATS = ['audio/mpeg', 'audio/mp3', 'audio/wav', 'audio/wave', 'audio/x-wav', 'audio/ogg', 'audio/aac', 'audio/m4a', 'audio/x-m4a'];+ if (!SUPPORTED_AUDIO_FORMATS.includes(file.type) && !['.mp3', '.wav', '.ogg', '.aac', '.m4a'].some(ext => file.name.toLowerCase().endsWith(ext))) {+ alert("Unsupported audio format. Please use MP3, WAV, OGG, AAC, or M4A.");return;}const MAX_AUDIO_FILE_SIZE = 10 * 1024 * 1024;if (file.size > MAX_AUDIO_FILE_SIZE) {- alert("El archivo es demasiado grande. El tamaño máximo es 10MB.");+ alert("The file is too large. The maximum size allowed is 10MB.");return;}onAudioUpload(file);}, [onAudioUpload]);+ const [renderingSound, setRenderingSound] = useState<SoundName | null>(null);+ const handleAddDefaultSound = useCallback(async (sound: SoundName) => {+ setRenderingSound(sound);+ try {+ const file = await renderSoundToFile(sound);+ onAudioUpload(file);+ } finally {+ setRenderingSound(null);+ }+ }, [onAudioUpload]);++ const SOUND_CATEGORIES: { label: string; sounds: SoundName[] }[] = [+ { label: t("categories.confirmation"), sounds: ["chime", "success", "ready", "sparkle"] },+ { label: t("categories.alert"), sounds: ["error"] },+ { label: t("categories.ui"), sounds: ["tick", "press", "release", "toggle", "pulse", "scan"] },+ { label: t("categories.transition"), sounds: ["page", "droplet"] },+ { label: t("categories.ambient"), sounds: ["bloom", "arrival", "whisper"] },+ { label: t("categories.system"), sounds: ["loading"] },+ ];++ const tracksNewestFirst = [...audioTracks].reverse();+return (<div className="p-4 flex flex-col gap-5"><div className="flex items-center gap-2 text-white font-medium">@@ -100,64 +99,52 @@ export function AudioMenu({</div><div- className={`flex flex-col items-center justify-center w-full rounded-lg transition-colors ${isDragOver ? "bg-blue-500/10 ring-1 ring-blue-500/40" : ""- }`}+ className={`flex flex-col items-center justify-center w-full rounded-lg transition-colors ${isDragOver ? "bg-blue-500/10 ring-1 ring-blue-500/40" : ""}`}onDragOver={handleDragOver}onDragLeave={handleDragLeave}onDrop={handleDrop}>- <input- ref={fileInputRef}- type="file"- accept=".mp3,.wav,.ogg,.aac,.m4a,audio/*"- onChange={handleFileSelect}- className="hidden"- aria-label={t("uploadButton")}- />- <Button- variant="outline"- className="w-full text-sm"- onClick={() => fileInputRef.current?.click()}- aria-label={t("uploadButton")}- >+ <input ref={fileInputRef} type="file" accept=".mp3,.wav,.ogg,.aac,.m4a,audio/*" onChange={handleFileSelect} className="hidden" aria-label={t("uploadButton")} />+ <Button variant="outline" className="w-full text-sm" onClick={() => fileInputRef.current?.click()} aria-label={t("uploadButton")}><Icon icon="solar:upload-minimalistic-outline" width="14" /><span>{t("uploadButton")}</span></Button>- <p className="text-xs text-white/40 mt-2 text-center">- {t("uploadHint")}- </p>+ <p className="text-xs text-white/40 mt-2 text-center">{t("uploadHint")}</p></div>- {audioTracks.length > 0 && (- <div className="flex flex-col gap-2">- <div className="text-xs font-medium text-white/70 flex items-center gap-2">- <Icon icon="mdi:timeline-clock" width="14" />- <span>{t("timelineTracks", { count: audioTracks.length })}</span>- </div>+ <div className="flex flex-col gap-2">+ <span className="text-xs font-medium text-white/70">{t("timelineTracks", { count: audioTracks.length })}</span>++ {audioTracks.length > 0 ? (<div className="flex flex-col gap-2">- {audioTracks.map((track) => {- const isSelected = selectedTrackId === track.id;+ {tracksNewestFirst.map((track) => {+ const isSelected = track.id === selectedAudioTrackId;const exceedsVideoDuration = (track.startTime + track.duration) > videoDuration;-return (<divkey={track.id}- className={`bg-[#09090B] border squircle-element p-3 transition-all ${isSelected- ? "border-blue-500/50 bg-blue-500/5"- : "border-white/5 hover:border-white/10"+ ref={(el) => {+ if (el) trackRefs.current.set(track.id, el);+ else trackRefs.current.delete(track.id);+ }}+ className={`bg-[#09090B] border squircle-element p-3 transition-all ${isSelected ? "border-blue-500/50 bg-blue-500/5" : "border-white/5 hover:border-white/10"}`}- onClick={() => setSelectedTrackId(isSelected ? null : track.id)}+ onClick={() => onSelectAudioTrack(isSelected ? null : track.id)}+ role="button"+ tabIndex={0}+ aria-pressed={isSelected}+ onKeyDown={(e) => {+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ onSelectAudioTrack(isSelected ? null : track.id);+ }+ }}>- <div className="flex items-start justify-between gap-2 mb-2">+ <div className="flex items-start justify-between gap-2"><div className="flex-1 min-w-0">- <div className="text-sm text-white font-medium truncate">- {track.name}- </div>- <div className="text-xs text-white/40 mt-0.5">- {t("start")}: {formatDuration(track.startTime)} • {t("duration")}: {formatDuration(track.duration)}- </div>+ <div className="text-sm text-white font-medium truncate">{track.name}</div>{exceedsVideoDuration && (- <div className="text-xs text-orange-400 mt-1 flex items-center gap-1">+ <div className="text-xs text-orange-400 flex items-center gap-1"><Icon icon="mdi:alert" width="12" />{t("exceedsDuration")}</div>@@ -166,11 +153,7 @@ export function AudioMenu({<div className="flex items-center gap-1"><TooltipAction label={t("trimAction")}><button- onClick={(e) => {- e.stopPropagation();- setTrimModalTrack(track);- setTrimModalOpen(true);- }}+ onClick={(e) => { e.stopPropagation(); setTrimModalTrack(track); setTrimModalOpen(true); }}className="p-1.5 rounded text-white/40 hover:text-blue-400 hover:bg-blue-500/10 transition-all"><Icon icon="mdi:content-cut" width="16" />@@ -181,9 +164,7 @@ export function AudioMenu({onClick={(e) => {e.stopPropagation();onDeleteAudioTrack(track.id);- if (selectedTrackId === track.id) {- setSelectedTrackId(null);- }+ if (selectedAudioTrackId === track.id) onSelectAudioTrack(null);}}className="p-1.5 rounded text-white/40 hover:text-red-400 hover:bg-red-500/10 transition-all">@@ -192,32 +173,30 @@ export function AudioMenu({</TooltipAction></div></div>-- <div className="flex flex-col gap-3 pt-2 border-t border-white/5 animate-in fade-in duration-150">- <TrackVolumeSlider- track={track}- onUpdateAudioTrack={onUpdateAudioTrack}- />- </div>+ <div className="flex flex-col gap-3 pt-2 animate-in fade-in duration-150">+ <TrackVolumeSlider track={track} onUpdateAudioTrack={onUpdateAudioTrack} />+ </div></div>);})}</div>- </div>- )}+ ) : (+ <div className="text-center py-6 px-4 text-white/40 rounded-md border border-dashed border-white/10" role="status">+ <Icon icon="mdi:music-note-off" width="32" className="mx-auto mb-2 opacity-30" aria-hidden="true" />+ <p className="text-xs">{t("noTracks")}</p>+ <p className="text-[10px] mt-1">{t("noTracksHint")}</p>+ </div>+ )}+ </div>- {audioTracks.length === 0 && (- <div className="text-center py-8 px-4 text-white/40" role="status">- <Icon icon="mdi:music-note-off" width="48" className="mx-auto mb-3 opacity-30" aria-hidden="true" />- <p className="text-sm">{t("noTracks")}</p>- <p className="text-xs mt-1">{t("noTracksHint")}</p>- </div>- )}+ <div className="flex flex-col gap-3">+ <div className="text-xs font-medium text-white/70 uppercase">{t("defaultSounds")}</div>+ <SoundLibrary categories={SOUND_CATEGORIES} renderingSound={renderingSound} onAdd={handleAddDefaultSound} />+ </div>{trimModalOpen && trimModalTrack && (() => {const originalAudio = uploadedAudios.find(a => a.id === trimModalTrack.audioId);if (!originalAudio) return null;-return (<AudioTrimModalkey={trimModalTrack.id}@@ -228,17 +207,11 @@ export function AudioMenu({initialTrimStart={trimModalTrack.trimStart ?? 0}initialTrimEnd={(trimModalTrack.trimStart ?? 0) + trimModalTrack.duration}onConfirm={(trimStart, trimEnd) => {- onUpdateAudioTrack(trimModalTrack.id, {- duration: trimEnd - trimStart,- trimStart: trimStart,- });- setTrimModalOpen(false);- setTrimModalTrack(null);- }}- onCancel={() => {+ onUpdateAudioTrack(trimModalTrack.id, { duration: trimEnd - trimStart, trimStart });setTrimModalOpen(false);setTrimModalTrack(null);}}+ onCancel={() => { setTrimModalOpen(false); setTrimModalTrack(null); }}/>);})()}diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsxindex 997645a..2be049c 100644--- a/app/components/ui/editor/ControlPanel.tsx+++ b/app/components/ui/editor/ControlPanel.tsx@@ -90,6 +90,8 @@ export function ControlPanel({onAudioUpload,onUpdateAudioTrack,onDeleteAudioTrack,+ selectedAudioTrackId,+ setSelectedAudioTrackId,videoDuration = 0,isRecordedVideo = false,// Videos library props@@ -127,7 +129,7 @@ export function ControlPanel({const t = useTranslations("controlPanel");const { imagePhoneActive } = useMockup3dContext();- const [isGlobalMotionEnabled, setIsGlobalMotionEnabled] = useState(false);+ const [isGlobalMotionEnabled, setIsGlobalMotionEnabled] = useState(true);return (<div className="relative w-full sm:w-[320px] h-screen bg-[#141417] border-r border-white/10 flex flex-col shrink-0" role="complementary" aria-label="Control panel"><header className="flex items-center justify-between h-13 p-2 border-b border-white/10 shrink-0" role="banner">@@ -327,6 +329,8 @@ export function ControlPanel({onAudioUpload={onAudioUpload || (() => { })}onUpdateAudioTrack={onUpdateAudioTrack || (() => { })}onDeleteAudioTrack={onDeleteAudioTrack || (() => { })}+ selectedAudioTrackId={selectedAudioTrackId ?? null}+ onSelectAudioTrack={setSelectedAudioTrackId || (() => { })}/></Suspense>)}diff --git a/app/components/ui/editor/MotionMenu.tsx b/app/components/ui/editor/MotionMenu.tsxindex a18fd27..cb04f68 100644--- a/app/components/ui/editor/MotionMenu.tsx+++ b/app/components/ui/editor/MotionMenu.tsx@@ -27,7 +27,7 @@ export function MotionMenu({onAddOrReplacePreset,onUpdateSelectedFragment,mediaType = "video",- isGlobalMotionEnabled = false,+ isGlobalMotionEnabled = true,onToggleGlobalMotion,}: MotionMenuProps) {const t = useTranslations("motionMenu");diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsxindex b7616af..0547508 100644--- a/app/components/ui/editor/Timeline.tsx+++ b/app/components/ui/editor/Timeline.tsx@@ -11,6 +11,8 @@ import { VideoClipTrackItem } from "./VideoClipTrackItem";import { Icon } from "@iconify/react";import { useTranslations } from "next-intl";import { MockupMotionTrackItem } from "./MockupMotionTrackItem";+import { assignAudioLanes } from "@/lib/audio.utils";+import { MIN_VISUAL_WIDTH_PX } from "@/types";const DEFAULT_ZOOM_FRAGMENT_DURATION = 2;@@ -68,6 +70,7 @@ export function Timeline({const ghostRafRef = useRef<number | null>(null);const pendingGhostXRef = useRef<number | null>(null);const lastValidPositionRef = useRef<{ startTime: number; endTime: number } | null>(null);+const isOverFragment = useMemo(() => {return hoveredFragmentId ? zoomFragments.some(f => f.id === hoveredFragmentId) : false;}, [hoveredFragmentId, zoomFragments]);@@ -75,6 +78,7 @@ export function Timeline({const isDraggingZoomFragment = useMemo(() => {return draggingFragmentId ? zoomFragments.some(f => f.id === draggingFragmentId) : false;}, [draggingFragmentId, zoomFragments]);+const validDuration = useMemo(() => {if (videoClips.length > 0) {const lastClipEnd = Math.max(...videoClips.map(c => c.startTime + (c.trimEnd - c.trimStart)));@@ -109,9 +113,11 @@ export function Timeline({useEffect(() => {contentWidthMotion.set(contentWidth);}, [contentWidth, contentWidthMotion]);+useEffect(() => {timelineWidthMotion.set(timelineWidth);}, [timelineWidth, timelineWidthMotion]);+useEffect(() => {validDurationMotion.set(validDuration);}, [validDuration, validDurationMotion]);@@ -136,6 +142,18 @@ export function Timeline({return (trimRange.end / scaledDuration) * contentWidth;}, [trimRange.end, scaledDuration, contentWidth]);+ const audioLanes = useMemo(() => {+ if (audioTracks.length === 0 || contentWidth === 0 || scaledDuration === 0) {+ return new Map<string, number>();+ }+ const timeToPx = (time: number) => (time / scaledDuration) * contentWidth;+ return assignAudioLanes(audioTracks, timeToPx, MIN_VISUAL_WIDTH_PX);+ }, [audioTracks, contentWidth, scaledDuration]);++ const audioLaneCount = useMemo(+ () => (audioLanes.size > 0 ? Math.max(...audioLanes.values()) + 1 : 1),+ [audioLanes],+ );useEffect(() => {if (!isDraggingTrim) {trimStartX.set(trimStartPosition);@@ -370,10 +388,10 @@ export function Timeline({return (<div ref={containerRef} className="flex flex-col w-full pr-2"><div className={`${(audioTracks.length > 0 && mockupMotionFragments.length > 0)- ? 'h-64'- : (audioTracks.length > 0 || mockupMotionFragments.length > 0)- ? 'h-50'- : 'h-38'+ ? 'h-64'+ : (audioTracks.length > 0 || mockupMotionFragments.length > 0)+ ? 'h-50'+ : 'h-38'} shrink-0 bg-[#0D0D11] border-t border-white/10 flex flex-col font-mono text-[11px]`}><div className="flex-1 flex flex-col relative overflow-hidden">@@ -647,10 +665,14 @@ export function Timeline({</div>{audioTracks.length > 0 && (- <div className="min-h-[55px] shrink-0 w-full flex items-center relative">- <div className="h-full w-full flex items-center relative">+ <div className="shrink-0 w-full relative" style={{ minHeight: audioLaneCount * 55 }}>+ <div className="h-full w-full relative">{audioTracks.map((track) => {const audio = uploadedAudios?.find(a => a.id === track.audioId);+ const trackLane = audioLanes.get(track.id) ?? 0;+ const sameLaneOtherTracks = audioTracks.filter(+ (t) => t.id !== track.id && (audioLanes.get(t.id) ?? 0) === trackLane+ );return (<AudioFragmentTrackItemkey={track.id}@@ -661,7 +683,10 @@ export function Timeline({videoDuration={scaledDuration}contentDuration={validDuration}speed={speed}- otherTracks={audioTracks.filter(t => t.id !== track.id)}+ lane={trackLane}+ laneHeight={55}+ laneCount={audioLaneCount}+ otherTracks={sameLaneOtherTracks}onSelect={() => onSelectAudioTrack?.(track.id)}onUpdate={(updates) => onUpdateAudioTrack?.(track.id, updates)}/>diff --git a/app/globals.css b/app/globals.cssindex 2aa6b10..19d6244 100644--- a/app/globals.css+++ b/app/globals.css@@ -391,4 +391,12 @@ button {opacity: 0;animation: fadeInUp 1s cubic-bezier(0.22, 1, 0.36, 1) forwards;animation-delay: 0.4s;+}++@keyframes shake {+ 0%, 100% { transform: translateX(0); }+ 20% { transform: translateX(-2px); }+ 40% { transform: translateX(2px); }+ 60% { transform: translateX(-1px); }+ 80% { transform: translateX(1px); }}\ No newline at end of filediff --git a/components/ui/SoundCard.tsx b/components/ui/SoundCard.tsxnew file mode 100644index 0000000..ac118e7--- /dev/null+++ b/components/ui/SoundCard.tsx@@ -0,0 +1,51 @@+"use client";+import { useState } from "react";+import { Icon } from "@iconify/react";+import { play, type SoundName } from "@/lib/sounds";+import { SOUND_VISUALS } from "./sound-visuals";++type SoundCardProps = {+ sound: SoundName;+ isRendering: boolean;+ onAdd: (sound: SoundName) => void;+};++export function SoundCard({ sound, isRendering, onAdd }: SoundCardProps) {+ const [active, setActive] = useState(false);+ const Visual = SOUND_VISUALS[sound];++ const trigger = () => {+ if (active) return;+ setActive(true);+ play(sound);+ };++ return (+ <div+ className="flex items-center gap-2 px-2 py-2 rounded-md border border-white/5 hover:border-white/10 hover:bg-white/5 transition-colors"+ onMouseEnter={trigger}+ onMouseLeave={() => setActive(false)}+ onFocus={trigger}+ onBlur={() => setActive(false)}+ tabIndex={0}+ role="button"+ aria-label={sound}+ >+ <div className="w-9 h-8 shrink-0 flex items-center justify-center rounded bg-black/20">+ <Visual active={active} />+ </div>+ <span className="flex-1 text-xs text-white/60 truncate">{sound}</span>+ <button+ onClick={(e) => {+ e.stopPropagation();+ onAdd(sound);+ }}+ disabled={isRendering}+ className="p-1 rounded text-white/40 hover:text-blue-400 hover:bg-blue-500/10 shrink-0"+ aria-label={`add-${sound}`}+ >+ <Icon icon={isRendering ? "svg-spinners:180-ring" : "mdi:plus"} width="14" />+ </button>+ </div>+ );+}\ No newline at end of filediff --git a/components/ui/SoundLibrary.tsx b/components/ui/SoundLibrary.tsxnew file mode 100644index 0000000..e6f9d8b--- /dev/null+++ b/components/ui/SoundLibrary.tsx@@ -0,0 +1,26 @@+"use client";+import type { SoundName } from "@/lib/sounds";+import { SoundCard } from "./SoundCard";++type SoundLibraryProps = {+ categories: { label: string; sounds: SoundName[] }[];+ renderingSound: SoundName | null;+ onAdd: (sound: SoundName) => void;+};++export function SoundLibrary({ categories, renderingSound, onAdd }: SoundLibraryProps) {+ return (+ <div className="flex flex-col gap-4">+ {categories.map(({ label, sounds }) => (+ <div key={label} className="flex flex-col gap-1.5">+ <div className="text-[12px] tracking-wide text-white/70">{label}</div>+ <div className="grid grid-cols-2 gap-1.5">+ {sounds.map((sound) => (+ <SoundCard key={sound} sound={sound} isRendering={renderingSound === sound} onAdd={onAdd} />+ ))}+ </div>+ </div>+ ))}+ </div>+ );+}\ No newline at end of filediff --git a/components/ui/sound-visuals.tsx b/components/ui/sound-visuals.tsxnew file mode 100644index 0000000..4831cca--- /dev/null+++ b/components/ui/sound-visuals.tsx@@ -0,0 +1,171 @@+"use client";+import { Icon } from "@iconify/react";+import type { SoundName } from "@/lib/sounds";++export type VisualProps = { active: boolean };+++function ChimeVisual({ active }: VisualProps) {+ return (+ <div className="relative flex items-end justify-center gap-1 h-5">+ <span className={`w-1.5 h-1.5 rounded-full bg-sky-400 transition-all duration-300 ${active ? "opacity-100 -translate-y-1 scale-125" : "opacity-40 translate-y-0"}`} />+ <span className={`w-1.5 h-1.5 rounded-full bg-sky-300 transition-all duration-300 delay-150 ${active ? "opacity-100 -translate-y-2.5 scale-125" : "opacity-30 translate-y-0"}`} />+ </div>+ );+}++function SparkleVisual({ active }: VisualProps) {+ return (+ <div className="relative w-8 h-6">+ {[0, 1, 2, 3].map((i) => (+ <span+ key={i}+ className={`absolute w-1 h-1 rounded-full bg-amber-300 transition-all ${active ? "opacity-100 scale-100" : "opacity-0 scale-0"}`}+ style={{ left: i * 7, bottom: i * 4, transitionDelay: active ? `${i * 45}ms` : "0ms", transitionDuration: "180ms" }}+ />+ ))}+ </div>+ );+}++function ReadyVisual({ active }: VisualProps) {+ const corner = "absolute w-2 h-2 border-emerald-300/70 transition-transform duration-200";+ return (+ <div className="relative w-6 h-6">+ <span className={`${corner} top-0 left-0 border-t border-l ${active ? "translate-x-0.5 translate-y-0.5" : ""}`} />+ <span className={`${corner} top-0 right-0 border-t border-r ${active ? "-translate-x-0.5 translate-y-0.5" : ""}`} />+ <span className={`${corner} bottom-0 left-0 border-b border-l ${active ? "translate-x-0.5 -translate-y-0.5" : ""}`} />+ <span className={`${corner} bottom-0 right-0 border-b border-r ${active ? "-translate-x-0.5 -translate-y-0.5" : ""}`} />+ <span className={`absolute inset-0 m-auto w-1 h-1 rounded-full bg-emerald-300 transition-opacity duration-150 delay-150 ${active ? "opacity-100" : "opacity-0"}`} />+ </div>+ );+}++function ErrorVisual({ active }: VisualProps) {+ return (+ <div className={`w-4 h-4 rounded-full border border-red-400/50 flex items-center justify-center ${active ? "animate-[shake_300ms_ease-in-out]" : ""}`}>+ <Icon icon="mdi:close" width="10" className="text-red-400/80" />+ </div>+ );+}++function TickVisual({ active }: VisualProps) {+ return (+ <div className={`w-4 h-4 rounded-[3px] border flex items-center justify-center transition-colors duration-150 ${active ? "bg-orange-400 border-orange-400" : "border-white/25"}`}>+ <Icon icon="mdi:check" width="10" className={`text-black transition-transform duration-150 ${active ? "scale-100" : "scale-0"}`} />+ </div>+ );+}++function PressVisual({ active }: VisualProps) {+ return <div className={`w-6 h-4 rounded border transition-all duration-100 ${active ? "translate-y-0.5 bg-white/5 shadow-inner border-white/10" : "border-white/20"}`} />;+}++function ReleaseVisual({ active }: VisualProps) {+ return <div className={`w-6 h-4 rounded border transition-all ${active ? "-translate-y-0.5 border-emerald-400/50 bg-emerald-400/10 duration-150 ease-out" : "translate-y-0 border-white/20 duration-100"}`} />;+}++function ToggleVisual({ active }: VisualProps) {+ return (+ <div className={`w-7 h-4 rounded-full flex items-center px-0.5 transition-colors duration-200 ${active ? "bg-fuchsia-500/70 justify-end" : "bg-white/15 justify-start"}`}>+ <span className="w-3 h-3 rounded-full bg-white" />+ </div>+ );+}++function PulseVisual({ active }: VisualProps) {+ return (+ <div className="relative w-5 h-5 flex items-center justify-center">+ {active && <span className="absolute inset-0 rounded-full bg-violet-400/40 animate-ping" />}+ <span className="relative w-2.5 h-2.5 rounded-full bg-violet-400" />+ </div>+ );+}++function ScanVisual({ active }: VisualProps) {+ return (+ <div className="relative w-8 h-3 flex items-center">+ <span className="absolute inset-x-0 top-1/2 border-b border-white/10" />+ <span className={`absolute w-1 h-1 rounded-full bg-teal-300 ease-linear ${active ? "left-[26px] transition-all duration-500" : "left-0"}`} />+ </div>+ );+}++function PageVisual({ active }: VisualProps) {+ return (+ <div className="relative w-7 h-6 flex items-center justify-center">+ <span className={`absolute w-4 h-5 rounded-sm bg-white/10 border border-white/15 transition-all duration-250 ease-out ${active ? "-translate-x-1.5 -rotate-6 opacity-40" : "opacity-70"}`} />+ <span className={`absolute w-4 h-5 rounded-sm bg-white/15 border border-white/20 transition-all duration-250 ease-out ${active ? "translate-x-1 rotate-3" : ""}`} />+ </div>+ );+}++function DropletVisual({ active }: VisualProps) {+ return (+ <div className="relative w-6 h-6 flex items-center justify-center">+ <span className={`absolute w-1.5 h-2 rounded-b-full rounded-t-sm bg-cyan-300 transition-all duration-300 ease-in ${active ? "translate-y-1.5 opacity-0" : "-translate-y-1.5 opacity-100"}`} />+ <span className={`absolute w-4 h-1 rounded-full border border-cyan-300/60 transition-all ${active ? "scale-100 opacity-70 duration-300 delay-200" : "scale-0 opacity-0"}`} />+ </div>+ );+}++function BloomVisual({ active }: VisualProps) {+ return (+ <div className="relative w-6 h-6 flex items-center justify-center">+ <span className={`absolute rounded-full bg-pink-400/30 transition-all duration-500 ease-out ${active ? "w-6 h-6 opacity-100" : "w-2 h-2 opacity-50"}`} />+ <span className="relative w-2 h-2 rounded-full bg-pink-300" />+ </div>+ );+}++function ArrivalVisual({ active }: VisualProps) {+ return (+ <div className="relative w-6 h-6 overflow-hidden">+ <span className={`absolute inset-x-0 bottom-0 h-4 rounded-t-sm bg-indigo-400/30 border-t border-indigo-300/50 transition-all duration-400 ease-out ${active ? "translate-y-0 opacity-100" : "translate-y-3 opacity-0"}`} />+ </div>+ );+}++function WhisperVisual({ active }: VisualProps) {+ return (+ <div className="w-8 h-6 flex items-center justify-center">+ <span className={`px-1.5 py-0.5 rounded text-[8px] bg-white/10 text-white/50 transition-all duration-300 ${active ? "opacity-100 translate-y-0" : "opacity-0 translate-y-1"}`}>tip</span>+ </div>+ );+}++function LoadingVisual({ active }: VisualProps) {+ return <Icon icon="mdi:loading" width="16" className={active ? "text-blue-400/80 animate-spin" : "text-blue-400/30"} />;+}++function SuccessVisual({ active }: VisualProps) {+ return (+ <svg width="20" height="20" viewBox="0 0 20 20">+ <circle cx="10" cy="10" r="8" fill="none" stroke="rgb(52 211 153)" strokeWidth="1.5"+ className="transition-[stroke-opacity] duration-300" strokeOpacity={active ? 1 : 0.25} />+ <path d="M6 10.5l2.5 2.5L14 7.5" fill="none" stroke="rgb(52 211 153)" strokeWidth="1.5"+ strokeLinecap="round" strokeLinejoin="round"+ style={{ strokeDasharray: 1, pathLength: 1, strokeDashoffset: active ? 0 : 1, transition: "stroke-dashoffset 300ms ease-out" } as React.CSSProperties} />+ </svg>+ );+}++export const SOUND_VISUALS: Record<SoundName, React.FC<VisualProps>> = {+ chime: ChimeVisual,+ sparkle: SparkleVisual,+ ready: ReadyVisual,+ success: SuccessVisual,+ error: ErrorVisual,+ tick: TickVisual,+ press: PressVisual,+ release: ReleaseVisual,+ toggle: ToggleVisual,+ pulse: PulseVisual,+ scan: ScanVisual,+ page: PageVisual,+ droplet: DropletVisual,+ bloom: BloomVisual,+ arrival: ArrivalVisual,+ whisper: WhisperVisual,+ loading: LoadingVisual,+};\ No newline at end of filediff --git a/lib/audio.utils.ts b/lib/audio.utils.tsnew file mode 100644index 0000000..91cc219--- /dev/null+++ b/lib/audio.utils.ts@@ -0,0 +1,50 @@+import type { AudioTrack } from "@/types/audio.types";++interface LaneBox {+ startPx: number;+ endPx: number;+}++function computeBox(+ track: AudioTrack,+ timeToPixels: (time: number) => number,+ minVisualWidthPx: number,+): LaneBox {+ const startPx = timeToPixels(track.startTime);+ const rawWidthPx = timeToPixels(track.startTime + track.duration) - startPx;+ return { startPx, endPx: startPx + Math.max(rawWidthPx, minVisualWidthPx) };+}++export function assignAudioLanes(+ tracks: AudioTrack[],+ timeToPixels: (time: number) => number,+ minVisualWidthPx: number,+): Map<string, number> {+ const laneEndPx = new Map<number, number>();+ const laneOf = new Map<string, number>();++ const pinned = tracks+ .filter((t) => t.lane !== undefined)+ .sort((a, b) => a.startTime - b.startTime);+ const unpinned = tracks+ .filter((t) => t.lane === undefined)+ .sort((a, b) => a.startTime - b.startTime);++ for (const t of pinned) {+ const { startPx, endPx } = computeBox(t, timeToPixels, minVisualWidthPx);+ let lane = t.lane!;+ while ((laneEndPx.get(lane) ?? 0) > startPx) lane++;+ laneEndPx.set(lane, endPx);+ laneOf.set(t.id, lane);+ }++ for (const t of unpinned) {+ const { startPx, endPx } = computeBox(t, timeToPixels, minVisualWidthPx);+ let lane = 0;+ while ((laneEndPx.get(lane) ?? 0) > startPx) lane++;+ laneEndPx.set(lane, endPx);+ laneOf.set(t.id, lane);+ }++ return laneOf;+}diff --git a/lib/sounds/engine.ts b/lib/sounds/engine.tsnew file mode 100644index 0000000..a97bd35--- /dev/null+++ b/lib/sounds/engine.ts@@ -0,0 +1,245 @@+import {+ RECIPES,+ isSoundName,+ type NoiseLayer,+ type Shimmer,+ type SoundName,+ type SoundRecipe,+ type ToneLayer,+} from "./recipes";++const SOURCE_STOP_PADDING = 0.05;+const CLEANUP_MARGIN = 0.05;+const INAUDIBLE_GAIN = 0.001;+const OUTPUT_GAIN = 4;++function renderTone(+ context: BaseAudioContext,+ destination: AudioNode,+ layer: ToneLayer,+ startTime: number,+): void {+ const oscillator = context.createOscillator();+ oscillator.type = layer.waveform;+ oscillator.frequency.setValueAtTime(layer.frequency, startTime);+ if (layer.detune) oscillator.detune.value = layer.detune;++ if (layer.glideTo !== undefined) {+ const glideTime = layer.glideTime ?? layer.attack + layer.decay;+ oscillator.frequency.exponentialRampToValueAtTime(layer.glideTo, startTime + glideTime);+ }++ const gain = context.createGain();+ gain.gain.setValueAtTime(0.0001, startTime);+ gain.gain.exponentialRampToValueAtTime(layer.peak, startTime + layer.attack);+ gain.gain.exponentialRampToValueAtTime(0.0001, startTime + layer.attack + layer.decay);++ oscillator.connect(gain).connect(destination);+ oscillator.start(startTime);+ oscillator.stop(startTime + layer.attack + layer.decay + SOURCE_STOP_PADDING);+}++function renderNoise(+ context: BaseAudioContext,+ destination: AudioNode,+ layer: NoiseLayer,+ startTime: number,+): void {+ const duration = layer.attack + layer.decay + SOURCE_STOP_PADDING;+ const length = Math.max(1, Math.floor(duration * context.sampleRate));+ const buffer = context.createBuffer(1, length, context.sampleRate);+ const data = buffer.getChannelData(0);+ for (let i = 0; i < length; i++) data[i] = 2 * Math.random() - 1;++ const source = context.createBufferSource();+ source.buffer = buffer;++ const filter = context.createBiquadFilter();+ filter.type = layer.filterType;+ filter.frequency.value = layer.filterFrequency;+ if (layer.filterQ !== undefined) filter.Q.value = layer.filterQ;++ const gain = context.createGain();+ gain.gain.setValueAtTime(0.0001, startTime);+ gain.gain.exponentialRampToValueAtTime(layer.peak, startTime + layer.attack);+ gain.gain.exponentialRampToValueAtTime(0.0001, startTime + layer.attack + layer.decay);++ source.connect(filter).connect(gain).connect(destination);+ source.start(startTime);+ source.stop(startTime + duration);+}++function attachShimmer(+ context: BaseAudioContext,+ source: AudioNode,+ destination: AudioNode,+ shimmer: Shimmer,+): AudioNode[] {+ const delay = context.createDelay(1);+ delay.delayTime.value = shimmer.delay;++ const feedbackFilter = context.createBiquadFilter();+ feedbackFilter.type = "lowpass";+ feedbackFilter.frequency.value = shimmer.lowpass;++ const feedbackGain = context.createGain();+ feedbackGain.gain.value = shimmer.feedback;++ const wetGain = context.createGain();+ wetGain.gain.value = shimmer.wet;++ source.connect(delay);+ delay.connect(feedbackFilter);+ feedbackFilter.connect(feedbackGain);+ feedbackGain.connect(delay);+ feedbackFilter.connect(wetGain);+ wetGain.connect(destination);++ return [delay, feedbackFilter, feedbackGain, wetGain];+}++export function sourceEnd(recipe: SoundRecipe): number {+ return Math.max(+ ...recipe.layers.map(+ (layer) => (layer.offset ?? 0) + layer.attack + layer.decay + SOURCE_STOP_PADDING,+ ),+ );+}++export function shimmerTail(shimmer?: Shimmer): number {+ if (!shimmer || shimmer.feedback <= 0) return 0;+ if (shimmer.feedback >= 1) return shimmer.delay;++ return shimmer.delay * (1 + Math.ceil(Math.log(INAUDIBLE_GAIN) / Math.log(shimmer.feedback)));+}++let sharedOutput: GainNode | null = null;++function getOutput(context: AudioContext): GainNode {+ if (sharedOutput) return sharedOutput;++ const output = context.createGain();+ output.gain.value = OUTPUT_GAIN;++ const limiter = context.createDynamicsCompressor();+ limiter.threshold.value = -8;+ limiter.knee.value = 6;+ limiter.ratio.value = 12;+ limiter.attack.value = 0.002;+ limiter.release.value = 0.08;++ output.connect(limiter).connect(context.destination);+ sharedOutput = output;+ return output;+}++function renderRecipe(context: AudioContext, recipe: SoundRecipe, volume: number): void {+ const now = context.currentTime;+ const output = getOutput(context);+ const master = context.createGain();+ master.gain.value = recipe.masterGain * volume;+ master.connect(output);++ const shimmerNodes = recipe.shimmer+ ? attachShimmer(context, master, output, recipe.shimmer)+ : [];++ for (const layer of recipe.layers) {+ const startTime = now + (layer.offset ?? 0);+ if (layer.kind === "tone") renderTone(context, master, layer, startTime);+ else renderNoise(context, master, layer, startTime);+ }++ const cleanupAfterMs = (sourceEnd(recipe) + shimmerTail(recipe.shimmer) + CLEANUP_MARGIN) * 1000;+ setTimeout(() => {+ master.disconnect();+ for (const node of shimmerNodes) node.disconnect();+ }, cleanupAfterMs);+}++export function renderRecipeOffline(context: OfflineAudioContext, recipe: SoundRecipe): void {+ const now = context.currentTime;+ const master = context.createGain();+ master.gain.value = recipe.masterGain;++ const limiter = context.createDynamicsCompressor();+ limiter.threshold.value = -8;+ limiter.knee.value = 6;+ limiter.ratio.value = 12;+ limiter.attack.value = 0.002;+ limiter.release.value = 0.08;++ const output = context.createGain();+ output.gain.value = OUTPUT_GAIN;++ master.connect(output);+ output.connect(limiter).connect(context.destination);++ if (recipe.shimmer) attachShimmer(context, master, output, recipe.shimmer);++ for (const layer of recipe.layers) {+ const startTime = now + (layer.offset ?? 0);+ if (layer.kind === "tone") renderTone(context, master, layer, startTime);+ else renderNoise(context, master, layer, startTime);+ }+}++let sharedContext: AudioContext | null = null;+let enabled = true;+let globalVolume = 1;++function normalizeVolume(value: unknown, fallback: number): number {+ return typeof value === "number" && Number.isFinite(value)+ ? Math.min(1, Math.max(0, value))+ : fallback;+}++export function setEnabled(value: boolean): void {+ if (typeof value === "boolean") enabled = value;+}++export function setVolume(value: number): void {+ globalVolume = normalizeVolume(value, globalVolume);+}++function getAudioContext(): AudioContext | null {+ if (sharedContext) return sharedContext;+ if (typeof window === "undefined") return null;+ const Ctor =+ window.AudioContext ??+ (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;+ if (!Ctor) return null;+ try {+ sharedContext = new Ctor();+ } catch {+ return null;+ }+ return sharedContext;+}++export function play(sound: SoundName = "chime", options?: { volume?: number }): void {+ if (!enabled || !isSoundName(sound)) return;+ if (typeof navigator !== "undefined" && navigator.userActivation?.hasBeenActive === false) return;++ const playVolume = globalVolume * normalizeVolume(options?.volume, 1);+ if (playVolume === 0) return;++ const context = getAudioContext();+ if (!context) return;++ const recipe = RECIPES[sound];+ if (context.state === "running") {+ renderRecipe(context, recipe, playVolume);+ } else {+ try {+ void context.resume().then(+ () => {+ if (enabled && context.state === "running") renderRecipe(context, recipe, playVolume);+ },+ () => {},+ );+ } catch {++ }+ }+}\ No newline at end of filediff --git a/lib/sounds/index.ts b/lib/sounds/index.tsnew file mode 100644index 0000000..cad2bcb--- /dev/null+++ b/lib/sounds/index.ts@@ -0,0 +1,3 @@+export { play, setEnabled, setVolume } from "./engine";+export { renderSoundToBuffer, renderSoundToFile } from "./offline-render";+export { RECIPES, isSoundName, sounds, type SoundName, type SoundRecipe } from "./recipes";\ No newline at end of filediff --git a/lib/sounds/offline-render.ts b/lib/sounds/offline-render.tsnew file mode 100644index 0000000..4efd108--- /dev/null+++ b/lib/sounds/offline-render.ts@@ -0,0 +1,33 @@+import { RECIPES, type SoundName, type SoundRecipe } from "./recipes";+import { renderRecipeOffline, sourceEnd, shimmerTail } from "./engine";+import { audioBufferToWavBlob } from "./wav-encoder";++const CLEANUP_MARGIN = 0.05;++function soundLength(recipe: SoundRecipe): number {+ return sourceEnd(recipe) + shimmerTail(recipe.shimmer) + CLEANUP_MARGIN;+}++export async function renderSoundToBuffer(+ sound: SoundName,+ sampleRate = 44100,+): Promise<AudioBuffer> {+ const recipe = RECIPES[sound];+ const duration = soundLength(recipe);+ const offlineCtx = new OfflineAudioContext(2, Math.ceil(duration * sampleRate), sampleRate);+ renderRecipeOffline(offlineCtx, recipe);+ return offlineCtx.startRendering();+}++const fileCache = new Map<SoundName, File>();++export async function renderSoundToFile(sound: SoundName): Promise<File> {+ const cached = fileCache.get(sound);+ if (cached) return cached;++ const buffer = await renderSoundToBuffer(sound);+ const blob = audioBufferToWavBlob(buffer);+ const file = new File([blob], `${sound}.wav`, { type: "audio/wav" });+ fileCache.set(sound, file);+ return file;+}\ No newline at end of filediff --git a/lib/sounds/recipes.ts b/lib/sounds/recipes.tsnew file mode 100644index 0000000..8e1c521--- /dev/null+++ b/lib/sounds/recipes.ts@@ -0,0 +1,201 @@+type BaseLayer = {+ offset?: number;+ attack: number;+ decay: number;+ peak: number;+};++export type ToneLayer = BaseLayer & {+ kind: "tone";+ waveform: OscillatorType;+ frequency: number;+ detune?: number;+ glideTo?: number;+ glideTime?: number;+};++export type NoiseLayer = BaseLayer & {+ kind: "noise";+ filterType: BiquadFilterType;+ filterFrequency: number;+ filterQ?: number;+};++export type SoundLayer = ToneLayer | NoiseLayer;++export type Shimmer = {+ delay: number;+ feedback: number;+ wet: number;+ lowpass: number;+};++export type SoundRecipe = {+ masterGain: number;+ layers: SoundLayer[];+ shimmer?: Shimmer;+};++export const RECIPES = {+ /** A soft two-note ascending bell, like an iOS/macOS confirmation tink. */+ chime: {+ masterGain: 0.5,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 1046.5, attack: 0.006, decay: 0.22, peak: 0.09 },+ { kind: "tone", waveform: "sine", frequency: 1568, offset: 0.09, attack: 0.006, decay: 0.26, peak: 0.08 },+ ],+ shimmer: { delay: 0.12, feedback: 0.25, wet: 0.18, lowpass: 4000 },+ },+ /** A quick ascending twinkle of four notes — bright and playful. */+ sparkle: {+ masterGain: 0.5,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 1760, offset: 0, attack: 0.003, decay: 0.09, peak: 0.045 },+ { kind: "tone", waveform: "sine", frequency: 2217, offset: 0.045, attack: 0.003, decay: 0.09, peak: 0.04 },+ { kind: "tone", waveform: "sine", frequency: 2637, offset: 0.09, attack: 0.003, decay: 0.1, peak: 0.038 },+ { kind: "tone", waveform: "sine", frequency: 3520, offset: 0.135, attack: 0.003, decay: 0.12, peak: 0.032 },+ ],+ shimmer: { delay: 0.07, feedback: 0.35, wet: 0.22, lowpass: 6000 },+ },+ /** A single note gliding smoothly downward, like a drop of water. */+ droplet: {+ masterGain: 0.55,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 1200, glideTo: 550, glideTime: 0.14, attack: 0.004, decay: 0.2, peak: 0.075 },+ ],+ shimmer: { delay: 0.09, feedback: 0.2, wet: 0.15, lowpass: 3000 },+ },+ /** A warm, slow-swelling pad from two gently detuned sines. */+ bloom: {+ masterGain: 0.5,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 528, attack: 0.06, decay: 0.32, peak: 0.06 },+ { kind: "tone", waveform: "sine", frequency: 528, detune: 12, attack: 0.06, decay: 0.34, peak: 0.05 },+ ],+ shimmer: { delay: 0.15, feedback: 0.2, wet: 0.12, lowpass: 2500 },+ },+ /** A soft hush with a falling tone — for tooltips and low-priority previews. */+ whisper: {+ masterGain: 0.48,+ layers: [+ { kind: "noise", filterType: "lowpass", filterFrequency: 1600, filterQ: 0.7, attack: 0.025, decay: 0.13, peak: 0.04 },+ { kind: "tone", waveform: "sine", frequency: 880, glideTo: 660, glideTime: 0.14, offset: 0.01, attack: 0.012, decay: 0.14, peak: 0.025 },+ ],+ },+ /** A focused, bandpass-filtered tick with a bright sine ping on top — crisp and instant. */+ tick: {+ masterGain: 0.4,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 5400, filterQ: 1.8, attack: 0.001, decay: 0.018, peak: 0.14 },+ { kind: "tone", waveform: "sine", frequency: 2600, attack: 0.001, decay: 0.012, peak: 0.018 },+ ],+ },+ /** A dull, muted knock — the "down" half of a press/release pair, like a key bottoming out. */+ press: {+ masterGain: 0.4,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 1700, filterQ: 1.4, attack: 0.001, decay: 0.02, peak: 0.13 },+ ],+ },+ /** A brighter, springier tick — the "up" half of a press/release pair, like a key returning. */+ release: {+ masterGain: 0.4,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 4600, filterQ: 1.8, attack: 0.001, decay: 0.016, peak: 0.12 },+ { kind: "tone", waveform: "sine", frequency: 3200, offset: 0.006, attack: 0.001, decay: 0.05, peak: 0.02 },+ ],+ },+ /** A two-part click-clack, like a mechanical switch flipping between states. */+ toggle: {+ masterGain: 0.4,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 2200, filterQ: 1.6, attack: 0.001, decay: 0.016, peak: 0.12 },+ { kind: "noise", filterType: "bandpass", filterFrequency: 3800, filterQ: 1.6, offset: 0.024, attack: 0.001, decay: 0.02, peak: 0.1 },+ ],+ },+ /** A short, warm three-note ascending confirmation — "done", not a fanfare. */+ success: {+ masterGain: 0.5,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 880, attack: 0.004, decay: 0.09, peak: 0.06 },+ { kind: "tone", waveform: "sine", frequency: 1108.73, offset: 0.06, attack: 0.004, decay: 0.1, peak: 0.06 },+ { kind: "tone", waveform: "sine", frequency: 1318.51, offset: 0.12, attack: 0.004, decay: 0.18, peak: 0.07 },+ ],+ shimmer: { delay: 0.1, feedback: 0.22, wet: 0.16, lowpass: 4500 },+ },+ /** A muted knock followed by two descending tones — a calm, recoverable refusal. */+ error: {+ masterGain: 0.42,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 850, filterQ: 1.1, attack: 0.001, decay: 0.035, peak: 0.13 },+ { kind: "tone", waveform: "triangle", frequency: 440, offset: 0.025, attack: 0.004, decay: 0.09, peak: 0.045 },+ { kind: "tone", waveform: "triangle", frequency: 349.23, offset: 0.1, attack: 0.004, decay: 0.14, peak: 0.04 },+ ],+ },+ /** A papery filtered flick with a tiny glass tick — for pages, galleries, and carousels. */+ page: {+ masterGain: 0.38,+ layers: [+ { kind: "noise", filterType: "lowpass", filterFrequency: 1800, filterQ: 0.7, attack: 0.006, decay: 0.08, peak: 0.11 },+ { kind: "noise", filterType: "bandpass", filterFrequency: 4200, filterQ: 1.2, offset: 0.04, attack: 0.004, decay: 0.065, peak: 0.08 },+ { kind: "tone", waveform: "sine", frequency: 2400, offset: 0.075, attack: 0.002, decay: 0.045, peak: 0.02 },+ ],+ },+ /** A brief unresolved lift — signals that user-initiated work has started. */+ loading: {+ masterGain: 0.42,+ layers: [+ { kind: "noise", filterType: "lowpass", filterFrequency: 1400, filterQ: 0.6, attack: 0.035, decay: 0.14, peak: 0.035 },+ { kind: "tone", waveform: "sine", frequency: 420, glideTo: 630, glideTime: 0.18, attack: 0.025, decay: 0.18, peak: 0.05 },+ ],+ shimmer: { delay: 0.11, feedback: 0.18, wet: 0.12, lowpass: 2800 },+ },+ /** A quick lock-on sweep resolving to a clear tone — the system is ready. */+ ready: {+ masterGain: 0.48,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 3600, filterQ: 1.8, attack: 0.001, decay: 0.02, peak: 0.11 },+ { kind: "tone", waveform: "triangle", frequency: 330, glideTo: 660, glideTime: 0.12, offset: 0.012, attack: 0.004, decay: 0.16, peak: 0.055 },+ { kind: "tone", waveform: "sine", frequency: 990, offset: 0.13, attack: 0.004, decay: 0.22, peak: 0.06 },+ ],+ shimmer: { delay: 0.1, feedback: 0.16, wet: 0.1, lowpass: 4200 },+ },+ /** A compact synthetic chirp — crisp feedback for primary buttons and controls. */+ pulse: {+ masterGain: 0.42,+ layers: [+ { kind: "noise", filterType: "bandpass", filterFrequency: 2600, filterQ: 2.4, attack: 0.001, decay: 0.022, peak: 0.08 },+ { kind: "tone", waveform: "triangle", frequency: 620, glideTo: 1240, glideTime: 0.07, attack: 0.002, decay: 0.085, peak: 0.055 },+ ],+ },+ /** A fast three-step locator signal — playful feedback for menus and secondary buttons. */+ scan: {+ masterGain: 0.4,+ layers: [+ { kind: "tone", waveform: "sine", frequency: 740, attack: 0.002, decay: 0.055, peak: 0.05 },+ { kind: "tone", waveform: "sine", frequency: 1110, offset: 0.045, attack: 0.002, decay: 0.055, peak: 0.045 },+ { kind: "tone", waveform: "sine", frequency: 1665, offset: 0.09, attack: 0.002, decay: 0.07, peak: 0.04 },+ ],+ shimmer: { delay: 0.065, feedback: 0.16, wet: 0.1, lowpass: 4200 },+ },+ /** A rising harmonic portal with a soft tail — for client-side page arrivals. */+ arrival: {+ masterGain: 0.44,+ layers: [+ { kind: "noise", filterType: "lowpass", filterFrequency: 900, filterQ: 0.8, attack: 0.05, decay: 0.24, peak: 0.035 },+ { kind: "tone", waveform: "sine", frequency: 220, glideTo: 440, glideTime: 0.32, attack: 0.04, decay: 0.34, peak: 0.055 },+ { kind: "tone", waveform: "sine", frequency: 659.25, offset: 0.12, attack: 0.045, decay: 0.32, peak: 0.04 },+ { kind: "tone", waveform: "sine", frequency: 987.77, offset: 0.19, attack: 0.045, decay: 0.34, peak: 0.032 },+ ],+ shimmer: { delay: 0.16, feedback: 0.28, wet: 0.18, lowpass: 3200 },+ },+} as const satisfies Record<string, SoundRecipe>;++export type SoundName = keyof typeof RECIPES;++export function isSoundName(value: unknown): value is SoundName {+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(RECIPES, value);+}++/** All available sound names, derived from the recipe palette. */+export const sounds = Object.keys(RECIPES) as readonly SoundName[];\ No newline at end of filediff --git a/lib/sounds/wav-encoder.ts b/lib/sounds/wav-encoder.tsnew file mode 100644index 0000000..683897f--- /dev/null+++ b/lib/sounds/wav-encoder.ts@@ -0,0 +1,38 @@+export function audioBufferToWavBlob(buffer: AudioBuffer): Blob {+ const numChannels = buffer.numberOfChannels;+ const sampleRate = buffer.sampleRate;+ const bytesPerSample = 2;+ const blockAlign = numChannels * bytesPerSample;+ const dataSize = buffer.length * blockAlign;+ const bufferArray = new ArrayBuffer(44 + dataSize);+ const view = new DataView(bufferArray);++ const writeStr = (offset: number, str: string) => {+ for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));+ };++ writeStr(0, "RIFF");+ view.setUint32(4, 36 + dataSize, true);+ writeStr(8, "WAVE");+ writeStr(12, "fmt ");+ view.setUint32(16, 16, true);+ view.setUint16(20, 1, true);+ view.setUint16(22, numChannels, true);+ view.setUint32(24, sampleRate, true);+ view.setUint32(28, sampleRate * blockAlign, true);+ view.setUint16(32, blockAlign, true);+ view.setUint16(34, bytesPerSample * 8, true);+ writeStr(36, "data");+ view.setUint32(40, dataSize, true);++ const channels = Array.from({ length: numChannels }, (_, i) => buffer.getChannelData(i));+ let offset = 44;+ for (let i = 0; i < buffer.length; i++) {+ for (let ch = 0; ch < numChannels; ch++) {+ const sample = Math.max(-1, Math.min(1, channels[ch][i]));+ view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);+ offset += 2;+ }+ }+ return new Blob([bufferArray], { type: "audio/wav" });+}\ No newline at end of filediff --git a/types/audio.types.ts b/types/audio.types.tsindex 4e300f4..9e9cc1f 100644--- a/types/audio.types.ts+++ b/types/audio.types.ts@@ -7,6 +7,7 @@ export interface AudioTrack {volume: number;loop: boolean;trimStart?: number;+ lane?: number;}export interface UploadedAudio {@@ -61,6 +62,8 @@ export interface AudioMenuProps {onAudioUpload: (file: File) => void;onUpdateAudioTrack: (trackId: string, updates: Partial<AudioTrack>) => void;onDeleteAudioTrack: (trackId: string) => void;+ selectedAudioTrackId: string | null;+ onSelectAudioTrack: (id: string | null) => void;}export const MIN_FRAGMENT_DURATION = 0.1;@@ -80,4 +83,7 @@ export interface AudioFragmentTrackItemProps {onMouseLeave?: () => void;contentDuration?: number;speed?: number;+ lane?: number;+ laneHeight?: number;+ laneCount?: number;}diff --git a/types/control-panel.types.ts b/types/control-panel.types.tsindex 8c12ae5..75ba893 100644--- a/types/control-panel.types.ts+++ b/types/control-panel.types.ts@@ -98,4 +98,6 @@ export interface ControlPanelProps {onUpdateMockupMotionFragment?: (id: string, updates: Partial<MockupMotionFragment>) => void;onSelectMockupMotionFragment?: (id: string | null) => void;onDeleteMockupMotionFragment?: (id: string) => void;+ selectedAudioTrackId?: string | null;+ setSelectedAudioTrackId?: (trackId: string | null) => void;}