start implementation of multicam panel

This commit is contained in:
itsmattkc
2022-09-21 13:16:19 -07:00
parent 2dc2edf3e0
commit 487cd166d7
21 changed files with 347 additions and 25 deletions
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2022 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/multicam/multicamwidget.cpp
widget/multicam/multicamwidget.h
PARENT_SCOPE
)
+104
View File
@@ -0,0 +1,104 @@
#include "multicamwidget.h"
namespace olive {
#define super ManagedDisplayWidget
MulticamWidget::MulticamWidget(QWidget *parent) :
super{parent},
node_(nullptr),
cacher_(nullptr),
tex_(nullptr)
{
}
void MulticamWidget::SetNode(MultiCamNode *n)
{
if (node_ == n) {
return;
}
if (node_) {
// Disconnect
}
node_ = n;
if (node_) {
// Connect
}
SetTime(time_);
}
void MulticamWidget::SetTime(const rational &r)
{
time_ = r;
if (node_) {
if (cacher_) {
int sources = node_->InputArraySize(node_->kSourcesInput);
watchers_.resize(sources);
textures_.resize(sources);
watchers_.fill(nullptr);
textures_.fill(nullptr);
for (int i=0; i<sources; i++) {
if (Node *n = node_->GetConnectedOutput(node_->kSourcesInput, 0)) {
auto w = new RenderTicketWatcher(this);
connect(w, &RenderTicketWatcher::Finished, this, &MulticamWidget::RenderedFrame);
w->SetTicket(cacher_->GetSingleFrame(n, time_, false));
watchers_[i] = w;
}
}
}
}
}
void MulticamWidget::OnInit()
{
super::OnInit();
pipeline_ = renderer()->CreateNativeShader(ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/multicam.frag"))));
}
void MulticamWidget::OnPaint()
{
// Clear display surface
renderer()->ClearDestination();
if (tex_) {
ColorTransformJob job;
job.SetColorProcessor(color_service());
job.SetInputTexture(tex_);
job.SetInputAlphaAssociation(kAlphaNone);
renderer()->BlitColorManaged(job, GetViewportParams());
}
}
void MulticamWidget::OnDestroy()
{
pipeline_.clear();
tex_ = nullptr;
super::OnDestroy();
}
void MulticamWidget::RenderedFrame()
{
auto watcher = static_cast<RenderTicketWatcher*>(sender());
if (watcher->HasResult()) {
int index = watchers_.indexOf(watcher);
if (index != -1) {
if ((textures_[index] = watcher->Get().value<TexturePtr>())) {
update();
}
}
}
delete watcher;
}
}
+59
View File
@@ -0,0 +1,59 @@
#ifndef MULTICAMWIDGET_H
#define MULTICAMWIDGET_H
#include "node/input/multicam/multicamnode.h"
#include "render/previewautocacher.h"
#include "widget/manageddisplay/manageddisplay.h"
namespace olive {
class MulticamWidget : public ManagedDisplayWidget
{
Q_OBJECT
public:
explicit MulticamWidget(QWidget *parent = nullptr);
MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR(MulticamWidget)
void SetNode(MultiCamNode *n);
void ConnectCacher(PreviewAutoCacher *c)
{
cacher_ = c;
}
public slots:
void SetTime(const rational &r);
protected slots:
virtual void OnInit() override;
virtual void OnPaint() override;
virtual void OnDestroy() override;
signals:
private:
MultiCamNode *node_;
QVariant pipeline_;
PreviewAutoCacher *cacher_;
rational time_;
TexturePtr tex_;
QVector<RenderTicketWatcher*> watchers_;
QVector<TexturePtr> textures_;
private slots:
void RenderedFrame();
};
}
#endif // MULTICAMWIDGET_H