From 38116b2319e42abbcb956635bc392183062886ec Mon Sep 17 00:00:00 2001 From: Sch <3516520171@qq.com> Date: Fri, 15 Sep 2023 09:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BD=B4=E6=B6=A6=E8=89=B2?= =?UTF-8?q?=EF=BC=88FIXME=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DragDropOperator/DragDropOperator.cpp | 6 ++-- Source/Cut5/Widgets/STimelineClip.cpp | 34 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp b/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp index 68f3de0..d6ce57c 100644 --- a/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp +++ b/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp @@ -832,7 +832,10 @@ void DragDropOperator::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& if (FUtils::DetectDragTypeCanDrop(NewClipData, TrackHead->TrackData.TrackType)) { TrackHead->TrackData.ClipData.Add(NewClipData); + + + UpdateClipProcess(TrackHead->MainWidgetInterface, NewClipData); if (NewClipData.ClipType == ETrackType::AudioTrack) { @@ -859,11 +862,8 @@ void DragDropOperator::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& } } } - - UpdateClipProcess(TrackHead->MainWidgetInterface, NewClipData); - } SavedMainInterface->GetCutTimeline()->RenderGroup(); diff --git a/Source/Cut5/Widgets/STimelineClip.cpp b/Source/Cut5/Widgets/STimelineClip.cpp index afe72d0..eb9bcfb 100644 --- a/Source/Cut5/Widgets/STimelineClip.cpp +++ b/Source/Cut5/Widgets/STimelineClip.cpp @@ -608,7 +608,7 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe const FSlateBrush Brush; - int32 NeedDrawCount = ClipData->GetLength() * FGlobalData::DefaultTimeTickSpace; + float DownSample = 4; // Draw Audio Waveform @@ -617,11 +617,17 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe const float RangeEnd = MainWidgetInterface->GetCutTimeline()->TrackBodyHScrollBox->GetCachedGeometry().LocalToAbsolute(FVector2D(MainWidgetInterface->GetCutTimeline()->TrackBodyHScrollBox->GetCachedGeometry().GetLocalSize().X, 0)).X; const float CurrentStartRange = AllottedGeometry.LocalToAbsolute(FVector2D(0, 0)).X; const float CurrentEndRange = AllottedGeometry.LocalToAbsolute(FVector2D(AllottedGeometry.GetLocalSize().X, 0)).X; - GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Red, FString::SanitizeFloat(RangeStart)); - GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green, FString::SanitizeFloat(RangeEnd)); - GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::White, FString::SanitizeFloat(CurrentStartRange)); - GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Yellow, FString::SanitizeFloat(CurrentEndRange)); + + + const int32 CropStartFrameOffset = ((CurrentStartRange * -1) + RangeStart > 0 ? (CurrentStartRange * -1) + RangeStart : 0) / FGlobalData::DefaultTimeTickSpace; + const int32 CropEndFrameOffset = (RangeEnd - CurrentEndRange > 0 ? + (RangeEnd - RangeStart) + CropStartFrameOffset * FGlobalData::DefaultTimeTickSpace : CropStartFrameOffset * FGlobalData::DefaultTimeTickSpace + (RangeEnd - RangeStart)) + / FGlobalData::DefaultTimeTickSpace; + + int32 NeedDrawCount = (CropEndFrameOffset - CropStartFrameOffset) * FGlobalData::DefaultTimeTickSpace; + + const int32 StartOffset = (ClipData->ResourcePropertyDataPtr->AudioSample / FGlobalData::GlobalFPS) @@ -631,8 +637,20 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe const int32 EndOffset = (ClipData->ResourcePropertyDataPtr->AudioSample / FGlobalData::GlobalFPS) * ClipData->VideoEndFrame * FUtils::GetFormatSampleBytesNum(ClipData->ResourcePropertyDataPtr->SampleFormat) * 2 / DownSample; + + const int32 CropStartDataOffset = (ClipData->ResourcePropertyDataPtr->AudioSample / FGlobalData::GlobalFPS) + * CropStartFrameOffset * FUtils::GetFormatSampleBytesNum(ClipData->ResourcePropertyDataPtr->SampleFormat) * 2 / DownSample; + + const int32 CropEndDataOffset = (ClipData->ResourcePropertyDataPtr->AudioSample / FGlobalData::GlobalFPS) + * CropEndFrameOffset * FUtils::GetFormatSampleBytesNum(ClipData->ResourcePropertyDataPtr->SampleFormat) * 2 / DownSample; + + const int32 Interval = ((EndOffset + CropEndDataOffset) - (StartOffset + CropStartDataOffset)) / NeedDrawCount; + + + GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Red, FString::FromInt(NeedDrawCount)); + GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green, FString::FromInt(Interval)); + - const int32 Interval = (EndOffset - StartOffset) / NeedDrawCount; for (int32 i = 0; i < NeedDrawCount / DownSample; i++) { const int32 CurrentIndex = (StartOffset * DownSample) + (i * (Interval * DownSample * 4)); @@ -643,8 +661,8 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe float Y = FMath::GetMappedRangeValueClamped(FVector2D(1.0, 0.0), FVector2D(0.0, AllottedGeometry.GetLocalSize().Y), FMath::Abs(NewFloat)); TArray NewLoc; - NewLoc.Add(FVector2D(i * DownSample, AllottedGeometry.GetLocalSize().Y)); - NewLoc.Add(FVector2D(i * DownSample, Y)); + NewLoc.Add(FVector2D((CropStartFrameOffset * FGlobalData::DefaultTimeTickSpace + i) * DownSample, AllottedGeometry.GetLocalSize().Y)); + NewLoc.Add(FVector2D((CropStartFrameOffset * FGlobalData::DefaultTimeTickSpace + i) * DownSample, Y)); FSlateDrawElement::MakeLines(OutDrawElements, LayerId + 6, AllottedGeometry.ToPaintGeometry(), NewLoc, ESlateDrawEffect::None, FColor(45, 214, 153, 255), true, DownSample * 1.2); }