Compare commits
2 Commits
c54d5089c5
...
441920ee70
| Author | SHA1 | Date | |
|---|---|---|---|
| 441920ee70 | |||
| c33a77270b |
92
components/controls/MasterControls.tsx
Normal file
92
components/controls/MasterControls.tsx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Volume2, VolumeX } from 'lucide-react';
|
||||||
|
import { Button } from '@/components/ui/Button';
|
||||||
|
import { CircularKnob } from '@/components/ui/CircularKnob';
|
||||||
|
import { MasterFader } from './MasterFader';
|
||||||
|
import { cn } from '@/lib/utils/cn';
|
||||||
|
|
||||||
|
export interface MasterControlsProps {
|
||||||
|
volume: number;
|
||||||
|
pan: number;
|
||||||
|
peakLevel: number;
|
||||||
|
rmsLevel: number;
|
||||||
|
isClipping: boolean;
|
||||||
|
isMuted?: boolean;
|
||||||
|
onVolumeChange: (volume: number) => void;
|
||||||
|
onPanChange: (pan: number) => void;
|
||||||
|
onMuteToggle: () => void;
|
||||||
|
onResetClip?: () => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MasterControls({
|
||||||
|
volume,
|
||||||
|
pan,
|
||||||
|
peakLevel,
|
||||||
|
rmsLevel,
|
||||||
|
isClipping,
|
||||||
|
isMuted = false,
|
||||||
|
onVolumeChange,
|
||||||
|
onPanChange,
|
||||||
|
onMuteToggle,
|
||||||
|
onResetClip,
|
||||||
|
className,
|
||||||
|
}: MasterControlsProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn(
|
||||||
|
'flex flex-col items-center gap-3 px-4 py-3 bg-muted/10 border-2 border-accent/30 rounded-lg',
|
||||||
|
className
|
||||||
|
)}>
|
||||||
|
{/* Master Label */}
|
||||||
|
<div className="text-[10px] font-bold text-accent uppercase tracking-wider">
|
||||||
|
Master
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Pan Control */}
|
||||||
|
<CircularKnob
|
||||||
|
value={pan}
|
||||||
|
onChange={onPanChange}
|
||||||
|
min={-1}
|
||||||
|
max={1}
|
||||||
|
step={0.01}
|
||||||
|
label="PAN"
|
||||||
|
size={48}
|
||||||
|
formatter={(value) => {
|
||||||
|
if (Math.abs(value) < 0.01) return 'C';
|
||||||
|
if (value < 0) return `${Math.abs(value * 100).toFixed(0)}L`;
|
||||||
|
return `${(value * 100).toFixed(0)}R`;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Master Fader with Integrated Meters */}
|
||||||
|
<MasterFader
|
||||||
|
value={volume}
|
||||||
|
peakLevel={peakLevel}
|
||||||
|
rmsLevel={rmsLevel}
|
||||||
|
isClipping={isClipping}
|
||||||
|
onChange={onVolumeChange}
|
||||||
|
onResetClip={onResetClip}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Mute Button */}
|
||||||
|
<Button
|
||||||
|
variant={isMuted ? 'default' : 'outline'}
|
||||||
|
size="sm"
|
||||||
|
onClick={onMuteToggle}
|
||||||
|
title={isMuted ? 'Unmute' : 'Mute'}
|
||||||
|
className={cn(
|
||||||
|
'w-full h-8',
|
||||||
|
isMuted && 'bg-red-500/20 hover:bg-red-500/30 border-red-500/50'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isMuted ? (
|
||||||
|
<VolumeX className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<Volume2 className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
217
components/controls/MasterFader.tsx
Normal file
217
components/controls/MasterFader.tsx
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils/cn';
|
||||||
|
|
||||||
|
export interface MasterFaderProps {
|
||||||
|
value: number;
|
||||||
|
peakLevel: number;
|
||||||
|
rmsLevel: number;
|
||||||
|
isClipping: boolean;
|
||||||
|
onChange: (value: number) => void;
|
||||||
|
onResetClip?: () => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MasterFader({
|
||||||
|
value,
|
||||||
|
peakLevel,
|
||||||
|
rmsLevel,
|
||||||
|
isClipping,
|
||||||
|
onChange,
|
||||||
|
onResetClip,
|
||||||
|
className,
|
||||||
|
}: MasterFaderProps) {
|
||||||
|
const [isDragging, setIsDragging] = React.useState(false);
|
||||||
|
const containerRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Convert linear 0-1 to dB scale for display
|
||||||
|
const linearToDb = (linear: number): number => {
|
||||||
|
if (linear === 0) return -60;
|
||||||
|
const db = 20 * Math.log10(linear);
|
||||||
|
return Math.max(-60, Math.min(0, db));
|
||||||
|
};
|
||||||
|
|
||||||
|
const valueDb = linearToDb(value);
|
||||||
|
const peakDb = linearToDb(peakLevel);
|
||||||
|
const rmsDb = linearToDb(rmsLevel);
|
||||||
|
|
||||||
|
// Calculate bar widths (0-100%)
|
||||||
|
const peakWidth = ((peakDb + 60) / 60) * 100;
|
||||||
|
const rmsWidth = ((rmsDb + 60) / 60) * 100;
|
||||||
|
|
||||||
|
const handleMouseDown = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setIsDragging(true);
|
||||||
|
updateValue(e.clientY);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = React.useCallback(
|
||||||
|
(e: MouseEvent) => {
|
||||||
|
if (!isDragging) return;
|
||||||
|
updateValue(e.clientY);
|
||||||
|
},
|
||||||
|
[isDragging]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMouseUp = React.useCallback(() => {
|
||||||
|
setIsDragging(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const updateValue = (clientY: number) => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
|
const y = clientY - rect.top;
|
||||||
|
// Inverted: top = max (1), bottom = min (0)
|
||||||
|
const percentage = Math.max(0, Math.min(1, 1 - (y / rect.height)));
|
||||||
|
onChange(percentage);
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isDragging) {
|
||||||
|
window.addEventListener('mousemove', handleMouseMove);
|
||||||
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('mousemove', handleMouseMove);
|
||||||
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [isDragging, handleMouseMove, handleMouseUp]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn('flex gap-3', className)}>
|
||||||
|
{/* dB Labels (Left) */}
|
||||||
|
<div className="flex flex-col justify-between text-[10px] font-mono text-muted-foreground py-1">
|
||||||
|
<span>0</span>
|
||||||
|
<span>-12</span>
|
||||||
|
<span>-24</span>
|
||||||
|
<span>-60</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Fader Container */}
|
||||||
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
className="relative w-12 h-40 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
||||||
|
onMouseDown={handleMouseDown}
|
||||||
|
>
|
||||||
|
{/* Peak Meter (Horizontal Bar - Top) */}
|
||||||
|
<div className="absolute inset-x-2 top-2 h-3 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-0 bottom-0 transition-all duration-75 ease-out"
|
||||||
|
style={{ width: `${Math.max(0, Math.min(100, peakWidth))}%` }}
|
||||||
|
>
|
||||||
|
<div className={cn(
|
||||||
|
'w-full h-full',
|
||||||
|
peakDb > -3 ? 'bg-red-500' :
|
||||||
|
peakDb > -6 ? 'bg-yellow-500' :
|
||||||
|
'bg-green-500'
|
||||||
|
)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* RMS Meter (Horizontal Bar - Bottom) */}
|
||||||
|
<div className="absolute inset-x-2 bottom-2 h-3 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-0 bottom-0 transition-all duration-150 ease-out"
|
||||||
|
style={{ width: `${Math.max(0, Math.min(100, rmsWidth))}%` }}
|
||||||
|
>
|
||||||
|
<div className={cn(
|
||||||
|
'w-full h-full',
|
||||||
|
rmsDb > -3 ? 'bg-red-400' :
|
||||||
|
rmsDb > -6 ? 'bg-yellow-400' :
|
||||||
|
'bg-green-400'
|
||||||
|
)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Fader Track */}
|
||||||
|
<div className="absolute top-8 bottom-8 left-1/2 -translate-x-1/2 w-1.5 bg-muted/50 rounded-full" />
|
||||||
|
|
||||||
|
{/* Fader Handle */}
|
||||||
|
<div
|
||||||
|
className="absolute left-1/2 -translate-x-1/2 w-10 h-4 bg-primary/80 border-2 border-primary rounded-md shadow-lg cursor-grab active:cursor-grabbing pointer-events-none transition-all"
|
||||||
|
style={{
|
||||||
|
// Inverted: value 1 = top, value 0 = bottom
|
||||||
|
top: `calc(${(1 - value) * 100}% - 0.5rem)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Handle grip lines */}
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center gap-0.5">
|
||||||
|
<div className="h-2 w-px bg-primary-foreground/30" />
|
||||||
|
<div className="h-2 w-px bg-primary-foreground/30" />
|
||||||
|
<div className="h-2 w-px bg-primary-foreground/30" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Clip Indicator */}
|
||||||
|
{isClipping && (
|
||||||
|
<button
|
||||||
|
onClick={onResetClip}
|
||||||
|
className="absolute top-0 left-0 right-0 px-1 py-0.5 text-[9px] font-bold text-white bg-red-500 border-b border-red-600 rounded-t-md shadow-lg shadow-red-500/50 animate-pulse"
|
||||||
|
title="Click to reset clip indicator"
|
||||||
|
>
|
||||||
|
CLIP
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* dB Scale Markers */}
|
||||||
|
<div className="absolute inset-0 px-2 py-8 pointer-events-none">
|
||||||
|
<div className="relative h-full">
|
||||||
|
{/* -12 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-border/20" style={{ top: '50%' }} />
|
||||||
|
{/* -6 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-yellow-500/20" style={{ top: '20%' }} />
|
||||||
|
{/* -3 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-red-500/30" style={{ top: '10%' }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Value and Level Display (Right) */}
|
||||||
|
<div className="flex flex-col justify-between items-start text-[9px] font-mono py-1">
|
||||||
|
{/* Current dB Value */}
|
||||||
|
<div className={cn(
|
||||||
|
'font-bold text-[11px]',
|
||||||
|
valueDb > -3 ? 'text-red-500' :
|
||||||
|
valueDb > -6 ? 'text-yellow-500' :
|
||||||
|
'text-green-500'
|
||||||
|
)}>
|
||||||
|
{valueDb > -60 ? `${valueDb.toFixed(1)}` : '-∞'}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Spacer */}
|
||||||
|
<div className="flex-1" />
|
||||||
|
|
||||||
|
{/* Peak Level */}
|
||||||
|
<div className="flex flex-col items-start">
|
||||||
|
<span className="text-muted-foreground/60">PK</span>
|
||||||
|
<span className={cn(
|
||||||
|
'font-mono text-[10px]',
|
||||||
|
peakDb > -3 ? 'text-red-500' :
|
||||||
|
peakDb > -6 ? 'text-yellow-500' :
|
||||||
|
'text-green-500'
|
||||||
|
)}>
|
||||||
|
{peakDb > -60 ? `${peakDb.toFixed(1)}` : '-∞'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* RMS Level */}
|
||||||
|
<div className="flex flex-col items-start">
|
||||||
|
<span className="text-muted-foreground/60">RM</span>
|
||||||
|
<span className={cn(
|
||||||
|
'font-mono text-[10px]',
|
||||||
|
rmsDb > -3 ? 'text-red-400' :
|
||||||
|
rmsDb > -6 ? 'text-yellow-400' :
|
||||||
|
'text-green-400'
|
||||||
|
)}>
|
||||||
|
{rmsDb > -60 ? `${rmsDb.toFixed(1)}` : '-∞'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* dB Label */}
|
||||||
|
<span className="text-muted-foreground/60 text-[8px]">dB</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
120
components/controls/MasterMeter.tsx
Normal file
120
components/controls/MasterMeter.tsx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export interface MasterMeterProps {
|
||||||
|
/** Peak level (0-1) */
|
||||||
|
peakLevel: number;
|
||||||
|
/** RMS level (0-1) */
|
||||||
|
rmsLevel: number;
|
||||||
|
/** Whether clipping has occurred */
|
||||||
|
isClipping: boolean;
|
||||||
|
/** Callback to reset clip indicator */
|
||||||
|
onResetClip?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MasterMeter({
|
||||||
|
peakLevel,
|
||||||
|
rmsLevel,
|
||||||
|
isClipping,
|
||||||
|
onResetClip,
|
||||||
|
}: MasterMeterProps) {
|
||||||
|
// Convert linear 0-1 to dB scale for display
|
||||||
|
const linearToDb = (linear: number): number => {
|
||||||
|
if (linear === 0) return -60;
|
||||||
|
const db = 20 * Math.log10(linear);
|
||||||
|
return Math.max(-60, Math.min(0, db));
|
||||||
|
};
|
||||||
|
|
||||||
|
const peakDb = linearToDb(peakLevel);
|
||||||
|
const rmsDb = linearToDb(rmsLevel);
|
||||||
|
|
||||||
|
// Calculate bar heights (0-100%)
|
||||||
|
const peakHeight = ((peakDb + 60) / 60) * 100;
|
||||||
|
const rmsHeight = ((rmsDb + 60) / 60) * 100;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 px-3 py-2 bg-muted/30 rounded-md border border-border/50">
|
||||||
|
{/* Clip Indicator */}
|
||||||
|
<button
|
||||||
|
onClick={onResetClip}
|
||||||
|
className={`w-6 h-6 rounded-sm border transition-colors ${
|
||||||
|
isClipping
|
||||||
|
? 'bg-red-500 border-red-600 shadow-lg shadow-red-500/50'
|
||||||
|
: 'bg-muted border-border/50'
|
||||||
|
}`}
|
||||||
|
title={isClipping ? 'Click to reset clip indicator' : 'No clipping'}
|
||||||
|
>
|
||||||
|
<span className="text-[10px] font-bold text-white">C</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Meters */}
|
||||||
|
<div className="flex gap-1">
|
||||||
|
{/* Peak Meter (Left) */}
|
||||||
|
<div className="w-6 h-24 bg-background/50 rounded-sm relative overflow-hidden border border-border/50">
|
||||||
|
<div className="absolute bottom-0 left-0 right-0 transition-all duration-75 ease-out"
|
||||||
|
style={{ height: `${Math.max(0, Math.min(100, peakHeight))}%` }}>
|
||||||
|
<div className={`w-full h-full ${
|
||||||
|
peakDb > -3 ? 'bg-red-500' :
|
||||||
|
peakDb > -6 ? 'bg-yellow-500' :
|
||||||
|
'bg-green-500'
|
||||||
|
}`} />
|
||||||
|
</div>
|
||||||
|
{/* dB markers */}
|
||||||
|
<div className="absolute inset-0 pointer-events-none">
|
||||||
|
<div className="absolute top-0 left-0 right-0 h-px bg-red-500/30" title="0 dB" />
|
||||||
|
<div className="absolute top-[5%] left-0 right-0 h-px bg-yellow-500/20" title="-3 dB" />
|
||||||
|
<div className="absolute top-[10%] left-0 right-0 h-px bg-border/20" title="-6 dB" />
|
||||||
|
<div className="absolute top-[25%] left-0 right-0 h-px bg-border/20" title="-12 dB" />
|
||||||
|
<div className="absolute top-[50%] left-0 right-0 h-px bg-border/20" title="-18 dB" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* RMS Meter (Right) */}
|
||||||
|
<div className="w-6 h-24 bg-background/50 rounded-sm relative overflow-hidden border border-border/50">
|
||||||
|
<div className="absolute bottom-0 left-0 right-0 transition-all duration-150 ease-out"
|
||||||
|
style={{ height: `${Math.max(0, Math.min(100, rmsHeight))}%` }}>
|
||||||
|
<div className={`w-full h-full ${
|
||||||
|
rmsDb > -3 ? 'bg-red-400' :
|
||||||
|
rmsDb > -6 ? 'bg-yellow-400' :
|
||||||
|
'bg-green-400'
|
||||||
|
}`} />
|
||||||
|
</div>
|
||||||
|
{/* dB markers */}
|
||||||
|
<div className="absolute inset-0 pointer-events-none">
|
||||||
|
<div className="absolute top-0 left-0 right-0 h-px bg-red-500/30" />
|
||||||
|
<div className="absolute top-[5%] left-0 right-0 h-px bg-yellow-500/20" />
|
||||||
|
<div className="absolute top-[10%] left-0 right-0 h-px bg-border/20" />
|
||||||
|
<div className="absolute top-[25%] left-0 right-0 h-px bg-border/20" />
|
||||||
|
<div className="absolute top-[50%] left-0 right-0 h-px bg-border/20" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Labels and Values */}
|
||||||
|
<div className="flex flex-col text-[10px] font-mono">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span className="text-muted-foreground w-6">PK:</span>
|
||||||
|
<span className={`w-12 text-right ${
|
||||||
|
peakDb > -3 ? 'text-red-500' :
|
||||||
|
peakDb > -6 ? 'text-yellow-500' :
|
||||||
|
'text-green-500'
|
||||||
|
}`}>
|
||||||
|
{peakDb > -60 ? `${peakDb.toFixed(1)}` : '-∞'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span className="text-muted-foreground w-6">RM:</span>
|
||||||
|
<span className={`w-12 text-right ${
|
||||||
|
rmsDb > -3 ? 'text-red-400' :
|
||||||
|
rmsDb > -6 ? 'text-yellow-400' :
|
||||||
|
'text-green-400'
|
||||||
|
}`}>
|
||||||
|
{rmsDb > -60 ? `${rmsDb.toFixed(1)}` : '-∞'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-muted-foreground text-center mt-0.5">dB</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -35,6 +35,8 @@ export function AudioEditor() {
|
|||||||
const [selectedTrackId, setSelectedTrackId] = React.useState<string | null>(null);
|
const [selectedTrackId, setSelectedTrackId] = React.useState<string | null>(null);
|
||||||
const [zoom, setZoom] = React.useState(1);
|
const [zoom, setZoom] = React.useState(1);
|
||||||
const [masterVolume, setMasterVolume] = React.useState(0.8);
|
const [masterVolume, setMasterVolume] = React.useState(0.8);
|
||||||
|
const [masterPan, setMasterPan] = React.useState(0);
|
||||||
|
const [isMasterMuted, setIsMasterMuted] = React.useState(false);
|
||||||
const [clipboard, setClipboard] = React.useState<AudioBuffer | null>(null);
|
const [clipboard, setClipboard] = React.useState<AudioBuffer | null>(null);
|
||||||
const [recordingTrackId, setRecordingTrackId] = React.useState<string | null>(null);
|
const [recordingTrackId, setRecordingTrackId] = React.useState<string | null>(null);
|
||||||
const [punchInEnabled, setPunchInEnabled] = React.useState(false);
|
const [punchInEnabled, setPunchInEnabled] = React.useState(false);
|
||||||
@@ -219,6 +221,10 @@ export function AudioEditor() {
|
|||||||
currentTime,
|
currentTime,
|
||||||
duration,
|
duration,
|
||||||
trackLevels,
|
trackLevels,
|
||||||
|
masterPeakLevel,
|
||||||
|
masterRmsLevel,
|
||||||
|
masterIsClipping,
|
||||||
|
resetClipIndicator,
|
||||||
play,
|
play,
|
||||||
pause,
|
pause,
|
||||||
stop,
|
stop,
|
||||||
@@ -1038,11 +1044,22 @@ export function AudioEditor() {
|
|||||||
currentTime={currentTime}
|
currentTime={currentTime}
|
||||||
duration={duration}
|
duration={duration}
|
||||||
volume={masterVolume}
|
volume={masterVolume}
|
||||||
|
pan={masterPan}
|
||||||
onPlay={play}
|
onPlay={play}
|
||||||
onPause={pause}
|
onPause={pause}
|
||||||
onStop={stop}
|
onStop={stop}
|
||||||
onSeek={seek}
|
onSeek={seek}
|
||||||
onVolumeChange={setMasterVolume}
|
onVolumeChange={setMasterVolume}
|
||||||
|
onPanChange={setMasterPan}
|
||||||
|
onMuteToggle={() => {
|
||||||
|
if (isMasterMuted) {
|
||||||
|
setMasterVolume(0.8);
|
||||||
|
setIsMasterMuted(false);
|
||||||
|
} else {
|
||||||
|
setMasterVolume(0);
|
||||||
|
setIsMasterMuted(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
currentTimeFormatted={formatDuration(currentTime)}
|
currentTimeFormatted={formatDuration(currentTime)}
|
||||||
durationFormatted={formatDuration(duration)}
|
durationFormatted={formatDuration(duration)}
|
||||||
isRecording={recordingState.isRecording}
|
isRecording={recordingState.isRecording}
|
||||||
@@ -1056,6 +1073,10 @@ export function AudioEditor() {
|
|||||||
onPunchOutTimeChange={setPunchOutTime}
|
onPunchOutTimeChange={setPunchOutTime}
|
||||||
overdubEnabled={overdubEnabled}
|
overdubEnabled={overdubEnabled}
|
||||||
onOverdubEnabledChange={setOverdubEnabled}
|
onOverdubEnabledChange={setOverdubEnabled}
|
||||||
|
masterPeakLevel={masterPeakLevel}
|
||||||
|
masterRmsLevel={masterRmsLevel}
|
||||||
|
masterIsClipping={masterIsClipping}
|
||||||
|
onResetClip={resetClipIndicator}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Play, Pause, Square, SkipBack, Volume2, VolumeX, Circle, AlignVerticalJustifyStart, AlignVerticalJustifyEnd, Layers } from 'lucide-react';
|
import { Play, Pause, Square, SkipBack, Circle, AlignVerticalJustifyStart, AlignVerticalJustifyEnd, Layers } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/Button';
|
import { Button } from '@/components/ui/Button';
|
||||||
import { Slider } from '@/components/ui/Slider';
|
import { MasterControls } from '@/components/controls/MasterControls';
|
||||||
import { cn } from '@/lib/utils/cn';
|
import { cn } from '@/lib/utils/cn';
|
||||||
|
|
||||||
export interface PlaybackControlsProps {
|
export interface PlaybackControlsProps {
|
||||||
@@ -12,11 +12,14 @@ export interface PlaybackControlsProps {
|
|||||||
currentTime: number;
|
currentTime: number;
|
||||||
duration: number;
|
duration: number;
|
||||||
volume: number;
|
volume: number;
|
||||||
|
pan?: number;
|
||||||
onPlay: () => void;
|
onPlay: () => void;
|
||||||
onPause: () => void;
|
onPause: () => void;
|
||||||
onStop: () => void;
|
onStop: () => void;
|
||||||
onSeek: (time: number, autoPlay?: boolean) => void;
|
onSeek: (time: number, autoPlay?: boolean) => void;
|
||||||
onVolumeChange: (volume: number) => void;
|
onVolumeChange: (volume: number) => void;
|
||||||
|
onPanChange?: (pan: number) => void;
|
||||||
|
onMuteToggle?: () => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
currentTimeFormatted?: string;
|
currentTimeFormatted?: string;
|
||||||
@@ -32,6 +35,10 @@ export interface PlaybackControlsProps {
|
|||||||
onPunchOutTimeChange?: (time: number) => void;
|
onPunchOutTimeChange?: (time: number) => void;
|
||||||
overdubEnabled?: boolean;
|
overdubEnabled?: boolean;
|
||||||
onOverdubEnabledChange?: (enabled: boolean) => void;
|
onOverdubEnabledChange?: (enabled: boolean) => void;
|
||||||
|
masterPeakLevel?: number;
|
||||||
|
masterRmsLevel?: number;
|
||||||
|
masterIsClipping?: boolean;
|
||||||
|
onResetClip?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PlaybackControls({
|
export function PlaybackControls({
|
||||||
@@ -40,11 +47,14 @@ export function PlaybackControls({
|
|||||||
currentTime,
|
currentTime,
|
||||||
duration,
|
duration,
|
||||||
volume,
|
volume,
|
||||||
|
pan = 0,
|
||||||
onPlay,
|
onPlay,
|
||||||
onPause,
|
onPause,
|
||||||
onStop,
|
onStop,
|
||||||
onSeek,
|
onSeek,
|
||||||
onVolumeChange,
|
onVolumeChange,
|
||||||
|
onPanChange,
|
||||||
|
onMuteToggle,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
className,
|
className,
|
||||||
currentTimeFormatted,
|
currentTimeFormatted,
|
||||||
@@ -60,10 +70,11 @@ export function PlaybackControls({
|
|||||||
onPunchOutTimeChange,
|
onPunchOutTimeChange,
|
||||||
overdubEnabled = false,
|
overdubEnabled = false,
|
||||||
onOverdubEnabledChange,
|
onOverdubEnabledChange,
|
||||||
|
masterPeakLevel = 0,
|
||||||
|
masterRmsLevel = 0,
|
||||||
|
masterIsClipping = false,
|
||||||
|
onResetClip,
|
||||||
}: PlaybackControlsProps) {
|
}: PlaybackControlsProps) {
|
||||||
const [isMuted, setIsMuted] = React.useState(false);
|
|
||||||
const [previousVolume, setPreviousVolume] = React.useState(volume);
|
|
||||||
|
|
||||||
const handlePlayPause = () => {
|
const handlePlayPause = () => {
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
onPause();
|
onPause();
|
||||||
@@ -72,26 +83,6 @@ export function PlaybackControls({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMuteToggle = () => {
|
|
||||||
if (isMuted) {
|
|
||||||
onVolumeChange(previousVolume);
|
|
||||||
setIsMuted(false);
|
|
||||||
} else {
|
|
||||||
setPreviousVolume(volume);
|
|
||||||
onVolumeChange(0);
|
|
||||||
setIsMuted(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleVolumeChange = (newVolume: number) => {
|
|
||||||
onVolumeChange(newVolume);
|
|
||||||
if (newVolume === 0) {
|
|
||||||
setIsMuted(true);
|
|
||||||
} else {
|
|
||||||
setIsMuted(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const progress = duration > 0 ? (currentTime / duration) * 100 : 0;
|
const progress = duration > 0 ? (currentTime / duration) * 100 : 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -275,30 +266,21 @@ export function PlaybackControls({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Volume Control */}
|
{/* Master Controls */}
|
||||||
<div className="flex items-center gap-3 min-w-[200px]">
|
{onPanChange && onMuteToggle && (
|
||||||
<Button
|
<MasterControls
|
||||||
variant="ghost"
|
volume={volume}
|
||||||
size="icon"
|
pan={pan}
|
||||||
onClick={handleMuteToggle}
|
peakLevel={masterPeakLevel}
|
||||||
title={isMuted ? 'Unmute' : 'Mute'}
|
rmsLevel={masterRmsLevel}
|
||||||
>
|
isClipping={masterIsClipping}
|
||||||
{isMuted || volume === 0 ? (
|
isMuted={volume === 0}
|
||||||
<VolumeX className="h-5 w-5" />
|
onVolumeChange={onVolumeChange}
|
||||||
) : (
|
onPanChange={onPanChange}
|
||||||
<Volume2 className="h-5 w-5" />
|
onMuteToggle={onMuteToggle}
|
||||||
)}
|
onResetClip={onResetClip}
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Slider
|
|
||||||
value={volume}
|
|
||||||
onChange={handleVolumeChange}
|
|
||||||
min={0}
|
|
||||||
max={1}
|
|
||||||
step={0.01}
|
|
||||||
className="flex-1"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import { Button } from '@/components/ui/Button';
|
|||||||
import { Slider } from '@/components/ui/Slider';
|
import { Slider } from '@/components/ui/Slider';
|
||||||
import { cn } from '@/lib/utils/cn';
|
import { cn } from '@/lib/utils/cn';
|
||||||
import type { EffectType } from '@/lib/audio/effects/chain';
|
import type { EffectType } from '@/lib/audio/effects/chain';
|
||||||
import { VerticalFader } from '@/components/ui/VerticalFader';
|
import { TrackControls } from './TrackControls';
|
||||||
import { CircularKnob } from '@/components/ui/CircularKnob';
|
|
||||||
import { AutomationLane } from '@/components/automation/AutomationLane';
|
import { AutomationLane } from '@/components/automation/AutomationLane';
|
||||||
import type { AutomationLane as AutomationLaneType, AutomationPoint as AutomationPointType } from '@/types/automation';
|
import type { AutomationLane as AutomationLaneType, AutomationPoint as AutomationPointType } from '@/types/automation';
|
||||||
import { createAutomationPoint } from '@/lib/audio/automation/utils';
|
import { createAutomationPoint } from '@/lib/audio/automation/utils';
|
||||||
@@ -647,39 +646,25 @@ export function Track({
|
|||||||
{/* Track Controls - Only show when not collapsed */}
|
{/* Track Controls - Only show when not collapsed */}
|
||||||
{!track.collapsed && (
|
{!track.collapsed && (
|
||||||
<div className="flex-1 flex flex-col items-center justify-between min-h-0 overflow-hidden">
|
<div className="flex-1 flex flex-col items-center justify-between min-h-0 overflow-hidden">
|
||||||
{/* Pan Knob */}
|
{/* Integrated Track Controls (Pan + Fader + Mute) */}
|
||||||
<div className="flex-shrink-0">
|
<TrackControls
|
||||||
<CircularKnob
|
volume={track.volume}
|
||||||
value={track.pan}
|
pan={track.pan}
|
||||||
onChange={onPanChange}
|
peakLevel={track.recordEnabled || isRecording ? recordingLevel : playbackLevel}
|
||||||
min={-1}
|
rmsLevel={track.recordEnabled || isRecording ? recordingLevel * 0.7 : playbackLevel * 0.7}
|
||||||
max={1}
|
isMuted={track.mute}
|
||||||
step={0.01}
|
onVolumeChange={onVolumeChange}
|
||||||
size={48}
|
onPanChange={onPanChange}
|
||||||
label="PAN"
|
onMuteToggle={onToggleMute}
|
||||||
onTouchStart={handlePanTouchStart}
|
onVolumeTouchStart={handleVolumeTouchStart}
|
||||||
onTouchEnd={handlePanTouchEnd}
|
onVolumeTouchEnd={handleVolumeTouchEnd}
|
||||||
/>
|
onPanTouchStart={handlePanTouchStart}
|
||||||
</div>
|
onPanTouchEnd={handlePanTouchEnd}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Vertical Volume Fader with integrated meter */}
|
{/* Inline Button Row - Below controls */}
|
||||||
<div className="flex-1 flex items-center justify-center min-h-0">
|
|
||||||
<VerticalFader
|
|
||||||
value={track.volume}
|
|
||||||
level={track.recordEnabled || isRecording ? recordingLevel : playbackLevel}
|
|
||||||
onChange={onVolumeChange}
|
|
||||||
min={0}
|
|
||||||
max={1}
|
|
||||||
step={0.01}
|
|
||||||
showDb={true}
|
|
||||||
onTouchStart={handleVolumeTouchStart}
|
|
||||||
onTouchEnd={handleVolumeTouchEnd}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Inline Button Row - Below fader */}
|
|
||||||
<div className="flex-shrink-0 w-full">
|
<div className="flex-shrink-0 w-full">
|
||||||
{/* R/S/M inline row with icons */}
|
{/* R/S/A inline row with icons */}
|
||||||
<div className="flex items-center gap-1 justify-center">
|
<div className="flex items-center gap-1 justify-center">
|
||||||
{/* Record Arm */}
|
{/* Record Arm */}
|
||||||
{onToggleRecordEnable && (
|
{onToggleRecordEnable && (
|
||||||
@@ -712,20 +697,6 @@ export function Track({
|
|||||||
<Headphones className="h-3 w-3" />
|
<Headphones className="h-3 w-3" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Mute Button */}
|
|
||||||
<button
|
|
||||||
onClick={onToggleMute}
|
|
||||||
className={cn(
|
|
||||||
'h-6 w-6 rounded flex items-center justify-center transition-all',
|
|
||||||
track.mute
|
|
||||||
? 'bg-blue-500 text-white shadow-md shadow-blue-500/30'
|
|
||||||
: 'bg-card hover:bg-accent text-muted-foreground border border-border/50'
|
|
||||||
)}
|
|
||||||
title="Mute track"
|
|
||||||
>
|
|
||||||
{track.mute ? <VolumeX className="h-3 w-3" /> : <Volume2 className="h-3 w-3" />}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Automation Toggle */}
|
{/* Automation Toggle */}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
85
components/tracks/TrackControls.tsx
Normal file
85
components/tracks/TrackControls.tsx
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Volume2, VolumeX } from 'lucide-react';
|
||||||
|
import { CircularKnob } from '@/components/ui/CircularKnob';
|
||||||
|
import { TrackFader } from './TrackFader';
|
||||||
|
import { cn } from '@/lib/utils/cn';
|
||||||
|
|
||||||
|
export interface TrackControlsProps {
|
||||||
|
volume: number;
|
||||||
|
pan: number;
|
||||||
|
peakLevel: number;
|
||||||
|
rmsLevel: number;
|
||||||
|
isMuted?: boolean;
|
||||||
|
onVolumeChange: (volume: number) => void;
|
||||||
|
onPanChange: (pan: number) => void;
|
||||||
|
onMuteToggle: () => void;
|
||||||
|
onVolumeTouchStart?: () => void;
|
||||||
|
onVolumeTouchEnd?: () => void;
|
||||||
|
onPanTouchStart?: () => void;
|
||||||
|
onPanTouchEnd?: () => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TrackControls({
|
||||||
|
volume,
|
||||||
|
pan,
|
||||||
|
peakLevel,
|
||||||
|
rmsLevel,
|
||||||
|
isMuted = false,
|
||||||
|
onVolumeChange,
|
||||||
|
onPanChange,
|
||||||
|
onMuteToggle,
|
||||||
|
onVolumeTouchStart,
|
||||||
|
onVolumeTouchEnd,
|
||||||
|
onPanTouchStart,
|
||||||
|
onPanTouchEnd,
|
||||||
|
className,
|
||||||
|
}: TrackControlsProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn('flex flex-col items-center gap-2 py-2', className)}>
|
||||||
|
{/* Pan Control */}
|
||||||
|
<CircularKnob
|
||||||
|
value={pan}
|
||||||
|
onChange={onPanChange}
|
||||||
|
onTouchStart={onPanTouchStart}
|
||||||
|
onTouchEnd={onPanTouchEnd}
|
||||||
|
min={-1}
|
||||||
|
max={1}
|
||||||
|
step={0.01}
|
||||||
|
label="PAN"
|
||||||
|
size={40}
|
||||||
|
formatter={(value) => {
|
||||||
|
if (Math.abs(value) < 0.01) return 'C';
|
||||||
|
if (value < 0) return `${Math.abs(value * 100).toFixed(0)}L`;
|
||||||
|
return `${(value * 100).toFixed(0)}R`;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Track Fader with Integrated Meters */}
|
||||||
|
<TrackFader
|
||||||
|
value={volume}
|
||||||
|
peakLevel={peakLevel}
|
||||||
|
rmsLevel={rmsLevel}
|
||||||
|
onChange={onVolumeChange}
|
||||||
|
onTouchStart={onVolumeTouchStart}
|
||||||
|
onTouchEnd={onVolumeTouchEnd}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Mute Button */}
|
||||||
|
<button
|
||||||
|
onClick={onMuteToggle}
|
||||||
|
className={cn(
|
||||||
|
'w-8 h-6 rounded text-[10px] font-bold transition-colors border',
|
||||||
|
isMuted
|
||||||
|
? 'bg-red-500/20 hover:bg-red-500/30 border-red-500/50 text-red-500'
|
||||||
|
: 'bg-muted/20 hover:bg-muted/30 border-border/50 text-muted-foreground'
|
||||||
|
)}
|
||||||
|
title={isMuted ? 'Unmute' : 'Mute'}
|
||||||
|
>
|
||||||
|
M
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
176
components/tracks/TrackFader.tsx
Normal file
176
components/tracks/TrackFader.tsx
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { cn } from '@/lib/utils/cn';
|
||||||
|
|
||||||
|
export interface TrackFaderProps {
|
||||||
|
value: number;
|
||||||
|
peakLevel: number;
|
||||||
|
rmsLevel: number;
|
||||||
|
onChange: (value: number) => void;
|
||||||
|
onTouchStart?: () => void;
|
||||||
|
onTouchEnd?: () => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TrackFader({
|
||||||
|
value,
|
||||||
|
peakLevel,
|
||||||
|
rmsLevel,
|
||||||
|
onChange,
|
||||||
|
onTouchStart,
|
||||||
|
onTouchEnd,
|
||||||
|
className,
|
||||||
|
}: TrackFaderProps) {
|
||||||
|
const [isDragging, setIsDragging] = React.useState(false);
|
||||||
|
const containerRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Convert linear 0-1 to dB scale for display
|
||||||
|
const linearToDb = (linear: number): number => {
|
||||||
|
if (linear === 0) return -60;
|
||||||
|
const db = 20 * Math.log10(linear);
|
||||||
|
return Math.max(-60, Math.min(0, db));
|
||||||
|
};
|
||||||
|
|
||||||
|
const valueDb = linearToDb(value);
|
||||||
|
const peakDb = linearToDb(peakLevel);
|
||||||
|
const rmsDb = linearToDb(rmsLevel);
|
||||||
|
|
||||||
|
// Calculate bar widths (0-100%)
|
||||||
|
const peakWidth = ((peakDb + 60) / 60) * 100;
|
||||||
|
const rmsWidth = ((rmsDb + 60) / 60) * 100;
|
||||||
|
|
||||||
|
const handleMouseDown = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setIsDragging(true);
|
||||||
|
onTouchStart?.();
|
||||||
|
updateValue(e.clientY);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = React.useCallback(
|
||||||
|
(e: MouseEvent) => {
|
||||||
|
if (!isDragging) return;
|
||||||
|
updateValue(e.clientY);
|
||||||
|
},
|
||||||
|
[isDragging]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMouseUp = React.useCallback(() => {
|
||||||
|
setIsDragging(false);
|
||||||
|
onTouchEnd?.();
|
||||||
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
|
const updateValue = (clientY: number) => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
|
const y = clientY - rect.top;
|
||||||
|
// Inverted: top = max (1), bottom = min (0)
|
||||||
|
const percentage = Math.max(0, Math.min(1, 1 - (y / rect.height)));
|
||||||
|
onChange(percentage);
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isDragging) {
|
||||||
|
window.addEventListener('mousemove', handleMouseMove);
|
||||||
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('mousemove', handleMouseMove);
|
||||||
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [isDragging, handleMouseMove, handleMouseUp]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn('flex gap-2', className)}>
|
||||||
|
{/* dB Labels (Left) */}
|
||||||
|
<div className="flex flex-col justify-between text-[9px] font-mono text-muted-foreground py-1">
|
||||||
|
<span>0</span>
|
||||||
|
<span>-12</span>
|
||||||
|
<span>-24</span>
|
||||||
|
<span>-60</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Fader Container */}
|
||||||
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
className="relative w-10 h-32 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
||||||
|
onMouseDown={handleMouseDown}
|
||||||
|
>
|
||||||
|
{/* Peak Meter (Horizontal Bar - Top) */}
|
||||||
|
<div className="absolute inset-x-1.5 top-1.5 h-2.5 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-0 bottom-0 transition-all duration-75 ease-out"
|
||||||
|
style={{ width: `${Math.max(0, Math.min(100, peakWidth))}%` }}
|
||||||
|
>
|
||||||
|
<div className={cn(
|
||||||
|
'w-full h-full',
|
||||||
|
peakDb > -3 ? 'bg-red-500' :
|
||||||
|
peakDb > -6 ? 'bg-yellow-500' :
|
||||||
|
'bg-green-500'
|
||||||
|
)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* RMS Meter (Horizontal Bar - Bottom) */}
|
||||||
|
<div className="absolute inset-x-1.5 bottom-1.5 h-2.5 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-0 bottom-0 transition-all duration-150 ease-out"
|
||||||
|
style={{ width: `${Math.max(0, Math.min(100, rmsWidth))}%` }}
|
||||||
|
>
|
||||||
|
<div className={cn(
|
||||||
|
'w-full h-full',
|
||||||
|
rmsDb > -3 ? 'bg-red-400' :
|
||||||
|
rmsDb > -6 ? 'bg-yellow-400' :
|
||||||
|
'bg-green-400'
|
||||||
|
)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Fader Track */}
|
||||||
|
<div className="absolute top-6 bottom-6 left-1/2 -translate-x-1/2 w-1 bg-muted/50 rounded-full" />
|
||||||
|
|
||||||
|
{/* Fader Handle */}
|
||||||
|
<div
|
||||||
|
className="absolute left-1/2 -translate-x-1/2 w-9 h-3.5 bg-primary/80 border-2 border-primary rounded-md shadow-lg cursor-grab active:cursor-grabbing pointer-events-none transition-all"
|
||||||
|
style={{
|
||||||
|
// Inverted: value 1 = top, value 0 = bottom
|
||||||
|
top: `calc(${(1 - value) * 100}% - 0.4375rem)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Handle grip lines */}
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center gap-0.5">
|
||||||
|
<div className="h-1.5 w-px bg-primary-foreground/30" />
|
||||||
|
<div className="h-1.5 w-px bg-primary-foreground/30" />
|
||||||
|
<div className="h-1.5 w-px bg-primary-foreground/30" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* dB Scale Markers */}
|
||||||
|
<div className="absolute inset-0 px-1.5 py-6 pointer-events-none">
|
||||||
|
<div className="relative h-full">
|
||||||
|
{/* -12 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-border/20" style={{ top: '50%' }} />
|
||||||
|
{/* -6 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-yellow-500/20" style={{ top: '20%' }} />
|
||||||
|
{/* -3 dB */}
|
||||||
|
<div className="absolute left-0 right-0 h-px bg-red-500/30" style={{ top: '10%' }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Value Display (Right) */}
|
||||||
|
<div className="flex flex-col justify-center items-start text-[9px] font-mono">
|
||||||
|
{/* Current dB Value */}
|
||||||
|
<div className={cn(
|
||||||
|
'font-bold text-[10px]',
|
||||||
|
valueDb > -3 ? 'text-red-500' :
|
||||||
|
valueDb > -6 ? 'text-yellow-500' :
|
||||||
|
'text-green-500'
|
||||||
|
)}>
|
||||||
|
{valueDb > -60 ? `${valueDb.toFixed(1)}` : '-∞'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -29,6 +29,9 @@ export function useMultiTrackPlayer(
|
|||||||
const [currentTime, setCurrentTime] = useState(0);
|
const [currentTime, setCurrentTime] = useState(0);
|
||||||
const [duration, setDuration] = useState(0);
|
const [duration, setDuration] = useState(0);
|
||||||
const [trackLevels, setTrackLevels] = useState<Record<string, number>>({});
|
const [trackLevels, setTrackLevels] = useState<Record<string, number>>({});
|
||||||
|
const [masterPeakLevel, setMasterPeakLevel] = useState(0);
|
||||||
|
const [masterRmsLevel, setMasterRmsLevel] = useState(0);
|
||||||
|
const [masterIsClipping, setMasterIsClipping] = useState(false);
|
||||||
|
|
||||||
const audioContextRef = useRef<AudioContext | null>(null);
|
const audioContextRef = useRef<AudioContext | null>(null);
|
||||||
const sourceNodesRef = useRef<AudioBufferSourceNode[]>([]);
|
const sourceNodesRef = useRef<AudioBufferSourceNode[]>([]);
|
||||||
@@ -37,6 +40,8 @@ export function useMultiTrackPlayer(
|
|||||||
const analyserNodesRef = useRef<AnalyserNode[]>([]);
|
const analyserNodesRef = useRef<AnalyserNode[]>([]);
|
||||||
const effectNodesRef = useRef<EffectNodeInfo[][]>([]); // Effect nodes per track
|
const effectNodesRef = useRef<EffectNodeInfo[][]>([]); // Effect nodes per track
|
||||||
const masterGainNodeRef = useRef<GainNode | null>(null);
|
const masterGainNodeRef = useRef<GainNode | null>(null);
|
||||||
|
const masterAnalyserRef = useRef<AnalyserNode | null>(null);
|
||||||
|
const masterLevelMonitorFrameRef = useRef<number | null>(null);
|
||||||
const startTimeRef = useRef<number>(0);
|
const startTimeRef = useRef<number>(0);
|
||||||
const pausedAtRef = useRef<number>(0);
|
const pausedAtRef = useRef<number>(0);
|
||||||
const animationFrameRef = useRef<number | null>(null);
|
const animationFrameRef = useRef<number | null>(null);
|
||||||
@@ -116,6 +121,46 @@ export function useMultiTrackPlayer(
|
|||||||
levelMonitorFrameRef.current = requestAnimationFrame(monitorPlaybackLevels);
|
levelMonitorFrameRef.current = requestAnimationFrame(monitorPlaybackLevels);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Monitor master output levels (peak and RMS)
|
||||||
|
const monitorMasterLevels = useCallback(() => {
|
||||||
|
if (!masterAnalyserRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const analyser = masterAnalyserRef.current;
|
||||||
|
const bufferLength = analyser.fftSize;
|
||||||
|
const dataArray = new Float32Array(bufferLength);
|
||||||
|
|
||||||
|
analyser.getFloatTimeDomainData(dataArray);
|
||||||
|
|
||||||
|
// Calculate peak level (max absolute value)
|
||||||
|
let peak = 0;
|
||||||
|
for (let i = 0; i < bufferLength; i++) {
|
||||||
|
const abs = Math.abs(dataArray[i]);
|
||||||
|
if (abs > peak) {
|
||||||
|
peak = abs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate RMS level (root mean square)
|
||||||
|
let sumSquares = 0;
|
||||||
|
for (let i = 0; i < bufferLength; i++) {
|
||||||
|
sumSquares += dataArray[i] * dataArray[i];
|
||||||
|
}
|
||||||
|
const rms = Math.sqrt(sumSquares / bufferLength);
|
||||||
|
|
||||||
|
// Detect clipping (signal >= 1.0)
|
||||||
|
const isClipping = peak >= 1.0;
|
||||||
|
|
||||||
|
setMasterPeakLevel(peak);
|
||||||
|
setMasterRmsLevel(rms);
|
||||||
|
if (isClipping) {
|
||||||
|
setMasterIsClipping(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
masterLevelMonitorFrameRef.current = requestAnimationFrame(monitorMasterLevels);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Apply automation values during playback
|
// Apply automation values during playback
|
||||||
const applyAutomation = useCallback(() => {
|
const applyAutomation = useCallback(() => {
|
||||||
if (!audioContextRef.current) return;
|
if (!audioContextRef.current) return;
|
||||||
@@ -303,11 +348,20 @@ export function useMultiTrackPlayer(
|
|||||||
analyserNodesRef.current = [];
|
analyserNodesRef.current = [];
|
||||||
effectNodesRef.current = [];
|
effectNodesRef.current = [];
|
||||||
|
|
||||||
// Create master gain node
|
// Create master gain node with analyser for metering
|
||||||
const masterGain = audioContext.createGain();
|
const masterGain = audioContext.createGain();
|
||||||
masterGain.gain.setValueAtTime(masterVolume, audioContext.currentTime);
|
masterGain.gain.setValueAtTime(masterVolume, audioContext.currentTime);
|
||||||
masterGain.connect(audioContext.destination);
|
|
||||||
|
const masterAnalyser = audioContext.createAnalyser();
|
||||||
|
masterAnalyser.fftSize = 256;
|
||||||
|
masterAnalyser.smoothingTimeConstant = 0.8;
|
||||||
|
|
||||||
|
// Connect: masterGain -> analyser -> destination
|
||||||
|
masterGain.connect(masterAnalyser);
|
||||||
|
masterAnalyser.connect(audioContext.destination);
|
||||||
|
|
||||||
masterGainNodeRef.current = masterGain;
|
masterGainNodeRef.current = masterGain;
|
||||||
|
masterAnalyserRef.current = masterAnalyser;
|
||||||
|
|
||||||
// Create audio graph for each track
|
// Create audio graph for each track
|
||||||
for (const track of tracks) {
|
for (const track of tracks) {
|
||||||
@@ -376,10 +430,11 @@ export function useMultiTrackPlayer(
|
|||||||
// Start level monitoring
|
// Start level monitoring
|
||||||
isMonitoringLevelsRef.current = true;
|
isMonitoringLevelsRef.current = true;
|
||||||
monitorPlaybackLevels();
|
monitorPlaybackLevels();
|
||||||
|
monitorMasterLevels();
|
||||||
|
|
||||||
// Start automation
|
// Start automation
|
||||||
applyAutomation();
|
applyAutomation();
|
||||||
}, [tracks, duration, masterVolume, updatePlaybackPosition, monitorPlaybackLevels, applyAutomation]);
|
}, [tracks, duration, masterVolume, updatePlaybackPosition, monitorPlaybackLevels, monitorMasterLevels, applyAutomation]);
|
||||||
|
|
||||||
const pause = useCallback(() => {
|
const pause = useCallback(() => {
|
||||||
if (!audioContextRef.current || !isPlaying) return;
|
if (!audioContextRef.current || !isPlaying) return;
|
||||||
@@ -414,6 +469,11 @@ export function useMultiTrackPlayer(
|
|||||||
levelMonitorFrameRef.current = null;
|
levelMonitorFrameRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (masterLevelMonitorFrameRef.current) {
|
||||||
|
cancelAnimationFrame(masterLevelMonitorFrameRef.current);
|
||||||
|
masterLevelMonitorFrameRef.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (automationFrameRef.current) {
|
if (automationFrameRef.current) {
|
||||||
cancelAnimationFrame(automationFrameRef.current);
|
cancelAnimationFrame(automationFrameRef.current);
|
||||||
automationFrameRef.current = null;
|
automationFrameRef.current = null;
|
||||||
@@ -650,6 +710,10 @@ export function useMultiTrackPlayer(
|
|||||||
cancelAnimationFrame(levelMonitorFrameRef.current);
|
cancelAnimationFrame(levelMonitorFrameRef.current);
|
||||||
levelMonitorFrameRef.current = null;
|
levelMonitorFrameRef.current = null;
|
||||||
}
|
}
|
||||||
|
if (masterLevelMonitorFrameRef.current) {
|
||||||
|
cancelAnimationFrame(masterLevelMonitorFrameRef.current);
|
||||||
|
masterLevelMonitorFrameRef.current = null;
|
||||||
|
}
|
||||||
if (automationFrameRef.current) {
|
if (automationFrameRef.current) {
|
||||||
cancelAnimationFrame(automationFrameRef.current);
|
cancelAnimationFrame(automationFrameRef.current);
|
||||||
automationFrameRef.current = null;
|
automationFrameRef.current = null;
|
||||||
@@ -662,12 +726,13 @@ export function useMultiTrackPlayer(
|
|||||||
};
|
};
|
||||||
updatePosition();
|
updatePosition();
|
||||||
monitorPlaybackLevels();
|
monitorPlaybackLevels();
|
||||||
|
monitorMasterLevels();
|
||||||
applyAutomation();
|
applyAutomation();
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
previousEffectStructureRef.current = currentStructure;
|
previousEffectStructureRef.current = currentStructure;
|
||||||
}, [tracks, isPlaying, duration, masterVolume, monitorPlaybackLevels, applyAutomation]);
|
}, [tracks, isPlaying, duration, masterVolume, monitorPlaybackLevels, monitorMasterLevels, applyAutomation]);
|
||||||
|
|
||||||
// Stop playback when all tracks are deleted
|
// Stop playback when all tracks are deleted
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -730,6 +795,9 @@ export function useMultiTrackPlayer(
|
|||||||
if (levelMonitorFrameRef.current) {
|
if (levelMonitorFrameRef.current) {
|
||||||
cancelAnimationFrame(levelMonitorFrameRef.current);
|
cancelAnimationFrame(levelMonitorFrameRef.current);
|
||||||
}
|
}
|
||||||
|
if (masterLevelMonitorFrameRef.current) {
|
||||||
|
cancelAnimationFrame(masterLevelMonitorFrameRef.current);
|
||||||
|
}
|
||||||
if (automationFrameRef.current) {
|
if (automationFrameRef.current) {
|
||||||
cancelAnimationFrame(automationFrameRef.current);
|
cancelAnimationFrame(automationFrameRef.current);
|
||||||
}
|
}
|
||||||
@@ -750,11 +818,19 @@ export function useMultiTrackPlayer(
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const resetClipIndicator = useCallback(() => {
|
||||||
|
setMasterIsClipping(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isPlaying,
|
isPlaying,
|
||||||
currentTime,
|
currentTime,
|
||||||
duration,
|
duration,
|
||||||
trackLevels,
|
trackLevels,
|
||||||
|
masterPeakLevel,
|
||||||
|
masterRmsLevel,
|
||||||
|
masterIsClipping,
|
||||||
|
resetClipIndicator,
|
||||||
play,
|
play,
|
||||||
pause,
|
pause,
|
||||||
stop,
|
stop,
|
||||||
|
|||||||
Reference in New Issue
Block a user