106 lines
3.0 KiB
C++
106 lines
3.0 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "ChannelRack.h"
|
|
|
|
#include "ChannelRackItem.h"
|
|
#include "SlateOptMacros.h"
|
|
#include "SScrollBox.h"
|
|
#include "Singleton/PluginHostList.h"
|
|
#include "Pattern/MidiPattern.h"
|
|
#include "Singleton/MidiSequencer.h"
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
void SChannelRack::Construct(const FArguments& InArgs)
|
|
{
|
|
FPluginHostList::Get().OnInstrumentHostCreated.AddRaw(this, &SChannelRack::OnInstrumentHostCreated);
|
|
FPluginHostList::Get().OnPluginHostRemoved.AddRaw(this, &SChannelRack::OnInstrumentHostRemoved);
|
|
FPatternSelector::Get().OnPatternSelected.AddRaw(this, &SChannelRack::OnSelectPattern);
|
|
|
|
for (FPluginHost* PluginHost : FPluginHostList::Get().Instruments)
|
|
{
|
|
OnInstrumentHostCreated(PluginHost);
|
|
}
|
|
|
|
ChildSlot
|
|
[
|
|
SAssignNew(ListView, SScrollBox)
|
|
.AnimateWheelScrolling(true)
|
|
.ScrollBarThickness(FVector2D(2, 2))
|
|
];
|
|
|
|
OnSelectPattern(FPatternSelector::Get().GetSelectedPattern());
|
|
}
|
|
|
|
void SChannelRack::SelectPattern(FMidiPattern* Pattern)
|
|
{
|
|
TSharedPtr<SScrollPanel> ScrollPanel = ListView->GetScrollPanel();
|
|
auto& Children = ScrollPanel->Children;
|
|
for (int i = 0; i < Children.Num(); ++i)
|
|
{
|
|
TSharedRef<SChannelRackItem, ESPMode::ThreadSafe> Item = StaticCastSharedRef<SChannelRackItem>(Children.GetChildAt(i));
|
|
Item->SetPattern(Pattern);
|
|
}
|
|
}
|
|
|
|
void SChannelRack::OnSelectPattern(FPattern* Pattern)
|
|
{
|
|
if (!Pattern)
|
|
return;
|
|
if (Pattern->Type != EPatternType::Midi)
|
|
return;
|
|
SelectPattern((FMidiPattern*)Pattern);
|
|
}
|
|
|
|
void SChannelRack::UpdateSplitterAPosition(float A)
|
|
{
|
|
TSharedPtr<SScrollPanel> ScrollPanel = ListView->GetScrollPanel();
|
|
auto& Children = ScrollPanel->Children;
|
|
for (int i = 0; i < Children.Num(); ++i)
|
|
{
|
|
TSharedPtr<SChannelRackItem, ESPMode::ThreadSafe> Item = StaticCastSharedRef<SChannelRackItem>(Children.GetChildAt(i));
|
|
Item->SetSplliterASize(A);
|
|
}
|
|
}
|
|
|
|
void SChannelRack::UpdateSplitterBPosition(float B)
|
|
{
|
|
TSharedPtr<SScrollPanel> ScrollPanel = ListView->GetScrollPanel();
|
|
auto& Children = ScrollPanel->Children;
|
|
for (int i = 0; i < Children.Num(); ++i)
|
|
{
|
|
TSharedPtr<SChannelRackItem, ESPMode::ThreadSafe> Item = StaticCastSharedRef<SChannelRackItem>(Children.GetChildAt(i));
|
|
Item->SetSplliterBSize(B);
|
|
}
|
|
}
|
|
|
|
void SChannelRack::OnInstrumentHostCreated(FPluginHost* PluginHost)
|
|
{
|
|
ListView->AddSlot()
|
|
.AutoSize()
|
|
.Padding(0, 0, 0, 10)
|
|
[
|
|
SNew(SChannelRackItem, PluginHost)
|
|
.OnSplliterAPositionChanged(this, &SChannelRack::UpdateSplitterAPosition)
|
|
.OnSplliterBPositionChanged(this, &SChannelRack::UpdateSplitterBPosition)
|
|
];
|
|
}
|
|
|
|
void SChannelRack::OnInstrumentHostRemoved(FPluginHost* PluginHost)
|
|
{
|
|
TSharedPtr<SScrollPanel> ScrollPanel = ListView->GetScrollPanel();
|
|
FChildren* Children = ScrollPanel->GetChildren();
|
|
for (int i = 0; i < Children->Num(); ++i)
|
|
{
|
|
const TSharedRef<SChannelRackItem> ChannelRackItem = StaticCastSharedRef<SChannelRackItem>(Children->GetChildAt(i));
|
|
if (ChannelRackItem->GetPluginHost() == PluginHost)
|
|
{
|
|
ListView->RemoveSlot(ChannelRackItem);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|