began merging footage and viewer

This commit is contained in:
itsmattkc
2021-04-05 16:41:37 +10:00
parent da4a93f1a5
commit 4066fcba90
26 changed files with 162 additions and 419 deletions
+30 -48
View File
@@ -35,7 +35,6 @@ TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_statu
TimelineScaledWidget(parent),
viewer_node_(nullptr),
auto_max_scrollbar_(false),
points_(nullptr),
toggle_show_all_(false),
auto_set_timebase_(true)
{
@@ -89,7 +88,6 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
SetTimebase(rational());
}
points_ = nullptr;
ruler()->ConnectTimelinePoints(nullptr);
scrollbar_->ConnectTimelinePoints(nullptr);
}
@@ -101,10 +99,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
if (viewer_node_) {
connect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
if ((points_ = GetTimelinePointsToConnect())) {
ruler()->ConnectTimelinePoints(points_);
scrollbar_->ConnectTimelinePoints(points_);
}
ruler()->ConnectTimelinePoints(viewer_node_->GetTimelinePoints());
scrollbar_->ConnectTimelinePoints(viewer_node_->GetTimelinePoints());
if (auto_set_timebase_) {
if (!viewer_node_->video_params().time_base().isNull()) {
@@ -242,27 +238,6 @@ void TimeBasedWidget::resizeEvent(QResizeEvent *event)
UpdateMaximumScroll();
}
TimelinePoints *TimeBasedWidget::GetTimelinePointsToConnect()
{
Sequence* sequence = dynamic_cast<Sequence*>(viewer_node_);
if (sequence) {
return sequence->timeline_points();
}
return nullptr;
}
Project *TimeBasedWidget::GetTimelinePointsProject()
{
return viewer_node_->project();
}
TimelinePoints *TimeBasedWidget::GetConnectedTimelinePoints() const
{
return points_;
}
void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base, bool connect_time_change_event)
{
if (connect_time_change_event) {
@@ -442,15 +417,16 @@ void TimeBasedWidget::SetAutoSetTimebase(bool e)
void TimeBasedWidget::SetPoint(Timeline::MovementMode m, const rational& time)
{
if (!points_) {
if (!viewer_node_) {
return;
}
MultiUndoCommand* command = new MultiUndoCommand();
TimelinePoints* points = viewer_node_->GetTimelinePoints();
// Enable workarea if it isn't already enabled
if (!points_->workarea()->enabled()) {
command->add_child(new WorkareaSetEnabledCommand(GetTimelinePointsProject(), points_, true));
if (!points->workarea()->enabled()) {
command->add_child(new WorkareaSetEnabledCommand(viewer_node_->project(), points, true));
}
// Determine our new range
@@ -459,34 +435,40 @@ void TimeBasedWidget::SetPoint(Timeline::MovementMode m, const rational& time)
if (m == Timeline::kTrimIn) {
in_point = time;
if (!points_->workarea()->enabled() || points_->workarea()->out() < in_point) {
if (!points->workarea()->enabled() || points->workarea()->out() < in_point) {
out_point = TimelineWorkArea::kResetOut;
} else {
out_point = points_->workarea()->out();
out_point = points->workarea()->out();
}
} else {
out_point = time;
if (!points_->workarea()->enabled() || points_->workarea()->in() > out_point) {
if (!points->workarea()->enabled() || points->workarea()->in() > out_point) {
in_point = TimelineWorkArea::kResetIn;
} else {
in_point = points_->workarea()->in();
in_point = points->workarea()->in();
}
}
// Set workarea
command->add_child(new WorkareaSetRangeCommand(GetTimelinePointsProject(), points_, TimeRange(in_point, out_point)));
command->add_child(new WorkareaSetRangeCommand(viewer_node_->project(), points, TimeRange(in_point, out_point)));
Core::instance()->undo_stack()->push(command);
}
void TimeBasedWidget::ResetPoint(Timeline::MovementMode m)
{
if (!points_ || !points_->workarea()->enabled()) {
if (!GetConnectedNode()) {
return;
}
TimeRange r = points_->workarea()->range();
TimelinePoints* points = GetConnectedNode()->GetTimelinePoints();
if (!GetConnectedNode() || !points->workarea()->enabled()) {
return;
}
TimeRange r = points->workarea()->range();
if (m == Timeline::kTrimIn) {
r.set_in(TimelineWorkArea::kResetIn);
@@ -494,7 +476,7 @@ void TimeBasedWidget::ResetPoint(Timeline::MovementMode m)
r.set_out(TimelineWorkArea::kResetOut);
}
Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(GetTimelinePointsProject(), points_, r));
Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(viewer_node_->project(), points, r));
}
void TimeBasedWidget::PageScrollInternal(QScrollBar *bar, int maximum, int screen_position, bool whole_page_scroll)
@@ -561,17 +543,17 @@ void TimeBasedWidget::ResetOut()
void TimeBasedWidget::ClearInOutPoints()
{
if (!points_) {
if (!GetConnectedNode()) {
return;
}
Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(GetTimelinePointsProject(), points_, false));
Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(GetConnectedNode()->project(), GetConnectedNode()->GetTimelinePoints(), false));
}
void TimeBasedWidget::SetMarker()
{
if (!points_) {
if (!GetConnectedNode()) {
return;
}
@@ -586,7 +568,7 @@ void TimeBasedWidget::SetMarker()
if (ok) {
Core::instance()->undo_stack()->push(new MarkerAddCommand(GetConnectedNode()->project(),
points_->markers(), TimeRange(GetTime(), GetTime()), marker_name));
GetConnectedNode()->GetTimelinePoints()->markers(), TimeRange(GetTime(), GetTime()), marker_name));
}
}
@@ -625,9 +607,9 @@ void TimeBasedWidget::ToggleShowAll()
void TimeBasedWidget::GoToIn()
{
if (viewer_node_) {
if (points_ && points_->workarea()->enabled()) {
SetTimeAndSignal(Timecode::time_to_timestamp(points_->workarea()->in(), timebase()));
if (GetConnectedNode()) {
if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase()));
} else {
GoToStart();
}
@@ -636,9 +618,9 @@ void TimeBasedWidget::GoToIn()
void TimeBasedWidget::GoToOut()
{
if (viewer_node_) {
if (points_ && points_->workarea()->enabled()) {
SetTimeAndSignal(Timecode::time_to_timestamp(points_->workarea()->out(), timebase()));
if (GetConnectedNode()) {
if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->out(), timebase()));
} else {
GoToEnd();
}
-8
View File
@@ -48,8 +48,6 @@ public:
ViewerOutput* GetConnectedNode() const;
TimelinePoints* GetConnectedTimelinePoints() const;
void ConnectViewerNode(ViewerOutput *node);
void SetScaleAndCenterOnPlayhead(const double& scale);
@@ -117,10 +115,6 @@ protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual TimelinePoints* GetTimelinePointsToConnect();
virtual Project* GetTimelinePointsProject();
void ConnectTimelineView(TimeBasedView* base, bool connect_time_change_event = true);
void PassWheelEventsToScrollBar(QObject* object);
@@ -197,8 +191,6 @@ private:
bool auto_max_scrollbar_;
TimelinePoints* points_;
QList<TimeBasedView*> timeline_views_;
bool toggle_show_all_;
+12 -12
View File
@@ -630,8 +630,7 @@ void TimelineWidget::Paste(bool insert)
void TimelineWidget::DeleteInToOut(bool ripple)
{
if (!GetConnectedNode()
|| !GetConnectedTimelinePoints()
|| !GetConnectedTimelinePoints()->workarea()->enabled()) {
|| !GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
return;
}
@@ -639,9 +638,10 @@ void TimelineWidget::DeleteInToOut(bool ripple)
if (ripple) {
command->add_child(new TimelineRippleRemoveAreaCommand(sequence(),
GetConnectedTimelinePoints()->workarea()->in(),
GetConnectedTimelinePoints()->workarea()->out()));
command->add_child(new TimelineRippleRemoveAreaCommand(
sequence(),
GetConnectedNode()->GetTimelinePoints()->workarea()->in(),
GetConnectedNode()->GetTimelinePoints()->workarea()->out()));
} else {
QVector<Track*> unlocked_tracks = sequence()->GetUnlockedTracks();
@@ -649,7 +649,7 @@ void TimelineWidget::DeleteInToOut(bool ripple)
foreach (Track* track, unlocked_tracks) {
GapBlock* gap = new GapBlock();
gap->set_length_and_media_out(GetConnectedTimelinePoints()->workarea()->length());
gap->set_length_and_media_out(GetConnectedNode()->GetTimelinePoints()->workarea()->length());
command->add_child(new NodeAddCommand(static_cast<NodeGraph*>(track->parent()),
gap));
@@ -657,17 +657,17 @@ void TimelineWidget::DeleteInToOut(bool ripple)
command->add_child(new TrackPlaceBlockCommand(sequence()->track_list(track->type()),
track->Index(),
gap,
GetConnectedTimelinePoints()->workarea()->in()));
GetConnectedNode()->GetTimelinePoints()->workarea()->in()));
}
}
// Clear workarea after this
command->add_child(new WorkareaSetEnabledCommand(GetTimelinePointsProject(),
GetConnectedTimelinePoints(),
command->add_child(new WorkareaSetEnabledCommand(GetConnectedNode()->project(),
GetConnectedNode()->GetTimelinePoints(),
false));
if (ripple) {
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedTimelinePoints()->workarea()->in(),
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(),
timebase()));
}
@@ -1513,8 +1513,8 @@ bool TimelineWidget::SnapPoint(QVector<rational> start_times, rational* movement
}
}
if ((snap_points & kSnapToMarkers) && GetConnectedTimelinePoints()) {
foreach (TimelineMarker* m, GetConnectedTimelinePoints()->markers()->list()) {
if ((snap_points & kSnapToMarkers)) {
foreach (TimelineMarker* m, GetConnectedNode()->GetTimelinePoints()->markers()->list()) {
qreal marker_pos = TimeToScene(m->time().in());
potential_snaps.append(AttemptSnap(screen_pt, marker_pos, start_times, m->time().in()));
+4 -3
View File
@@ -237,9 +237,10 @@ void ImportTool::FootageToGhosts(rational ghost_start, const QMap<Footage *, QVe
} else {
// Rescale stream duration to timeline timebase
// Convert to rational time
if (it.key()->workarea()->enabled()) {
footage_duration = qMax(footage_duration, it.key()->workarea()->range().length());
ghost->SetMediaIn(it.key()->workarea()->in());
TimelinePoints* tp = it.key()->GetTimelinePoints();
if (tp->workarea()->enabled()) {
footage_duration = qMax(footage_duration, tp->workarea()->range().length());
ghost->SetMediaIn(tp->workarea()->in());
} else {
int64_t dur;
rational tb;
+12 -106
View File
@@ -28,9 +28,10 @@
namespace olive {
#define super ViewerWidget
FootageViewerWidget::FootageViewerWidget(QWidget *parent) :
ViewerWidget(parent),
footage_(nullptr)
super(parent)
{
connect(display_widget(), &ViewerDisplayWidget::DragStarted, this, &FootageViewerWidget::StartFootageDrag);
@@ -39,71 +40,21 @@ FootageViewerWidget::FootageViewerWidget(QWidget *parent) :
connect(controls_, &PlaybackControls::AudioPressed, this, &FootageViewerWidget::StartAudioDrag);
}
Footage *FootageViewerWidget::GetFootage() const
void FootageViewerWidget::ConnectNodeInternal(ViewerOutput *n)
{
return footage_;
SetTimestamp(cached_timestamps_.value(n, 0));
}
void FootageViewerWidget::SetFootage(Footage *footage)
void FootageViewerWidget::DisconnectNodeInternal(ViewerOutput *n)
{
if (footage && !footage->project()) {
qCritical() << "Failed to set footage in footage viewer - footage had no project";
return;
}
if (footage_) {
cached_timestamps_.insert(footage_, GetTimestamp());
ViewerOutput* old_viewer = footage_->project()->footage_viewer();
ConnectViewerNode(nullptr);
if (old_viewer->IsInputConnected(ViewerOutput::kTextureInput)) {
Node::DisconnectEdge(old_viewer->GetConnectedOutput(ViewerOutput::kTextureInput), NodeInput(old_viewer, ViewerOutput::kTextureInput));
}
if (old_viewer->IsInputConnected(ViewerOutput::kSamplesInput)) {
Node::DisconnectEdge(old_viewer->GetConnectedOutput(ViewerOutput::kSamplesInput), NodeInput(old_viewer, ViewerOutput::kSamplesInput));
}
}
footage_ = footage;
if (footage_) {
ViewerOutput* new_viewer = footage_->project()->footage_viewer();
// Update sequence media name
new_viewer->SetLabel(footage_->GetLabel());
// Reset parameters and then attempt to set from footage
new_viewer->set_default_parameters();
new_viewer->set_parameters_from_footage({footage_});
// Try to connect video stream
TryConnectingType(new_viewer, footage, Stream::kVideo);
TryConnectingType(new_viewer, footage, Stream::kAudio);
ConnectViewerNode(new_viewer);
SetTimestamp(cached_timestamps_.value(footage_, 0));
} else {
SetTimestamp(0);
}
}
TimelinePoints *FootageViewerWidget::GetTimelinePointsToConnect()
{
return footage_;
}
Project *FootageViewerWidget::GetTimelinePointsProject()
{
return footage_->project();
// Cache timestamp in case this footage is opened again later
cached_timestamps_.insert(n, GetTimestamp());
SetTimestamp(0);
}
void FootageViewerWidget::StartFootageDragInternal(bool enable_video, bool enable_audio)
{
if (!GetFootage()) {
if (!GetConnectedNode()) {
return;
}
@@ -113,7 +64,7 @@ void FootageViewerWidget::StartFootageDragInternal(bool enable_video, bool enabl
QByteArray encoded_data;
QDataStream data_stream(&encoded_data, QIODevice::WriteOnly);
QVector<Footage::StreamReference> streams = GetFootage()->GetEnabledStreamsAsReferences();
QVector<Footage::StreamReference> streams = GetConnectedNode()->GetEnabledStreamsAsReferences();
// Disable streams that have been disabled
if (!enable_video || !enable_audio) {
@@ -129,7 +80,7 @@ void FootageViewerWidget::StartFootageDragInternal(bool enable_video, bool enabl
}
if (!streams.isEmpty()) {
data_stream << streams << reinterpret_cast<quintptr>(GetFootage());
data_stream << streams << reinterpret_cast<quintptr>(GetConnectedNode());
mimedata->setData(QStringLiteral("application/x-oliveprojectitemdata"), encoded_data);
drag->setMimeData(mimedata);
@@ -138,51 +89,6 @@ void FootageViewerWidget::StartFootageDragInternal(bool enable_video, bool enabl
}
}
void FootageViewerWidget::TryConnectingType(ViewerOutput* viewer, Footage *footage, Stream::Type type)
{
int index = -1;
for (int i=0; ; i++) {
if (type == Stream::kVideo) {
VideoParams vp = footage->GetVideoParams(i);
if (!vp.is_valid()) {
break;
}
if (vp.enabled()) {
index = i;
break;
}
} else if (type == Stream::kAudio) {
AudioParams vp = footage->GetAudioParams(i);
if (!vp.is_valid()) {
break;
}
if (vp.enabled()) {
index = i;
break;
}
}
}
if (index != -1) {
QString s = Footage::GetStringFromReference(type, index);
QString input_param;
if (type == Stream::kVideo) {
input_param = ViewerOutput::kTextureInput;
} else {
input_param = ViewerOutput::kSamplesInput;
}
Node::ConnectEdge(NodeOutput(footage, s), NodeInput(viewer, input_param));
}
}
void FootageViewerWidget::StartFootageDrag()
{
StartFootageDragInternal(true, true);
+3 -10
View File
@@ -32,22 +32,15 @@ class FootageViewerWidget : public ViewerWidget
public:
FootageViewerWidget(QWidget* parent = nullptr);
Footage* GetFootage() const;
void SetFootage(Footage* footage);
protected:
virtual TimelinePoints* GetTimelinePointsToConnect() override;
virtual void ConnectNodeInternal(ViewerOutput *) override;
virtual Project* GetTimelinePointsProject() override;
virtual void DisconnectNodeInternal(ViewerOutput *) override;
private:
void StartFootageDragInternal(bool enable_video, bool enable_audio);
void TryConnectingType(ViewerOutput *viewer, Footage* footage, Stream::Type type);
Footage* footage_;
QHash<Footage*, int64_t> cached_timestamps_;
QHash<ViewerOutput*, int64_t> cached_timestamps_;
private slots:
void StartFootageDrag();
+9 -12
View File
@@ -212,9 +212,7 @@ void ViewerWidget::ConnectNodeInternal(ViewerOutput *n)
UpdateStack();
waveform_view_->SetViewer(GetConnectedNode()->audio_playback_cache());
if (GetConnectedTimelinePoints()) {
waveform_view_->ConnectTimelinePoints(GetConnectedTimelinePoints());
}
waveform_view_->ConnectTimelinePoints(GetConnectedNode()->GetTimelinePoints());
UpdateRendererVideoParameters();
UpdateRendererAudioParameters();
@@ -361,8 +359,8 @@ void ViewerWidget::CacheEntireSequence()
void ViewerWidget::CacheSequenceInOut()
{
if (GetConnectedTimelinePoints() && GetConnectedTimelinePoints()->workarea()->enabled()) {
auto_cacher_.ForceCacheRange(GetConnectedTimelinePoints()->workarea()->range());
if (GetConnectedNode() && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
auto_cacher_.ForceCacheRange(GetConnectedNode()->GetTimelinePoints()->workarea()->range());
} else {
QMessageBox::warning(this,
tr("Error"),
@@ -974,10 +972,10 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos)
void ViewerWidget::Play(bool in_to_out_only)
{
if (in_to_out_only) {
if (GetConnectedTimelinePoints()
&& GetConnectedTimelinePoints()->workarea()->enabled()) {
if (GetConnectedNode()
&& GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
// Jump to in point
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedTimelinePoints()->workarea()->in(), timebase()));
SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase()));
} else {
in_to_out_only = false;
}
@@ -1072,12 +1070,11 @@ void ViewerWidget::PlaybackTimerUpdate()
{
if ((play_in_to_out_only_ || Config::Current()["Loop"].toBool())
&& GetConnectedTimelinePoints()
&& GetConnectedTimelinePoints()->workarea()->enabled()) {
&& GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) {
// If "play in to out" is enabled or we're looping AND we have a workarea, only play the workarea
min_time = Timecode::time_to_timestamp(GetConnectedTimelinePoints()->workarea()->in(), timebase());
max_time = Timecode::time_to_timestamp(GetConnectedTimelinePoints()->workarea()->out(), timebase());
min_time = Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase());
max_time = Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->out(), timebase());
} else {