Major improvements: - Fixed multi-file import (FileList to Array conversion) - Auto-select first track when adding to empty project - Global effects panel folding state (independent of track selection) - Effects panel collapsed/disabled when no track selected - Effect device expansion state persisted per-device - Effect browser with searchable descriptions Visual refinements: - Removed center dot from pan knob for cleaner look - Simplified fader: removed volume fill overlay, dynamic level meter visible through semi-transparent handle - Level meter capped at fader position (realistic mixer behavior) - Solid background instead of gradient for fader track - Subtle volume overlay up to fader handle - Fixed track control width flickering (consistent 4px border) - Effect devices: removed shadows/rounded corners for flatter DAW-style look, added consistent border-radius - Added border between track control and waveform area 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
160 lines
5.0 KiB
TypeScript
160 lines
5.0 KiB
TypeScript
'use client';
|
|
|
|
import * as React from 'react';
|
|
import { Upload, Plus } from 'lucide-react';
|
|
import { Modal } from '@/components/ui/Modal';
|
|
import { Button } from '@/components/ui/Button';
|
|
import { decodeAudioFile } from '@/lib/audio/decoder';
|
|
|
|
export interface ImportTrackDialogProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
onImportTrack: (buffer: AudioBuffer, name: string) => void;
|
|
}
|
|
|
|
export function ImportTrackDialog({
|
|
open,
|
|
onClose,
|
|
onImportTrack,
|
|
}: ImportTrackDialogProps) {
|
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
|
|
|
const handleFiles = async (files: FileList) => {
|
|
setIsLoading(true);
|
|
|
|
// Convert FileList to Array to prevent any weird behavior
|
|
const fileArray = Array.from(files);
|
|
console.log(`[ImportTrackDialog] Processing ${fileArray.length} files`, fileArray);
|
|
|
|
try {
|
|
// Process files sequentially
|
|
for (let i = 0; i < fileArray.length; i++) {
|
|
console.log(`[ImportTrackDialog] Loop iteration ${i}, fileArray.length: ${fileArray.length}`);
|
|
const file = fileArray[i];
|
|
console.log(`[ImportTrackDialog] Processing file ${i + 1}/${fileArray.length}: ${file.name}, type: ${file.type}`);
|
|
|
|
if (!file.type.startsWith('audio/')) {
|
|
console.warn(`Skipping non-audio file: ${file.name} (type: ${file.type})`);
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
console.log(`[ImportTrackDialog] Decoding file ${i + 1}/${files.length}: ${file.name}`);
|
|
const buffer = await decodeAudioFile(file);
|
|
const trackName = file.name.replace(/\.[^/.]+$/, ''); // Remove extension
|
|
console.log(`[ImportTrackDialog] Importing track: ${trackName}`);
|
|
onImportTrack(buffer, trackName);
|
|
console.log(`[ImportTrackDialog] Track imported: ${trackName}`);
|
|
} catch (error) {
|
|
console.error(`Failed to import ${file.name}:`, error);
|
|
}
|
|
console.log(`[ImportTrackDialog] Finished processing file ${i + 1}`);
|
|
}
|
|
|
|
console.log('[ImportTrackDialog] Loop completed, all files processed');
|
|
} catch (error) {
|
|
console.error('[ImportTrackDialog] Error in handleFiles:', error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
console.log('[ImportTrackDialog] Closing dialog');
|
|
onClose();
|
|
}
|
|
};
|
|
|
|
const handleFileSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const files = e.target.files;
|
|
if (files && files.length > 0) {
|
|
handleFiles(files);
|
|
}
|
|
// Reset input
|
|
e.target.value = '';
|
|
};
|
|
|
|
const handleDragOver = (e: React.DragEvent) => {
|
|
e.preventDefault();
|
|
setIsDragging(true);
|
|
};
|
|
|
|
const handleDragLeave = (e: React.DragEvent) => {
|
|
e.preventDefault();
|
|
setIsDragging(false);
|
|
};
|
|
|
|
const handleDrop = (e: React.DragEvent) => {
|
|
e.preventDefault();
|
|
setIsDragging(false);
|
|
|
|
const files = e.dataTransfer.files;
|
|
if (files && files.length > 0) {
|
|
handleFiles(files);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
onClose={onClose}
|
|
title="Import Audio as Tracks"
|
|
description="Import one or more audio files as new tracks"
|
|
>
|
|
<div className="space-y-4">
|
|
{/* Drag and Drop Area */}
|
|
<div
|
|
onDragOver={handleDragOver}
|
|
onDragLeave={handleDragLeave}
|
|
onDrop={handleDrop}
|
|
className={`
|
|
border-2 border-dashed rounded-lg p-8 text-center transition-colors
|
|
${isDragging
|
|
? 'border-primary bg-primary/10'
|
|
: 'border-border hover:border-primary/50'
|
|
}
|
|
${isLoading ? 'opacity-50 pointer-events-none' : ''}
|
|
`}
|
|
>
|
|
<Upload className="h-12 w-12 mx-auto mb-4 text-muted-foreground" />
|
|
<p className="text-sm text-foreground mb-2">
|
|
{isLoading ? 'Importing files...' : 'Drag and drop audio files here'}
|
|
</p>
|
|
<p className="text-xs text-muted-foreground mb-4">
|
|
or
|
|
</p>
|
|
<Button
|
|
onClick={() => fileInputRef.current?.click()}
|
|
disabled={isLoading}
|
|
>
|
|
<Plus className="h-4 w-4 mr-2" />
|
|
Choose Files
|
|
</Button>
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept="audio/*"
|
|
multiple
|
|
onChange={handleFileSelect}
|
|
className="hidden"
|
|
/>
|
|
</div>
|
|
|
|
{/* Supported Formats */}
|
|
<div className="text-xs text-muted-foreground">
|
|
<p className="font-medium mb-1">Supported formats:</p>
|
|
<p>MP3, WAV, OGG, FLAC, M4A, AAC, and more</p>
|
|
<p className="mt-2">
|
|
💡 Tip: Select multiple files at once or drag multiple files to import them all as separate tracks
|
|
</p>
|
|
</div>
|
|
|
|
{/* Actions */}
|
|
<div className="flex justify-end gap-2 pt-2 border-t border-border">
|
|
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|