mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-26 15:55:35 +00:00
audio part seperated from video editor
This commit is contained in:
@@ -140,11 +140,10 @@ import {
|
||||
validateProjectData,
|
||||
} from "./projectPersistence";
|
||||
import { SettingsPanel } from "./SettingsPanel";
|
||||
import { SOURCE_AUDIO_NORMALIZE_GAIN, getSourceTrackIdFromPath } from "./audio/sourceAudioTracks";
|
||||
import { useAudioPreviewSync } from "./audio/useAudioPreviewSync";
|
||||
import { useClipAudioSettingsController } from "./audio/useClipAudioSettingsController";
|
||||
import { useSourceAudioFallback } from "./audio/useSourceAudioFallback";
|
||||
import { getActiveClipIdAtSourceTime, isClipMutedById } from "./audio/clipAudio";
|
||||
import { useSourceAudioTrackSettings } from "./audio/useSourceAudioTrackSettings";
|
||||
import {
|
||||
APP_HEADER_ICON_BUTTON_CLASS,
|
||||
DiscordLinkButton,
|
||||
@@ -1791,24 +1790,12 @@ export default function VideoEditor() {
|
||||
onSourceAudioTracksMetaChange,
|
||||
onSelectedClipSourceAudioTrackVolumeChange,
|
||||
onSelectedClipSourceAudioTrackNormalizeChange,
|
||||
} = useSourceAudioTrackSettings({
|
||||
embeddedSourcePreviewGain,
|
||||
getSourceTrackPreviewGain,
|
||||
} = useClipAudioSettingsController({
|
||||
selectedClipId,
|
||||
activeClipId: activeClipIdAtCurrentTime,
|
||||
});
|
||||
const embeddedSourcePreviewGain = useMemo(() => {
|
||||
const settings = activeSourceAudioTrackSettings.mixed ?? { volume: 1, normalize: false };
|
||||
const normalizeGain = settings.normalize ? SOURCE_AUDIO_NORMALIZE_GAIN : 1;
|
||||
return Math.max(0, Math.min(2, settings.volume * normalizeGain));
|
||||
}, [activeSourceAudioTrackSettings]);
|
||||
const getSourceTrackPreviewGain = useCallback(
|
||||
(audioPath: string) => {
|
||||
const trackId = getSourceTrackIdFromPath(audioPath);
|
||||
const settings = activeSourceAudioTrackSettings[trackId] ?? { volume: 1, normalize: false };
|
||||
const normalizeGain = settings.normalize ? SOURCE_AUDIO_NORMALIZE_GAIN : 1;
|
||||
return Math.max(0, Math.min(2, settings.volume * normalizeGain));
|
||||
},
|
||||
[activeSourceAudioTrackSettings],
|
||||
);
|
||||
const isCurrentClipMuted = useMemo(() => {
|
||||
return isClipMutedById(activeClipIdAtCurrentTime, clipRegions);
|
||||
}, [activeClipIdAtCurrentTime, clipRegions]);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useCallback, useMemo } from "react";
|
||||
import {
|
||||
SOURCE_AUDIO_NORMALIZE_GAIN,
|
||||
getSourceTrackIdFromPath,
|
||||
} from "./sourceAudioTracks";
|
||||
import { useSourceAudioTrackSettings } from "./useSourceAudioTrackSettings";
|
||||
|
||||
interface UseClipAudioSettingsControllerParams {
|
||||
selectedClipId: string | null;
|
||||
activeClipId: string | null;
|
||||
}
|
||||
|
||||
export function useClipAudioSettingsController({
|
||||
selectedClipId,
|
||||
activeClipId,
|
||||
}: UseClipAudioSettingsControllerParams) {
|
||||
const {
|
||||
sourceAudioTrackMeta,
|
||||
activeSourceAudioTrackSettings,
|
||||
selectedClipSourceAudioTrackSettings,
|
||||
onSourceAudioTracksMetaChange,
|
||||
onSelectedClipSourceAudioTrackVolumeChange,
|
||||
onSelectedClipSourceAudioTrackNormalizeChange,
|
||||
} = useSourceAudioTrackSettings({
|
||||
selectedClipId,
|
||||
activeClipId,
|
||||
});
|
||||
|
||||
const embeddedSourcePreviewGain = useMemo(() => {
|
||||
const settings = activeSourceAudioTrackSettings.mixed ?? { volume: 1, normalize: false };
|
||||
const normalizeGain = settings.normalize ? SOURCE_AUDIO_NORMALIZE_GAIN : 1;
|
||||
return Math.max(0, Math.min(2, settings.volume * normalizeGain));
|
||||
}, [activeSourceAudioTrackSettings]);
|
||||
|
||||
const getSourceTrackPreviewGain = useCallback(
|
||||
(audioPath: string) => {
|
||||
const trackId = getSourceTrackIdFromPath(audioPath);
|
||||
const settings = activeSourceAudioTrackSettings[trackId] ?? {
|
||||
volume: 1,
|
||||
normalize: false,
|
||||
};
|
||||
const normalizeGain = settings.normalize ? SOURCE_AUDIO_NORMALIZE_GAIN : 1;
|
||||
return Math.max(0, Math.min(2, settings.volume * normalizeGain));
|
||||
},
|
||||
[activeSourceAudioTrackSettings],
|
||||
);
|
||||
|
||||
return {
|
||||
sourceAudioTrackMeta,
|
||||
activeSourceAudioTrackSettings,
|
||||
selectedClipSourceAudioTrackSettings,
|
||||
onSourceAudioTracksMetaChange,
|
||||
onSelectedClipSourceAudioTrackVolumeChange,
|
||||
onSelectedClipSourceAudioTrackNormalizeChange,
|
||||
embeddedSourcePreviewGain,
|
||||
getSourceTrackPreviewGain,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user