159 lines
3.5 KiB
C++
159 lines
3.5 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "SMixerTrack.h"
|
|
|
|
#include "MultiBoxBuilder.h"
|
|
#include "SBorder.h"
|
|
#include "SlateApplication.h"
|
|
#include "SlateOptMacros.h"
|
|
|
|
#include "Mixer/MixerTrack.h"
|
|
|
|
#include "SSlider.h"
|
|
#include "STextBlock.h"
|
|
#include "Singleton/MixerList.h"
|
|
#include "Singleton/PluginHostList.h"
|
|
#include "UI/Widget/SVolumeMeterBar.h"
|
|
#include "Widgets/SBoxPanel.h"
|
|
|
|
#include "DSP/Dsp.h"
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
#define LOCTEXT_NAMESPACE "SMixerTrack"
|
|
|
|
void SMixerTrack::Construct(const FArguments& InArgs)
|
|
{
|
|
MixerTrack = InArgs._MixerTrack;
|
|
OnClicked = InArgs._OnClicked;
|
|
FText Name = FText::FromString(MixerTrack->GetName());
|
|
ChildSlot
|
|
[
|
|
SNew(SOverlay)
|
|
+SOverlay::Slot()
|
|
[
|
|
SAssignNew(Border, SBorder)
|
|
.Visibility(EVisibility::Collapsed)
|
|
.BorderImage(&White)
|
|
]
|
|
|
|
+SOverlay::Slot()
|
|
[
|
|
SNew(SVerticalBox)
|
|
+SVerticalBox::Slot()
|
|
.FillHeight(0.3f)
|
|
[
|
|
SNew(STextBlock)
|
|
.OverflowPolicy(ETextOverflowPolicy::Ellipsis)
|
|
.Text(Name)
|
|
.WrapTextAt(1)
|
|
]
|
|
+SVerticalBox::Slot()
|
|
.FillHeight(1.f)
|
|
[
|
|
SNew(SHorizontalBox)
|
|
+SHorizontalBox::Slot()
|
|
[
|
|
SNew(SVolumeMeterBar)
|
|
.Width(5)
|
|
.MinValue(-96.f)
|
|
.MaxValue(6.f)
|
|
.MeterValue(this, &SMixerTrack::MeterValue)
|
|
]
|
|
+SHorizontalBox::Slot()
|
|
[
|
|
SNew(SSlider)
|
|
.Orientation(EOrientation::Orient_Vertical)
|
|
.MinValue(-96.f)
|
|
.MaxValue(10.f)
|
|
.Value(Audio::ConvertToDecibels(MixerTrack->Gain))
|
|
.OnValueChanged(this, &SMixerTrack::OnVolumeChanged)
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
FReply SMixerTrack::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
|
{
|
|
if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
|
{
|
|
OnClicked.ExecuteIfBound(MixerTrack);
|
|
return FReply::Handled();
|
|
}
|
|
|
|
if (MouseEvent.GetEffectingButton() == EKeys::RightMouseButton)
|
|
{
|
|
ShowMenu();
|
|
}
|
|
return FReply::Unhandled();
|
|
}
|
|
|
|
void SMixerTrack::SetSelected(bool bInSelected)
|
|
{
|
|
Border->SetVisibility(bInSelected ? EVisibility::SelfHitTestInvisible : EVisibility::Collapsed);
|
|
}
|
|
|
|
void SMixerTrack::ShowMenu()
|
|
{
|
|
FMenuBuilder MenuBuilder(true, nullptr);
|
|
|
|
if (MixerTrack->Type == EMixerTrackType::Dummy)
|
|
{
|
|
MenuBuilder.AddMenuEntry(
|
|
LOCTEXT("DeleteTrack", "删除轨道"),
|
|
LOCTEXT("DeleteTrack", "删除轨道"),
|
|
FSlateIcon(),
|
|
FUIAction(FExecuteAction::CreateRaw(this, &SMixerTrack::DeleteTrack))
|
|
);
|
|
}
|
|
else
|
|
{
|
|
MenuBuilder.AddMenuEntry(
|
|
LOCTEXT("DeleteTrack", "删除乐器轨道"),
|
|
LOCTEXT("DeleteTrack", "删除乐器轨道(这将会导致删除乐器)"),
|
|
FSlateIcon(),
|
|
FUIAction(FExecuteAction::CreateRaw(this, &SMixerTrack::DeleteInstrument))
|
|
);
|
|
}
|
|
|
|
FSlateApplication::Get().PushMenu(
|
|
AsShared(),
|
|
FWidgetPath(),
|
|
MenuBuilder.MakeWidget(),
|
|
FSlateApplication::Get().GetCursorPos(),
|
|
FPopupTransitionEffect(FPopupTransitionEffect::ContextMenu)
|
|
);
|
|
}
|
|
|
|
void SMixerTrack::DeleteTrack()
|
|
{
|
|
FMixerList::Get().RemoveTrack(MixerTrack);
|
|
}
|
|
|
|
void SMixerTrack::DeleteInstrument()
|
|
{
|
|
FInstrumentMixerTrack* InstrumentMixerTrack = static_cast<FInstrumentMixerTrack*>(MixerTrack);
|
|
FPluginHostList::Get().RemoveInstrument(InstrumentMixerTrack->GetHost());
|
|
}
|
|
|
|
TArray<float> SMixerTrack::MeterValue() const
|
|
{
|
|
TArray<float> Out;
|
|
Out.Reset(2);
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
Out.Add(MixerTrack->GetPeak(i));
|
|
}
|
|
return Out;
|
|
}
|
|
|
|
void SMixerTrack::OnVolumeChanged(float X)
|
|
{
|
|
MixerTrack->Gain = Audio::ConvertToLinear(X);
|
|
}
|
|
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
#undef LOCTEXT_NAMESPACE
|