Files
UnrealEngineUWP/Engine/Source/Editor/Sequencer/Public/SequencerKeyCollection.h
Max Chen 0167d4ea0f Sequencer: MVVM2 branch and Layer Bars
Copying //Tasks/UE5/Dev-SequencerMVVM2 to Main (//UE5/Main) @20364093

#preflight 628866dfb94f739b152c1e29
#preflight 628866e4585e8f793ee80943
#rb ludovic.chabant, andrew.rodham
#fyi ludovic.chabant, andrew.rodham, andrew.porter
#jira UE-105322

[CL 20364493 by Max Chen in ue5-main branch]
2022-05-25 10:39:33 -04:00

144 lines
5.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/ContainersFwd.h"
#include "CoreTypes.h"
#include "Misc/FrameNumber.h"
#include "Misc/Guid.h"
#include "Misc/OptionalFwd.h"
#include "MVVM/ViewModels/ViewModelHierarchy.h"
#include "Templates/SharedPointer.h"
class UMovieSceneSection;
class IKeyArea;
namespace UE
{
namespace Sequencer
{
class FViewModel;
}
}
template<typename> class TRange;
/** Enumeration used to define how to search for keys */
enum class EFindKeyDirection
{
Backwards, Forwards
};
struct FSequencerKeyCollectionSignature
{
using FViewModel = UE::Sequencer::FViewModel;
FSequencerKeyCollectionSignature()
{}
/** Initialize this key collection from the specified nodes. Only gathers keys from those explicitly specified. */
SEQUENCER_API static FSequencerKeyCollectionSignature FromNodes(const TArray<TSharedRef<FViewModel>>& InNodes, FFrameNumber InDuplicateThreshold);
/** Initialize this key collection from the specified nodes. Gathers keys from all child nodes. */
SEQUENCER_API static FSequencerKeyCollectionSignature FromNodesRecursive(const TArray<TSharedRef<FViewModel>>& InNodes, FFrameNumber InDuplicateThreshold);
/** Initialize this key collection from the specified node and section index. */
SEQUENCER_API static FSequencerKeyCollectionSignature FromNodeRecursive(TSharedRef<FViewModel> InNode, UMovieSceneSection* InSection, FFrameNumber InDuplicateThreshold);
/** Compare this signature for inequality with another */
SEQUENCER_API friend bool operator!=(const FSequencerKeyCollectionSignature& A, const FSequencerKeyCollectionSignature& B);
/** Compare this signature for equality with another */
SEQUENCER_API friend bool operator==(const FSequencerKeyCollectionSignature& A, const FSequencerKeyCollectionSignature& B);
/** Access the map of keyareas and signatures this signature was generated for */
const TMap<TSharedRef<IKeyArea>, FGuid>& GetKeyAreas() const
{
return KeyAreaToSignature;
}
/** Access duplicate threshold that this signature was generated for */
FFrameNumber GetDuplicateThreshold() const
{
return DuplicateThresholdTime;
}
private:
/** Check whether this signature contains content that cannot be cached (such content causes this signature to never compare equal with another) */
bool HasUncachableContent() const;
/** The time at which proximal keys are considered duplicates */
FFrameNumber DuplicateThresholdTime;
/** Map of key areas to the section signature with with this signature was generated */
TMap<TSharedRef<IKeyArea>, FGuid> KeyAreaToSignature;
};
/**
* A collection of keys gathered recursively from a particular node or nodes
*/
class FSequencerKeyCollection
{
public:
/**
* Search forwards or backwards for the first key within the specified range
*
* @param Range The range to search within
* @param Direction Whether to return the first or last key that reside in the given range
* @return (Optional) the time of the key that matched the range
*/
SEQUENCER_API TOptional<FFrameNumber> FindFirstKeyInRange(const TRange<FFrameNumber>& Range, EFindKeyDirection Direction) const;
SEQUENCER_API TOptional<FFrameNumber> FindFirstSectionKeyInRange(const TRange<FFrameNumber>& Range, EFindKeyDirection Direction) const;
/**
* Get a view of all key times that reside within the specified range
*
* @param Range The range to search within
* @return A (possibly empty) array view of all the times that lie within the range
*/
SEQUENCER_API TArrayView<const FFrameNumber> GetKeysInRange(const TRange<FFrameNumber>& Range) const;
SEQUENCER_API TArrayView<const FFrameNumber> GetSectionKeysInRange(const TRange<FFrameNumber>& Range) const;
/**
* Search forwards or backwards for the next key from the specified frame number
* @param FrameNumber The frame number to search from
* @param Direction Whether to return the next key or previous key from that time
* @return (Optional) Frame number of the key that's next or previous from that time
*/
SEQUENCER_API TOptional<FFrameNumber> GetNextKey(FFrameNumber FrameNumber, EFindKeyDirection Direction) const;
SEQUENCER_API TOptional<FFrameNumber> GetNextSectionKey(FFrameNumber FrameNumber, EFindKeyDirection Direction) const;
/**
* Access the signature this collection was generated with
*
* @return The signature that this collection was generated with
*/
const FSequencerKeyCollectionSignature& GetSignature() const
{
return Signature;
}
public:
/**
* Update this key collection using the specified signature
*
* @param InSignature The signature to generate keys for, containing all key areas to use for the generation
* @return true if this collection was updated, or false if it was already up to date
*/
bool Update(const FSequencerKeyCollectionSignature& InSignature);
private:
/** Times grouped by the supplied threshold */
TArray<FFrameNumber> GroupedTimes;
/** Section times grouped by the supplied threshold */
TArray<FFrameNumber> GroupedSectionTimes;
/** The signature with which the above array was generated */
FSequencerKeyCollectionSignature Signature;
};