various: fix broken transition creation

It's now possible to create transitions! But they're still broken in
a multitude of other ways so plenty more work to do hahahahahahahahaha
This commit is contained in:
itsmattkc
2020-07-14 22:31:11 +10:00
parent 11afdf32fe
commit ae62750d9d
21 changed files with 415 additions and 33 deletions
+11 -1
View File
@@ -281,16 +281,26 @@ const Tool::Item &Core::tool() const
return tool_;
}
const Tool::AddableObject &Core::selected_addable_object() const
const Tool::AddableObject &Core::GetSelectedAddableObject() const
{
return addable_object_;
}
const QString &Core::GetSelectedTransition() const
{
return selected_transition_;
}
void Core::SetSelectedAddableObject(const Tool::AddableObject &obj)
{
addable_object_ = obj;
}
void Core::SetSelectedTransitionObject(const QString &obj)
{
selected_transition_ = obj;
}
void Core::ClearOpenRecentList()
{
recent_projects_.clear();
+16 -1
View File
@@ -114,7 +114,12 @@ public:
/**
* @brief Get the currently selected object that the add tool should make (if the add tool is active)
*/
const Tool::AddableObject& selected_addable_object() const;
const Tool::AddableObject& GetSelectedAddableObject() const;
/**
* @brief Get the currently selected node that the transition tool should make (if the transition tool is active)
*/
const QString& GetSelectedTransition() const;
/**
* @brief Get current snapping value
@@ -341,6 +346,11 @@ public slots:
*/
void SetSelectedAddableObject(const Tool::AddableObject& obj);
/**
* @brief Set the currently selected object that the add tool should make
*/
void SetSelectedTransitionObject(const QString& obj);
/**
* @brief Clears the list of recently opened/saved projects
*/
@@ -456,6 +466,11 @@ private:
*/
Tool::AddableObject addable_object_;
/**
* @brief Currently selected transition
*/
QString selected_transition_;
/**
* @brief Current snapping setting
*/
+3
View File
@@ -14,6 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(crossdissolve)
add_subdirectory(diptocolor)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/block/transition/transition.h
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 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}
node/block/transition/crossdissolve/crossdissolvetransition.h
node/block/transition/crossdissolve/crossdissolvetransition.cpp
PARENT_SCOPE
)
@@ -0,0 +1,62 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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/>.
***/
#include "crossdissolvetransition.h"
OLIVE_NAMESPACE_ENTER
CrossDissolveTransition::CrossDissolveTransition()
{
}
Node *CrossDissolveTransition::copy() const
{
return new CrossDissolveTransition();
}
QString CrossDissolveTransition::Name() const
{
return tr("Cross Dissolve");
}
QString CrossDissolveTransition::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.crossdissolve");
}
QList<Node::CategoryID> CrossDissolveTransition::Category() const
{
return {kCategoryTransition};
}
QString CrossDissolveTransition::Description() const
{
return tr("Smoothly transition between two clips.");
}
ShaderCode CrossDissolveTransition::GetShaderCode(const QString &shader_id) const
{
Q_UNUSED(shader_id)
return ShaderCode(Node::ReadFileAsString(":/shaders/crossdissolve.frag"), QString());
}
OLIVE_NAMESPACE_EXIT
@@ -0,0 +1,48 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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/>.
***/
#ifndef CROSSDISSOLVETRANSITION_H
#define CROSSDISSOLVETRANSITION_H
#include "node/block/transition/transition.h"
OLIVE_NAMESPACE_ENTER
class CrossDissolveTransition : public TransitionBlock
{
public:
CrossDissolveTransition();
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QList<CategoryID> Category() const override;
virtual QString Description() const override;
//virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const QString& shader_id) const override;
};
OLIVE_NAMESPACE_EXIT
#endif // CROSSDISSOLVETRANSITION_H
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 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}
node/block/transition/diptocolor/diptocolortransition.h
node/block/transition/diptocolor/diptocolortransition.cpp
PARENT_SCOPE
)
@@ -0,0 +1,68 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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/>.
***/
#include "diptocolortransition.h"
OLIVE_NAMESPACE_ENTER
DipToColorTransition::DipToColorTransition()
{
color_input_ = new NodeInput(QStringLiteral("color_in"), NodeParam::kColor, QVariant::fromValue(Color(0, 0, 0)));
AddInput(color_input_);
}
Node *DipToColorTransition::copy() const
{
return new DipToColorTransition();
}
QString DipToColorTransition::Name() const
{
return tr("Dip To Color");
}
QString DipToColorTransition::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.diptocolor");
}
QList<Node::CategoryID> DipToColorTransition::Category() const
{
return {kCategoryTransition};
}
QString DipToColorTransition::Description() const
{
return tr("Transition between clips by dipping to a color.");
}
ShaderCode DipToColorTransition::GetShaderCode(const QString &shader_id) const
{
Q_UNUSED(shader_id)
return ShaderCode(Node::ReadFileAsString(":/shaders/diptoblack.frag"), QString());
}
void DipToColorTransition::ShaderJobEvent(NodeValueDatabase &value, ShaderJob &job) const
{
job.InsertValue(color_input_, value);
}
OLIVE_NAMESPACE_EXIT
@@ -0,0 +1,52 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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/>.
***/
#ifndef DIPTOCOLORTRANSITION_H
#define DIPTOCOLORTRANSITION_H
#include "node/block/transition/transition.h"
OLIVE_NAMESPACE_ENTER
class DipToColorTransition : public TransitionBlock
{
public:
DipToColorTransition();
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QList<CategoryID> Category() const override;
virtual QString Description() const override;
virtual ShaderCode GetShaderCode(const QString& shader_id) const override;
protected:
virtual void ShaderJobEvent(NodeValueDatabase &value, ShaderJob& job) const override;
private:
NodeInput* color_input_;
};
OLIVE_NAMESPACE_EXIT
#endif // DIPTOCOLORTRANSITION_H
+23 -8
View File
@@ -131,6 +131,8 @@ double TransitionBlock::GetInProgress(const rational &time) const
void TransitionBlock::Hash(QCryptographicHash &hash, const rational &time) const
{
Node::Hash(hash, time);
double all_prog = GetTotalProgress(time);
double in_prog = GetInProgress(time);
double out_prog = GetOutProgress(time);
@@ -138,14 +140,6 @@ void TransitionBlock::Hash(QCryptographicHash &hash, const rational &time) const
hash.addData(reinterpret_cast<const char*>(&all_prog), sizeof(double));
hash.addData(reinterpret_cast<const char*>(&in_prog), sizeof(double));
hash.addData(reinterpret_cast<const char*>(&out_prog), sizeof(double));
if (out_block_input_->is_connected()) {
out_block_input_->get_connected_node()->Hash(hash, time);
}
if (in_block_input_->is_connected()) {
in_block_input_->get_connected_node()->Hash(hash, time);
}
}
double TransitionBlock::GetInternalTransitionTime(const rational &time) const
@@ -177,4 +171,25 @@ void TransitionBlock::BlockDisconnected(NodeEdgePtr edge)
}
}
NodeValueTable TransitionBlock::Value(NodeValueDatabase &value) const
{
ShaderJob job;
job.InsertValue(out_block_input(), value);
job.InsertValue(in_block_input(), value);
job.SetAlphaChannelRequired(true);
ShaderJobEvent(value, job);
NodeValueTable table = value.Merge();
table.Push(NodeParam::kShaderJob, QVariant::fromValue(job), this);
return table;
}
void TransitionBlock::ShaderJobEvent(NodeValueDatabase &value, ShaderJob &job) const
{
Q_UNUSED(value)
Q_UNUSED(job)
}
OLIVE_NAMESPACE_EXIT
+5
View File
@@ -49,6 +49,11 @@ public:
virtual void Hash(QCryptographicHash& hash, const rational &time) const override;
virtual NodeValueTable Value(NodeValueDatabase &value) const override;
protected:
virtual void ShaderJobEvent(NodeValueDatabase &value, ShaderJob& job) const;
private:
double GetInternalTransitionTime(const rational& time) const;
+14 -3
View File
@@ -24,6 +24,8 @@
#include "audio/volume/volume.h"
#include "block/clip/clip.h"
#include "block/gap/gap.h"
#include "block/transition/crossdissolve/crossdissolvetransition.h"
#include "block/transition/diptocolor/diptocolortransition.h"
#include "generator/matrix/matrix.h"
#include "generator/polygon/polygon.h"
#include "generator/solid/solid.h"
@@ -48,7 +50,7 @@ void NodeFactory::Initialize()
// Add internal types
for (int i=0;i<kInternalNodeCount;i++) {
library_.append(CreateInternal(static_cast<InternalID>(i)));
library_.append(CreateFromFactoryIndex(static_cast<InternalID>(i)));
}
/*
@@ -63,7 +65,7 @@ void NodeFactory::Destroy()
library_.clear();
}
Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item)
Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item, Node::CategoryID restrict_to)
{
Menu* menu = new Menu(parent);
menu->setToolTipsVisible(true);
@@ -71,6 +73,11 @@ Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item)
for (int i=0;i<library_.size();i++) {
Node* n = library_.at(i);
if (restrict_to != Node::kCategoryUnknown && !n->Category().contains(restrict_to)) {
// Skip this node
continue;
}
// Make sure nodes are up-to-date with the current translation
n->Retranslate();
@@ -165,7 +172,7 @@ Node *NodeFactory::CreateFromID(const QString &id)
return nullptr;
}
Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id)
Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
{
switch (id) {
case kClipBlock:
@@ -204,6 +211,10 @@ Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id)
return new StrokeFilterNode();
case kTextGenerator:
return new TextGenerator();
case kCrossDissolveTransition:
return new CrossDissolveTransition();
case kDipToColorTransition:
return new DipToColorTransition();
case kInternalNodeCount:
break;
+6 -3
View File
@@ -50,6 +50,8 @@ public:
kMerge,
kStrokeFilter,
kTextGenerator,
kCrossDissolveTransition,
kDipToColorTransition,
// Count value
kInternalNodeCount
@@ -61,7 +63,7 @@ public:
static void Destroy();
static Menu* CreateMenu(QWidget *parent, bool create_none_item = false);
static Menu* CreateMenu(QWidget *parent, bool create_none_item = false, Node::CategoryID restrict_to = Node::kCategoryUnknown);
static Node* CreateFromMenuAction(QAction* action);
@@ -71,10 +73,11 @@ public:
static Node* CreateFromID(const QString& id);
private:
static Node* CreateInternal(const InternalID& id);
static Node* CreateFromFactoryIndex(const InternalID& id);
private:
static QList<Node*> library_;
};
OLIVE_NAMESPACE_EXIT
+2
View File
@@ -668,6 +668,8 @@ QString Node::GetCategoryName(const CategoryID &c)
return tr("Generator");
case kCategoryChannels:
return tr("Channel");
case kCategoryTransition:
return tr("Transition");
case kCategoryUnknown:
case kCategoryCount:
break;
+1
View File
@@ -70,6 +70,7 @@ public:
kCategoryGeneral,
kCategoryTimeline,
kCategoryChannels,
kCategoryTransition,
kCategoryCount
};
+1
View File
@@ -42,6 +42,7 @@ ToolPanel::ToolPanel(QWidget *parent) :
connect(Core::instance(), &Core::SnappingChanged, t, &Toolbar::SetSnapping);
connect(t, &Toolbar::AddableObjectChanged, Core::instance(), &Core::SetSelectedAddableObject);
connect(t, &Toolbar::SelectedTransitionChanged, Core::instance(), &Core::SetSelectedTransitionObject);
Retranslate();
}
+1 -2
View File
@@ -19,8 +19,7 @@ void main(void) {
}
if (in_block_in_enabled) {
vec4 in_block_col = texture(in_block_in, ove_texcoord) * ove_tprog_all;
composite += in_block_col;
composite += texture(in_block_in, ove_texcoord) * ove_tprog_all;
}
fragColor = composite;
+12 -14
View File
@@ -4,7 +4,9 @@ uniform sampler2D out_block_in;
uniform sampler2D in_block_in;
uniform bool out_block_in_enabled;
uniform bool in_block_in_enabled;
uniform vec4 color_in;
uniform float ove_tprog_all;
uniform float ove_tprog_out;
uniform float ove_tprog_in;
@@ -13,20 +15,16 @@ in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) {
vec4 out_block_col;
vec4 in_block_col;
if (out_block_in_enabled) {
out_block_col = texture(out_block_in, ove_texcoord) * pow(ove_tprog_out, 2.0);
} else {
out_block_col = vec4(0.0);
}
if (in_block_in_enabled) {
in_block_col = texture(in_block_in, ove_texcoord) * pow(ove_tprog_in, 2.0);
} else {
in_block_col = vec4(0.0);
}
if (out_block_in_enabled && in_block_in_enabled) {
vec4 out_block_col = mix(texture(out_block_in, ove_texcoord), color_in, ove_tprog_out);
vec4 in_block_col = mix(texture(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_in);
fragColor = out_block_col + in_block_col;
} else if (out_block_in_enabled) {
fragColor = mix(texture(out_block_in, ove_texcoord), color_in, ove_tprog_all);
} else if (in_block_in_enabled) {
fragColor = mix(texture(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_all);
} else {
fragColor = vec4(0.0);
}
}
@@ -20,6 +20,7 @@
#include "widget/timelinewidget/timelinewidget.h"
#include "node/block/transition/crossdissolve/crossdissolvetransition.h"
#include "node/block/transition/transition.h"
#include "node/factory.h"
#include "widget/nodeview/nodeviewundo.h"
@@ -111,7 +112,14 @@ void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
if (ghost_) {
if (!ghost_->AdjustedLength().isNull()) {
TransitionBlock* transition = static_cast<TransitionBlock*>(NodeFactory::CreateFromID("org.olivevideoeditor.Olive.crossdissolve"));
TransitionBlock* transition;
if (Core::instance()->GetSelectedTransition().isEmpty()) {
// Fallback if the user hasn't selected one yet
transition = new CrossDissolveTransition();
} else {
transition = static_cast<TransitionBlock*>(NodeFactory::CreateFromID(Core::instance()->GetSelectedTransition()));
}
QUndoCommand* command = new QUndoCommand();
+21 -1
View File
@@ -25,8 +25,9 @@
#include <QButtonGroup>
#include <QEvent>
#include "widget/menu/menu.h"
#include "node/factory.h"
#include "ui/icons/icons.h"
#include "widget/menu/menu.h"
OLIVE_NAMESPACE_ENTER
@@ -54,6 +55,9 @@ Toolbar::Toolbar(QWidget *parent) :
btn_snapping_toggle_ = CreateNonToolButton();
connect(btn_snapping_toggle_, &QPushButton::clicked, this, &Toolbar::SnappingButtonClicked);
// Connect transition button to menu signal
connect(btn_transition_tool_, &QPushButton::clicked, this, &Toolbar::TransitionButtonClicked);
// Connect add button to menu signal
connect(btn_add_, &QPushButton::clicked, this, &Toolbar::AddButtonClicked);
@@ -181,9 +185,25 @@ void Toolbar::AddButtonClicked()
m.exec(QCursor::pos());
}
void Toolbar::TransitionButtonClicked()
{
Menu* m = NodeFactory::CreateMenu(this, false, Node::kCategoryTransition);
connect(m, &QMenu::triggered, this, &Toolbar::TransitionMenuItemTriggered);
m->exec(QCursor::pos());
delete m;
}
void Toolbar::AddMenuItemTriggered(QAction* a)
{
emit AddableObjectChanged(static_cast<Tool::AddableObject>(a->data().toInt()));
}
void Toolbar::TransitionMenuItemTriggered(QAction *a)
{
emit SelectedTransitionChanged(NodeFactory::GetIDFromMenuAction(a));
}
OLIVE_NAMESPACE_EXIT
+17
View File
@@ -113,6 +113,11 @@ signals:
*/
void AddableObjectChanged(const Tool::AddableObject& obj);
/**
* @brief Emitted when the selected transition is changed from the transition tool menu
*/
void SelectedTransitionChanged(const QString& id);
private:
/**
* @brief Reset all strings based on the currently selected language
@@ -210,11 +215,23 @@ private slots:
*/
void AddButtonClicked();
/**
* @brief Receiver for the transition button
*
* The transition button pops up a list for which transition to create.
*/
void TransitionButtonClicked();
/**
* @brief Receiver for the menu created by AddButtonClicked()
*/
void AddMenuItemTriggered(QAction* a);
/**
* @brief Receiver for the menu created by TransitionButtonClicked()
*/
void TransitionMenuItemTriggered(QAction* a);
};
OLIVE_NAMESPACE_EXIT