tee342 commited on
Commit
9ea6d76
·
verified ·
1 Parent(s): 2490803

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -1061
app.py DELETED
@@ -1,1061 +0,0 @@
1
- "use client";
2
- import { useState, useRef, useEffect } from "react";
3
- import {
4
- Card,
5
- CardContent,
6
- CardHeader,
7
- CardTitle,
8
- CardDescription,
9
- } from "@/components/ui/card";
10
- import {
11
- Tabs,
12
- TabsContent,
13
- TabsList,
14
- TabsTrigger,
15
- } from "@/components/ui/tabs";
16
- import {
17
- Select,
18
- SelectContent,
19
- SelectItem,
20
- SelectTrigger,
21
- SelectValue,
22
- } from "@/components/ui/select";
23
- import { Slider } from "@/components/ui/slider";
24
- import { Switch } from "@/components/ui/switch";
25
- import { Label } from "@/components/ui/label";
26
- import { Badge } from "@/components/ui/badge";
27
- import { Button } from "@/components/ui/button";
28
- import { toast } from "@/components/ui/use-toast";
29
- import {
30
- Upload as UploadIcon,
31
- BarChart3 as BarChart3Icon,
32
- Sliders as SlidersIcon,
33
- RefreshCw as RefreshCwIcon,
34
- Music as MusicIcon,
35
- Headphones as HeadphonesIcon,
36
- Settings as SettingsIcon,
37
- Save as SaveIcon,
38
- Loader2 as Loader2Icon,
39
- ArrowLeft,
40
- Home,
41
- } from "lucide-react";
42
- import { useRouter } from "next/navigation";
43
- import { DownloadAudioButton } from "@/components/download-audio-button";
44
-
45
- // Your Hugging Face Space URL
46
- const HF_SPACE_URL = "https://tee342-audiomaster.hf.space";
47
-
48
- // Mastering Presets
49
- const masteringPresets = {
50
- pop: {
51
- lowGain: 2.0,
52
- lowMidGain: 0.5,
53
- midGain: 1.0,
54
- highMidGain: 2.0,
55
- highGain: 1.5,
56
- threshold: -18,
57
- ratio: 3.0,
58
- attack: 5,
59
- release: 80,
60
- knee: 8,
61
- limiterThreshold: -2.0,
62
- limiterRelease: 40,
63
- outputGain: 0.5,
64
- stereoWidth: 110,
65
- saturation: 15,
66
- },
67
- rock: {
68
- lowGain: 2.5,
69
- lowMidGain: 0.0,
70
- midGain: 0.5,
71
- highMidGain: 1.5,
72
- highGain: 2.0,
73
- threshold: -15,
74
- ratio: 4.0,
75
- attack: 3,
76
- release: 60,
77
- knee: 6,
78
- limiterThreshold: -1.5,
79
- limiterRelease: 30,
80
- outputGain: 0.0,
81
- stereoWidth: 105,
82
- saturation: 20,
83
- },
84
- electronic: {
85
- lowGain: 3.0,
86
- lowMidGain: 1.0,
87
- midGain: -0.5,
88
- highMidGain: 1.0,
89
- highGain: 3.0,
90
- threshold: -12,
91
- ratio: 4.5,
92
- attack: 2,
93
- release: 40,
94
- knee: 4,
95
- limiterThreshold: -1.0,
96
- limiterRelease: 20,
97
- outputGain: 0.0,
98
- stereoWidth: 120,
99
- saturation: 25,
100
- },
101
- hiphop: {
102
- lowGain: 3.5,
103
- lowMidGain: 1.5,
104
- midGain: -1.0,
105
- highMidGain: 0.5,
106
- highGain: 2.0,
107
- threshold: -14,
108
- ratio: 5.0,
109
- attack: 1,
110
- release: 50,
111
- knee: 5,
112
- limiterThreshold: -1.0,
113
- limiterRelease: 30,
114
- outputGain: 0.0,
115
- stereoWidth: 110,
116
- saturation: 30,
117
- },
118
- jazz: {
119
- lowGain: 1.5,
120
- lowMidGain: 1.0,
121
- midGain: 0.5,
122
- highMidGain: 1.0,
123
- highGain: 1.0,
124
- threshold: -20,
125
- ratio: 2.0,
126
- attack: 10,
127
- release: 120,
128
- knee: 10,
129
- limiterThreshold: -3.0,
130
- limiterRelease: 60,
131
- outputGain: 0.5,
132
- stereoWidth: 105,
133
- saturation: 10,
134
- },
135
- classical: {
136
- lowGain: 1.0,
137
- lowMidGain: 0.0,
138
- midGain: 0.0,
139
- highMidGain: 0.5,
140
- highGain: 1.0,
141
- threshold: -24,
142
- ratio: 1.5,
143
- attack: 20,
144
- release: 200,
145
- knee: 15,
146
- limiterThreshold: -3.5,
147
- limiterRelease: 80,
148
- outputGain: 1.0,
149
- stereoWidth: 115,
150
- saturation: 5,
151
- },
152
- acoustic: {
153
- lowGain: 1.5,
154
- lowMidGain: 1.0,
155
- midGain: 0.5,
156
- highMidGain: 0.5,
157
- highGain: 1.0,
158
- threshold: -20,
159
- ratio: 2.0,
160
- attack: 15,
161
- release: 150,
162
- knee: 12,
163
- limiterThreshold: -3.0,
164
- limiterRelease: 70,
165
- outputGain: 0.5,
166
- stereoWidth: 105,
167
- saturation: 10,
168
- },
169
- edm: {
170
- lowGain: 4.0,
171
- lowMidGain: 1.0,
172
- midGain: -1.0,
173
- highMidGain: 1.5,
174
- highGain: 3.5,
175
- threshold: -10,
176
- ratio: 5.0,
177
- attack: 1,
178
- release: 30,
179
- knee: 3,
180
- limiterThreshold: -0.5,
181
- limiterRelease: 15,
182
- outputGain: 0.0,
183
- stereoWidth: 125,
184
- saturation: 35,
185
- },
186
- };
187
- type MasteringParams = typeof masteringPresets.pop;
188
-
189
- export default function MasteringPage() {
190
- const [originalAudioUrl, setOriginalAudioUrl] = useState<string | null>(null);
191
- const [processedAudioUrl, setProcessedAudioUrl] = useState<string | null>(null);
192
- const [fileName, setFileName] = useState("No file selected");
193
- const [isProcessing, setIsProcessing] = useState(false);
194
- const [activeTab, setActiveTab] = useState("player");
195
- const [selectedPreset, setSelectedPreset] = useState("pop");
196
- const [useCustomSettings, setUseCustomSettings] = useState(false);
197
- const [customSettings, setCustomSettings] = useState<MasteringParams>(
198
- masteringPresets.pop
199
- );
200
- const router = useRouter();
201
-
202
- // Refs for audio elements
203
- const originalRef = useRef<HTMLAudioElement>(null);
204
- const processedRef = useRef<HTMLAudioElement>(null);
205
- const fileInputRef = useRef<HTMLInputElement>(null);
206
-
207
- // Handle file selection
208
- const handleFileSelect = (e) => {
209
- const file = e.target.files?.[0];
210
- if (!file) return;
211
- const formData = new FormData();
212
- formData.append("audio", file);
213
- formData.append("genre", selectedPreset);
214
- formData.append("target_lufs", "-14.0");
215
- fetch(`${HF_SPACE_URL}/api/master`, {
216
- method: "POST",
217
- body: formData,
218
- })
219
- .then((res) => res.json())
220
- .then((data) => {
221
- if (data && data.data && data.data.length >= 3) {
222
- setOriginalAudioUrl(data.data[0]);
223
- setProcessedAudioUrl(data.data[0]);
224
- setFileName(file.name);
225
- toast({
226
- title: "File Uploaded",
227
- description: `${file.name} is being processed.`,
228
- });
229
- }
230
- })
231
- .catch((err) => {
232
- console.error("Upload failed:", err);
233
- toast({
234
- title: "Error",
235
- description: "Could not process audio.",
236
- variant: "destructive",
237
- });
238
- });
239
- };
240
-
241
- // Apply mastering settings via Hugging Face API
242
- const applyMastering = async () => {
243
- if (!fileInputRef.current?.files?.[0]) {
244
- toast({
245
- title: "No Audio Selected",
246
- description: "Please upload a file first.",
247
- variant: "destructive",
248
- });
249
- return;
250
- }
251
- setIsProcessing(true);
252
- const file = fileInputRef.current.files[0];
253
- const formData = new FormData();
254
- formData.append("audio", file);
255
- formData.append("genre", selectedPreset);
256
- formData.append("target_lufs", "-14.0");
257
- try {
258
- const res = await fetch(`${HF_SPACE_URL}/api/master`, {
259
- method: "POST",
260
- body: formData,
261
- });
262
- const contentType = res.headers.get("content-type");
263
- if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
264
- if (contentType && contentType.includes("application/json")) {
265
- const data = await res.json();
266
- if (data.data && data.data.length >= 3) {
267
- setProcessedAudioUrl(data.data[0]);
268
- toast({
269
- title: "Mastering Complete",
270
- description: `Applied "${selectedPreset}" preset successfully.`,
271
- });
272
- }
273
- } else {
274
- const text = await res.text();
275
- console.error("Received HTML instead of JSON:", text);
276
- toast({
277
- title: "Server Error",
278
- description: "Your Hugging Face app returned an unexpected format.",
279
- variant: "destructive",
280
- });
281
- }
282
- } catch (error) {
283
- console.error("Mastering failed:", error);
284
- toast({
285
- title: "Error",
286
- description: error instanceof Error ? error.message : "Unknown error occurred.",
287
- variant: "destructive",
288
- });
289
- } finally {
290
- setIsProcessing(false);
291
- }
292
- };
293
-
294
- // Change genre/preset
295
- const handlePresetChange = (value: string) => {
296
- setSelectedPreset(value);
297
- setCustomSettings(masteringPresets[value as keyof typeof masteringPresets] || masteringPresets.pop);
298
- if (originalAudioUrl && !isProcessing) {
299
- applyMastering();
300
- }
301
- };
302
-
303
- // Update custom settings
304
- const updateCustomSetting = (key: keyof MasteringParams, value: number) => {
305
- setCustomSettings((prev) => ({
306
- ...prev,
307
- [key]: value,
308
- }));
309
- };
310
-
311
- // Cleanup URLs
312
- useEffect(() => {
313
- return () => {
314
- if (originalAudioUrl?.startsWith("blob:")) {
315
- URL.revokeObjectURL(originalAudioUrl);
316
- }
317
- if (processedAudioUrl?.startsWith("blob:")) {
318
- URL.revokeObjectURL(processedAudioUrl);
319
- }
320
- };
321
- }, [originalAudioUrl, processedAudioUrl]);
322
-
323
- // Stats for comparison view
324
- const [originalStats, setOriginalStats] = useState({
325
- rms: -18,
326
- peak: -3.5,
327
- crest: 14.5,
328
- lufs: -16.8,
329
- truePeak: -3.2,
330
- lra: 8.4,
331
- stereoWidth: 92,
332
- lowEnergy: -12.5,
333
- midEnergy: -15.2,
334
- highEnergy: -18.7,
335
- dynamicRange: 14.5,
336
- });
337
-
338
- const [processedStats, setProcessedStats] = useState({
339
- rms: -14,
340
- peak: -1.2,
341
- crest: 12.8,
342
- lufs: -14.0,
343
- truePeak: -1.0,
344
- lra: 6.8,
345
- stereoWidth: 105,
346
- lowEnergy: -10.2,
347
- midEnergy: -13.5,
348
- highEnergy: -16.3,
349
- dynamicRange: 12.8,
350
- });
351
-
352
- return (
353
- <div className="container mx-auto py-6 space-y-8">
354
- {/* Header + Upload Area */}
355
- <div className="flex flex-col md:flex-row justify-between items-start gap-4">
356
- <div className="flex items-center gap-4">
357
- <button
358
- onClick={() => router.back()}
359
- className="shrink-0 bg-gray-100 dark:bg-gray-800 p-2 rounded-full"
360
- >
361
- <span className="sr-only">Back</span>
362
- <ArrowLeft className="h-4 w-4" />
363
- </button>
364
- <button
365
- onClick={() => router.push("/dashboard")}
366
- className="shrink-0 bg-gray-100 dark:bg-gray-800 p-2 rounded-full"
367
- >
368
- <span className="sr-only">Home</span>
369
- <Home className="h-4 w-4" />
370
- </button>
371
- <div>
372
- <h1 className="text-3xl font-bold tracking-tight">AI Audio Mastering</h1>
373
- <p className="text-muted-foreground">Enhance your tracks with AI-powered tools.</p>
374
- </div>
375
- </div>
376
- <div className="flex items-center gap-2">
377
- <input
378
- type="file"
379
- ref={fileInputRef}
380
- onChange={handleFileSelect}
381
- accept="audio/*"
382
- className="hidden"
383
- />
384
- <button
385
- onClick={() => fileInputRef.current?.click()}
386
- className="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-md flex items-center"
387
- >
388
- <UploadIcon className="h-4 w-4 mr-2" />
389
- Upload Track
390
- </button>
391
- <button
392
- onClick={applyMastering}
393
- disabled={!originalAudioUrl || isProcessing}
394
- className={`${
395
- processedAudioUrl ? "bg-gray-100 text-black" : "bg-purple-600 hover:bg-purple-700 text-white"
396
- } px-4 py-2 rounded-md flex items-center`}
397
- >
398
- {isProcessing ? (
399
- <>
400
- <Loader2Icon className="h-4 w-4 mr-2 animate-spin" />
401
- Processing...
402
- </>
403
- ) : processedAudioUrl ? (
404
- <>
405
- <RefreshCwIcon className="h-4 w-4 mr-2" />
406
- Reprocess
407
- </>
408
- ) : (
409
- <>
410
- <SlidersIcon className="h-4 w-4 mr-2" />
411
- Apply Mastering
412
- </>
413
- )}
414
- </button>
415
- {processedAudioUrl && (
416
- <DownloadAudioButton
417
- audioUrl={processedAudioUrl}
418
- fileName={fileName}
419
- preset={selectedPreset}
420
- variant="secondary"
421
- />
422
- )}
423
- </div>
424
- </div>
425
- {/* Main Content */}
426
- {originalAudioUrl ? (
427
- <div className="space-y-6">
428
- <div className="flex flex-col md:flex-row gap-4">
429
- <Card className="w-full md:w-3/4">
430
- <CardHeader className="pb-3">
431
- <div className="flex justify-between items-center">
432
- <div>
433
- <CardTitle>Audio File</CardTitle>
434
- <CardDescription>{fileName}</CardDescription>
435
- </div>
436
- <div className="flex items-center gap-2">
437
- <Select value={selectedPreset} onValueChange={handlePresetChange}>
438
- <SelectTrigger className="w-[180px]">
439
- <SelectValue placeholder="Select Preset" />
440
- </SelectTrigger>
441
- <SelectContent>
442
- <SelectItem value="pop">Pop</SelectItem>
443
- <SelectItem value="rock">Rock</SelectItem>
444
- <SelectItem value="electronic">Electronic</SelectItem>
445
- <SelectItem value="hiphop">Hip Hop</SelectItem>
446
- <SelectItem value="jazz">Jazz</SelectItem>
447
- <SelectItem value="classical">Classical</SelectItem>
448
- <SelectItem value="acoustic">Acoustic</SelectItem>
449
- <SelectItem value="edm">EDM</SelectItem>
450
- </SelectContent>
451
- </Select>
452
- <div className="flex items-center gap-2">
453
- <Switch
454
- id="custom-settings"
455
- checked={useCustomSettings}
456
- onCheckedChange={setUseCustomSettings}
457
- />
458
- <Label htmlFor="custom-settings">Custom</Label>
459
- </div>
460
- </div>
461
- </div>
462
- </CardHeader>
463
- <CardContent>
464
- <Tabs value={activeTab} onValueChange={setActiveTab}>
465
- <TabsList className="grid grid-cols-4 mb-4">
466
- <TabsTrigger value="player">
467
- <VisualizerIcon className="h-4 w-4 mr-2" />
468
- Player
469
- </TabsTrigger>
470
- <TabsTrigger value="comparison">
471
- <HeadphonesIcon className="h-4 w-4 mr-2" />
472
- Comparison
473
- </TabsTrigger>
474
- <TabsTrigger value="analysis">
475
- <BarChart3Icon className="h-4 w-4 mr-2" />
476
- Analysis
477
- </TabsTrigger>
478
- <TabsTrigger value="settings" disabled={!useCustomSettings}>
479
- <SettingsIcon className="h-4 w-4 mr-2" />
480
- Settings
481
- </TabsTrigger>
482
- </TabsList>
483
- {/* Waveform & Preview */}
484
- <TabsContent value="player" className="space-y-4">
485
- <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
486
- <div>
487
- <h3 className="text-lg font-medium mb-2">Original</h3>
488
- <AudioWaveform src={originalAudioUrl} ref={originalRef} />
489
- </div>
490
- {processedAudioUrl && (
491
- <div>
492
- <h3 className="text-lg font-medium mb-2">Processed</h3>
493
- <AudioWaveform src={processedAudioUrl} ref={processedRef} />
494
- </div>
495
- )}
496
- </div>
497
- </TabsContent>
498
- {/* Compare Original vs Processed */}
499
- <TabsContent value="comparison">
500
- {processedAudioUrl ? (
501
- <ComparisonView
502
- originalRef={originalRef}
503
- processedRef={processedRef}
504
- originalSrc={originalAudioUrl}
505
- processedSrc={processedAudioUrl}
506
- />
507
- ) : (
508
- <div className="flex flex-col items-center justify-center py-12 text-center">
509
- <HeadphonesIcon className="h-12 w-12 text-gray-400 mb-4" />
510
- <h3 className="text-lg font-medium">No Processed Audio</h3>
511
- <p className="text-muted-foreground mt-2 max-w-md">
512
- Apply mastering to enable comparison between original and processed versions.
513
- </p>
514
- <button
515
- onClick={applyMastering}
516
- disabled={isProcessing}
517
- className="mt-4 bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-md flex items-center"
518
- >
519
- {isProcessing ? (
520
- <>
521
- <Loader2Icon className="h-4 w-4 mr-2 animate-spin" />
522
- Processing...
523
- </>
524
- ) : (
525
- <>
526
- <SlidersIcon className="h-4 w-4 mr-2" />
527
- Apply Mastering
528
- </>
529
- )}
530
- </button>
531
- </div>
532
- )}
533
- </TabsContent>
534
- {/* Analytics */}
535
- <TabsContent value="analysis">
536
- <AudioQualityAnalyzer
537
- audioUrl={originalAudioUrl}
538
- fileName={fileName}
539
- />
540
- </TabsContent>
541
- {/* Custom EQ Panel */}
542
- <TabsContent value="settings" className="space-y-6">
543
- {useCustomSettings && (
544
- <>
545
- <div className="space-y-4">
546
- <h3 className="text-lg font-medium">EQ Settings</h3>
547
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
548
- <div className="space-y-2">
549
- <div className="flex justify-between">
550
- <Label htmlFor="lowGain">Low Gain</Label>
551
- <span className="text-sm">{customSettings.lowGain} dB</span>
552
- </div>
553
- <Slider
554
- id="lowGain"
555
- min={-12}
556
- max={12}
557
- step={0.5}
558
- value={[customSettings.lowGain]}
559
- onValueChange={(val) =>
560
- updateCustomSetting("lowGain", val[0])
561
- }
562
- />
563
- </div>
564
- <div className="space-y-2">
565
- <div className="flex justify-between">
566
- <Label htmlFor="lowMidGain">Low Mid</Label>
567
- <span className="text-sm">{customSettings.lowMidGain} dB</span>
568
- </div>
569
- <Slider
570
- id="lowMidGain"
571
- min={-12}
572
- max={12}
573
- step={0.5}
574
- value={[customSettings.lowMidGain]}
575
- onValueChange={(val) =>
576
- updateCustomSetting("lowMidGain", val[0])
577
- }
578
- />
579
- </div>
580
- <div className="space-y-2">
581
- <div className="flex justify-between">
582
- <Label htmlFor="midGain">Mid</Label>
583
- <span className="text-sm">{customSettings.midGain} dB</span>
584
- </div>
585
- <Slider
586
- id="midGain"
587
- min={-12}
588
- max={12}
589
- step={0.5}
590
- value={[customSettings.midGain]}
591
- onValueChange={(val) =>
592
- updateCustomSetting("midGain", val[0])
593
- }
594
- />
595
- </div>
596
- <div className="space-y-2">
597
- <div className="flex justify-between">
598
- <Label htmlFor="highMidGain">High Mid</Label>
599
- <span className="text-sm">{customSettings.highMidGain} dB</span>
600
- </div>
601
- <Slider
602
- id="highMidGain"
603
- min={-12}
604
- max={12}
605
- step={0.5}
606
- value={[customSettings.highMidGain]}
607
- onValueChange={(val) =>
608
- updateCustomSetting("highMidGain", val[0])
609
- }
610
- />
611
- </div>
612
- <div className="space-y-2">
613
- <div className="flex justify-between">
614
- <Label htmlFor="highGain">High Gain</Label>
615
- <span className="text-sm">{customSettings.highGain} dB</span>
616
- </div>
617
- <Slider
618
- id="highGain"
619
- min={-12}
620
- max={12}
621
- step={0.5}
622
- value={[customSettings.highGain]}
623
- onValueChange={(val) =>
624
- updateCustomSetting("highGain", val[0])
625
- }
626
- />
627
- </div>
628
- </div>
629
- </div>
630
- <div className="space-y-4">
631
- <h3 className="text-lg font-medium">Compression</h3>
632
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
633
- <div className="space-y-2">
634
- <div className="flex justify-between">
635
- <Label htmlFor="threshold">Threshold</Label>
636
- <span className="text-sm">{customSettings.threshold} dB</span>
637
- </div>
638
- <Slider
639
- id="threshold"
640
- min={-50}
641
- max={0}
642
- step={1}
643
- value={[customSettings.threshold]}
644
- onValueChange={(val) =>
645
- updateCustomSetting("threshold", val[0])
646
- }
647
- />
648
- </div>
649
- <div className="space-y-2">
650
- <div className="flex justify-between">
651
- <Label htmlFor="ratio">Ratio</Label>
652
- <span className="text-sm">{customSettings.ratio}:1</span>
653
- </div>
654
- <Slider
655
- id="ratio"
656
- min={1}
657
- max={20}
658
- step={0.5}
659
- value={[customSettings.ratio]}
660
- onValueChange={(val) =>
661
- updateCustomSetting("ratio", val[0])
662
- }
663
- />
664
- </div>
665
- <div className="space-y-2">
666
- <div className="flex justify-between">
667
- <Label htmlFor="attack">Attack</Label>
668
- <span className="text-sm">{customSettings.attack} ms</span>
669
- </div>
670
- <Slider
671
- id="attack"
672
- min={0}
673
- max={100}
674
- step={1}
675
- value={[customSettings.attack]}
676
- onValueChange={(val) =>
677
- updateCustomSetting("attack", val[0])
678
- }
679
- />
680
- </div>
681
- <div className="space-y-2">
682
- <div className="flex justify-between">
683
- <Label htmlFor="release">Release</Label>
684
- <span className="text-sm">{customSettings.release} ms</span>
685
- </div>
686
- <Slider
687
- id="release"
688
- min={10}
689
- max={1000}
690
- step={10}
691
- value={[customSettings.release]}
692
- onValueChange={(val) =>
693
- updateCustomSetting("release", val[0])
694
- }
695
- />
696
- </div>
697
- <div className="space-y-2">
698
- <div className="flex justify-between">
699
- <Label htmlFor="knee">Knee</Label>
700
- <span className="text-sm">{customSettings.knee} dB</span>
701
- </div>
702
- <Slider
703
- id="knee"
704
- min={0}
705
- max={40}
706
- step={1}
707
- value={[customSettings.knee]}
708
- onValueChange={(val) =>
709
- updateCustomSetting("knee", val[0])
710
- }
711
- />
712
- </div>
713
- </div>
714
- </div>
715
- <div className="space-y-4">
716
- <h3 className="text-lg font-medium">Limiting & Output</h3>
717
- <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
718
- <div className="space-y-2">
719
- <div className="flex justify-between">
720
- <Label htmlFor="limiterThreshold">Limiter Threshold</Label>
721
- <span className="text-sm">{customSettings.limiterThreshold} dB</span>
722
- </div>
723
- <Slider
724
- id="limiterThreshold"
725
- min={-12}
726
- max={0}
727
- step={0.1}
728
- value={[customSettings.limiterThreshold]}
729
- onValueChange={(val) =>
730
- updateCustomSetting("limiterThreshold", val[0])
731
- }
732
- />
733
- </div>
734
- <div className="space-y-2">
735
- <div className="flex justify-between">
736
- <Label htmlFor="limiterRelease">Limiter Release</Label>
737
- <span className="text-sm">{customSettings.limiterRelease} ms</span>
738
- </div>
739
- <Slider
740
- id="limiterRelease"
741
- min={10}
742
- max={500}
743
- step={10}
744
- value={[customSettings.limiterRelease]}
745
- onValueChange={(val) =>
746
- updateCustomSetting("limiterRelease", val[0])
747
- }
748
- />
749
- </div>
750
- <div className="space-y-2">
751
- <div className="flex justify-between">
752
- <Label htmlFor="outputGain">Output Gain</Label>
753
- <span className="text-sm">{customSettings.outputGain} dB</span>
754
- </div>
755
- <Slider
756
- id="outputGain"
757
- min={-12}
758
- max={12}
759
- step={0.5}
760
- value={[customSettings.outputGain]}
761
- onValueChange={(val) =>
762
- updateCustomSetting("outputGain", val[0])
763
- }
764
- />
765
- </div>
766
- </div>
767
- </div>
768
- <div className="flex justify-end gap-2 mt-4">
769
- <Button
770
- variant="outline"
771
- onClick={() =>
772
- setCustomSettings(
773
- masteringPresets[
774
- selectedPreset as keyof typeof masteringPresets
775
- ] || masteringPresets.pop
776
- )
777
- }
778
- >
779
- Reset to Preset
780
- </Button>
781
- <Button
782
- onClick={applyMastering}
783
- disabled={isProcessing}
784
- >
785
- {isProcessing ? (
786
- <>
787
- <Loader2Icon className="h-4 w-4 mr-2 animate-spin" />
788
- Processing...
789
- </>
790
- ) : (
791
- <>
792
- <SaveIcon className="h-4 w-4 mr-2" />
793
- Apply Settings
794
- </>
795
- )}
796
- </Button>
797
- </div>
798
- </>
799
- )}
800
- </TabsContent>
801
- </Tabs>
802
- </CardContent>
803
- </Card>
804
- <Card className="w-full md:w-1/4">
805
- <CardHeader>
806
- <CardTitle>Genre Analysis</CardTitle>
807
- <CardDescription>Get genre-specific recommendations</CardDescription>
808
- </CardHeader>
809
- <CardContent>
810
- <div className="space-y-4">
811
- <div className="flex items-center gap-2">
812
- <MusicIcon className="h-5 w-5 text-primary" />
813
- <span>
814
- Selected Genre: <Badge>{selectedPreset}</Badge>
815
- </span>
816
- </div>
817
- <p className="text-sm text-muted-foreground">
818
- Analyze your track against genre standards for tailored mastering.
819
- </p>
820
- <button
821
- onClick={() => setActiveTab("analysis")}
822
- className="w-full bg-gray-100 hover:bg-gray-200 text-gray-800 px-4 py-2 rounded-md flex items-center justify-center"
823
- >
824
- <BarChart3Icon className="h-4 w-4 mr-2" />
825
- View Detailed Analysis
826
- </button>
827
- </div>
828
- </CardContent>
829
- </Card>
830
- </div>
831
- </div>
832
- ) : (
833
- <Card className="w-full">
834
- <CardContent className="flex flex-col items-center justify-center py-12 text-center">
835
- <UploadIcon className="h-12 w-12 text-muted-foreground mb-4" />
836
- <h3 className="text-lg font-medium">No Audio Selected</h3>
837
- <p className="text-muted-foreground mt-2 max-w-md">
838
- Upload a WAV, MP3, or FLAC file to begin mastering.
839
- </p>
840
- <button
841
- onClick={() => fileInputRef.current?.click()}
842
- className="mt-4 bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-md"
843
- >
844
- <UploadIcon className="h-4 w-4 mr-2" />
845
- Upload Audio
846
- </button>
847
- </CardContent>
848
- </Card>
849
- )}
850
- </div>
851
- );
852
- }
853
-
854
- // Simple Audio Player Component
855
- function AudioWaveform({ src, ref }) {
856
- const [isPlaying, setIsPlaying] = useState(false);
857
- const playerRef = ref || useRef(null);
858
- const togglePlayback = () => {
859
- if (!playerRef.current) return;
860
- if (isPlaying) {
861
- playerRef.current.pause();
862
- } else {
863
- playerRef.current.play().catch((err) => {
864
- console.error("Autoplay blocked:", err);
865
- alert("Click inside the waveform to start playback.");
866
- });
867
- }
868
- setIsPlaying(!isPlaying);
869
- };
870
- return (
871
- <div className="relative w-full">
872
- <div
873
- style={{
874
- height: "120px",
875
- background: isPlaying
876
- ? "linear-gradient(180deg, #a855fd22 0%, #9333ea88 100%)"
877
- : "#f3f4f6",
878
- position: "relative",
879
- overflow: "hidden",
880
- borderRadius: "0.5rem",
881
- cursor: "pointer",
882
- }}
883
- className="rounded-md overflow-hidden bg-muted/30 relative"
884
- onClick={togglePlayback}
885
- >
886
- <div className="absolute inset-0 flex items-center justify-center">
887
- <button
888
- onClick={(e) => {
889
- e.stopPropagation();
890
- togglePlayback();
891
- }}
892
- className="h-12 w-12 bg-white/80 backdrop-blur-sm rounded-full flex items-center justify-center shadow-md"
893
- >
894
- {isPlaying ? (
895
- <span className="h-4 w-4 block rounded-sm bg-primary"></span>
896
- ) : (
897
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
898
- <path d="M3 2.5L13 8L3 13.5V2.5Z" fill="#4f46e5" />
899
- </svg>
900
- )}
901
- </button>
902
- </div>
903
- </div>
904
- <audio
905
- ref={playerRef}
906
- src={src}
907
- onEnded={() => setIsPlaying(false)}
908
- onPause={() => setIsPlaying(false)}
909
- onPlay={() => setIsPlaying(true)}
910
- className="hidden"
911
- ></audio>
912
- </div>
913
- );
914
- }
915
-
916
- // Stats Display
917
- function MasteringStatistics({ originalStats, processedStats }) {
918
- return (
919
- <Card className="mt-4">
920
- <CardHeader className="pb-2">
921
- <CardTitle className="text-lg">Mastering Statistics</CardTitle>
922
- <CardDescription>Compare original and processed audio</CardDescription>
923
- </CardHeader>
924
- <CardContent>
925
- <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
926
- <div className="space-y-1">
927
- <div className="text-sm font-medium">LUFS</div>
928
- <div className="flex justify-between">
929
- <span className="text-xs">Original</span>
930
- <span className="font-mono">{originalStats.lufs.toFixed(1)}</span>
931
- </div>
932
- <div className="flex justify-between">
933
- <span className="text-xs">Processed</span>
934
- <span className="font-mono text-primary">
935
- {processedStats.lufs.toFixed(1)}
936
- </span>
937
- </div>
938
- </div>
939
- </div>
940
- </CardContent>
941
- </Card>
942
- );
943
- }
944
-
945
- // Compare Two Tracks
946
- function ComparisonView({ originalSrc, processedSrc, originalRef, processedRef }) {
947
- const [activeTrack, setActiveTrack] = useState<"original" | "processed">("processed");
948
- const switchTrack = (track: "original" | "processed") => {
949
- if (track === "original") {
950
- originalRef.current?.play().catch((err) => {
951
- console.error("Original playback failed:", err);
952
- alert("Click inside the waveform to enable playback.");
953
- });
954
- processedRef.current?.pause();
955
- } else {
956
- processedRef.current?.play().catch((err) => {
957
- console.error("Processed playback failed:", err);
958
- alert("Click inside the waveform to enable playback.");
959
- });
960
- originalRef.current?.pause();
961
- }
962
- setActiveTrack(track);
963
- };
964
- return (
965
- <div className="space-y-6">
966
- <div className="flex justify-center gap-4">
967
- <Button
968
- onClick={() => switchTrack("original")}
969
- variant={activeTrack === "original" ? "default" : "outline"}
970
- className="w-40"
971
- >
972
- Original
973
- </Button>
974
- <Button
975
- onClick={() => switchTrack("processed")}
976
- variant={activeTrack === "processed" ? "default" : "outline"}
977
- className="w-40"
978
- >
979
- Processed
980
- </Button>
981
- </div>
982
- </div>
983
- );
984
- }
985
-
986
- // Frequency Spectrum Analyzer
987
- function AudioQualityAnalyzer({ audioUrl, fileName }) {
988
- return (
989
- <div className="space-y-6">
990
- <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
991
- <Card>
992
- <CardHeader className="pb-2">
993
- <CardTitle className="text-lg">Frequency Spectrum</CardTitle>
994
- </CardHeader>
995
- <CardContent>
996
- <div className="h-40 bg-muted/30 rounded-md flex items-center justify-center">
997
- <p className="text-sm text-muted-foreground">Spectrum visualization</p>
998
- </div>
999
- </CardContent>
1000
- </Card>
1001
- <Card>
1002
- <CardHeader className="pb-2">
1003
- <CardTitle className="text-lg">Streaming Compatibility</CardTitle>
1004
- </CardHeader>
1005
- <CardContent>
1006
- <div className="space-y-3">
1007
- <div className="flex justify-between items-center">
1008
- <span className="text-sm">Spotify</span>
1009
- <div className="w-32 h-2 bg-muted rounded-full overflow-hidden">
1010
- <div className="h-full bg-green-500" style={{ width: "85%" }}></div>
1011
- </div>
1012
- <span className="text-sm font-medium">85%</span>
1013
- </div>
1014
- <div className="flex justify-between items-center">
1015
- <span className="text-sm">Apple Music</span>
1016
- <div className="w-32 h-2 bg-muted rounded-full overflow-hidden">
1017
- <div className="h-full bg-green-500" style={{ width: "90%" }}></div>
1018
- </div>
1019
- <span className="text-sm font-medium">90%</span>
1020
- </div>
1021
- <div className="flex justify-between items-center">
1022
- <span className="text-sm">YouTube</span>
1023
- <div className="w-32 h-2 bg-muted rounded-full overflow-hidden">
1024
- <div className="h-full bg-amber-500" style={{ width: "75%" }}></div>
1025
- </div>
1026
- <span className="text-sm font-medium">75%</span>
1027
- </div>
1028
- <div className="flex justify-between items-center">
1029
- <span className="text-sm">SoundCloud</span>
1030
- <div className="w-32 h-2 bg-muted rounded-full overflow-hidden">
1031
- <div className="h-full bg-green-500" style={{ width: "88%" }}></div>
1032
- </div>
1033
- <span className="text-sm font-medium">88%</span>
1034
- </div>
1035
- </div>
1036
- </CardContent>
1037
- </Card>
1038
- </div>
1039
- </div>
1040
- );
1041
- }
1042
-
1043
- // SVG Icon for waveform tab (used in Tabs)
1044
- function VisualizerIcon({ className }) {
1045
- return (
1046
- <svg
1047
- className={className}
1048
- fill="none"
1049
- stroke="currentColor"
1050
- viewBox="0 0 24 24"
1051
- xmlns="http://www.w3.org/2000/svg"
1052
- >
1053
- <path
1054
- strokeLinecap="round"
1055
- strokeLinejoin="round"
1056
- strokeWidth="2"
1057
- d="M6 18L18 6M6 6H2m10 12H2m4 0v-12"
1058
- ></path>
1059
- </svg>
1060
- );
1061
- }