change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+61 -51
View File
@@ -22,7 +22,8 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString PanNode::kSamplesInput = QStringLiteral("samples_in");
const QString PanNode::kPanningInput = QStringLiteral("panning_in");
@@ -31,88 +32,97 @@ const QString PanNode::kPanningInput = QStringLiteral("panning_in");
PanNode::PanNode()
{
AddInput(kSamplesInput, NodeValue::kSamples, InputFlags(kInputFlagNotKeyframable));
AddInput(kSamplesInput, NodeValue::kSamples,
InputFlags(kInputFlagNotKeyframable));
AddInput(kPanningInput, NodeValue::kFloat, 0.0);
SetInputProperty(kPanningInput, QStringLiteral("min"), -1.0);
SetInputProperty(kPanningInput, QStringLiteral("max"), 1.0);
SetInputProperty(kPanningInput, QStringLiteral("view"), FloatSlider::kPercentage);
AddInput(kPanningInput, NodeValue::kFloat, 0.0);
SetInputProperty(kPanningInput, QStringLiteral("min"), -1.0);
SetInputProperty(kPanningInput, QStringLiteral("max"), 1.0);
SetInputProperty(kPanningInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetFlag(kAudioEffect);
SetEffectInput(kSamplesInput);
SetFlag(kAudioEffect);
SetEffectInput(kSamplesInput);
}
QString PanNode::Name() const
{
return tr("Pan");
return tr("Pan");
}
QString PanNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.pan");
return QStringLiteral("org.olivevideoeditor.Olive.pan");
}
QVector<Node::CategoryID> PanNode::Category() const
{
return {kCategoryFilter};
return { kCategoryFilter };
}
QString PanNode::Description() const
{
return tr("Adjust the stereo panning of an audio source.");
return tr("Adjust the stereo panning of an audio source.");
}
void PanNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void PanNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
// Create a sample job
SampleBuffer samples = value[kSamplesInput].toSamples();
if (samples.is_allocated()) {
// This node is only compatible with stereo audio
if (samples.audio_params().channel_count() == 2) {
// If the input is static, we can just do it now which will be faster
if (IsInputStatic(kPanningInput)) {
float pan_volume = value[kPanningInput].toDouble();
if (!qIsNull(pan_volume)) {
if (pan_volume > 0) {
samples.transform_volume_for_channel(0, 1.0f - pan_volume);
} else {
samples.transform_volume_for_channel(1, 1.0f + pan_volume);
}
}
// Create a sample job
SampleBuffer samples = value[kSamplesInput].toSamples();
if (samples.is_allocated()) {
// This node is only compatible with stereo audio
if (samples.audio_params().channel_count() == 2) {
// If the input is static, we can just do it now which will be faster
if (IsInputStatic(kPanningInput)) {
float pan_volume = value[kPanningInput].toDouble();
if (!qIsNull(pan_volume)) {
if (pan_volume > 0) {
samples.transform_volume_for_channel(0,
1.0f - pan_volume);
} else {
samples.transform_volume_for_channel(1,
1.0f + pan_volume);
}
}
table->Push(NodeValue(NodeValue::kSamples, samples, this));
} else {
// Requires job
table->Push(NodeValue::kSamples, SampleJob(globals.time(), kSamplesInput, value), this);
}
} else {
// Pass right through
table->Push(value[kSamplesInput]);
}
}
table->Push(NodeValue(NodeValue::kSamples, samples, this));
} else {
// Requires job
table->Push(NodeValue::kSamples,
SampleJob(globals.time(), kSamplesInput, value),
this);
}
} else {
// Pass right through
table->Push(value[kSamplesInput]);
}
}
}
void PanNode::ProcessSamples(const NodeValueRow &values, const SampleBuffer &input, SampleBuffer &output, int index) const
void PanNode::ProcessSamples(const NodeValueRow &values,
const SampleBuffer &input, SampleBuffer &output,
int index) const
{
float pan_val = values[kPanningInput].toDouble();
float pan_val = values[kPanningInput].toDouble();
for (int i=0;i<input.audio_params().channel_count();i++) {
output.data(i)[index] = input.data(i)[index];
}
for (int i = 0; i < input.audio_params().channel_count(); i++) {
output.data(i)[index] = input.data(i)[index];
}
if (pan_val > 0) {
output.data(0)[index] *= (1.0F - pan_val);
} else if (pan_val < 0) {
output.data(1)[index] *= (1.0F - qAbs(pan_val));
}
if (pan_val > 0) {
output.data(0)[index] *= (1.0F - pan_val);
} else if (pan_val < 0) {
output.data(1)[index] *= (1.0F - qAbs(pan_val));
}
}
void PanNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kSamplesInput, tr("Samples"));
SetInputName(kPanningInput, tr("Pan"));
SetInputName(kSamplesInput, tr("Samples"));
SetInputName(kPanningInput, tr("Pan"));
}
}
+20 -18
View File
@@ -23,34 +23,36 @@
#include "node/node.h"
namespace olive {
class PanNode : public Node
namespace olive
{
Q_OBJECT
class PanNode : public Node {
Q_OBJECT
public:
PanNode();
PanNode();
NODE_DEFAULT_FUNCTIONS(PanNode)
NODE_DEFAULT_FUNCTIONS(PanNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void ProcessSamples(const NodeValueRow &values, const SampleBuffer &input, SampleBuffer &output, int index) const override;
virtual void ProcessSamples(const NodeValueRow &values,
const SampleBuffer &input, SampleBuffer &output,
int index) const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
static const QString kSamplesInput;
static const QString kPanningInput;
static const QString kSamplesInput;
static const QString kPanningInput;
private:
NodeInput* samples_input_;
NodeInput* panning_input_;
NodeInput *samples_input_;
NodeInput *panning_input_;
};
}
+41 -34
View File
@@ -22,7 +22,8 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString VolumeNode::kSamplesInput = QStringLiteral("samples_in");
const QString VolumeNode::kVolumeInput = QStringLiteral("volume_in");
@@ -31,71 +32,77 @@ const QString VolumeNode::kVolumeInput = QStringLiteral("volume_in");
VolumeNode::VolumeNode()
{
AddInput(kSamplesInput, NodeValue::kSamples, InputFlags(kInputFlagNotKeyframable));
AddInput(kSamplesInput, NodeValue::kSamples,
InputFlags(kInputFlagNotKeyframable));
AddInput(kVolumeInput, NodeValue::kFloat, 1.0);
SetInputProperty(kVolumeInput, QStringLiteral("min"), 0.0);
SetInputProperty(kVolumeInput, QStringLiteral("view"), FloatSlider::kDecibel);
AddInput(kVolumeInput, NodeValue::kFloat, 1.0);
SetInputProperty(kVolumeInput, QStringLiteral("min"), 0.0);
SetInputProperty(kVolumeInput, QStringLiteral("view"),
FloatSlider::kDecibel);
SetFlag(kAudioEffect);
SetEffectInput(kSamplesInput);
SetFlag(kAudioEffect);
SetEffectInput(kSamplesInput);
}
QString VolumeNode::Name() const
{
return tr("Volume");
return tr("Volume");
}
QString VolumeNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.volume");
return QStringLiteral("org.olivevideoeditor.Olive.volume");
}
QVector<Node::CategoryID> VolumeNode::Category() const
{
return {kCategoryFilter};
return { kCategoryFilter };
}
QString VolumeNode::Description() const
{
return tr("Adjusts the volume of an audio source.");
return tr("Adjusts the volume of an audio source.");
}
void VolumeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void VolumeNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
// Create a sample job
SampleBuffer buffer = value[kSamplesInput].toSamples();
// Create a sample job
SampleBuffer buffer = value[kSamplesInput].toSamples();
if (buffer.is_allocated()) {
// If the input is static, we can just do it now which will be faster
if (IsInputStatic(kVolumeInput)) {
auto volume = value[kVolumeInput].toDouble();
if (buffer.is_allocated()) {
// If the input is static, we can just do it now which will be faster
if (IsInputStatic(kVolumeInput)) {
auto volume = value[kVolumeInput].toDouble();
if (!qFuzzyCompare(volume, 1.0)) {
buffer.transform_volume(volume);
}
if (!qFuzzyCompare(volume, 1.0)) {
buffer.transform_volume(volume);
}
table->Push(NodeValue::kSamples, QVariant::fromValue(buffer), this);
} else {
// Requires job
SampleJob job(globals.time(), kSamplesInput, value);
job.Insert(kVolumeInput, value);
table->Push(NodeValue::kSamples, QVariant::fromValue(job), this);
}
}
table->Push(NodeValue::kSamples, QVariant::fromValue(buffer), this);
} else {
// Requires job
SampleJob job(globals.time(), kSamplesInput, value);
job.Insert(kVolumeInput, value);
table->Push(NodeValue::kSamples, QVariant::fromValue(job), this);
}
}
}
void VolumeNode::ProcessSamples(const NodeValueRow &values, const SampleBuffer &input, SampleBuffer &output, int index) const
void VolumeNode::ProcessSamples(const NodeValueRow &values,
const SampleBuffer &input, SampleBuffer &output,
int index) const
{
return ProcessSamplesInternal(values, kOpMultiply, kSamplesInput, kVolumeInput, input, output, index);
return ProcessSamplesInternal(values, kOpMultiply, kSamplesInput,
kVolumeInput, input, output, index);
}
void VolumeNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kSamplesInput, tr("Samples"));
SetInputName(kVolumeInput, tr("Volume"));
SetInputName(kSamplesInput, tr("Samples"));
SetInputName(kVolumeInput, tr("Volume"));
}
}
+18 -16
View File
@@ -23,30 +23,32 @@
#include "node/math/math/mathbase.h"
namespace olive {
class VolumeNode : public MathNodeBase
namespace olive
{
Q_OBJECT
class VolumeNode : public MathNodeBase {
Q_OBJECT
public:
VolumeNode();
VolumeNode();
NODE_DEFAULT_FUNCTIONS(VolumeNode)
NODE_DEFAULT_FUNCTIONS(VolumeNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void ProcessSamples(const NodeValueRow &values, const SampleBuffer &input, SampleBuffer &output, int index) const override;
virtual void ProcessSamples(const NodeValueRow &values,
const SampleBuffer &input, SampleBuffer &output,
int index) const override;
virtual void Retranslate() override;
static const QString kSamplesInput;
static const QString kVolumeInput;
virtual void Retranslate() override;
static const QString kSamplesInput;
static const QString kVolumeInput;
};
}
+61 -55
View File
@@ -27,121 +27,127 @@
#include "transition/transition.h"
#include "widget/slider/rationalslider.h"
namespace olive {
namespace olive
{
#define super Node
const QString Block::kLengthInput = QStringLiteral("length_in");
Block::Block() :
previous_(nullptr),
next_(nullptr),
track_(nullptr)
Block::Block()
: previous_(nullptr)
, next_(nullptr)
, track_(nullptr)
{
AddInput(kLengthInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable | kInputFlagHidden));
SetInputProperty(kLengthInput, QStringLiteral("min"), QVariant::fromValue(rational(0, 1)));
SetInputProperty(kLengthInput, QStringLiteral("view"), RationalSlider::kTime);
SetInputProperty(kLengthInput, QStringLiteral("viewlock"), true);
AddInput(kLengthInput, NodeValue::kRational,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable |
kInputFlagHidden));
SetInputProperty(kLengthInput, QStringLiteral("min"),
QVariant::fromValue(rational(0, 1)));
SetInputProperty(kLengthInput, QStringLiteral("view"),
RationalSlider::kTime);
SetInputProperty(kLengthInput, QStringLiteral("viewlock"), true);
SetInputFlag(kEnabledInput, kInputFlagNotConnectable);
SetInputFlag(kEnabledInput, kInputFlagNotKeyframable);
SetInputFlag(kEnabledInput, kInputFlagNotConnectable);
SetInputFlag(kEnabledInput, kInputFlagNotKeyframable);
SetFlag(kDontShowInParamView);
SetFlag(kDontShowInParamView);
}
QVector<Node::CategoryID> Block::Category() const
{
return {kCategoryTimeline};
return { kCategoryTimeline };
}
rational Block::length() const
{
return GetStandardValue(kLengthInput).value<rational>();
return GetStandardValue(kLengthInput).value<rational>();
}
void Block::set_length_and_media_out(const rational &length)
{
if (length == this->length()) {
return;
}
if (length == this->length()) {
return;
}
set_length_internal(length);
set_length_internal(length);
}
void Block::set_length_and_media_in(const rational &length)
{
if (length == this->length()) {
return;
}
if (length == this->length()) {
return;
}
// Set the length without setting media out
set_length_internal(length);
// Set the length without setting media out
set_length_internal(length);
}
bool Block::is_enabled() const
{
return GetStandardValue(kEnabledInput).toBool();
return GetStandardValue(kEnabledInput).toBool();
}
void Block::set_enabled(bool e)
{
SetStandardValue(kEnabledInput, e);
SetStandardValue(kEnabledInput, e);
emit EnabledChanged();
emit EnabledChanged();
}
void Block::InputValueChangedEvent(const QString &input, int element)
{
super::InputValueChangedEvent(input, element);
super::InputValueChangedEvent(input, element);
if (input == kLengthInput) {
emit LengthChanged();
} else if (input == kEnabledInput) {
emit EnabledChanged();
}
if (input == kLengthInput) {
emit LengthChanged();
} else if (input == kEnabledInput) {
emit EnabledChanged();
}
}
void Block::set_length_internal(const rational &length)
{
SetStandardValue(kLengthInput, QVariant::fromValue(length));
SetStandardValue(kLengthInput, QVariant::fromValue(length));
}
void Block::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kLengthInput, tr("Length"));
SetInputName(kEnabledInput, tr("Enabled"));
SetInputName(kLengthInput, tr("Length"));
SetInputName(kEnabledInput, tr("Enabled"));
}
void Block::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
void Block::InvalidateCache(const TimeRange &range, const QString &from,
int element, InvalidateCacheOptions options)
{
TimeRange r;
TimeRange r;
if (from == kLengthInput) {
// We must intercept the signal here
r = TimeRange(qMin(length(), last_length_), RATIONAL_MAX);
if (from == kLengthInput) {
// We must intercept the signal here
r = TimeRange(qMin(length(), last_length_), RATIONAL_MAX);
if (!NodeInputDragger::IsInputBeingDragged()) {
last_length_ = length();
}
if (!NodeInputDragger::IsInputBeingDragged()) {
last_length_ = length();
}
options.insert(QStringLiteral("lengthevent"), true);
} else {
r = range;
}
options.insert(QStringLiteral("lengthevent"), true);
} else {
r = range;
}
super::InvalidateCache(r, from, element, options);
super::InvalidateCache(r, from, element, options);
}
void Block::set_previous_next(Block *previous, Block *next)
{
if (previous) {
previous->set_next(next);
}
if (next) {
next->set_previous(previous);
}
if (previous) {
previous->set_next(next);
}
if (next) {
next->set_previous(previous);
}
}
}
+75 -73
View File
@@ -24,118 +24,120 @@
#include "node/node.h"
#include "timeline/timelinecommon.h"
namespace olive {
namespace olive
{
class TransitionBlock;
/**
* @brief A Node that represents a block of time, also displayable on a Timeline
*/
class Block : public Node
{
Q_OBJECT
class Block : public Node {
Q_OBJECT
public:
Block();
Block();
virtual QVector<CategoryID> Category() const override;
virtual QVector<CategoryID> Category() const override;
const rational& in() const
{
return in_point_;
}
const rational &in() const
{
return in_point_;
}
const rational& out() const
{
return out_point_;
}
const rational &out() const
{
return out_point_;
}
void set_in(const rational& in)
{
in_point_ = in;
}
void set_in(const rational &in)
{
in_point_ = in;
}
void set_out(const rational& out)
{
out_point_ = out;
}
void set_out(const rational &out)
{
out_point_ = out;
}
rational length() const;
virtual void set_length_and_media_out(const rational &length);
virtual void set_length_and_media_in(const rational &length);
rational length() const;
virtual void set_length_and_media_out(const rational &length);
virtual void set_length_and_media_in(const rational &length);
TimeRange range() const
{
return TimeRange(in(), out());
}
TimeRange range() const
{
return TimeRange(in(), out());
}
Block* previous() const
{
return previous_;
}
Block *previous() const
{
return previous_;
}
Block* next() const
{
return next_;
}
Block *next() const
{
return next_;
}
void set_previous(Block* previous)
{
previous_ = previous;
}
void set_previous(Block *previous)
{
previous_ = previous;
}
void set_next(Block* next)
{
next_ = next;
}
void set_next(Block *next)
{
next_ = next;
}
Track* track() const
{
return track_;
}
Track *track() const
{
return track_;
}
void set_track(Track* track)
{
track_ = track;
emit TrackChanged(track_);
}
void set_track(Track *track)
{
track_ = track;
emit TrackChanged(track_);
}
bool is_enabled() const;
void set_enabled(bool e);
bool is_enabled() const;
void set_enabled(bool e);
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1, InvalidateCacheOptions options = InvalidateCacheOptions()) override;
virtual void InvalidateCache(
const TimeRange &range, const QString &from, int element = -1,
InvalidateCacheOptions options = InvalidateCacheOptions()) override;
static const QString kLengthInput;
static const QString kLengthInput;
static void set_previous_next(Block *previous, Block *next);
static void set_previous_next(Block *previous, Block *next);
public slots:
signals:
void EnabledChanged();
void EnabledChanged();
void LengthChanged();
void LengthChanged();
void PreviewChanged();
void PreviewChanged();
void TrackChanged(Track *track);
void TrackChanged(Track *track);
protected:
virtual void InputValueChangedEvent(const QString& input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
Block* previous_;
Block* next_;
Block *previous_;
Block *next_;
private:
void set_length_internal(const rational &length);
void set_length_internal(const rational &length);
rational in_point_;
rational out_point_;
Track* track_;
rational last_length_;
rational in_point_;
rational out_point_;
Track *track_;
rational last_length_;
};
}
+411 -334
View File
@@ -28,7 +28,8 @@
#include "widget/slider/floatslider.h"
#include "widget/slider/rationalslider.h"
namespace olive {
namespace olive
{
#define super Block
@@ -36,149 +37,164 @@ const QString ClipBlock::kBufferIn = QStringLiteral("buffer_in");
const QString ClipBlock::kMediaInInput = QStringLiteral("media_in_in");
const QString ClipBlock::kSpeedInput = QStringLiteral("speed_in");
const QString ClipBlock::kReverseInput = QStringLiteral("reverse_in");
const QString ClipBlock::kMaintainAudioPitchInput = QStringLiteral("maintain_audio_pitch_in");
const QString ClipBlock::kMaintainAudioPitchInput =
QStringLiteral("maintain_audio_pitch_in");
const QString ClipBlock::kAutoCacheInput = QStringLiteral("autocache_in");
const QString ClipBlock::kLoopModeInput = QStringLiteral("loop_in");
ClipBlock::ClipBlock() :
in_transition_(nullptr),
out_transition_(nullptr),
connected_viewer_(nullptr)
ClipBlock::ClipBlock()
: in_transition_(nullptr)
, out_transition_(nullptr)
, connected_viewer_(nullptr)
{
AddInput(kMediaInInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
SetInputProperty(kMediaInInput, QStringLiteral("view"), RationalSlider::kTime);
SetInputProperty(kMediaInInput, QStringLiteral("viewlock"), true);
AddInput(kMediaInInput, NodeValue::kRational,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
SetInputProperty(kMediaInInput, QStringLiteral("view"),
RationalSlider::kTime);
SetInputProperty(kMediaInInput, QStringLiteral("viewlock"), true);
AddInput(kSpeedInput, NodeValue::kFloat, 1.0, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
SetInputProperty(kSpeedInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kSpeedInput, QStringLiteral("min"), 0.0);
AddInput(kSpeedInput, NodeValue::kFloat, 1.0,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
SetInputProperty(kSpeedInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kSpeedInput, QStringLiteral("min"), 0.0);
AddInput(kReverseInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kReverseInput, NodeValue::kBoolean, false,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kMaintainAudioPitchInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kMaintainAudioPitchInput, NodeValue::kBoolean, false,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kAutoCacheInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kAutoCacheInput, NodeValue::kBoolean, false,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
PrependInput(kBufferIn, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
//SetValueHintForInput(kBufferIn, ValueHint(NodeValue::kBuffer));
PrependInput(kBufferIn, NodeValue::kNone,
InputFlags(kInputFlagNotKeyframable));
//SetValueHintForInput(kBufferIn, ValueHint(NodeValue::kBuffer));
SetEffectInput(kBufferIn);
SetEffectInput(kBufferIn);
AddInput(kLoopModeInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kLoopModeInput, NodeValue::kCombo, 0,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
}
QString ClipBlock::Name() const
{
if (connected_viewer_ && !connected_viewer_->GetLabel().isEmpty()) {
return connected_viewer_->GetLabel();
} else if (track()) {
if (track()->type() == Track::kVideo) {
return tr("Video Clip");
} else if (track()->type() == Track::kAudio) {
return tr("Audio Clip");
}
}
if (connected_viewer_ && !connected_viewer_->GetLabel().isEmpty()) {
return connected_viewer_->GetLabel();
} else if (track()) {
if (track()->type() == Track::kVideo) {
return tr("Video Clip");
} else if (track()->type() == Track::kAudio) {
return tr("Audio Clip");
}
}
return tr("Clip");
return tr("Clip");
}
QString ClipBlock::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.clip");
return QStringLiteral("org.olivevideoeditor.Olive.clip");
}
QString ClipBlock::Description() const
{
return tr("A time-based node that represents a media source.");
return tr("A time-based node that represents a media source.");
}
void ClipBlock::set_length_and_media_out(const rational &length)
{
if (length == this->length()) {
return;
}
if (length == this->length()) {
return;
}
if (reverse()) {
// Calculate media_in adjustment
rational proposed_media_in = SequenceToMediaTime(this->length() - length, kSTMIgnoreReverse | kSTMIgnoreLoop);
set_media_in(proposed_media_in);
}
if (reverse()) {
// Calculate media_in adjustment
rational proposed_media_in = SequenceToMediaTime(
this->length() - length, kSTMIgnoreReverse | kSTMIgnoreLoop);
set_media_in(proposed_media_in);
}
super::set_length_and_media_out(length);
super::set_length_and_media_out(length);
}
void ClipBlock::set_length_and_media_in(const rational &length)
{
if (length == this->length()) {
return;
}
if (length == this->length()) {
return;
}
rational old_length = this->length();
rational old_length = this->length();
super::set_length_and_media_in(length);
super::set_length_and_media_in(length);
if (!reverse()) {
// Calculate media_in adjustment
set_media_in(SequenceToMediaTime(old_length - length, kSTMIgnoreLoop));
}
if (!reverse()) {
// Calculate media_in adjustment
set_media_in(SequenceToMediaTime(old_length - length, kSTMIgnoreLoop));
}
}
rational ClipBlock::media_in() const
{
return GetStandardValue(kMediaInInput).value<rational>();
return GetStandardValue(kMediaInInput).value<rational>();
}
void ClipBlock::set_media_in(const rational &media_in)
{
SetStandardValue(kMediaInInput, QVariant::fromValue(media_in));
SetStandardValue(kMediaInInput, QVariant::fromValue(media_in));
RequestInvalidatedFromConnected();
RequestInvalidatedFromConnected();
}
void ClipBlock::SetAutocache(bool e)
{
SetStandardValue(kAutoCacheInput, e);
SetStandardValue(kAutoCacheInput, e);
}
void ClipBlock::DiscardCache()
{
if (Node *connected = GetConnectedOutput(kBufferIn)) {
Track::Type type = GetTrackType();
if (type == Track::kVideo) {
connected->video_frame_cache()->Invalidate(TimeRange(RATIONAL_MIN, RATIONAL_MAX));
} else if (type == Track::kAudio) {
connected->audio_playback_cache()->Invalidate(TimeRange(RATIONAL_MIN, RATIONAL_MAX));
}
}
if (Node *connected = GetConnectedOutput(kBufferIn)) {
Track::Type type = GetTrackType();
if (type == Track::kVideo) {
connected->video_frame_cache()->Invalidate(
TimeRange(RATIONAL_MIN, RATIONAL_MAX));
} else if (type == Track::kAudio) {
connected->audio_playback_cache()->Invalidate(
TimeRange(RATIONAL_MIN, RATIONAL_MAX));
}
}
}
rational ClipBlock::SequenceToMediaTime(const rational &sequence_time, uint64_t flags) const
rational ClipBlock::SequenceToMediaTime(const rational &sequence_time,
uint64_t flags) const
{
// These constants are not considered "values" per se, so we don't modify them
if (sequence_time == RATIONAL_MIN || sequence_time == RATIONAL_MAX) {
return sequence_time;
}
// These constants are not considered "values" per se, so we don't modify them
if (sequence_time == RATIONAL_MIN || sequence_time == RATIONAL_MAX) {
return sequence_time;
}
rational media_time = sequence_time;
rational media_time = sequence_time;
if (reverse() && !(flags & kSTMIgnoreReverse)) {
media_time = length() - media_time;
}
if (reverse() && !(flags & kSTMIgnoreReverse)) {
media_time = length() - media_time;
}
if (!(flags & kSTMIgnoreSpeed)) {
double speed_value = speed();
if (qIsNull(speed_value)) {
// Effectively holds the frame at the in point
media_time = 0;
} else if (!qFuzzyCompare(speed_value, 1.0)) {
// Multiply time
media_time = rational::fromDouble(media_time.toDouble() * speed_value);
}
}
if (!(flags & kSTMIgnoreSpeed)) {
double speed_value = speed();
if (qIsNull(speed_value)) {
// Effectively holds the frame at the in point
media_time = 0;
} else if (!qFuzzyCompare(speed_value, 1.0)) {
// Multiply time
media_time =
rational::fromDouble(media_time.toDouble() * speed_value);
}
}
media_time += media_in();
media_time += media_in();
/*if (!(flags & kSTMIgnoreLoop)
/*if (!(flags & kSTMIgnoreLoop)
&& this->loop_mode() != kLoopModeOff
&& connected_viewer_
&& !connected_viewer_->GetLength().isNull()
@@ -195,366 +211,427 @@ rational ClipBlock::SequenceToMediaTime(const rational &sequence_time, uint64_t
}
}*/
return media_time;
return media_time;
}
rational ClipBlock::MediaToSequenceTime(const rational &media_time) const
{
// These constants are not considered "values" per se, so we don't modify them
if (media_time == RATIONAL_MIN || media_time == RATIONAL_MAX) {
return media_time;
}
// These constants are not considered "values" per se, so we don't modify them
if (media_time == RATIONAL_MIN || media_time == RATIONAL_MAX) {
return media_time;
}
rational sequence_time = media_time - media_in();
rational sequence_time = media_time - media_in();
double speed_value = speed();
if (qIsNull(speed_value)) {
// I don't know what to return here yet...
sequence_time = rational::NaN;
} else if (!qFuzzyCompare(speed_value, 1.0)) {
// Divide time
sequence_time = rational::fromDouble(sequence_time.toDouble() / speed_value);
}
double speed_value = speed();
if (qIsNull(speed_value)) {
// I don't know what to return here yet...
sequence_time = rational::NaN;
} else if (!qFuzzyCompare(speed_value, 1.0)) {
// Divide time
sequence_time =
rational::fromDouble(sequence_time.toDouble() / speed_value);
}
if (reverse()) {
sequence_time = length() - sequence_time;
}
if (reverse()) {
sequence_time = length() - sequence_time;
}
return sequence_time;
return sequence_time;
}
void ClipBlock::RequestRangeFromConnected(const TimeRange &range)
{
Track::Type type = GetTrackType();
Track::Type type = GetTrackType();
if (type == Track::kVideo || type == Track::kAudio) {
if (Node *connected = GetConnectedOutput(kBufferIn)) {
TimeRange max_range = media_range();
if (type == Track::kVideo) {
// Handle thumbnails
RequestRangeForCache(connected->thumbnail_cache(), max_range, range, true, false);
{
TimeRange thumb_range = range.Intersected(max_range);
if (GetAdjustedThumbnailRange(&thumb_range)) {
connected->thumbnail_cache()->Request(this->track()->sequence(), thumb_range);
}
}
if (type == Track::kVideo || type == Track::kAudio) {
if (Node *connected = GetConnectedOutput(kBufferIn)) {
TimeRange max_range = media_range();
if (type == Track::kVideo) {
// Handle thumbnails
RequestRangeForCache(connected->thumbnail_cache(), max_range,
range, true, false);
{
TimeRange thumb_range = range.Intersected(max_range);
if (GetAdjustedThumbnailRange(&thumb_range)) {
connected->thumbnail_cache()->Request(
this->track()->sequence(), thumb_range);
}
}
// Handle video cache
RequestRangeForCache(connected->video_frame_cache(), max_range, range, true, IsAutocaching());
} else if (type == Track::kAudio) {
// Handle waveforms
RequestRangeForCache(connected->waveform_cache(), max_range, range, true, (OLIVE_CONFIG("TimelineWaveformMode").toInt() == Timeline::kWaveformsEnabled));
// Handle video cache
RequestRangeForCache(connected->video_frame_cache(), max_range,
range, true, IsAutocaching());
} else if (type == Track::kAudio) {
// Handle waveforms
RequestRangeForCache(
connected->waveform_cache(), max_range, range, true,
(OLIVE_CONFIG("TimelineWaveformMode").toInt() ==
Timeline::kWaveformsEnabled));
// Handle audio cache
RequestRangeForCache(connected->audio_playback_cache(), max_range, range, true, IsAutocaching());
}
}
}
// Handle audio cache
RequestRangeForCache(connected->audio_playback_cache(),
max_range, range, true, IsAutocaching());
}
}
}
}
void ClipBlock::RequestInvalidatedFromConnected(bool force_all, const TimeRange &intersect)
void ClipBlock::RequestInvalidatedFromConnected(bool force_all,
const TimeRange &intersect)
{
Track::Type type = GetTrackType();
Track::Type type = GetTrackType();
if (type == Track::kVideo || type == Track::kAudio) {
if (Node *connected = GetConnectedOutput(kBufferIn)) {
TimeRange max_range = media_range();
if (type == Track::kVideo || type == Track::kAudio) {
if (Node *connected = GetConnectedOutput(kBufferIn)) {
TimeRange max_range = media_range();
if (!intersect.length().isNull()) {
max_range = max_range.Intersected(intersect);
}
if (!intersect.length().isNull()) {
max_range = max_range.Intersected(intersect);
}
if (type == Track::kVideo) {
// Handle thumbnails
TimeRange thumb_range = max_range;
if (GetAdjustedThumbnailRange(&thumb_range)) {
RequestInvalidatedForCache(connected->thumbnail_cache(), thumb_range);
}
if (type == Track::kVideo) {
// Handle thumbnails
TimeRange thumb_range = max_range;
if (GetAdjustedThumbnailRange(&thumb_range)) {
RequestInvalidatedForCache(connected->thumbnail_cache(),
thumb_range);
}
// Handle video cache
if (IsAutocaching() || force_all) {
RequestInvalidatedForCache(connected->video_frame_cache(), max_range);
}
} else if (type == Track::kAudio) {
// Handle waveforms
if (OLIVE_CONFIG("TimelineWaveformMode").toInt() == Timeline::kWaveformsEnabled) {
RequestInvalidatedForCache(connected->waveform_cache(), max_range);
}
// Handle video cache
if (IsAutocaching() || force_all) {
RequestInvalidatedForCache(connected->video_frame_cache(),
max_range);
}
} else if (type == Track::kAudio) {
// Handle waveforms
if (OLIVE_CONFIG("TimelineWaveformMode").toInt() ==
Timeline::kWaveformsEnabled) {
RequestInvalidatedForCache(connected->waveform_cache(),
max_range);
}
// Handle audio cache
if (IsAutocaching() || force_all) {
RequestInvalidatedForCache(connected->audio_playback_cache(), max_range);
}
}
}
}
// Handle audio cache
if (IsAutocaching() || force_all) {
RequestInvalidatedForCache(
connected->audio_playback_cache(), max_range);
}
}
}
}
}
void ClipBlock::RequestRangeForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range, bool invalidate, bool request)
void ClipBlock::RequestRangeForCache(PlaybackCache *cache,
const TimeRange &max_range,
const TimeRange &range, bool invalidate,
bool request)
{
TimeRange r = range.Intersected(max_range);
TimeRange r = range.Intersected(max_range);
if (invalidate) {
cache->Invalidate(r);
}
if (invalidate) {
cache->Invalidate(r);
}
if (request) {
cache->Request(this->track()->sequence(), r);
}
if (request) {
cache->Request(this->track()->sequence(), r);
}
}
void ClipBlock::RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range)
void ClipBlock::RequestInvalidatedForCache(PlaybackCache *cache,
const TimeRange &max_range)
{
TimeRangeList invalid = cache->GetInvalidatedRanges(max_range);
TimeRangeList invalid = cache->GetInvalidatedRanges(max_range);
for (const PlaybackCache::Passthrough &p : cache->GetPassthroughs()) {
invalid.remove(p);
}
for (const PlaybackCache::Passthrough &p : cache->GetPassthroughs()) {
invalid.remove(p);
}
for (const TimeRange &r : invalid) {
RequestRangeForCache(cache, max_range, r, false, true);
}
for (const TimeRange &r : invalid) {
RequestRangeForCache(cache, max_range, r, false, true);
}
}
bool ClipBlock::GetAdjustedThumbnailRange(TimeRange *r) const
{
switch (static_cast<Timeline::ThumbnailMode>(OLIVE_CONFIG("TimelineThumbnailMode").toInt())) {
case Timeline::kThumbnailOff:
// Don't cache any range
return false;
case Timeline::kThumbnailInOut:
{
// Only cache in point
rational in = this->media_range().in();
if (r->Contains(in)) {
// Cache only the in point
*r = TimeRange(in, in + thumbnail_cache()->GetTimebase());
return true;
} else {
// Cache nothing
return false;
}
}
case Timeline::kThumbnailOn:
// Cache entire range
return true;
}
switch (static_cast<Timeline::ThumbnailMode>(
OLIVE_CONFIG("TimelineThumbnailMode").toInt())) {
case Timeline::kThumbnailOff:
// Don't cache any range
return false;
case Timeline::kThumbnailInOut: {
// Only cache in point
rational in = this->media_range().in();
if (r->Contains(in)) {
// Cache only the in point
*r = TimeRange(in, in + thumbnail_cache()->GetTimebase());
return true;
} else {
// Cache nothing
return false;
}
}
case Timeline::kThumbnailOn:
// Cache entire range
return true;
}
// Fallback
return true;
// Fallback
return true;
}
void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
void ClipBlock::InvalidateCache(const TimeRange &range, const QString &from,
int element, InvalidateCacheOptions options)
{
Q_UNUSED(element)
Q_UNUSED(element)
// If signal is from texture input, transform all times from media time to sequence time
if (from == kBufferIn) {
// Render caches where necessary
if (AreCachesEnabled()) {
RequestRangeFromConnected(range);
}
// If signal is from texture input, transform all times from media time to sequence time
if (from == kBufferIn) {
// Render caches where necessary
if (AreCachesEnabled()) {
RequestRangeFromConnected(range);
}
// Adjust range from media time to sequence time
TimeRange adj;
double speed_value = speed();
// Adjust range from media time to sequence time
TimeRange adj;
double speed_value = speed();
if (qIsNull(speed_value)) {
// Handle 0 speed by invalidating the whole clip
adj = TimeRange(RATIONAL_MIN, RATIONAL_MAX);
} else {
adj = TimeRange(MediaToSequenceTime(range.in()), MediaToSequenceTime(range.out()));
}
if (qIsNull(speed_value)) {
// Handle 0 speed by invalidating the whole clip
adj = TimeRange(RATIONAL_MIN, RATIONAL_MAX);
} else {
adj = TimeRange(MediaToSequenceTime(range.in()),
MediaToSequenceTime(range.out()));
}
// Find connected viewer node
auto viewers = FindInputNodesConnectedToInput<ViewerOutput>(NodeInput(this, kBufferIn), 1);
ViewerOutput *new_connected_viewer = viewers.isEmpty() ? nullptr : viewers.first();
// Find connected viewer node
auto viewers = FindInputNodesConnectedToInput<ViewerOutput>(
NodeInput(this, kBufferIn), 1);
ViewerOutput *new_connected_viewer =
viewers.isEmpty() ? nullptr : viewers.first();
if (new_connected_viewer != connected_viewer_) {
if (connected_viewer_) {
disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged);
disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged);
disconnect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged);
}
if (new_connected_viewer != connected_viewer_) {
if (connected_viewer_) {
disconnect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerAdded, this,
&ClipBlock::PreviewChanged);
disconnect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerRemoved, this,
&ClipBlock::PreviewChanged);
disconnect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerModified, this,
&ClipBlock::PreviewChanged);
}
connected_viewer_ = new_connected_viewer;
connected_viewer_ = new_connected_viewer;
if (connected_viewer_) {
connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerAdded, this, &ClipBlock::PreviewChanged);
connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerRemoved, this, &ClipBlock::PreviewChanged);
connect(connected_viewer_->GetMarkers(), &TimelineMarkerList::MarkerModified, this, &ClipBlock::PreviewChanged);
}
}
if (connected_viewer_) {
connect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerAdded, this,
&ClipBlock::PreviewChanged);
connect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerRemoved, this,
&ClipBlock::PreviewChanged);
connect(connected_viewer_->GetMarkers(),
&TimelineMarkerList::MarkerModified, this,
&ClipBlock::PreviewChanged);
}
}
super::InvalidateCache(adj, from, element, options);
} else {
// Otherwise, pass signal along normally
super::InvalidateCache(range, from, element, options);
}
super::InvalidateCache(adj, from, element, options);
} else {
// Otherwise, pass signal along normally
super::InvalidateCache(range, from, element, options);
}
}
void ClipBlock::LinkChangeEvent()
{
block_links_.clear();
block_links_.clear();
foreach (Node* n, links()) {
ClipBlock* b = dynamic_cast<ClipBlock*>(n);
foreach (Node *n, links()) {
ClipBlock *b = dynamic_cast<ClipBlock *>(n);
if (b) {
block_links_.append(b);
}
}
if (b) {
block_links_.append(b);
}
}
}
void ClipBlock::InputConnectedEvent(const QString &input, int element, Node *output)
void ClipBlock::InputConnectedEvent(const QString &input, int element,
Node *output)
{
super::InputConnectedEvent(input, element, output);
super::InputConnectedEvent(input, element, output);
if (input == kBufferIn) {
connect(output->thumbnail_cache(), &FrameHashCache::Invalidated, this, &Block::PreviewChanged);
connect(output->waveform_cache(), &AudioPlaybackCache::Invalidated, this, &Block::PreviewChanged);
connect(output->video_frame_cache(), &FrameHashCache::Invalidated, this, &Block::PreviewChanged);
connect(output->audio_playback_cache(), &AudioPlaybackCache::Invalidated, this, &Block::PreviewChanged);
connect(output->thumbnail_cache(), &FrameHashCache::Validated, this, &Block::PreviewChanged);
connect(output->waveform_cache(), &AudioPlaybackCache::Validated, this, &Block::PreviewChanged);
connect(output->video_frame_cache(), &FrameHashCache::Validated, this, &Block::PreviewChanged);
connect(output->audio_playback_cache(), &AudioPlaybackCache::Validated, this, &Block::PreviewChanged);
}
if (input == kBufferIn) {
connect(output->thumbnail_cache(), &FrameHashCache::Invalidated, this,
&Block::PreviewChanged);
connect(output->waveform_cache(), &AudioPlaybackCache::Invalidated,
this, &Block::PreviewChanged);
connect(output->video_frame_cache(), &FrameHashCache::Invalidated, this,
&Block::PreviewChanged);
connect(output->audio_playback_cache(),
&AudioPlaybackCache::Invalidated, this, &Block::PreviewChanged);
connect(output->thumbnail_cache(), &FrameHashCache::Validated, this,
&Block::PreviewChanged);
connect(output->waveform_cache(), &AudioPlaybackCache::Validated, this,
&Block::PreviewChanged);
connect(output->video_frame_cache(), &FrameHashCache::Validated, this,
&Block::PreviewChanged);
connect(output->audio_playback_cache(), &AudioPlaybackCache::Validated,
this, &Block::PreviewChanged);
}
}
void ClipBlock::InputDisconnectedEvent(const QString &input, int element, Node *output)
void ClipBlock::InputDisconnectedEvent(const QString &input, int element,
Node *output)
{
super::InputDisconnectedEvent(input, element, output);
super::InputDisconnectedEvent(input, element, output);
if (input == kBufferIn) {
disconnect(output->thumbnail_cache(), &FrameHashCache::Invalidated, this, &Block::PreviewChanged);
disconnect(output->waveform_cache(), &AudioPlaybackCache::Invalidated, this, &Block::PreviewChanged);
disconnect(output->video_frame_cache(), &FrameHashCache::Invalidated, this, &Block::PreviewChanged);
disconnect(output->audio_playback_cache(), &AudioPlaybackCache::Invalidated, this, &Block::PreviewChanged);
disconnect(output->thumbnail_cache(), &FrameHashCache::Validated, this, &Block::PreviewChanged);
disconnect(output->waveform_cache(), &AudioPlaybackCache::Validated, this, &Block::PreviewChanged);
disconnect(output->video_frame_cache(), &FrameHashCache::Validated, this, &Block::PreviewChanged);
disconnect(output->audio_playback_cache(), &AudioPlaybackCache::Validated, this, &Block::PreviewChanged);
}
if (input == kBufferIn) {
disconnect(output->thumbnail_cache(), &FrameHashCache::Invalidated,
this, &Block::PreviewChanged);
disconnect(output->waveform_cache(), &AudioPlaybackCache::Invalidated,
this, &Block::PreviewChanged);
disconnect(output->video_frame_cache(), &FrameHashCache::Invalidated,
this, &Block::PreviewChanged);
disconnect(output->audio_playback_cache(),
&AudioPlaybackCache::Invalidated, this,
&Block::PreviewChanged);
disconnect(output->thumbnail_cache(), &FrameHashCache::Validated, this,
&Block::PreviewChanged);
disconnect(output->waveform_cache(), &AudioPlaybackCache::Validated,
this, &Block::PreviewChanged);
disconnect(output->video_frame_cache(), &FrameHashCache::Validated,
this, &Block::PreviewChanged);
disconnect(output->audio_playback_cache(),
&AudioPlaybackCache::Validated, this,
&Block::PreviewChanged);
}
}
void ClipBlock::InputValueChangedEvent(const QString &input, int element)
{
super::InputValueChangedEvent(input, element);
super::InputValueChangedEvent(input, element);
if (input == kAutoCacheInput) {
if (IsAutocaching()) {
RequestInvalidatedFromConnected();
} else {
Track::Type type = GetTrackType();
if (input == kAutoCacheInput) {
if (IsAutocaching()) {
RequestInvalidatedFromConnected();
} else {
Track::Type type = GetTrackType();
if (Node *connected = GetConnectedOutput(kBufferIn)) {
if (type == Track::kVideo) {
emit connected->video_frame_cache()->CancelAll();
} else if (type == Track::kAudio) {
emit connected->audio_playback_cache()->CancelAll();
}
}
}
} else if (input == kLoopModeInput) {
emit PreviewChanged();
}
if (Node *connected = GetConnectedOutput(kBufferIn)) {
if (type == Track::kVideo) {
emit connected->video_frame_cache()->CancelAll();
} else if (type == Track::kAudio) {
emit connected->audio_playback_cache()->CancelAll();
}
}
}
} else if (input == kLoopModeInput) {
emit PreviewChanged();
}
}
TimeRange ClipBlock::InputTimeAdjustment(const QString& input, int element, const TimeRange& input_time, bool clamp) const
TimeRange ClipBlock::InputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time,
bool clamp) const
{
Q_UNUSED(element)
Q_UNUSED(element)
if (input == kBufferIn) {
return TimeRange(SequenceToMediaTime(input_time.in()), SequenceToMediaTime(input_time.out()));
}
if (input == kBufferIn) {
return TimeRange(SequenceToMediaTime(input_time.in()),
SequenceToMediaTime(input_time.out()));
}
return super::InputTimeAdjustment(input, element, input_time, clamp);
return super::InputTimeAdjustment(input, element, input_time, clamp);
}
TimeRange ClipBlock::OutputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const
TimeRange ClipBlock::OutputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time) const
{
Q_UNUSED(element)
Q_UNUSED(element)
if (input == kBufferIn) {
return TimeRange(MediaToSequenceTime(input_time.in()), MediaToSequenceTime(input_time.out()));
}
if (input == kBufferIn) {
return TimeRange(MediaToSequenceTime(input_time.in()),
MediaToSequenceTime(input_time.out()));
}
return super::OutputTimeAdjustment(input, element, input_time);
return super::OutputTimeAdjustment(input, element, input_time);
}
void ClipBlock::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void ClipBlock::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
Q_UNUSED(globals)
Q_UNUSED(globals)
// We discard most values here except for the buffer we received
NodeValue data = value[kBufferIn];
// We discard most values here except for the buffer we received
NodeValue data = value[kBufferIn];
table->Clear();
if (data.type() != NodeValue::kNone) {
table->Push(data);
}
table->Clear();
if (data.type() != NodeValue::kNone) {
table->Push(data);
}
}
void ClipBlock::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBufferIn, tr("Buffer"));
SetInputName(kMediaInInput, tr("Media In"));
SetInputName(kSpeedInput, tr("Speed"));
SetInputName(kReverseInput, tr("Reverse"));
SetInputName(kMaintainAudioPitchInput, tr("Maintain Audio Pitch"));
SetInputName(kLoopModeInput, tr("Loop"));
SetComboBoxStrings(kLoopModeInput, {tr("None"), tr("Loop"), tr("Clamp")});
SetInputName(kBufferIn, tr("Buffer"));
SetInputName(kMediaInInput, tr("Media In"));
SetInputName(kSpeedInput, tr("Speed"));
SetInputName(kReverseInput, tr("Reverse"));
SetInputName(kMaintainAudioPitchInput, tr("Maintain Audio Pitch"));
SetInputName(kLoopModeInput, tr("Loop"));
SetComboBoxStrings(kLoopModeInput, { tr("None"), tr("Loop"), tr("Clamp") });
}
void ClipBlock::AddCachePassthroughFrom(ClipBlock *other)
{
if (auto tc = this->video_frame_cache()) {
if (auto oc = other->video_frame_cache()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->video_frame_cache()) {
if (auto oc = other->video_frame_cache()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->audio_playback_cache()) {
if (auto oc = other->audio_playback_cache()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->audio_playback_cache()) {
if (auto oc = other->audio_playback_cache()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->thumbnails()) {
if (auto oc = other->thumbnails()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->thumbnails()) {
if (auto oc = other->thumbnails()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->waveform()) {
if (auto oc = other->waveform()) {
tc->SetPassthrough(oc);
}
}
if (auto tc = this->waveform()) {
if (auto oc = other->waveform()) {
tc->SetPassthrough(oc);
}
}
}
void ClipBlock::ConnectedToPreviewEvent()
{
RequestInvalidatedFromConnected();
RequestInvalidatedFromConnected();
}
TimeRange ClipBlock::media_range() const
{
return InputTimeAdjustment(kBufferIn, -1, TimeRange(0, length()), false);
return InputTimeAdjustment(kBufferIn, -1, TimeRange(0, length()), false);
}
MultiCamNode *ClipBlock::FindMulticam()
{
auto v = FindInputNodesConnectedToInput<MultiCamNode>(NodeInput(this, kBufferIn), 1);
if (v.empty()) {
return nullptr;
} else {
return v.first();
}
auto v = FindInputNodesConnectedToInput<MultiCamNode>(
NodeInput(this, kBufferIn), 1);
if (v.empty()) {
return nullptr;
} else {
return v.first();
}
}
}
+174 -157
View File
@@ -27,227 +27,244 @@
#include "node/input/multicam/multicamnode.h"
#include "node/output/track/track.h"
namespace olive {
namespace olive
{
class ViewerOutput;
/**
* @brief Node that represents a block of Media
*/
class ClipBlock : public Block
{
Q_OBJECT
class ClipBlock : public Block {
Q_OBJECT
public:
ClipBlock();
ClipBlock();
NODE_DEFAULT_FUNCTIONS(ClipBlock)
NODE_DEFAULT_FUNCTIONS(ClipBlock)
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
virtual void set_length_and_media_out(const rational &length) override;
virtual void set_length_and_media_in(const rational &length) override;
virtual void set_length_and_media_out(const rational &length) override;
virtual void set_length_and_media_in(const rational &length) override;
Track::Type GetTrackType() const
{
if (track()) {
return track()->type();
} else {
return Track::kNone;
}
}
Track::Type GetTrackType() const
{
if (track()) {
return track()->type();
} else {
return Track::kNone;
}
}
rational media_in() const;
void set_media_in(const rational& media_in);
rational media_in() const;
void set_media_in(const rational &media_in);
bool IsAutocaching() const { return GetStandardValue(kAutoCacheInput).toBool(); }
void SetAutocache(bool e);
bool IsAutocaching() const
{
return GetStandardValue(kAutoCacheInput).toBool();
}
void SetAutocache(bool e);
void DiscardCache();
void DiscardCache();
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options) override;
virtual void InvalidateCache(const TimeRange &range, const QString &from,
int element,
InvalidateCacheOptions options) override;
virtual TimeRange InputTimeAdjustment(const QString& input, int element, const TimeRange& input_time, bool clamp) const override;
virtual TimeRange InputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time,
bool clamp) const override;
virtual TimeRange OutputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const override;
virtual TimeRange
OutputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
void RequestInvalidatedFromConnected(bool force_all = false, const TimeRange &intersect = TimeRange());
void
RequestInvalidatedFromConnected(bool force_all = false,
const TimeRange &intersect = TimeRange());
double speed() const
{
return GetStandardValue(kSpeedInput).toDouble();
}
double speed() const
{
return GetStandardValue(kSpeedInput).toDouble();
}
bool reverse() const
{
return GetStandardValue(kReverseInput).toBool();
}
bool reverse() const
{
return GetStandardValue(kReverseInput).toBool();
}
void set_reverse(bool e)
{
SetStandardValue(kReverseInput, e);
}
void set_reverse(bool e)
{
SetStandardValue(kReverseInput, e);
}
bool maintain_audio_pitch() const
{
return GetStandardValue(kMaintainAudioPitchInput).toBool();
}
bool maintain_audio_pitch() const
{
return GetStandardValue(kMaintainAudioPitchInput).toBool();
}
void set_maintain_audio_pitch(bool e)
{
SetStandardValue(kMaintainAudioPitchInput, e);
}
void set_maintain_audio_pitch(bool e)
{
SetStandardValue(kMaintainAudioPitchInput, e);
}
TransitionBlock* in_transition()
{
return in_transition_;
}
TransitionBlock *in_transition()
{
return in_transition_;
}
void set_in_transition(TransitionBlock* t)
{
in_transition_ = t;
}
void set_in_transition(TransitionBlock *t)
{
in_transition_ = t;
}
TransitionBlock* out_transition()
{
return out_transition_;
}
TransitionBlock *out_transition()
{
return out_transition_;
}
void set_out_transition(TransitionBlock* t)
{
out_transition_ = t;
}
void set_out_transition(TransitionBlock *t)
{
out_transition_ = t;
}
const QVector<Block*>& block_links() const
{
return block_links_;
}
const QVector<Block *> &block_links() const
{
return block_links_;
}
FrameHashCache *connected_video_cache() const
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->video_frame_cache();
} else {
return nullptr;
}
}
FrameHashCache *connected_video_cache() const
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->video_frame_cache();
} else {
return nullptr;
}
}
AudioPlaybackCache *connected_audio_cache() const
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->audio_playback_cache();
} else {
return nullptr;
}
}
AudioPlaybackCache *connected_audio_cache() const
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->audio_playback_cache();
} else {
return nullptr;
}
}
FrameHashCache *thumbnails()
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->thumbnail_cache();
} else {
return nullptr;
}
}
FrameHashCache *thumbnails()
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->thumbnail_cache();
} else {
return nullptr;
}
}
AudioWaveformCache *waveform()
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->waveform_cache();
} else {
return nullptr;
}
}
AudioWaveformCache *waveform()
{
if (Node *n = GetConnectedOutput(kBufferIn)) {
return n->waveform_cache();
} else {
return nullptr;
}
}
void AddCachePassthroughFrom(ClipBlock *other);
void AddCachePassthroughFrom(ClipBlock *other);
ViewerOutput *connected_viewer() const
{
return connected_viewer_;
}
ViewerOutput *connected_viewer() const
{
return connected_viewer_;
}
virtual TimeRange GetVideoCacheRange() const override
{
return TimeRange(0, length());
}
virtual TimeRange GetVideoCacheRange() const override
{
return TimeRange(0, length());
}
virtual TimeRange GetAudioCacheRange() const override
{
return TimeRange(0, length());
}
virtual TimeRange GetAudioCacheRange() const override
{
return TimeRange(0, length());
}
virtual void ConnectedToPreviewEvent() override;
virtual void ConnectedToPreviewEvent() override;
TimeRange media_range() const;
TimeRange media_range() const;
/**
/**
* @brief Get currently set loop mode
*/
LoopMode loop_mode() const
{
return static_cast<LoopMode>(GetStandardValue(kLoopModeInput).toInt());
}
LoopMode loop_mode() const
{
return static_cast<LoopMode>(GetStandardValue(kLoopModeInput).toInt());
}
void set_loop_mode(LoopMode l)
{
SetStandardValue(kLoopModeInput, int(l));
}
void set_loop_mode(LoopMode l)
{
SetStandardValue(kLoopModeInput, int(l));
}
MultiCamNode *FindMulticam();
MultiCamNode *FindMulticam();
static const QString kBufferIn;
static const QString kMediaInInput;
static const QString kSpeedInput;
static const QString kReverseInput;
static const QString kMaintainAudioPitchInput;
static const QString kLoopModeInput;
static const QString kBufferIn;
static const QString kMediaInInput;
static const QString kSpeedInput;
static const QString kReverseInput;
static const QString kMaintainAudioPitchInput;
static const QString kLoopModeInput;
static const QString kAutoCacheInput;
static const QString kAutoCacheInput;
protected:
virtual void LinkChangeEvent() override;
virtual void LinkChangeEvent() override;
virtual void InputConnectedEvent(const QString& input, int element, Node *output) override;
virtual void InputConnectedEvent(const QString &input, int element,
Node *output) override;
virtual void InputDisconnectedEvent(const QString& input, int element, Node *output) override;
virtual void InputDisconnectedEvent(const QString &input, int element,
Node *output) override;
virtual void InputValueChangedEvent(const QString& input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
private:
enum SequenceToMediaTimeFlag
{
kSTMNone = 0x0,
kSTMIgnoreReverse = 0x1,
kSTMIgnoreSpeed = 0x2,
kSTMIgnoreLoop = 0x4
};
enum SequenceToMediaTimeFlag {
kSTMNone = 0x0,
kSTMIgnoreReverse = 0x1,
kSTMIgnoreSpeed = 0x2,
kSTMIgnoreLoop = 0x4
};
rational SequenceToMediaTime(const rational& sequence_time, uint64_t flags = kSTMNone) const;
rational SequenceToMediaTime(const rational &sequence_time,
uint64_t flags = kSTMNone) const;
rational MediaToSequenceTime(const rational& media_time) const;
rational MediaToSequenceTime(const rational &media_time) const;
void RequestRangeFromConnected(const TimeRange &range);
void RequestRangeFromConnected(const TimeRange &range);
void RequestRangeForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range, bool invalidate, bool request);
void RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range);
void RequestRangeForCache(PlaybackCache *cache, const TimeRange &max_range,
const TimeRange &range, bool invalidate,
bool request);
void RequestInvalidatedForCache(PlaybackCache *cache,
const TimeRange &max_range);
bool GetAdjustedThumbnailRange(TimeRange *r) const;
bool GetAdjustedThumbnailRange(TimeRange *r) const;
QVector<Block*> block_links_;
QVector<Block *> block_links_;
TransitionBlock* in_transition_;
TransitionBlock* out_transition_;
TransitionBlock *in_transition_;
TransitionBlock *out_transition_;
ViewerOutput *connected_viewer_;
ViewerOutput *connected_viewer_;
private:
rational last_media_in_;
rational last_media_in_;
};
}
+5 -4
View File
@@ -20,7 +20,8 @@
#include "gap.h"
namespace olive {
namespace olive
{
GapBlock::GapBlock()
{
@@ -28,17 +29,17 @@ GapBlock::GapBlock()
QString GapBlock::Name() const
{
return tr("Gap");
return tr("Gap");
}
QString GapBlock::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.gap");
return QStringLiteral("org.olivevideoeditor.Olive.gap");
}
QString GapBlock::Description() const
{
return tr("A time-based node that represents an empty space.");
return tr("A time-based node that represents an empty space.");
}
}
+9 -10
View File
@@ -23,23 +23,22 @@
#include "node/block/block.h"
namespace olive {
namespace olive
{
/**
* @brief Node that represents nothing in its respective track for a certain period of time
*/
class GapBlock : public Block
{
Q_OBJECT
class GapBlock : public Block {
Q_OBJECT
public:
GapBlock();
GapBlock();
NODE_DEFAULT_FUNCTIONS(GapBlock)
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
NODE_DEFAULT_FUNCTIONS(GapBlock)
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
};
}
+22 -19
View File
@@ -20,7 +20,8 @@
#include "subtitle.h"
namespace olive {
namespace olive
{
#define super ClipBlock
@@ -28,43 +29,45 @@ const QString SubtitleBlock::kTextIn = QStringLiteral("text_in");
SubtitleBlock::SubtitleBlock()
{
AddInput(kTextIn, NodeValue::kText, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kTextIn, NodeValue::kText,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
SetInputFlag(kBufferIn, kInputFlagHidden);
SetInputFlag(kLengthInput, kInputFlagHidden);
SetInputFlag(kMediaInInput, kInputFlagHidden);
SetInputFlag(kSpeedInput, kInputFlagHidden);
SetInputFlag(kReverseInput, kInputFlagHidden);
SetInputFlag(kMaintainAudioPitchInput, kInputFlagHidden);
SetInputFlag(kBufferIn, kInputFlagHidden);
SetInputFlag(kLengthInput, kInputFlagHidden);
SetInputFlag(kMediaInInput, kInputFlagHidden);
SetInputFlag(kSpeedInput, kInputFlagHidden);
SetInputFlag(kReverseInput, kInputFlagHidden);
SetInputFlag(kMaintainAudioPitchInput, kInputFlagHidden);
// Undo block flag that hides in param view
SetFlag(kDontShowInParamView, false);
// Undo block flag that hides in param view
SetFlag(kDontShowInParamView, false);
}
QString SubtitleBlock::Name() const
{
if (GetText().isEmpty()) {
return tr("Subtitle");
} else {
return GetText();
}
if (GetText().isEmpty()) {
return tr("Subtitle");
} else {
return GetText();
}
}
QString SubtitleBlock::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.subtitle");
return QStringLiteral("org.olivevideoeditor.Olive.subtitle");
}
QString SubtitleBlock::Description() const
{
return tr("A time-based node representing a single subtitle element for a certain period of time.");
return tr(
"A time-based node representing a single subtitle element for a certain period of time.");
}
void SubtitleBlock::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextIn, tr("Text"));
SetInputName(kTextIn, tr("Text"));
}
}
+19 -20
View File
@@ -23,34 +23,33 @@
#include "node/block/clip/clip.h"
namespace olive {
class SubtitleBlock : public ClipBlock
namespace olive
{
Q_OBJECT
class SubtitleBlock : public ClipBlock {
Q_OBJECT
public:
SubtitleBlock();
SubtitleBlock();
NODE_DEFAULT_FUNCTIONS(SubtitleBlock)
NODE_DEFAULT_FUNCTIONS(SubtitleBlock)
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
static const QString kTextIn;
static const QString kTextIn;
QString GetText() const
{
return GetStandardValue(kTextIn).toString();
}
void SetText(const QString &text)
{
SetStandardValue(kTextIn, text);
}
QString GetText() const
{
return GetStandardValue(kTextIn).toString();
}
void SetText(const QString &text)
{
SetStandardValue(kTextIn, text);
}
};
}
@@ -20,7 +20,8 @@
#include "crossdissolvetransition.h"
namespace olive {
namespace olive
{
CrossDissolveTransition::CrossDissolveTransition()
{
@@ -28,56 +29,66 @@ CrossDissolveTransition::CrossDissolveTransition()
QString CrossDissolveTransition::Name() const
{
return tr("Cross Dissolve");
return tr("Cross Dissolve");
}
QString CrossDissolveTransition::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.crossdissolve");
return QStringLiteral("org.olivevideoeditor.Olive.crossdissolve");
}
QVector<Node::CategoryID> CrossDissolveTransition::Category() const
{
return {kCategoryTransition};
return { kCategoryTransition };
}
QString CrossDissolveTransition::Description() const
{
return tr("Smoothly transition between two clips.");
return tr("Smoothly transition between two clips.");
}
ShaderCode CrossDissolveTransition::GetShaderCode(const ShaderRequest &request) const
ShaderCode
CrossDissolveTransition::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/crossdissolve.frag"), QString());
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/crossdissolve.frag"),
QString());
}
void CrossDissolveTransition::SampleJobEvent(const SampleBuffer &from_samples, const SampleBuffer &to_samples, SampleBuffer &out_samples, double time_in) const
void CrossDissolveTransition::SampleJobEvent(const SampleBuffer &from_samples,
const SampleBuffer &to_samples,
SampleBuffer &out_samples,
double time_in) const
{
for (size_t i=0; i<out_samples.sample_count(); i++) {
double this_sample_time = out_samples.audio_params().samples_to_time(i).toDouble() + time_in;
double progress = GetTotalProgress(this_sample_time);
for (size_t i = 0; i < out_samples.sample_count(); i++) {
double this_sample_time =
out_samples.audio_params().samples_to_time(i).toDouble() + time_in;
double progress = GetTotalProgress(this_sample_time);
for (int j=0; j<out_samples.audio_params().channel_count(); j++) {
out_samples.data(j)[i] = 0;
for (int j = 0; j < out_samples.audio_params().channel_count(); j++) {
out_samples.data(j)[i] = 0;
if (from_samples.is_allocated()) {
if (i < from_samples.sample_count()) {
out_samples.data(j)[i] += from_samples.data(j)[i] * TransformCurve(1.0 - progress);
}
}
if (from_samples.is_allocated()) {
if (i < from_samples.sample_count()) {
out_samples.data(j)[i] += from_samples.data(j)[i] *
TransformCurve(1.0 - progress);
}
}
if (to_samples.is_allocated()) {
// Offset input samples from the end
size_t remain = (out_samples.sample_count() - to_samples.sample_count());
if (i >= remain) {
qint64 in_index = i - remain;
out_samples.data(j)[i] += to_samples.data(j)[in_index] * TransformCurve(progress);
}
}
}
}
if (to_samples.is_allocated()) {
// Offset input samples from the end
size_t remain =
(out_samples.sample_count() - to_samples.sample_count());
if (i >= remain) {
qint64 in_index = i - remain;
out_samples.data(j)[i] +=
to_samples.data(j)[in_index] * TransformCurve(progress);
}
}
}
}
}
}
@@ -23,28 +23,31 @@
#include "node/block/transition/transition.h"
namespace olive {
class CrossDissolveTransition : public TransitionBlock
namespace olive
{
Q_OBJECT
class CrossDissolveTransition : public TransitionBlock {
Q_OBJECT
public:
CrossDissolveTransition();
CrossDissolveTransition();
NODE_DEFAULT_FUNCTIONS(CrossDissolveTransition)
NODE_DEFAULT_FUNCTIONS(CrossDissolveTransition)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
//virtual void Retranslate() override;
//virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
protected:
virtual void SampleJobEvent(const SampleBuffer &from_samples, const SampleBuffer &to_samples, SampleBuffer &out_samples, double time_in) const override;
virtual void SampleJobEvent(const SampleBuffer &from_samples,
const SampleBuffer &to_samples,
SampleBuffer &out_samples,
double time_in) const override;
};
}
@@ -20,7 +20,8 @@
#include "diptocolortransition.h"
namespace olive {
namespace olive
{
const QString DipToColorTransition::kColorInput = QStringLiteral("color_in");
@@ -28,46 +29,51 @@ const QString DipToColorTransition::kColorInput = QStringLiteral("color_in");
DipToColorTransition::DipToColorTransition()
{
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(0, 0, 0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(0, 0, 0)));
}
QString DipToColorTransition::Name() const
{
return tr("Dip To Color");
return tr("Dip To Color");
}
QString DipToColorTransition::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.diptocolor");
return QStringLiteral("org.olivevideoeditor.Olive.diptocolor");
}
QVector<Node::CategoryID> DipToColorTransition::Category() const
{
return {kCategoryTransition};
return { kCategoryTransition };
}
QString DipToColorTransition::Description() const
{
return tr("Transition between clips by dipping to a color.");
return tr("Transition between clips by dipping to a color.");
}
ShaderCode DipToColorTransition::GetShaderCode(const ShaderRequest &request) const
ShaderCode
DipToColorTransition::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/diptoblack.frag"), QString());
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/diptoblack.frag"),
QString());
}
void DipToColorTransition::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kColorInput, tr("Color"));
SetInputName(kColorInput, tr("Color"));
}
void DipToColorTransition::ShaderJobEvent(const NodeValueRow &value, ShaderJob *job) const
void DipToColorTransition::ShaderJobEvent(const NodeValueRow &value,
ShaderJob *job) const
{
job->Insert(kColorInput, value);
job->Insert(kColorInput, value);
}
}
@@ -23,30 +23,31 @@
#include "node/block/transition/transition.h"
namespace olive {
class DipToColorTransition : public TransitionBlock
namespace olive
{
Q_OBJECT
class DipToColorTransition : public TransitionBlock {
Q_OBJECT
public:
DipToColorTransition();
DipToColorTransition();
NODE_DEFAULT_FUNCTIONS(DipToColorTransition)
NODE_DEFAULT_FUNCTIONS(DipToColorTransition)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
static const QString kColorInput;
static const QString kColorInput;
protected:
virtual void ShaderJobEvent(const NodeValueRow &value, ShaderJob *job) const override;
virtual void ShaderJobEvent(const NodeValueRow &value,
ShaderJob *job) const override;
};
}
+200 -171
View File
@@ -24,7 +24,8 @@
#include "node/output/track/track.h"
#include "widget/slider/rationalslider.h"
namespace olive {
namespace olive
{
#define super Block
@@ -33,282 +34,310 @@ const QString TransitionBlock::kInBlockInput = QStringLiteral("in_block_in");
const QString TransitionBlock::kCurveInput = QStringLiteral("curve_in");
const QString TransitionBlock::kCenterInput = QStringLiteral("center_in");
TransitionBlock::TransitionBlock() :
connected_out_block_(nullptr),
connected_in_block_(nullptr)
TransitionBlock::TransitionBlock()
: connected_out_block_(nullptr)
, connected_in_block_(nullptr)
{
AddInput(kOutBlockInput, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
AddInput(kOutBlockInput, NodeValue::kNone,
InputFlags(kInputFlagNotKeyframable));
AddInput(kInBlockInput, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
AddInput(kInBlockInput, NodeValue::kNone,
InputFlags(kInputFlagNotKeyframable));
AddInput(kCurveInput, NodeValue::kCombo, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kCurveInput, NodeValue::kCombo,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kCenterInput, NodeValue::kRational, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
SetInputProperty(kCenterInput, QStringLiteral("view"), RationalSlider::kTime);
SetInputProperty(kCenterInput, QStringLiteral("viewlock"), true);
AddInput(kCenterInput, NodeValue::kRational,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
SetInputProperty(kCenterInput, QStringLiteral("view"),
RationalSlider::kTime);
SetInputProperty(kCenterInput, QStringLiteral("viewlock"), true);
SetFlag(kDontShowInParamView, false);
SetFlag(kDontShowInParamView, false);
}
void TransitionBlock::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kOutBlockInput, tr("From"));
SetInputName(kInBlockInput, tr("To"));
SetInputName(kCurveInput, tr("Curve"));
SetInputName(kCenterInput, tr("Center Offset"));
SetInputName(kOutBlockInput, tr("From"));
SetInputName(kInBlockInput, tr("To"));
SetInputName(kCurveInput, tr("Curve"));
SetInputName(kCenterInput, tr("Center Offset"));
// These must correspond to the CurveType enum
SetComboBoxStrings(kCurveInput, { tr("Linear"), tr("Exponential"), tr("Logarithmic") });
// These must correspond to the CurveType enum
SetComboBoxStrings(kCurveInput,
{ tr("Linear"), tr("Exponential"), tr("Logarithmic") });
}
rational TransitionBlock::in_offset() const
{
if (is_dual_transition()) {
return length()/2 + offset_center();
} else if (connected_in_block()) {
return length();
} else {
return 0;
}
if (is_dual_transition()) {
return length() / 2 + offset_center();
} else if (connected_in_block()) {
return length();
} else {
return 0;
}
}
rational TransitionBlock::out_offset() const
{
if (is_dual_transition()) {
return length()/2 - offset_center();
} else if (connected_out_block()) {
return length();
} else {
return 0;
}
if (is_dual_transition()) {
return length() / 2 - offset_center();
} else if (connected_out_block()) {
return length();
} else {
return 0;
}
}
rational TransitionBlock::offset_center() const
{
return GetStandardValue(kCenterInput).value<rational>();
return GetStandardValue(kCenterInput).value<rational>();
}
void TransitionBlock::set_offset_center(const rational &r)
{
SetStandardValue(kCenterInput, QVariant::fromValue(r));
SetStandardValue(kCenterInput, QVariant::fromValue(r));
}
void TransitionBlock::set_offsets_and_length(const rational &in_offset, const rational &out_offset)
void TransitionBlock::set_offsets_and_length(const rational &in_offset,
const rational &out_offset)
{
rational len = in_offset + out_offset;
rational center = len / 2 - in_offset;
rational len = in_offset + out_offset;
rational center = len / 2 - in_offset;
set_length_and_media_out(len);
set_offset_center(center);
set_length_and_media_out(len);
set_offset_center(center);
}
Block *TransitionBlock::connected_out_block() const
{
return connected_out_block_;
return connected_out_block_;
}
Block *TransitionBlock::connected_in_block() const
{
return connected_in_block_;
return connected_in_block_;
}
double TransitionBlock::GetTotalProgress(const double &time) const
{
return GetInternalTransitionTime(time) / length().toDouble();
return GetInternalTransitionTime(time) / length().toDouble();
}
double TransitionBlock::GetOutProgress(const double &time) const
{
if (out_offset() == 0) {
return 0;
}
if (out_offset() == 0) {
return 0;
}
return std::clamp(1.0 - (GetInternalTransitionTime(time) / out_offset().toDouble()), 0.0, 1.0);
return std::clamp(
1.0 - (GetInternalTransitionTime(time) / out_offset().toDouble()), 0.0,
1.0);
}
double TransitionBlock::GetInProgress(const double &time) const
{
if (in_offset() == 0) {
return 0;
}
if (in_offset() == 0) {
return 0;
}
return std::clamp((GetInternalTransitionTime(time) - out_offset().toDouble()) / in_offset().toDouble(), 0.0, 1.0);
return std::clamp(
(GetInternalTransitionTime(time) - out_offset().toDouble()) /
in_offset().toDouble(),
0.0, 1.0);
}
double TransitionBlock::GetInternalTransitionTime(const double &time) const
{
return time;
return time;
}
void TransitionBlock::InsertTransitionTimes(AcceleratedJob *job, const double &time) const
void TransitionBlock::InsertTransitionTimes(AcceleratedJob *job,
const double &time) const
{
// Provides total transition progress from 0.0 (start) - 1.0 (end)
job->Insert(QStringLiteral("ove_tprog_all"),
NodeValue(NodeValue::kFloat, GetTotalProgress(time), this));
// Provides total transition progress from 0.0 (start) - 1.0 (end)
job->Insert(QStringLiteral("ove_tprog_all"),
NodeValue(NodeValue::kFloat, GetTotalProgress(time), this));
// Provides progress of out section from 1.0 (start) - 0.0 (end)
job->Insert(QStringLiteral("ove_tprog_out"),
NodeValue(NodeValue::kFloat, GetOutProgress(time), this));
// Provides progress of out section from 1.0 (start) - 0.0 (end)
job->Insert(QStringLiteral("ove_tprog_out"),
NodeValue(NodeValue::kFloat, GetOutProgress(time), this));
// Provides progress of in section from 0.0 (start) - 1.0 (end)
job->Insert(QStringLiteral("ove_tprog_in"),
NodeValue(NodeValue::kFloat, GetInProgress(time), this));
// Provides progress of in section from 0.0 (start) - 1.0 (end)
job->Insert(QStringLiteral("ove_tprog_in"),
NodeValue(NodeValue::kFloat, GetInProgress(time), this));
}
void TransitionBlock::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TransitionBlock::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
NodeValue out_buffer = value[kOutBlockInput];
NodeValue in_buffer = value[kInBlockInput];
NodeValue::Type data_type = (out_buffer.type() != NodeValue::kNone) ? out_buffer.type() : in_buffer.type();
NodeValue out_buffer = value[kOutBlockInput];
NodeValue in_buffer = value[kInBlockInput];
NodeValue::Type data_type = (out_buffer.type() != NodeValue::kNone) ?
out_buffer.type() :
in_buffer.type();
NodeValue::Type job_type = NodeValue::kNone;
QVariant push_job;
NodeValue::Type job_type = NodeValue::kNone;
QVariant push_job;
if (data_type == NodeValue::kTexture) {
// This must be a visual transition
ShaderJob job;
if (data_type == NodeValue::kTexture) {
// This must be a visual transition
ShaderJob job;
if (out_buffer.type() != NodeValue::kNone) {
job.Insert(kOutBlockInput, out_buffer);
} else {
job.Insert(kOutBlockInput, NodeValue(NodeValue::kTexture, nullptr));
}
if (out_buffer.type() != NodeValue::kNone) {
job.Insert(kOutBlockInput, out_buffer);
} else {
job.Insert(kOutBlockInput, NodeValue(NodeValue::kTexture, nullptr));
}
if (in_buffer.type() != NodeValue::kNone) {
job.Insert(kInBlockInput, in_buffer);
} else {
job.Insert(kInBlockInput, NodeValue(NodeValue::kTexture, nullptr));
}
if (in_buffer.type() != NodeValue::kNone) {
job.Insert(kInBlockInput, in_buffer);
} else {
job.Insert(kInBlockInput, NodeValue(NodeValue::kTexture, nullptr));
}
job.Insert(kCurveInput, value);
job.Insert(kCurveInput, value);
double time = globals.time().in().toDouble();
InsertTransitionTimes(&job, time);
double time = globals.time().in().toDouble();
InsertTransitionTimes(&job, time);
ShaderJobEvent(value, &job);
ShaderJobEvent(value, &job);
job_type = NodeValue::kTexture;
push_job = QVariant::fromValue(Texture::Job(globals.vparams(), job));
} else if (data_type == NodeValue::kSamples) {
// This must be an audio transition
SampleBuffer from_samples = out_buffer.toSamples();
SampleBuffer to_samples = in_buffer.toSamples();
job_type = NodeValue::kTexture;
push_job = QVariant::fromValue(Texture::Job(globals.vparams(), job));
} else if (data_type == NodeValue::kSamples) {
// This must be an audio transition
SampleBuffer from_samples = out_buffer.toSamples();
SampleBuffer to_samples = in_buffer.toSamples();
if (from_samples.is_allocated() || to_samples.is_allocated()) {
double time_in = globals.time().in().toDouble();
double time_out = globals.time().out().toDouble();
if (from_samples.is_allocated() || to_samples.is_allocated()) {
double time_in = globals.time().in().toDouble();
double time_out = globals.time().out().toDouble();
const AudioParams& params = (from_samples.is_allocated()) ? from_samples.audio_params() : to_samples.audio_params();
const AudioParams &params = (from_samples.is_allocated()) ?
from_samples.audio_params() :
to_samples.audio_params();
SampleBuffer out_samples;
SampleBuffer out_samples;
if (params.is_valid()) {
int nb_samples = params.time_to_samples(time_out - time_in);
if (params.is_valid()) {
int nb_samples = params.time_to_samples(time_out - time_in);
out_samples = SampleBuffer(params, nb_samples);
SampleJobEvent(from_samples, to_samples, out_samples, time_in);
}
out_samples = SampleBuffer(params, nb_samples);
SampleJobEvent(from_samples, to_samples, out_samples, time_in);
}
job_type = NodeValue::kSamples;
push_job = QVariant::fromValue(out_samples);
}
}
job_type = NodeValue::kSamples;
push_job = QVariant::fromValue(out_samples);
}
}
if (!push_job.isNull()) {
table->Push(job_type, push_job, this);
}
if (!push_job.isNull()) {
table->Push(job_type, push_job, this);
}
}
void TransitionBlock::InvalidateCache(const TimeRange &range, const QString &from, int element, InvalidateCacheOptions options)
void TransitionBlock::InvalidateCache(const TimeRange &range,
const QString &from, int element,
InvalidateCacheOptions options)
{
TimeRange r = range;
TimeRange r = range;
if (from == kOutBlockInput || from == kInBlockInput) {
Block *n = dynamic_cast<Block*>(GetConnectedOutput(from));
if (n) {
r = Track::TransformRangeFromBlock(n, r);
}
}
if (from == kOutBlockInput || from == kInBlockInput) {
Block *n = dynamic_cast<Block *>(GetConnectedOutput(from));
if (n) {
r = Track::TransformRangeFromBlock(n, r);
}
}
super::InvalidateCache(r, from, element, options);
super::InvalidateCache(r, from, element, options);
}
double TransitionBlock::TransformCurve(double linear) const
{
switch (static_cast<CurveType>(GetStandardValue(kCurveInput).toInt())) {
case kLinear:
break;
case kExponential:
linear *= linear;
break;
case kLogarithmic:
linear = std::sqrt(linear);
break;
}
switch (static_cast<CurveType>(GetStandardValue(kCurveInput).toInt())) {
case kLinear:
break;
case kExponential:
linear *= linear;
break;
case kLogarithmic:
linear = std::sqrt(linear);
break;
}
return linear;
return linear;
}
void TransitionBlock::InputConnectedEvent(const QString &input, int element, Node *output)
void TransitionBlock::InputConnectedEvent(const QString &input, int element,
Node *output)
{
Q_UNUSED(element)
Q_UNUSED(element)
if (input == kOutBlockInput) {
// If node is not a block, this will just be null
if ((connected_out_block_ = dynamic_cast<ClipBlock*>(output))) {
connected_out_block_->set_out_transition(this);
}
} else if (input == kInBlockInput) {
// If node is not a block, this will just be null
if ((connected_in_block_ = dynamic_cast<ClipBlock*>(output))) {
connected_in_block_->set_in_transition(this);
}
}
if (input == kOutBlockInput) {
// If node is not a block, this will just be null
if ((connected_out_block_ = dynamic_cast<ClipBlock *>(output))) {
connected_out_block_->set_out_transition(this);
}
} else if (input == kInBlockInput) {
// If node is not a block, this will just be null
if ((connected_in_block_ = dynamic_cast<ClipBlock *>(output))) {
connected_in_block_->set_in_transition(this);
}
}
}
void TransitionBlock::InputDisconnectedEvent(const QString &input, int element, Node *output)
void TransitionBlock::InputDisconnectedEvent(const QString &input, int element,
Node *output)
{
Q_UNUSED(element)
Q_UNUSED(output)
Q_UNUSED(element)
Q_UNUSED(output)
if (input == kOutBlockInput) {
if (connected_out_block_) {
connected_out_block_->set_out_transition(nullptr);
connected_out_block_ = nullptr;
}
} else if (input == kInBlockInput) {
if (connected_in_block_) {
connected_in_block_->set_in_transition(nullptr);
connected_in_block_ = nullptr;
}
}
if (input == kOutBlockInput) {
if (connected_out_block_) {
connected_out_block_->set_out_transition(nullptr);
connected_out_block_ = nullptr;
}
} else if (input == kInBlockInput) {
if (connected_in_block_) {
connected_in_block_->set_in_transition(nullptr);
connected_in_block_ = nullptr;
}
}
}
TimeRange TransitionBlock::InputTimeAdjustment(const QString &input, int element, const TimeRange &input_time, bool clamp) const
TimeRange TransitionBlock::InputTimeAdjustment(const QString &input,
int element,
const TimeRange &input_time,
bool clamp) const
{
if (input == kInBlockInput || input == kOutBlockInput) {
Block* block = dynamic_cast<Block*>(GetConnectedOutput(input));
if (block) {
// Retransform time as if it came from the track
return input_time + in() - block->in();
}
}
if (input == kInBlockInput || input == kOutBlockInput) {
Block *block = dynamic_cast<Block *>(GetConnectedOutput(input));
if (block) {
// Retransform time as if it came from the track
return input_time + in() - block->in();
}
}
return super::InputTimeAdjustment(input, element, input_time, clamp);
return super::InputTimeAdjustment(input, element, input_time, clamp);
}
TimeRange TransitionBlock::OutputTimeAdjustment(const QString &input, int element, const TimeRange &input_time) const
TimeRange
TransitionBlock::OutputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time) const
{
if (input == kInBlockInput || input == kOutBlockInput) {
Block* block = dynamic_cast<Block*>(GetConnectedOutput(input));
if (block) {
return input_time + block->in() - in();
}
}
if (input == kInBlockInput || input == kOutBlockInput) {
Block *block = dynamic_cast<Block *>(GetConnectedOutput(input));
if (block) {
return input_time + block->in() - in();
}
}
return super::OutputTimeAdjustment(input, element, input_time);
return super::OutputTimeAdjustment(input, element, input_time);
}
}
+55 -44
View File
@@ -23,22 +23,22 @@
#include "node/block/block.h"
namespace olive {
namespace olive
{
class ClipBlock;
class TransitionBlock : public Block
{
Q_OBJECT
class TransitionBlock : public Block {
Q_OBJECT
public:
TransitionBlock();
TransitionBlock();
virtual void Retranslate() override;
virtual void Retranslate() override;
rational in_offset() const;
rational out_offset() const;
rational in_offset() const;
rational out_offset() const;
/**
/**
* @brief Return the "middle point" of the transition, relative to the transition
*
* Used to calculate in/out offsets.
@@ -46,62 +46,73 @@ public:
* 0 means the center of the transition is right in the middle and the in and out offsets will
* be equal.
*/
rational offset_center() const;
void set_offset_center(const rational &r);
rational offset_center() const;
void set_offset_center(const rational &r);
void set_offsets_and_length(const rational &in_offset, const rational &out_offset);
void set_offsets_and_length(const rational &in_offset,
const rational &out_offset);
bool is_dual_transition() const
{
return connected_out_block() && connected_in_block();
}
bool is_dual_transition() const
{
return connected_out_block() && connected_in_block();
}
Block* connected_out_block() const;
Block* connected_in_block() const;
Block *connected_out_block() const;
Block *connected_in_block() const;
double GetTotalProgress(const double &time) const;
double GetOutProgress(const double &time) const;
double GetInProgress(const double &time) const;
double GetTotalProgress(const double &time) const;
double GetOutProgress(const double &time) const;
double GetInProgress(const double &time) const;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1, InvalidateCacheOptions options = InvalidateCacheOptions()) override;
virtual void InvalidateCache(
const TimeRange &range, const QString &from, int element = -1,
InvalidateCacheOptions options = InvalidateCacheOptions()) override;
static const QString kOutBlockInput;
static const QString kInBlockInput;
static const QString kCurveInput;
static const QString kCenterInput;
static const QString kOutBlockInput;
static const QString kInBlockInput;
static const QString kCurveInput;
static const QString kCenterInput;
protected:
virtual void ShaderJobEvent(const NodeValueRow &value, ShaderJob *job) const {}
virtual void ShaderJobEvent(const NodeValueRow &value, ShaderJob *job) const
{
}
virtual void SampleJobEvent(const SampleBuffer &from_samples, const SampleBuffer &to_samples, SampleBuffer &out_samples, double time_in) const {}
virtual void SampleJobEvent(const SampleBuffer &from_samples,
const SampleBuffer &to_samples,
SampleBuffer &out_samples, double time_in) const
{
}
double TransformCurve(double linear) const;
double TransformCurve(double linear) const;
virtual void InputConnectedEvent(const QString& input, int element, Node *output) override;
virtual void InputConnectedEvent(const QString &input, int element,
Node *output) override;
virtual void InputDisconnectedEvent(const QString& input, int element, Node *output) override;
virtual void InputDisconnectedEvent(const QString &input, int element,
Node *output) override;
virtual TimeRange InputTimeAdjustment(const QString& input, int element, const TimeRange& input_time, bool clamp) const override;
virtual TimeRange InputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time,
bool clamp) const override;
virtual TimeRange OutputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const override;
virtual TimeRange
OutputTimeAdjustment(const QString &input, int element,
const TimeRange &input_time) const override;
private:
enum CurveType {
kLinear,
kExponential,
kLogarithmic
};
enum CurveType { kLinear, kExponential, kLogarithmic };
double GetInternalTransitionTime(const double &time) const;
double GetInternalTransitionTime(const double &time) const;
void InsertTransitionTimes(AcceleratedJob* job, const double& time) const;
void InsertTransitionTimes(AcceleratedJob *job, const double &time) const;
ClipBlock* connected_out_block_;
ClipBlock* connected_in_block_;
ClipBlock *connected_out_block_;
ClipBlock *connected_in_block_;
};
}
+122 -115
View File
@@ -28,239 +28,246 @@
#include "config/config.h"
#include "core.h"
namespace olive {
namespace olive
{
#define super Node
OCIO::ConstConfigRcPtr ColorManager::default_config_ = nullptr;
ColorManager::ColorManager(Project *project) :
QObject(project),
config_(nullptr)
ColorManager::ColorManager(Project *project)
: QObject(project)
, config_(nullptr)
{
}
void ColorManager::Init()
{
// Set config to our built-in default
config_ = GetDefaultConfig();
SetDefaultInputColorSpace(config_->getCanonicalName(OCIO::ROLE_DEFAULT));
project()->SetColorReferenceSpace(OCIO::ROLE_SCENE_LINEAR);
// Set config to our built-in default
config_ = GetDefaultConfig();
SetDefaultInputColorSpace(config_->getCanonicalName(OCIO::ROLE_DEFAULT));
project()->SetColorReferenceSpace(OCIO::ROLE_SCENE_LINEAR);
}
OCIO::ConstConfigRcPtr ColorManager::GetConfig() const
{
return config_;
return config_;
}
OCIO::ConstConfigRcPtr ColorManager::CreateConfigFromFile(const QString &filename)
OCIO::ConstConfigRcPtr
ColorManager::CreateConfigFromFile(const QString &filename)
{
return OCIO::Config::CreateFromFile(filename.toUtf8());
return OCIO::Config::CreateFromFile(filename.toUtf8());
}
QString ColorManager::GetConfigFilename() const
{
return project()->GetColorConfigFilename();
return project()->GetColorConfigFilename();
}
OCIO::ConstConfigRcPtr ColorManager::GetDefaultConfig()
{
return default_config_;
return default_config_;
}
void ColorManager::SetUpDefaultConfig()
{
if (!qEnvironmentVariableIsEmpty("OCIO")) {
// Attempt to set config from "OCIO" environment variable
try {
default_config_ = OCIO::Config::CreateFromEnv();
if (!qEnvironmentVariableIsEmpty("OCIO")) {
// Attempt to set config from "OCIO" environment variable
try {
default_config_ = OCIO::Config::CreateFromEnv();
return;
} catch (OCIO::Exception& e) {
qWarning() << "Failed to load config from OCIO environment variable config:" << e.what();
}
}
return;
} catch (OCIO::Exception &e) {
qWarning()
<< "Failed to load config from OCIO environment variable config:"
<< e.what();
}
}
// Extract OCIO config - kind of hacky, but it'll work
QString dir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).filePath(QStringLiteral("ocioconf"));
// Extract OCIO config - kind of hacky, but it'll work
QString dir =
QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
.filePath(QStringLiteral("ocioconf"));
FileFunctions::CopyDirectory(QStringLiteral(":/ocioconf"),
dir,
true);
FileFunctions::CopyDirectory(QStringLiteral(":/ocioconf"), dir, true);
qDebug() << "Extracting default OCIO config to" << dir;
qDebug() << "Extracting default OCIO config to" << dir;
default_config_ = CreateConfigFromFile(QDir(dir).filePath(QStringLiteral("config.ocio")));
default_config_ =
CreateConfigFromFile(QDir(dir).filePath(QStringLiteral("config.ocio")));
}
void ColorManager::SetConfigFilename(const QString &filename)
{
project()->SetColorConfigFilename(filename);
project()->SetColorConfigFilename(filename);
}
QStringList ColorManager::ListAvailableDisplays()
{
QStringList displays;
QStringList displays;
int number_of_displays = config_->getNumDisplays();
int number_of_displays = config_->getNumDisplays();
for (int i=0;i<number_of_displays;i++) {
displays.append(config_->getDisplay(i));
}
for (int i = 0; i < number_of_displays; i++) {
displays.append(config_->getDisplay(i));
}
return displays;
return displays;
}
QString ColorManager::GetDefaultDisplay()
{
return config_->getDefaultDisplay();
return config_->getDefaultDisplay();
}
QStringList ColorManager::ListAvailableViews(QString display)
{
QStringList views;
QStringList views;
int number_of_views = config_->getNumViews(display.toUtf8());
int number_of_views = config_->getNumViews(display.toUtf8());
for (int i=0;i<number_of_views;i++) {
views.append(config_->getView(display.toUtf8(), i));
}
for (int i = 0; i < number_of_views; i++) {
views.append(config_->getView(display.toUtf8(), i));
}
return views;
return views;
}
QString ColorManager::GetDefaultView(const QString &display)
{
return config_->getDefaultView(display.toUtf8());
return config_->getDefaultView(display.toUtf8());
}
QStringList ColorManager::ListAvailableLooks()
{
QStringList looks;
QStringList looks;
int number_of_looks = config_->getNumLooks();
int number_of_looks = config_->getNumLooks();
for (int i=0;i<number_of_looks;i++) {
looks.append(config_->getLookNameByIndex(i));
}
for (int i = 0; i < number_of_looks; i++) {
looks.append(config_->getLookNameByIndex(i));
}
return looks;
return looks;
}
QStringList ColorManager::ListAvailableColorspaces() const
{
return ListAvailableColorspaces(config_);
return ListAvailableColorspaces(config_);
}
QString ColorManager::GetDefaultInputColorSpace() const
{
return project()->GetDefaultInputColorSpace();
return project()->GetDefaultInputColorSpace();
}
void ColorManager::SetDefaultInputColorSpace(const QString &s)
{
project()->SetDefaultInputColorSpace(s);
project()->SetDefaultInputColorSpace(s);
}
QString ColorManager::GetReferenceColorSpace() const
{
return project()->GetColorReferenceSpace();
return project()->GetColorReferenceSpace();
}
QString ColorManager::GetCompliantColorSpace(const QString &s)
{
if (ListAvailableColorspaces().contains(s)) {
return s;
} else {
return GetDefaultInputColorSpace();
}
if (ListAvailableColorspaces().contains(s)) {
return s;
} else {
return GetDefaultInputColorSpace();
}
}
ColorTransform ColorManager::GetCompliantColorSpace(const ColorTransform &transform, bool force_display)
ColorTransform
ColorManager::GetCompliantColorSpace(const ColorTransform &transform,
bool force_display)
{
if (transform.is_display() || force_display) {
// Get display information
QString display = transform.display();
QString view = transform.view();
QString look = transform.look();
if (transform.is_display() || force_display) {
// Get display information
QString display = transform.display();
QString view = transform.view();
QString look = transform.look();
// Check if display still exists in config
if (!ListAvailableDisplays().contains(display)) {
display = GetDefaultDisplay();
}
// Check if display still exists in config
if (!ListAvailableDisplays().contains(display)) {
display = GetDefaultDisplay();
}
// Check if view still exists in display
if (!ListAvailableViews(display).contains(view)) {
view = GetDefaultView(display);
}
// Check if view still exists in display
if (!ListAvailableViews(display).contains(view)) {
view = GetDefaultView(display);
}
// Check if looks still exists
if (!ListAvailableLooks().contains(look)) {
look.clear();
}
// Check if looks still exists
if (!ListAvailableLooks().contains(look)) {
look.clear();
}
return ColorTransform(display, view, look);
return ColorTransform(display, view, look);
} else {
} else {
QString output = transform.output();
QString output = transform.output();
if (!ListAvailableColorspaces().contains(output)) {
output = GetDefaultInputColorSpace();
}
if (!ListAvailableColorspaces().contains(output)) {
output = GetDefaultInputColorSpace();
}
return ColorTransform(output);
}
return ColorTransform(output);
}
}
QStringList ColorManager::ListAvailableColorspaces(OCIO::ConstConfigRcPtr config)
QStringList
ColorManager::ListAvailableColorspaces(OCIO::ConstConfigRcPtr config)
{
QStringList spaces;
QStringList spaces;
if (config) {
int number_of_colorspaces = config->getNumColorSpaces();
if (config) {
int number_of_colorspaces = config->getNumColorSpaces();
for (int i=0;i<number_of_colorspaces;i++) {
spaces.append(config->getColorSpaceNameByIndex(i));
}
}
for (int i = 0; i < number_of_colorspaces; i++) {
spaces.append(config->getColorSpaceNameByIndex(i));
}
}
return spaces;
return spaces;
}
void ColorManager::GetDefaultLumaCoefs(double *rgb) const
{
config_->getDefaultLumaCoefs(rgb);
config_->getDefaultLumaCoefs(rgb);
}
Project *ColorManager::project() const
{
return static_cast<Project*>(parent());
return static_cast<Project *>(parent());
}
void ColorManager::UpdateConfigFromFilename()
{
try {
QString config_filename = GetConfigFilename();
QString old_default_cs = GetDefaultInputColorSpace();
try {
QString config_filename = GetConfigFilename();
QString old_default_cs = GetDefaultInputColorSpace();
config_ = OCIO::Config::CreateFromFile(config_filename.toUtf8());
config_ = OCIO::Config::CreateFromFile(config_filename.toUtf8());
// Set new default colorspace appropriately
QString new_default = old_default_cs;
QStringList available_cs = ListAvailableColorspaces();
for (int i=0; i<available_cs.size(); i++) {
const QString &c = available_cs.at(i);
if (c.compare(old_default_cs, Qt::CaseInsensitive)) {
new_default = c;
break;
}
}
SetDefaultInputColorSpace(new_default);
// Set new default colorspace appropriately
QString new_default = old_default_cs;
QStringList available_cs = ListAvailableColorspaces();
for (int i = 0; i < available_cs.size(); i++) {
const QString &c = available_cs.at(i);
if (c.compare(old_default_cs, Qt::CaseInsensitive)) {
new_default = c;
break;
}
}
SetDefaultInputColorSpace(new_default);
emit ConfigChanged(config_filename);
} catch (OCIO::Exception&) {}
emit ConfigChanged(config_filename);
} catch (OCIO::Exception &) {
}
}
}
+33 -33
View File
@@ -28,70 +28,70 @@
#include "node/node.h"
#include "render/colorprocessor.h"
namespace olive {
class ColorManager : public QObject
namespace olive
{
Q_OBJECT
class ColorManager : public QObject {
Q_OBJECT
public:
ColorManager(Project *project);
ColorManager(Project *project);
void Init();
void Init();
OCIO::ConstConfigRcPtr GetConfig() const;
OCIO::ConstConfigRcPtr GetConfig() const;
static OCIO::ConstConfigRcPtr CreateConfigFromFile(const QString& filename);
static OCIO::ConstConfigRcPtr CreateConfigFromFile(const QString &filename);
QString GetConfigFilename() const;
QString GetConfigFilename() const;
static OCIO::ConstConfigRcPtr GetDefaultConfig();
static OCIO::ConstConfigRcPtr GetDefaultConfig();
static void SetUpDefaultConfig();
static void SetUpDefaultConfig();
void SetConfigFilename(const QString& filename);
void SetConfigFilename(const QString &filename);
QStringList ListAvailableDisplays();
QStringList ListAvailableDisplays();
QString GetDefaultDisplay();
QString GetDefaultDisplay();
QStringList ListAvailableViews(QString display);
QStringList ListAvailableViews(QString display);
QString GetDefaultView(const QString& display);
QString GetDefaultView(const QString &display);
QStringList ListAvailableLooks();
QStringList ListAvailableLooks();
QStringList ListAvailableColorspaces() const;
QStringList ListAvailableColorspaces() const;
QString GetDefaultInputColorSpace() const;
QString GetDefaultInputColorSpace() const;
void SetDefaultInputColorSpace(const QString& s);
void SetDefaultInputColorSpace(const QString &s);
QString GetReferenceColorSpace() const;
QString GetReferenceColorSpace() const;
QString GetCompliantColorSpace(const QString& s);
QString GetCompliantColorSpace(const QString &s);
ColorTransform GetCompliantColorSpace(const ColorTransform& transform, bool force_display = false);
ColorTransform GetCompliantColorSpace(const ColorTransform &transform,
bool force_display = false);
static QStringList ListAvailableColorspaces(OCIO::ConstConfigRcPtr config);
static QStringList ListAvailableColorspaces(OCIO::ConstConfigRcPtr config);
void GetDefaultLumaCoefs(double *rgb) const;
void GetDefaultLumaCoefs(double *rgb) const;
Project *project() const;
Project *project() const;
void UpdateConfigFromFilename();
void UpdateConfigFromFilename();
signals:
void ConfigChanged(const QString &s);
void ConfigChanged(const QString &s);
void ReferenceSpaceChanged(const QString &s);
void ReferenceSpaceChanged(const QString &s);
void DefaultInputChanged(const QString &s);
void DefaultInputChanged(const QString &s);
private:
OCIO::ConstConfigRcPtr config_;
static OCIO::ConstConfigRcPtr default_config_;
OCIO::ConstConfigRcPtr config_;
static OCIO::ConstConfigRcPtr default_config_;
};
}
@@ -22,9 +22,11 @@
#include "node/color/colormanager/colormanager.h"
namespace olive {
namespace olive
{
const QString DisplayTransformNode::kDisplayInput = QStringLiteral("display_in");
const QString DisplayTransformNode::kDisplayInput =
QStringLiteral("display_in");
const QString DisplayTransformNode::kViewInput = QStringLiteral("view_in");
const QString DisplayTransformNode::kDirectionInput = QStringLiteral("dir_in");
@@ -32,113 +34,123 @@ const QString DisplayTransformNode::kDirectionInput = QStringLiteral("dir_in");
DisplayTransformNode::DisplayTransformNode()
{
AddInput(kDisplayInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kDisplayInput, NodeValue::kCombo, 0,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kViewInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kViewInput, NodeValue::kCombo, 0,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kDirectionInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kDirectionInput, NodeValue::kCombo, 0,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
}
QString DisplayTransformNode::Name() const
{
return tr("Display Transform");
return tr("Display Transform");
}
QString DisplayTransformNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.displaytransform");
return QStringLiteral("org.olivevideoeditor.Olive.displaytransform");
}
QVector<Node::CategoryID> DisplayTransformNode::Category() const
{
return {kCategoryColor};
return { kCategoryColor };
}
QString DisplayTransformNode::Description() const
{
return tr("Converts an image to or from a display color space.");
return tr("Converts an image to or from a display color space.");
}
void DisplayTransformNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kDisplayInput, tr("Display"));
SetInputName(kViewInput, tr("View"));
SetInputName(kDirectionInput, tr("Direction"));
SetComboBoxStrings(kDirectionInput, {tr("Forward"), tr("Inverse")});
SetInputName(kTextureInput, tr("Input"));
SetInputName(kDisplayInput, tr("Display"));
SetInputName(kViewInput, tr("View"));
SetInputName(kDirectionInput, tr("Direction"));
SetComboBoxStrings(kDirectionInput, { tr("Forward"), tr("Inverse") });
}
void DisplayTransformNode::InputValueChangedEvent(const QString &input, int element)
void DisplayTransformNode::InputValueChangedEvent(const QString &input,
int element)
{
Q_UNUSED(element);
if (input == kDisplayInput || input == kDirectionInput || input == kViewInput) {
if (input == kDisplayInput) {
UpdateViews();
}
GenerateProcessor();
}
Q_UNUSED(element);
if (input == kDisplayInput || input == kDirectionInput ||
input == kViewInput) {
if (input == kDisplayInput) {
UpdateViews();
}
GenerateProcessor();
}
}
QString DisplayTransformNode::GetDisplay() const
{
if (manager()) {
int index = GetStandardValue(kDisplayInput).toInt();
if (index < manager()->ListAvailableDisplays().size()) {
return manager()->ListAvailableDisplays().at(index);
}
}
return QString();
if (manager()) {
int index = GetStandardValue(kDisplayInput).toInt();
if (index < manager()->ListAvailableDisplays().size()) {
return manager()->ListAvailableDisplays().at(index);
}
}
return QString();
}
QString DisplayTransformNode::GetView() const
{
if (manager()) {
QString display = GetDisplay();
if (!display.isEmpty()) {
int index = GetStandardValue(kViewInput).toInt();
QStringList views = manager()->ListAvailableViews(display);
if (index < views.size()) {
return views.at(index);
}
}
}
return QString();
if (manager()) {
QString display = GetDisplay();
if (!display.isEmpty()) {
int index = GetStandardValue(kViewInput).toInt();
QStringList views = manager()->ListAvailableViews(display);
if (index < views.size()) {
return views.at(index);
}
}
}
return QString();
}
ColorProcessor::Direction DisplayTransformNode::GetDirection() const
{
return static_cast<ColorProcessor::Direction>(GetStandardValue(kDirectionInput).toInt());;
return static_cast<ColorProcessor::Direction>(
GetStandardValue(kDirectionInput).toInt());
;
}
void DisplayTransformNode::UpdateDisplays()
{
if (manager()) {
SetComboBoxStrings(kDisplayInput, manager()->ListAvailableDisplays());
}
if (manager()) {
SetComboBoxStrings(kDisplayInput, manager()->ListAvailableDisplays());
}
}
void DisplayTransformNode::UpdateViews()
{
if (manager()) {
SetComboBoxStrings(kViewInput, manager()->ListAvailableViews(GetDisplay()));
}
if (manager()) {
SetComboBoxStrings(kViewInput,
manager()->ListAvailableViews(GetDisplay()));
}
}
void DisplayTransformNode::ConfigChanged()
{
UpdateDisplays();
UpdateViews();
GenerateProcessor();
UpdateDisplays();
UpdateViews();
GenerateProcessor();
}
void DisplayTransformNode::GenerateProcessor()
{
if (manager()) {
ColorTransform transform(GetDisplay(), GetView(), QString());
set_processor(ColorProcessor::Create(manager(), manager()->GetReferenceColorSpace(), transform, GetDirection()));
}
if (manager()) {
ColorTransform transform(GetDisplay(), GetView(), QString());
set_processor(ColorProcessor::Create(
manager(), manager()->GetReferenceColorSpace(), transform,
GetDirection()));
}
}
}
@@ -24,42 +24,42 @@
#include "node/color/ociobase/ociobase.h"
#include "render/colorprocessor.h"
namespace olive {
class DisplayTransformNode : public OCIOBaseNode
namespace olive
{
Q_OBJECT
public:
DisplayTransformNode();
NODE_DEFAULT_FUNCTIONS(DisplayTransformNode)
class DisplayTransformNode : public OCIOBaseNode {
Q_OBJECT
public:
DisplayTransformNode();
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
NODE_DEFAULT_FUNCTIONS(DisplayTransformNode)
virtual void Retranslate() override;
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
QString GetDisplay() const;
QString GetView() const;
ColorProcessor::Direction GetDirection() const;
virtual void Retranslate() override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
static const QString kDisplayInput;
static const QString kViewInput;
static const QString kDirectionInput;
QString GetDisplay() const;
QString GetView() const;
ColorProcessor::Direction GetDirection() const;
static const QString kDisplayInput;
static const QString kViewInput;
static const QString kDirectionInput;
protected slots:
virtual void ConfigChanged() override;
virtual void ConfigChanged() override;
private:
void GenerateProcessor();
void GenerateProcessor();
void UpdateDisplays();
void UpdateViews();
void UpdateDisplays();
void UpdateViews();
};
} // olive
+28 -23
View File
@@ -23,48 +23,53 @@
#include "node/color/colormanager/colormanager.h"
#include "node/project.h"
namespace olive {
namespace olive
{
const QString OCIOBaseNode::kTextureInput = QStringLiteral("tex_in");
OCIOBaseNode::OCIOBaseNode() :
manager_(nullptr),
processor_(nullptr)
OCIOBaseNode::OCIOBaseNode()
: manager_(nullptr)
, processor_(nullptr)
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
SetEffectInput(kTextureInput);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetFlag(kVideoEffect);
}
void OCIOBaseNode::AddedToGraphEvent(Project *p)
{
manager_ = p->color_manager();
connect(manager_, &ColorManager::ConfigChanged, this, &OCIOBaseNode::ConfigChanged);
ConfigChanged();
manager_ = p->color_manager();
connect(manager_, &ColorManager::ConfigChanged, this,
&OCIOBaseNode::ConfigChanged);
ConfigChanged();
}
void OCIOBaseNode::RemovedFromGraphEvent(Project *p)
{
if (manager_) {
disconnect(manager_, &ColorManager::ConfigChanged, this, &OCIOBaseNode::ConfigChanged);
manager_ = nullptr;
}
if (manager_) {
disconnect(manager_, &ColorManager::ConfigChanged, this,
&OCIOBaseNode::ConfigChanged);
manager_ = nullptr;
}
}
void OCIOBaseNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void OCIOBaseNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
auto tex_met = value[kTextureInput];
TexturePtr t = tex_met.toTexture();
if (t && processor_) {
ColorTransformJob job;
auto tex_met = value[kTextureInput];
TexturePtr t = tex_met.toTexture();
if (t && processor_) {
ColorTransformJob job;
job.SetColorProcessor(processor_);
job.SetInputTexture(tex_met);
job.SetColorProcessor(processor_);
job.SetInputTexture(tex_met);
table->Push(NodeValue::kTexture, t->toJob(job), this);
}
table->Push(NodeValue::kTexture, t->toJob(job), this);
}
}
}
+25 -16
View File
@@ -24,35 +24,44 @@
#include "node/node.h"
#include "render/job/colortransformjob.h"
namespace olive {
class OCIOBaseNode : public Node
namespace olive
{
Q_OBJECT
class OCIOBaseNode : public Node {
Q_OBJECT
public:
OCIOBaseNode();
OCIOBaseNode();
virtual void AddedToGraphEvent(Project *p) override;
virtual void RemovedFromGraphEvent(Project *p) override;
virtual void AddedToGraphEvent(Project *p) override;
virtual void RemovedFromGraphEvent(Project *p) override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kTextureInput;
protected slots:
virtual void ConfigChanged() = 0;
virtual void ConfigChanged() = 0;
protected:
ColorManager *manager() const { return manager_; }
ColorManager *manager() const
{
return manager_;
}
ColorProcessorPtr processor() const { return processor_; }
void set_processor(ColorProcessorPtr p) { processor_ = p; }
ColorProcessorPtr processor() const
{
return processor_;
}
void set_processor(ColorProcessorPtr p)
{
processor_ = p;
}
private:
ColorManager *manager_;
ColorProcessorPtr processor_;
ColorManager *manager_;
ColorProcessorPtr processor_;
};
}
@@ -27,192 +27,236 @@
#include "render/colorprocessor.h"
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString OCIOGradingTransformLinearNode::kContrastInput = QStringLiteral("ocio_grading_primary_contrast");
const QString OCIOGradingTransformLinearNode::kOffsetInput = QStringLiteral("ocio_grading_primary_offset");
const QString OCIOGradingTransformLinearNode::kExposureInput = QStringLiteral("ocio_grading_primary_exposure");
const QString OCIOGradingTransformLinearNode::kSaturationInput = QStringLiteral("ocio_grading_primary_saturation");
const QString OCIOGradingTransformLinearNode::kPivotInput = QStringLiteral("ocio_grading_primary_pivot");
const QString OCIOGradingTransformLinearNode::kClampBlackEnableInput = QStringLiteral("clamp_black_enable_in");
const QString OCIOGradingTransformLinearNode::kClampBlackInput = QStringLiteral("ocio_grading_primary_clampBlack");
const QString OCIOGradingTransformLinearNode::kClampWhiteEnableInput = QStringLiteral("clamp_white_enable_in");
const QString OCIOGradingTransformLinearNode::kClampWhiteInput = QStringLiteral("ocio_grading_primary_clampWhite");
const QString OCIOGradingTransformLinearNode::kContrastInput =
QStringLiteral("ocio_grading_primary_contrast");
const QString OCIOGradingTransformLinearNode::kOffsetInput =
QStringLiteral("ocio_grading_primary_offset");
const QString OCIOGradingTransformLinearNode::kExposureInput =
QStringLiteral("ocio_grading_primary_exposure");
const QString OCIOGradingTransformLinearNode::kSaturationInput =
QStringLiteral("ocio_grading_primary_saturation");
const QString OCIOGradingTransformLinearNode::kPivotInput =
QStringLiteral("ocio_grading_primary_pivot");
const QString OCIOGradingTransformLinearNode::kClampBlackEnableInput =
QStringLiteral("clamp_black_enable_in");
const QString OCIOGradingTransformLinearNode::kClampBlackInput =
QStringLiteral("ocio_grading_primary_clampBlack");
const QString OCIOGradingTransformLinearNode::kClampWhiteEnableInput =
QStringLiteral("clamp_white_enable_in");
const QString OCIOGradingTransformLinearNode::kClampWhiteInput =
QStringLiteral("ocio_grading_primary_clampWhite");
#define super OCIOBaseNode
OCIOGradingTransformLinearNode::OCIOGradingTransformLinearNode()
{
AddInput(kContrastInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0});
// Minimum based on OCIO::GradingPrimary::validate
SetInputProperty(kContrastInput, QStringLiteral("min"), QVector4D{0.01f, 0.01f, 0.01f, 0.01f});
SetInputProperty(kContrastInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kContrastInput);
AddInput(kContrastInput, NodeValue::kVec4, QVector4D{ 1.0, 1.0, 1.0, 1.0 });
// Minimum based on OCIO::GradingPrimary::validate
SetInputProperty(kContrastInput, QStringLiteral("min"),
QVector4D{ 0.01f, 0.01f, 0.01f, 0.01f });
SetInputProperty(kContrastInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kContrastInput);
AddInput(kOffsetInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
SetInputProperty(kOffsetInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kOffsetInput);
AddInput(kOffsetInput, NodeValue::kVec4, QVector4D{ 0.0, 0.0, 0.0, 0.0 });
SetInputProperty(kOffsetInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kOffsetInput);
AddInput(kExposureInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
SetInputProperty(kExposureInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kExposureInput);
AddInput(kExposureInput, NodeValue::kVec4, QVector4D{ 0.0, 0.0, 0.0, 0.0 });
SetInputProperty(kExposureInput, QStringLiteral("base"), 0.01);
SetVec4InputColors(kExposureInput);
AddInput(kSaturationInput, NodeValue::kFloat, 1.0);
SetInputProperty(kSaturationInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kSaturationInput, QStringLiteral("min"), 0.0);
AddInput(kSaturationInput, NodeValue::kFloat, 1.0);
SetInputProperty(kSaturationInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kSaturationInput, QStringLiteral("min"), 0.0);
AddInput(kPivotInput, NodeValue::kFloat, 0.18); // Default listed in OCIO::GradingPrimary
SetInputProperty(kPivotInput, QStringLiteral("base"), 0.01);
AddInput(kPivotInput, NodeValue::kFloat,
0.18); // Default listed in OCIO::GradingPrimary
SetInputProperty(kPivotInput, QStringLiteral("base"), 0.01);
AddInput(kClampBlackEnableInput, NodeValue::kBoolean, false);
AddInput(kClampBlackEnableInput, NodeValue::kBoolean, false);
AddInput(kClampBlackInput, NodeValue::kFloat, 0.0);
SetInputProperty(kClampBlackInput, QStringLiteral("enabled"), GetStandardValue(kClampBlackEnableInput).toBool());
SetInputProperty(kClampBlackInput, QStringLiteral("base"), 0.01);
AddInput(kClampBlackInput, NodeValue::kFloat, 0.0);
SetInputProperty(kClampBlackInput, QStringLiteral("enabled"),
GetStandardValue(kClampBlackEnableInput).toBool());
SetInputProperty(kClampBlackInput, QStringLiteral("base"), 0.01);
AddInput(kClampWhiteEnableInput, NodeValue::kBoolean, false);
AddInput(kClampWhiteEnableInput, NodeValue::kBoolean, false);
AddInput(kClampWhiteInput, NodeValue::kFloat, 1.0);
SetInputProperty(kClampWhiteInput, QStringLiteral("enabled"), GetStandardValue(kClampWhiteEnableInput).toBool());
SetInputProperty(kClampWhiteInput, QStringLiteral("base"), 0.01);
AddInput(kClampWhiteInput, NodeValue::kFloat, 1.0);
SetInputProperty(kClampWhiteInput, QStringLiteral("enabled"),
GetStandardValue(kClampWhiteEnableInput).toBool());
SetInputProperty(kClampWhiteInput, QStringLiteral("base"), 0.01);
// FIXME: Temporarily disabled. This will break if "clamp black" is keyframed or connected to
// something and there's currently no solution to remedy that. If there is in the future,
// we can look into re-enabling this.
//SetInputProperty(kClampWhiteInput, QStringLiteral("min"), GetStandardValue(kClampBlackInput).toDouble() + 0.000001);
// FIXME: Temporarily disabled. This will break if "clamp black" is keyframed or connected to
// something and there's currently no solution to remedy that. If there is in the future,
// we can look into re-enabling this.
//SetInputProperty(kClampWhiteInput, QStringLiteral("min"), GetStandardValue(kClampBlackInput).toDouble() + 0.000001);
}
QString OCIOGradingTransformLinearNode::Name() const
{
return tr("OCIO Color Grading (Linear)");
return tr("OCIO Color Grading (Linear)");
}
QString OCIOGradingTransformLinearNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.ociogradingtransformlinear");
return QStringLiteral(
"org.olivevideoeditor.Olive.ociogradingtransformlinear");
}
QVector<Node::CategoryID> OCIOGradingTransformLinearNode::Category() const
{
return {kCategoryColor};
return { kCategoryColor };
}
QString OCIOGradingTransformLinearNode::Description() const
{
return tr("Simple linear color grading using OpenColorIO.");
return tr("Simple linear color grading using OpenColorIO.");
}
void OCIOGradingTransformLinearNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kContrastInput, tr("Contrast"));
SetInputName(kOffsetInput, tr("Offset"));
SetInputName(kExposureInput, tr("Exposure"));
SetInputProperty(kExposureInput, QStringLiteral("tooltip"), tr("Exposure increments in stops."));
SetInputName(kSaturationInput, tr("Saturation"));
SetInputName(kPivotInput, tr("Pivot"));
SetInputName(kClampBlackEnableInput, tr("Enable Black Clamp"));
SetInputName(kClampBlackInput, tr("Black Clamp"));
SetInputName(kClampWhiteEnableInput, tr("Enable White Clamp"));
SetInputName(kClampWhiteInput, tr("White Clamp"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kContrastInput, tr("Contrast"));
SetInputName(kOffsetInput, tr("Offset"));
SetInputName(kExposureInput, tr("Exposure"));
SetInputProperty(kExposureInput, QStringLiteral("tooltip"),
tr("Exposure increments in stops."));
SetInputName(kSaturationInput, tr("Saturation"));
SetInputName(kPivotInput, tr("Pivot"));
SetInputName(kClampBlackEnableInput, tr("Enable Black Clamp"));
SetInputName(kClampBlackInput, tr("Black Clamp"));
SetInputName(kClampWhiteEnableInput, tr("Enable White Clamp"));
SetInputName(kClampWhiteInput, tr("White Clamp"));
}
void OCIOGradingTransformLinearNode::InputValueChangedEvent(const QString &input, int element)
void OCIOGradingTransformLinearNode::InputValueChangedEvent(
const QString &input, int element)
{
Q_UNUSED(element);
Q_UNUSED(element);
if (input == kClampWhiteEnableInput) {
SetInputProperty(kClampWhiteInput, QStringLiteral("enabled"), GetStandardValue(kClampWhiteEnableInput).toBool());
} else if (input == kClampBlackEnableInput) {
SetInputProperty(kClampBlackInput, QStringLiteral("enabled"), GetStandardValue(kClampBlackEnableInput).toBool());
} else if (input == kClampBlackInput) {
// Ensure the white clamp is always greater than the black clamp as per OCIO::GradingPrimary::validate
// FIXME: Temporarily disabled. This will break if "clamp black" is keyframed or connected to
// something and there's currently no solution to remedy that. If there is in the future,
// we can look into re-enabling this.
//SetInputProperty(kClampWhiteInput, QStringLiteral("min"), GetStandardValue(kClampBlackInput).toDouble() + 0.000001);
}
if (input == kClampWhiteEnableInput) {
SetInputProperty(kClampWhiteInput, QStringLiteral("enabled"),
GetStandardValue(kClampWhiteEnableInput).toBool());
} else if (input == kClampBlackEnableInput) {
SetInputProperty(kClampBlackInput, QStringLiteral("enabled"),
GetStandardValue(kClampBlackEnableInput).toBool());
} else if (input == kClampBlackInput) {
// Ensure the white clamp is always greater than the black clamp as per OCIO::GradingPrimary::validate
// FIXME: Temporarily disabled. This will break if "clamp black" is keyframed or connected to
// something and there's currently no solution to remedy that. If there is in the future,
// we can look into re-enabling this.
//SetInputProperty(kClampWhiteInput, QStringLiteral("min"), GetStandardValue(kClampBlackInput).toDouble() + 0.000001);
}
GenerateProcessor();
GenerateProcessor();
}
void OCIOGradingTransformLinearNode::GenerateProcessor()
{
if (manager()) {
OCIO::GradingPrimaryTransformRcPtr gp = OCIO::GradingPrimaryTransform::Create(OCIO::GRADING_LIN);
gp->makeDynamic();
gp->setDirection(OCIO::TransformDirection::TRANSFORM_DIR_FORWARD);
if (manager()) {
OCIO::GradingPrimaryTransformRcPtr gp =
OCIO::GradingPrimaryTransform::Create(OCIO::GRADING_LIN);
gp->makeDynamic();
gp->setDirection(OCIO::TransformDirection::TRANSFORM_DIR_FORWARD);
try {
set_processor(ColorProcessor::Create(manager()->GetConfig()->getProcessor(gp)));
} catch (const OCIO::Exception &e) {
std::cerr << std::endl << e.what() << std::endl;
}
}
try {
set_processor(ColorProcessor::Create(
manager()->GetConfig()->getProcessor(gp)));
} catch (const OCIO::Exception &e) {
std::cerr << std::endl << e.what() << std::endl;
}
}
}
void OCIOGradingTransformLinearNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void OCIOGradingTransformLinearNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (processor()) {
ColorTransformJob job(value);
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (processor()) {
ColorTransformJob job(value);
job.SetColorProcessor(processor());
job.SetInputTexture(value[kTextureInput]);
job.SetColorProcessor(processor());
job.SetInputTexture(value[kTextureInput]);
const int MASTER_CHANNEL = 0;
const int RED_CHANNEL = 1;
const int GREEN_CHANNEL = 2;
const int BLUE_CHANNEL = 3;
const int MASTER_CHANNEL = 0;
const int RED_CHANNEL = 1;
const int GREEN_CHANNEL = 2;
const int BLUE_CHANNEL = 3;
// Oddly, OCIO uses RGBMs when setting the GradingPrimary on the CPU, but uses vec3s on the GPU.
// Even more oddly, the conversion from RGBM to vec3 does not appear to have a public API.
// Therefore, this code has been duplicated from OCIO here:
// https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/3abbe5b20521169580fcfe3692aca81859859953/src/OpenColorIO/ops/gradingprimary/GradingPrimary.cpp#L157
QVector4D offset = value[kOffsetInput].toVec4();
offset[RED_CHANNEL] += offset[MASTER_CHANNEL];
offset[GREEN_CHANNEL] += offset[MASTER_CHANNEL];
offset[BLUE_CHANNEL] += offset[MASTER_CHANNEL];
job.Insert(kOffsetInput, NodeValue(NodeValue::kVec3, QVector3D(offset[RED_CHANNEL], offset[GREEN_CHANNEL], offset[BLUE_CHANNEL])));
// Oddly, OCIO uses RGBMs when setting the GradingPrimary on the CPU, but uses vec3s on the GPU.
// Even more oddly, the conversion from RGBM to vec3 does not appear to have a public API.
// Therefore, this code has been duplicated from OCIO here:
// https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/3abbe5b20521169580fcfe3692aca81859859953/src/OpenColorIO/ops/gradingprimary/GradingPrimary.cpp#L157
QVector4D offset = value[kOffsetInput].toVec4();
offset[RED_CHANNEL] += offset[MASTER_CHANNEL];
offset[GREEN_CHANNEL] += offset[MASTER_CHANNEL];
offset[BLUE_CHANNEL] += offset[MASTER_CHANNEL];
job.Insert(kOffsetInput,
NodeValue(NodeValue::kVec3,
QVector3D(offset[RED_CHANNEL],
offset[GREEN_CHANNEL],
offset[BLUE_CHANNEL])));
QVector4D exposure = value[kExposureInput].toVec4();
exposure[RED_CHANNEL] = std::pow(2.0f, exposure[MASTER_CHANNEL] + exposure[RED_CHANNEL]);
exposure[GREEN_CHANNEL] = std::pow(2.0f, exposure[MASTER_CHANNEL] + exposure[GREEN_CHANNEL]);
exposure[BLUE_CHANNEL] = std::pow(2.0f, exposure[MASTER_CHANNEL] + exposure[BLUE_CHANNEL]);
job.Insert(kExposureInput, NodeValue(NodeValue::kVec3, QVector3D(exposure[RED_CHANNEL], exposure[GREEN_CHANNEL], exposure[BLUE_CHANNEL])));
QVector4D exposure = value[kExposureInput].toVec4();
exposure[RED_CHANNEL] = std::pow(2.0f, exposure[MASTER_CHANNEL] +
exposure[RED_CHANNEL]);
exposure[GREEN_CHANNEL] = std::pow(
2.0f, exposure[MASTER_CHANNEL] + exposure[GREEN_CHANNEL]);
exposure[BLUE_CHANNEL] = std::pow(2.0f, exposure[MASTER_CHANNEL] +
exposure[BLUE_CHANNEL]);
job.Insert(kExposureInput,
NodeValue(NodeValue::kVec3,
QVector3D(exposure[RED_CHANNEL],
exposure[GREEN_CHANNEL],
exposure[BLUE_CHANNEL])));
QVector4D contrast = value[kContrastInput].toVec4();
contrast[RED_CHANNEL] *= contrast[MASTER_CHANNEL];
contrast[GREEN_CHANNEL] *= contrast[MASTER_CHANNEL];
contrast[BLUE_CHANNEL] *= contrast[MASTER_CHANNEL];
job.Insert(kContrastInput, NodeValue(NodeValue::kVec3, QVector3D(contrast[RED_CHANNEL], contrast[GREEN_CHANNEL], contrast[BLUE_CHANNEL])));
QVector4D contrast = value[kContrastInput].toVec4();
contrast[RED_CHANNEL] *= contrast[MASTER_CHANNEL];
contrast[GREEN_CHANNEL] *= contrast[MASTER_CHANNEL];
contrast[BLUE_CHANNEL] *= contrast[MASTER_CHANNEL];
job.Insert(kContrastInput,
NodeValue(NodeValue::kVec3,
QVector3D(contrast[RED_CHANNEL],
contrast[GREEN_CHANNEL],
contrast[BLUE_CHANNEL])));
if (!value[kClampBlackEnableInput].toBool()) {
job.Insert(kClampBlackInput, NodeValue(NodeValue::kFloat, OCIO::GradingPrimary::NoClampBlack()));
}
if (!value[kClampBlackEnableInput].toBool()) {
job.Insert(kClampBlackInput,
NodeValue(NodeValue::kFloat,
OCIO::GradingPrimary::NoClampBlack()));
}
if (!value[kClampWhiteEnableInput].toBool()) {
job.Insert(kClampWhiteInput, NodeValue(NodeValue::kFloat, OCIO::GradingPrimary::NoClampWhite()));
}
if (!value[kClampWhiteEnableInput].toBool()) {
job.Insert(kClampWhiteInput,
NodeValue(NodeValue::kFloat,
OCIO::GradingPrimary::NoClampWhite()));
}
table->Push(NodeValue::kTexture, tex->toJob(job), this);
}
}
table->Push(NodeValue::kTexture, tex->toJob(job), this);
}
}
}
void OCIOGradingTransformLinearNode::ConfigChanged()
{
GenerateProcessor();
GenerateProcessor();
}
void OCIOGradingTransformLinearNode::SetVec4InputColors(const QString &input)
{
SetInputProperty(input, QStringLiteral("color0"), QColor(192, 192, 192).name());
SetInputProperty(input, QStringLiteral("color1"), QColor(255, 0, 0).name());
SetInputProperty(input, QStringLiteral("color2"), QColor(0, 255, 0).name());
SetInputProperty(input, QStringLiteral("color3"), QColor(0, 0, 255).name());
SetInputProperty(input, QStringLiteral("color0"),
QColor(192, 192, 192).name());
SetInputProperty(input, QStringLiteral("color1"), QColor(255, 0, 0).name());
SetInputProperty(input, QStringLiteral("color2"), QColor(0, 255, 0).name());
SetInputProperty(input, QStringLiteral("color3"), QColor(0, 0, 255).name());
}
}
@@ -24,43 +24,44 @@
#include "node/color/ociobase/ociobase.h"
#include "render/colorprocessor.h"
namespace olive {
class OCIOGradingTransformLinearNode : public OCIOBaseNode
namespace olive
{
Q_OBJECT
public:
OCIOGradingTransformLinearNode();
NODE_DEFAULT_FUNCTIONS(OCIOGradingTransformLinearNode)
class OCIOGradingTransformLinearNode : public OCIOBaseNode {
Q_OBJECT
public:
OCIOGradingTransformLinearNode();
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
NODE_DEFAULT_FUNCTIONS(OCIOGradingTransformLinearNode)
virtual void Retranslate() override;
virtual void InputValueChangedEvent(const QString &input, int element) override;
void GenerateProcessor();
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Retranslate() override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
void GenerateProcessor();
static const QString kContrastInput;
static const QString kOffsetInput;
static const QString kExposureInput;
static const QString kSaturationInput;
static const QString kPivotInput;
static const QString kClampBlackEnableInput;
static const QString kClampBlackInput;
static const QString kClampWhiteEnableInput;
static const QString kClampWhiteInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kContrastInput;
static const QString kOffsetInput;
static const QString kExposureInput;
static const QString kSaturationInput;
static const QString kPivotInput;
static const QString kClampBlackEnableInput;
static const QString kClampBlackInput;
static const QString kClampWhiteEnableInput;
static const QString kClampWhiteInput;
protected slots:
virtual void ConfigChanged() override;
virtual void ConfigChanged() override;
private:
void SetVec4InputColors(const QString &input);
void SetVec4InputColors(const QString &input);
};
} // olive
@@ -24,155 +24,200 @@
#include "core.h"
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString CornerPinDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString CornerPinDistortNode::kTopLeftInput = QStringLiteral("top_left_in");
const QString CornerPinDistortNode::kTopRightInput = QStringLiteral("top_right_in");
const QString CornerPinDistortNode::kBottomRightInput = QStringLiteral("bottom_right_in");
const QString CornerPinDistortNode::kBottomLeftInput = QStringLiteral("bottom_left_in");
const QString CornerPinDistortNode::kPerspectiveInput = QStringLiteral("perspective_in");
const QString CornerPinDistortNode::kTopLeftInput =
QStringLiteral("top_left_in");
const QString CornerPinDistortNode::kTopRightInput =
QStringLiteral("top_right_in");
const QString CornerPinDistortNode::kBottomRightInput =
QStringLiteral("bottom_right_in");
const QString CornerPinDistortNode::kBottomLeftInput =
QStringLiteral("bottom_left_in");
const QString CornerPinDistortNode::kPerspectiveInput =
QStringLiteral("perspective_in");
#define super Node
CornerPinDistortNode::CornerPinDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kPerspectiveInput, NodeValue::kBoolean, true);
AddInput(kTopLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kTopRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kBottomRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kBottomLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kPerspectiveInput, NodeValue::kBoolean, true);
AddInput(kTopLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kTopRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kBottomRightInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kBottomLeftInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
// Initiate gizmos
gizmo_whole_rect_ = AddDraggableGizmo<PolygonGizmo>();
gizmo_resize_handle_[0] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 0), NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 1)});
gizmo_resize_handle_[1] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 0), NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 1)});
gizmo_resize_handle_[2] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 0), NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 1)});
gizmo_resize_handle_[3] = AddDraggableGizmo<PointGizmo>({NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 0), NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 1)});
// Initiate gizmos
gizmo_whole_rect_ = AddDraggableGizmo<PolygonGizmo>();
gizmo_resize_handle_[0] = AddDraggableGizmo<PointGizmo>(
{ NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kTopLeftInput), 1) });
gizmo_resize_handle_[1] = AddDraggableGizmo<PointGizmo>(
{ NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kTopRightInput), 1) });
gizmo_resize_handle_[2] = AddDraggableGizmo<PointGizmo>(
{ NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kBottomRightInput), 1) });
gizmo_resize_handle_[3] = AddDraggableGizmo<PointGizmo>(
{ NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kBottomLeftInput), 1) });
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
void CornerPinDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kPerspectiveInput, tr("Perspective"));
SetInputName(kTopLeftInput, tr("Top Left"));
SetInputName(kTopRightInput, tr("Top Right"));
SetInputName(kBottomRightInput, tr("Bottom Right"));
SetInputName(kBottomLeftInput, tr("Bottom Left"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kPerspectiveInput, tr("Perspective"));
SetInputName(kTopLeftInput, tr("Top Left"));
SetInputName(kTopRightInput, tr("Top Right"));
SetInputName(kBottomRightInput, tr("Bottom Right"));
SetInputName(kBottomLeftInput, tr("Bottom Left"));
}
void CornerPinDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void CornerPinDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If no texture do nothing
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// In the special case that all sliders are in their default position just
// push the texture.
if (!(value[kTopLeftInput].toVec2().isNull()
&& value[kTopRightInput].toVec2().isNull() &&
value[kBottomRightInput].toVec2().isNull() &&
value[kBottomLeftInput].toVec2().isNull())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
// If no texture do nothing
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// In the special case that all sliders are in their default position just
// push the texture.
if (!(value[kTopLeftInput].toVec2().isNull() &&
value[kTopRightInput].toVec2().isNull() &&
value[kBottomRightInput].toVec2().isNull() &&
value[kBottomLeftInput].toVec2().isNull())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
// Convert slider values to their pixel values and then convert to clip space (-1.0 ... 1.0) for overriding the
// vertex coordinates.
const QVector2D &resolution = tex->virtual_resolution();
QVector2D half_resolution = resolution * 0.5;
QVector2D top_left = QVector2D(ValueToPixel(0, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
QVector2D top_right = QVector2D(ValueToPixel(1, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
QVector2D bottom_right = QVector2D(ValueToPixel(2, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
QVector2D bottom_left = QVector2D(ValueToPixel(3, value, resolution)) / half_resolution - QVector2D(1.0, 1.0);
// Convert slider values to their pixel values and then convert to clip space (-1.0 ... 1.0) for overriding the
// vertex coordinates.
const QVector2D &resolution = tex->virtual_resolution();
QVector2D half_resolution = resolution * 0.5;
QVector2D top_left = QVector2D(ValueToPixel(0, value, resolution)) /
half_resolution -
QVector2D(1.0, 1.0);
QVector2D top_right =
QVector2D(ValueToPixel(1, value, resolution)) /
half_resolution -
QVector2D(1.0, 1.0);
QVector2D bottom_right =
QVector2D(ValueToPixel(2, value, resolution)) /
half_resolution -
QVector2D(1.0, 1.0);
QVector2D bottom_left =
QVector2D(ValueToPixel(3, value, resolution)) /
half_resolution -
QVector2D(1.0, 1.0);
// Override default vertex coordinates.
QVector<float> adjusted_vertices = {top_left.x(), top_left.y(), 0.0f,
top_right.x(), top_right.y(), 0.0f,
bottom_right.x(), bottom_right.y(), 0.0f,
// Override default vertex coordinates.
QVector<float> adjusted_vertices = {
top_left.x(), top_left.y(), 0.0f,
top_right.x(), top_right.y(), 0.0f,
bottom_right.x(), bottom_right.y(), 0.0f,
top_left.x(), top_left.y(), 0.0f,
bottom_left.x(), bottom_left.y(), 0.0f,
bottom_right.x(), bottom_right.y(), 0.0f};
job.SetVertexCoordinates(adjusted_vertices);
top_left.x(), top_left.y(), 0.0f,
bottom_left.x(), bottom_left.y(), 0.0f,
bottom_right.x(), bottom_right.y(), 0.0f
};
job.SetVertexCoordinates(adjusted_vertices);
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
}
ShaderCode CornerPinDistortNode::GetShaderCode(const ShaderRequest &request) const
ShaderCode
CornerPinDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.frag")),
FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.vert")));
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/cornerpin.frag")),
FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/cornerpin.vert")));
}
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow& row, const QVector2D &resolution) const
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow &row,
const QVector2D &resolution) const
{
Q_ASSERT(value >= 0 && value <= 3);
Q_ASSERT(value >= 0 && value <= 3);
QVector2D v;
QVector2D v;
switch (value) {
case 0: // Top left
v = row[kTopLeftInput].toVec2();
return QPointF(v.x(), v.y());
case 1: // Top right
v = row[kTopRightInput].toVec2();
return QPointF(resolution.x() + v.x(), v.y());
case 2: // Bottom right
v = row[kBottomRightInput].toVec2();
return QPointF(resolution.x() + v.x(), resolution.y() + v.y());
case 3: //Bottom left
v = row[kBottomLeftInput].toVec2();
return QPointF(v.x(), v.y() + resolution.y());
default: // We should never get here
return QPointF();
}
switch (value) {
case 0: // Top left
v = row[kTopLeftInput].toVec2();
return QPointF(v.x(), v.y());
case 1: // Top right
v = row[kTopRightInput].toVec2();
return QPointF(resolution.x() + v.x(), v.y());
case 2: // Bottom right
v = row[kBottomRightInput].toVec2();
return QPointF(resolution.x() + v.x(), resolution.y() + v.y());
case 3: //Bottom left
v = row[kBottomLeftInput].toVec2();
return QPointF(v.x(), v.y() + resolution.y());
default: // We should never get here
return QPointF();
}
}
void CornerPinDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void CornerPinDistortNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo != gizmo_whole_rect_) {
gizmo->GetDraggers()[0].Drag(gizmo->GetDraggers()[0].GetStartValue().toDouble() + x);
gizmo->GetDraggers()[1].Drag(gizmo->GetDraggers()[1].GetStartValue().toDouble() + y);
}
if (gizmo != gizmo_whole_rect_) {
gizmo->GetDraggers()[0].Drag(
gizmo->GetDraggers()[0].GetStartValue().toDouble() + x);
gizmo->GetDraggers()[1].Drag(
gizmo->GetDraggers()[1].GetStartValue().toDouble() + y);
}
}
void CornerPinDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void CornerPinDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
if (TexturePtr tex = row[kTextureInput].toTexture()) {
const QVector2D &resolution = tex->virtual_resolution();
if (TexturePtr tex = row[kTextureInput].toTexture()) {
const QVector2D &resolution = tex->virtual_resolution();
QPointF top_left = ValueToPixel(0, row, resolution);
QPointF top_right = ValueToPixel(1, row, resolution);
QPointF bottom_right = ValueToPixel(2, row, resolution);
QPointF bottom_left = ValueToPixel(3, row, resolution);
QPointF top_left = ValueToPixel(0, row, resolution);
QPointF top_right = ValueToPixel(1, row, resolution);
QPointF bottom_right = ValueToPixel(2, row, resolution);
QPointF bottom_left = ValueToPixel(3, row, resolution);
// Add the correct offset to each slider
SetInputProperty(kTopLeftInput, QStringLiteral("offset"), QVector2D(0.0, 0.0));
SetInputProperty(kTopRightInput, QStringLiteral("offset"), QVector2D(resolution.x() , 0.0));
SetInputProperty(kBottomRightInput, QStringLiteral("offset"), resolution);
SetInputProperty(kBottomLeftInput, QStringLiteral("offset"), QVector2D(0.0, resolution.y()));
// Add the correct offset to each slider
SetInputProperty(kTopLeftInput, QStringLiteral("offset"),
QVector2D(0.0, 0.0));
SetInputProperty(kTopRightInput, QStringLiteral("offset"),
QVector2D(resolution.x(), 0.0));
SetInputProperty(kBottomRightInput, QStringLiteral("offset"),
resolution);
SetInputProperty(kBottomLeftInput, QStringLiteral("offset"),
QVector2D(0.0, resolution.y()));
// Draw bounding box
gizmo_whole_rect_->SetPolygon(QPolygonF({top_left, top_right, bottom_right, bottom_left, top_left}));
// Draw bounding box
gizmo_whole_rect_->SetPolygon(QPolygonF(
{ top_left, top_right, bottom_right, bottom_left, top_left }));
// Create handles
gizmo_resize_handle_[0]->SetPoint(top_left);
gizmo_resize_handle_[1]->SetPoint(top_right);
gizmo_resize_handle_[2]->SetPoint(bottom_right);
gizmo_resize_handle_[3]->SetPoint(bottom_left);
}
// Create handles
gizmo_resize_handle_[0]->SetPoint(top_left);
gizmo_resize_handle_[1]->SetPoint(top_right);
gizmo_resize_handle_[2]->SetPoint(bottom_right);
gizmo_resize_handle_[3]->SetPoint(bottom_left);
}
}
}
@@ -28,68 +28,71 @@
#include "node/inputdragger.h"
#include "node/node.h"
namespace olive {
class CornerPinDistortNode : public Node
namespace olive
{
Q_OBJECT
class CornerPinDistortNode : public Node {
Q_OBJECT
public:
CornerPinDistortNode();
CornerPinDistortNode();
NODE_DEFAULT_FUNCTIONS(CornerPinDistortNode)
NODE_DEFAULT_FUNCTIONS(CornerPinDistortNode)
virtual QString Name() const override
{
return tr("Corner Pin");
}
virtual QString Name() const override
{
return tr("Corner Pin");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.cornerpin");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.cornerpin");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryDistort};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryDistort };
}
virtual QString Description() const override
{
return tr("Distort the image by dragging the corners.");
}
virtual QString Description() const override
{
return tr("Distort the image by dragging the corners.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
/**
/**
* @brief Convenience function - converts the 2D slider values from being
* an offset to the actual pixel value.
*/
QPointF ValueToPixel(int value, const NodeValueRow &row, const QVector2D &resolution) const;
QPointF ValueToPixel(int value, const NodeValueRow &row,
const QVector2D &resolution) const;
static const QString kTextureInput;
static const QString kPerspectiveInput;
static const QString kTopLeftInput;
static const QString kTopRightInput;
static const QString kBottomRightInput;
static const QString kBottomLeftInput;
static const QString kTextureInput;
static const QString kPerspectiveInput;
static const QString kTopLeftInput;
static const QString kTopRightInput;
static const QString kBottomRightInput;
static const QString kBottomLeftInput;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
// Gizmo variables
static const int kGizmoCornerCount = 4;
PointGizmo *gizmo_resize_handle_[kGizmoCornerCount];
PolygonGizmo *gizmo_whole_rect_;
// Gizmo variables
static const int kGizmoCornerCount = 4;
PointGizmo *gizmo_resize_handle_[kGizmoCornerCount];
PolygonGizmo *gizmo_whole_rect_;
};
}
#endif // CORNERPINDISTORTNODE_H
+113 -85
View File
@@ -24,7 +24,8 @@
#include "core.h"
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString CropDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString CropDistortNode::kLeftInput = QStringLiteral("left_in");
@@ -37,124 +38,151 @@ const QString CropDistortNode::kFeatherInput = QStringLiteral("feather_in");
CropDistortNode::CropDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
CreateCropSideInput(kLeftInput);
CreateCropSideInput(kTopInput);
CreateCropSideInput(kRightInput);
CreateCropSideInput(kBottomInput);
CreateCropSideInput(kLeftInput);
CreateCropSideInput(kTopInput);
CreateCropSideInput(kRightInput);
CreateCropSideInput(kBottomInput);
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
// Initiate gizmos
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({kLeftInput, kTopInput, kRightInput, kBottomInput});
// Initiate gizmos
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>(
{ kLeftInput, kTopInput, kRightInput, kBottomInput });
point_gizmo_[kGizmoScaleTopLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput, kTopInput});
point_gizmo_[kGizmoScaleTopCenter] = AddDraggableGizmo<PointGizmo>({kTopInput});
point_gizmo_[kGizmoScaleTopRight] = AddDraggableGizmo<PointGizmo>({kRightInput, kTopInput});
point_gizmo_[kGizmoScaleBottomLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput, kBottomInput});
point_gizmo_[kGizmoScaleBottomCenter] = AddDraggableGizmo<PointGizmo>({kBottomInput});
point_gizmo_[kGizmoScaleBottomRight] = AddDraggableGizmo<PointGizmo>({kRightInput, kBottomInput});
point_gizmo_[kGizmoScaleCenterLeft] = AddDraggableGizmo<PointGizmo>({kLeftInput});
point_gizmo_[kGizmoScaleCenterRight] = AddDraggableGizmo<PointGizmo>({kRightInput});
point_gizmo_[kGizmoScaleTopLeft] =
AddDraggableGizmo<PointGizmo>({ kLeftInput, kTopInput });
point_gizmo_[kGizmoScaleTopCenter] =
AddDraggableGizmo<PointGizmo>({ kTopInput });
point_gizmo_[kGizmoScaleTopRight] =
AddDraggableGizmo<PointGizmo>({ kRightInput, kTopInput });
point_gizmo_[kGizmoScaleBottomLeft] =
AddDraggableGizmo<PointGizmo>({ kLeftInput, kBottomInput });
point_gizmo_[kGizmoScaleBottomCenter] =
AddDraggableGizmo<PointGizmo>({ kBottomInput });
point_gizmo_[kGizmoScaleBottomRight] =
AddDraggableGizmo<PointGizmo>({ kRightInput, kBottomInput });
point_gizmo_[kGizmoScaleCenterLeft] =
AddDraggableGizmo<PointGizmo>({ kLeftInput });
point_gizmo_[kGizmoScaleCenterRight] =
AddDraggableGizmo<PointGizmo>({ kRightInput });
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
void CropDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kLeftInput, tr("Left"));
SetInputName(kTopInput, tr("Top"));
SetInputName(kRightInput, tr("Right"));
SetInputName(kBottomInput, tr("Bottom"));
SetInputName(kFeatherInput, tr("Feather"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kLeftInput, tr("Left"));
SetInputName(kTopInput, tr("Top"));
SetInputName(kRightInput, tr("Right"));
SetInputName(kBottomInput, tr("Bottom"));
SetInputName(kFeatherInput, tr("Feather"));
}
void CropDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void CropDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
ShaderJob job;
job.Insert(value);
ShaderJob job;
job.Insert(value);
if (TexturePtr texture = job.Get(kTextureInput).toTexture()) {
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, QVector2D(texture->params().width(), texture->params().height()), this));
if (TexturePtr texture = job.Get(kTextureInput).toTexture()) {
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2,
QVector2D(texture->params().width(),
texture->params().height()),
this));
if (!qIsNull(job.Get(kLeftInput).toDouble())
|| !qIsNull(job.Get(kRightInput).toDouble())
|| !qIsNull(job.Get(kTopInput).toDouble())
|| !qIsNull(job.Get(kBottomInput).toDouble())) {
table->Push(NodeValue::kTexture, texture->toJob(job), this);
} else {
table->Push(job.Get(kTextureInput));
}
}
if (!qIsNull(job.Get(kLeftInput).toDouble()) ||
!qIsNull(job.Get(kRightInput).toDouble()) ||
!qIsNull(job.Get(kTopInput).toDouble()) ||
!qIsNull(job.Get(kBottomInput).toDouble())) {
table->Push(NodeValue::kTexture, texture->toJob(job), this);
} else {
table->Push(job.Get(kTextureInput));
}
}
}
ShaderCode CropDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/crop.frag")));
Q_UNUSED(request)
return ShaderCode(
FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/crop.frag")));
}
void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
if (TexturePtr tex = row[kTextureInput].toTexture()) {
const QVector2D &resolution = tex->virtual_resolution();
temp_resolution_ = resolution;
if (TexturePtr tex = row[kTextureInput].toTexture()) {
const QVector2D &resolution = tex->virtual_resolution();
temp_resolution_ = resolution;
double left_pt = resolution.x() * row[kLeftInput].toDouble();
double top_pt = resolution.y() * row[kTopInput].toDouble();
double right_pt = resolution.x() * (1.0 - row[kRightInput].toDouble());
double bottom_pt = resolution.y() * (1.0 - row[kBottomInput].toDouble());
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
double left_pt = resolution.x() * row[kLeftInput].toDouble();
double top_pt = resolution.y() * row[kTopInput].toDouble();
double right_pt = resolution.x() * (1.0 - row[kRightInput].toDouble());
double bottom_pt =
resolution.y() * (1.0 - row[kBottomInput].toDouble());
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(QPointF(right_pt, center_y_pt));
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(
QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(
QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
QPointF(right_pt, center_y_pt));
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
}
poly_gizmo_->SetPolygon(
QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
}
}
void CropDistortNode::GizmoDragMove(double x_diff, double y_diff, const Qt::KeyboardModifiers &modifiers)
void CropDistortNode::GizmoDragMove(double x_diff, double y_diff,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
QVector2D res = temp_resolution_;
x_diff /= res.x();
y_diff /= res.y();
QVector2D res = temp_resolution_;
x_diff /= res.x();
y_diff /= res.y();
for (int j=0; j<gizmo->GetDraggers().size(); j++) {
NodeInputDragger& i = gizmo->GetDraggers()[j];
double s = i.GetStartValue().toDouble();
if (i.GetInput().input().input() == kLeftInput) {
i.Drag(s + x_diff);
} else if (i.GetInput().input().input() == kTopInput) {
i.Drag(s + y_diff);
} else if (i.GetInput().input().input() == kRightInput) {
i.Drag(s - x_diff);
} else if (i.GetInput().input().input() == kBottomInput) {
i.Drag(s - y_diff);
}
}
for (int j = 0; j < gizmo->GetDraggers().size(); j++) {
NodeInputDragger &i = gizmo->GetDraggers()[j];
double s = i.GetStartValue().toDouble();
if (i.GetInput().input().input() == kLeftInput) {
i.Drag(s + x_diff);
} else if (i.GetInput().input().input() == kTopInput) {
i.Drag(s + y_diff);
} else if (i.GetInput().input().input() == kRightInput) {
i.Drag(s - x_diff);
} else if (i.GetInput().input().input() == kBottomInput) {
i.Drag(s - y_diff);
}
}
}
void CropDistortNode::CreateCropSideInput(const QString &id)
{
AddInput(id, NodeValue::kFloat, 0.0);
SetInputProperty(id, QStringLiteral("min"), 0.0);
SetInputProperty(id, QStringLiteral("max"), 1.0);
SetInputProperty(id, QStringLiteral("view"), FloatSlider::kPercentage);
AddInput(id, NodeValue::kFloat, 0.0);
SetInputProperty(id, QStringLiteral("min"), 0.0);
SetInputProperty(id, QStringLiteral("max"), 1.0);
SetInputProperty(id, QStringLiteral("view"), FloatSlider::kPercentage);
}
}
+42 -39
View File
@@ -28,62 +28,65 @@
#include "node/inputdragger.h"
#include "node/node.h"
namespace olive {
class CropDistortNode : public Node
namespace olive
{
Q_OBJECT
class CropDistortNode : public Node {
Q_OBJECT
public:
CropDistortNode();
CropDistortNode();
NODE_DEFAULT_FUNCTIONS(CropDistortNode)
NODE_DEFAULT_FUNCTIONS(CropDistortNode)
virtual QString Name() const override
{
return tr("Crop");
}
virtual QString Name() const override
{
return tr("Crop");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.crop");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.crop");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryDistort};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryDistort };
}
virtual QString Description() const override
{
return tr("Crop the edges of an image.");
}
virtual QString Description() const override
{
return tr("Crop the edges of an image.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
static const QString kTextureInput;
static const QString kLeftInput;
static const QString kTopInput;
static const QString kRightInput;
static const QString kBottomInput;
static const QString kFeatherInput;
static const QString kTextureInput;
static const QString kLeftInput;
static const QString kTopInput;
static const QString kRightInput;
static const QString kBottomInput;
static const QString kFeatherInput;
protected slots:
virtual void GizmoDragMove(double delta_x, double delta_y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double delta_x, double delta_y,
const Qt::KeyboardModifiers &modifiers) override;
private:
void CreateCropSideInput(const QString& id);
// Gizmo variables
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
QVector2D temp_resolution_;
void CreateCropSideInput(const QString &id);
// Gizmo variables
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
QVector2D temp_resolution_;
};
}
+33 -27
View File
@@ -20,7 +20,8 @@
#include "flipdistortnode.h"
namespace olive {
namespace olive
{
const QString FlipDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString FlipDistortNode::kHorizontalInput = QStringLiteral("horiz_in");
@@ -30,63 +31,68 @@ const QString FlipDistortNode::kVerticalInput = QStringLiteral("vert_in");
FlipDistortNode::FlipDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kHorizontalInput, NodeValue::kBoolean, false);
AddInput(kHorizontalInput, NodeValue::kBoolean, false);
AddInput(kVerticalInput, NodeValue::kBoolean, false);
AddInput(kVerticalInput, NodeValue::kBoolean, false);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
QString FlipDistortNode::Name() const
{
return tr("Flip");
return tr("Flip");
}
QString FlipDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.flip");
return QStringLiteral("org.oliveeditor.Olive.flip");
}
QVector<Node::CategoryID> FlipDistortNode::Category() const
{
return {kCategoryDistort};
return { kCategoryDistort };
}
QString FlipDistortNode::Description() const
{
return tr("Flips an image horizontally or vertically");
return tr("Flips an image horizontally or vertically");
}
void FlipDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kHorizontalInput, tr("Horizontal"));
SetInputName(kVerticalInput, tr("Vertical"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kHorizontalInput, tr("Horizontal"));
SetInputName(kVerticalInput, tr("Vertical"));
}
ShaderCode FlipDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/flip.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/flip.frag"));
}
void FlipDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void FlipDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (value[kHorizontalInput].toBool() || value[kVerticalInput].toBool()) {
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (value[kHorizontalInput].toBool() ||
value[kVerticalInput].toBool()) {
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)),
this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
}
}
+18 -17
View File
@@ -23,30 +23,31 @@
#include "node/node.h"
namespace olive {
class FlipDistortNode : public Node
namespace olive
{
Q_OBJECT
class FlipDistortNode : public Node {
Q_OBJECT
public:
FlipDistortNode();
FlipDistortNode();
NODE_DEFAULT_FUNCTIONS(FlipDistortNode)
NODE_DEFAULT_FUNCTIONS(FlipDistortNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kHorizontalInput;
static const QString kVerticalInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kHorizontalInput;
static const QString kVerticalInput;
};
}
+75 -54
View File
@@ -22,7 +22,8 @@
#include "node/filter/blur/blur.h"
namespace olive {
namespace olive
{
#define super PolygonGenerator
@@ -31,81 +32,101 @@ const QString MaskDistortNode::kInvertInput = QStringLiteral("invert_in");
MaskDistortNode::MaskDistortNode()
{
// Mask should always be (1.0, 1.0, 1.0) for multiply to work correctly
SetInputFlag(kColorInput, kInputFlagHidden);
// Mask should always be (1.0, 1.0, 1.0) for multiply to work correctly
SetInputFlag(kColorInput, kInputFlagHidden);
AddInput(kInvertInput, NodeValue::kBoolean, false);
AddInput(kInvertInput, NodeValue::kBoolean, false);
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
AddInput(kFeatherInput, NodeValue::kFloat, 0.0);
SetInputProperty(kFeatherInput, QStringLiteral("min"), 0.0);
}
ShaderCode MaskDistortNode::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/multiply.frag")));
} else if (request.id == QStringLiteral("feather")) {
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/blur.frag")));
} else if (request.id == QStringLiteral("invert")) {
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/invertrgba.frag")));
} else {
return super::GetShaderCode(request);
}
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/multiply.frag")));
} else if (request.id == QStringLiteral("feather")) {
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/blur.frag")));
} else if (request.id == QStringLiteral("invert")) {
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/invertrgba.frag")));
} else {
return super::GetShaderCode(request);
}
}
void MaskDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBaseInput, tr("Texture"));
SetInputName(kInvertInput, tr("Invert"));
SetInputName(kFeatherInput, tr("Feather"));
SetInputName(kBaseInput, tr("Texture"));
SetInputName(kInvertInput, tr("Invert"));
SetInputName(kFeatherInput, tr("Feather"));
}
void MaskDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void MaskDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
TexturePtr texture = value[kBaseInput].toTexture();
TexturePtr texture = value[kBaseInput].toTexture();
VideoParams job_params = texture ? texture->params() : globals.vparams();
NodeValue job(NodeValue::kTexture, Texture::Job(job_params, GetGenerateJob(value, job_params)), this);
VideoParams job_params = texture ? texture->params() : globals.vparams();
NodeValue job(NodeValue::kTexture,
Texture::Job(job_params, GetGenerateJob(value, job_params)),
this);
if (value[kInvertInput].toBool()) {
ShaderJob invert;
invert.SetShaderID(QStringLiteral("invert"));
invert.Insert(QStringLiteral("tex_in"), job);
job.set_value(Texture::Job(job_params, invert));
}
if (value[kInvertInput].toBool()) {
ShaderJob invert;
invert.SetShaderID(QStringLiteral("invert"));
invert.Insert(QStringLiteral("tex_in"), job);
job.set_value(Texture::Job(job_params, invert));
}
if (texture) {
// Push as merge node
ShaderJob merge;
if (texture) {
// Push as merge node
ShaderJob merge;
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(QStringLiteral("tex_a"), value[kBaseInput]);
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(QStringLiteral("tex_a"), value[kBaseInput]);
if (value[kFeatherInput].toDouble() > 0.0) {
// Nest a blur shader in there too
ShaderJob feather;
if (value[kFeatherInput].toDouble() > 0.0) {
// Nest a blur shader in there too
ShaderJob feather;
feather.SetShaderID(QStringLiteral("feather"));
feather.Insert(BlurFilterNode::kTextureInput, job);
feather.Insert(BlurFilterNode::kMethodInput, NodeValue(NodeValue::kInt, int(BlurFilterNode::kGaussian), this));
feather.Insert(BlurFilterNode::kHorizInput, NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kVertInput, NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kRepeatEdgePixelsInput, NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kRadiusInput, NodeValue(NodeValue::kFloat, value[kFeatherInput].toDouble(), this));
feather.SetIterations(2, BlurFilterNode::kTextureInput);
feather.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, texture ? texture->virtual_resolution() : globals.square_resolution(), this));
feather.SetShaderID(QStringLiteral("feather"));
feather.Insert(BlurFilterNode::kTextureInput, job);
feather.Insert(BlurFilterNode::kMethodInput,
NodeValue(NodeValue::kInt,
int(BlurFilterNode::kGaussian), this));
feather.Insert(BlurFilterNode::kHorizInput,
NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kVertInput,
NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kRepeatEdgePixelsInput,
NodeValue(NodeValue::kBoolean, true, this));
feather.Insert(BlurFilterNode::kRadiusInput,
NodeValue(NodeValue::kFloat,
value[kFeatherInput].toDouble(), this));
feather.SetIterations(2, BlurFilterNode::kTextureInput);
feather.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2,
texture ? texture->virtual_resolution() :
globals.square_resolution(),
this));
merge.Insert(QStringLiteral("tex_b"), NodeValue(NodeValue::kTexture, Texture::Job(job_params, feather), this));
} else {
merge.Insert(QStringLiteral("tex_b"), job);
}
merge.Insert(QStringLiteral("tex_b"),
NodeValue(NodeValue::kTexture,
Texture::Job(job_params, feather), this));
} else {
merge.Insert(QStringLiteral("tex_b"), job);
}
table->Push(NodeValue::kTexture, Texture::Job(job_params, merge), this);
} else {
table->Push(job);
}
table->Push(NodeValue::kTexture, Texture::Job(job_params, merge), this);
} else {
table->Push(job);
}
}
}
+29 -28
View File
@@ -23,45 +23,46 @@
#include "node/generator/polygon/polygon.h"
namespace olive {
class MaskDistortNode : public PolygonGenerator
namespace olive
{
Q_OBJECT
class MaskDistortNode : public PolygonGenerator {
Q_OBJECT
public:
MaskDistortNode();
MaskDistortNode();
NODE_DEFAULT_FUNCTIONS(MaskDistortNode)
NODE_DEFAULT_FUNCTIONS(MaskDistortNode)
virtual QString Name() const override
{
return tr("Mask");
}
virtual QString Name() const override
{
return tr("Mask");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.mask");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.mask");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryDistort};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryDistort };
}
virtual QString Description() const override
{
return tr("Apply a polygonal mask.");
}
virtual QString Description() const override
{
return tr("Apply a polygonal mask.");
}
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kInvertInput;
static const QString kFeatherInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kInvertInput;
static const QString kFeatherInput;
};
}
+66 -54
View File
@@ -20,12 +20,16 @@
#include "rippledistortnode.h"
namespace olive {
namespace olive
{
const QString RippleDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString RippleDistortNode::kEvolutionInput = QStringLiteral("evolution_in");
const QString RippleDistortNode::kIntensityInput = QStringLiteral("intensity_in");
const QString RippleDistortNode::kFrequencyInput = QStringLiteral("frequency_in");
const QString RippleDistortNode::kEvolutionInput =
QStringLiteral("evolution_in");
const QString RippleDistortNode::kIntensityInput =
QStringLiteral("intensity_in");
const QString RippleDistortNode::kFrequencyInput =
QStringLiteral("frequency_in");
const QString RippleDistortNode::kPositionInput = QStringLiteral("position_in");
const QString RippleDistortNode::kStretchInput = QStringLiteral("stretch_in");
@@ -33,96 +37,104 @@ const QString RippleDistortNode::kStretchInput = QStringLiteral("stretch_in");
RippleDistortNode::RippleDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
AddInput(kIntensityInput, NodeValue::kFloat, 100);
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
AddInput(kIntensityInput, NodeValue::kFloat, 100);
AddInput(kFrequencyInput, NodeValue::kFloat, 1);
SetInputProperty(kFrequencyInput, QStringLiteral("base"), 0.01);
AddInput(kFrequencyInput, NodeValue::kFloat, 1);
SetInputProperty(kFrequencyInput, QStringLiteral("base"), 0.01);
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kStretchInput, NodeValue::kBoolean, false);
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kStretchInput, NodeValue::kBoolean, false);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
}
QString RippleDistortNode::Name() const
{
return tr("Ripple");
return tr("Ripple");
}
QString RippleDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.ripple");
return QStringLiteral("org.oliveeditor.Olive.ripple");
}
QVector<Node::CategoryID> RippleDistortNode::Category() const
{
return {kCategoryDistort};
return { kCategoryDistort };
}
QString RippleDistortNode::Description() const
{
return tr("Distorts an image with a ripple effect.");
return tr("Distorts an image with a ripple effect.");
}
void RippleDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kFrequencyInput, tr("Frequency"));
SetInputName(kIntensityInput, tr("Intensity"));
SetInputName(kEvolutionInput, tr("Evolution"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kStretchInput, tr("Stretch"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kFrequencyInput, tr("Frequency"));
SetInputName(kIntensityInput, tr("Intensity"));
SetInputName(kEvolutionInput, tr("Evolution"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kStretchInput, tr("Stretch"));
}
ShaderCode RippleDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/ripple.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/ripple.frag"));
}
void RippleDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void RippleDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kIntensityInput].toDouble())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kIntensityInput].toDouble())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
}
void RippleDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void RippleDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
if (TexturePtr tex = row[kTextureInput].toTexture()) {
QPointF half_res(tex->virtual_resolution().x()/2, tex->virtual_resolution().y()/2);
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
}
if (TexturePtr tex = row[kTextureInput].toTexture()) {
QPointF half_res(tex->virtual_resolution().x() / 2,
tex->virtual_resolution().y() / 2);
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
}
}
void RippleDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void RippleDistortNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
}
+26 -23
View File
@@ -24,41 +24,44 @@
#include "node/gizmo/point.h"
#include "node/node.h"
namespace olive {
class RippleDistortNode : public Node
namespace olive
{
Q_OBJECT
class RippleDistortNode : public Node {
Q_OBJECT
public:
RippleDistortNode();
RippleDistortNode();
NODE_DEFAULT_FUNCTIONS(RippleDistortNode)
NODE_DEFAULT_FUNCTIONS(RippleDistortNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
static const QString kTextureInput;
static const QString kEvolutionInput;
static const QString kIntensityInput;
static const QString kFrequencyInput;
static const QString kPositionInput;
static const QString kStretchInput;
static const QString kTextureInput;
static const QString kEvolutionInput;
static const QString kIntensityInput;
static const QString kFrequencyInput;
static const QString kPositionInput;
static const QString kStretchInput;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
PointGizmo *gizmo_;
PointGizmo *gizmo_;
};
}
+56 -46
View File
@@ -20,7 +20,8 @@
#include "swirldistortnode.h"
namespace olive {
namespace olive
{
const QString SwirlDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString SwirlDistortNode::kRadiusInput = QStringLiteral("radius_in");
@@ -31,92 +32,101 @@ const QString SwirlDistortNode::kPositionInput = QStringLiteral("pos_in");
SwirlDistortNode::SwirlDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kRadiusInput, NodeValue::kFloat, 200);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0);
AddInput(kRadiusInput, NodeValue::kFloat, 200);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0);
AddInput(kAngleInput, NodeValue::kFloat, 10);
SetInputProperty(kAngleInput, QStringLiteral("base"), 0.1);
AddInput(kAngleInput, NodeValue::kFloat, 10);
SetInputProperty(kAngleInput, QStringLiteral("base"), 0.1);
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
}
QString SwirlDistortNode::Name() const
{
return tr("Swirl");
return tr("Swirl");
}
QString SwirlDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.swirl");
return QStringLiteral("org.oliveeditor.Olive.swirl");
}
QVector<Node::CategoryID> SwirlDistortNode::Category() const
{
return {kCategoryDistort};
return { kCategoryDistort };
}
QString SwirlDistortNode::Description() const
{
return tr("Distorts an image along a sine wave.");
return tr("Distorts an image along a sine wave.");
}
void SwirlDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kAngleInput, tr("Angle"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kAngleInput, tr("Angle"));
SetInputName(kPositionInput, tr("Position"));
}
ShaderCode SwirlDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/swirl.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/swirl.frag"));
}
void SwirlDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void SwirlDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kAngleInput].toDouble()) && !qIsNull(value[kRadiusInput].toDouble())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kAngleInput].toDouble()) &&
!qIsNull(value[kRadiusInput].toDouble())) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
}
void SwirlDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void SwirlDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
QPointF half_res(globals.square_resolution().x()/2, globals.square_resolution().y()/2);
QPointF half_res(globals.square_resolution().x() / 2,
globals.square_resolution().y() / 2);
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
gizmo_->SetPoint(half_res + row[kPositionInput].toVec2().toPointF());
}
void SwirlDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void SwirlDistortNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
}
+24 -21
View File
@@ -24,39 +24,42 @@
#include "node/gizmo/point.h"
#include "node/node.h"
namespace olive {
class SwirlDistortNode : public Node
namespace olive
{
Q_OBJECT
class SwirlDistortNode : public Node {
Q_OBJECT
public:
SwirlDistortNode();
SwirlDistortNode();
NODE_DEFAULT_FUNCTIONS(SwirlDistortNode)
NODE_DEFAULT_FUNCTIONS(SwirlDistortNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
static const QString kTextureInput;
static const QString kRadiusInput;
static const QString kAngleInput;
static const QString kPositionInput;
static const QString kTextureInput;
static const QString kRadiusInput;
static const QString kAngleInput;
static const QString kPositionInput;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
PointGizmo *gizmo_;
PointGizmo *gizmo_;
};
}
+93 -81
View File
@@ -22,7 +22,8 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString TileDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString TileDistortNode::kScaleInput = QStringLiteral("scale_in");
@@ -35,130 +36,141 @@ const QString TileDistortNode::kMirrorYInput = QStringLiteral("mirrory_in");
TileDistortNode::TileDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kScaleInput, NodeValue::kFloat, 0.5);
SetInputProperty(kScaleInput, QStringLiteral("min"), 0);
SetInputProperty(kScaleInput, QStringLiteral("view"), FloatSlider::kPercentage);
AddInput(kScaleInput, NodeValue::kFloat, 0.5);
SetInputProperty(kScaleInput, QStringLiteral("min"), 0);
SetInputProperty(kScaleInput, QStringLiteral("view"),
FloatSlider::kPercentage);
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kAnchorInput, NodeValue::kCombo, kMiddleCenter);
AddInput(kAnchorInput, NodeValue::kCombo, kMiddleCenter);
AddInput(kMirrorXInput, NodeValue::kBoolean, false);
AddInput(kMirrorYInput, NodeValue::kBoolean, false);
AddInput(kMirrorXInput, NodeValue::kBoolean, false);
AddInput(kMirrorYInput, NodeValue::kBoolean, false);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
gizmo_ = AddDraggableGizmo<PointGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
gizmo_->SetShape(PointGizmo::kAnchorPoint);
}
QString TileDistortNode::Name() const
{
return tr("Tile");
return tr("Tile");
}
QString TileDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.tile");
return QStringLiteral("org.oliveeditor.Olive.tile");
}
QVector<Node::CategoryID> TileDistortNode::Category() const
{
return {kCategoryDistort};
return { kCategoryDistort };
}
QString TileDistortNode::Description() const
{
return tr("Infinitely tile an image horizontally and vertically.");
return tr("Infinitely tile an image horizontally and vertically.");
}
void TileDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kMirrorXInput, tr("Mirror Horizontally"));
SetInputName(kMirrorYInput, tr("Mirror Vertically"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kMirrorXInput, tr("Mirror Horizontally"));
SetInputName(kMirrorYInput, tr("Mirror Vertically"));
SetInputName(kAnchorInput, tr("Anchor"));
SetComboBoxStrings(kAnchorInput, {
tr("Top-Left"),
tr("Top-Center"),
tr("Top-Right"),
tr("Middle-Left"),
tr("Middle-Center"),
tr("Middle-Right"),
tr("Bottom-Left"),
tr("Bottom-Center"),
tr("Bottom-Right"),
});
SetInputName(kAnchorInput, tr("Anchor"));
SetComboBoxStrings(kAnchorInput, {
tr("Top-Left"),
tr("Top-Center"),
tr("Top-Right"),
tr("Middle-Left"),
tr("Middle-Center"),
tr("Middle-Right"),
tr("Bottom-Left"),
tr("Bottom-Center"),
tr("Bottom-Right"),
});
}
ShaderCode TileDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/tile.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/tile.frag"));
}
void TileDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TileDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qFuzzyCompare(value[kScaleInput].toDouble(), 1.0)) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qFuzzyCompare(value[kScaleInput].toDouble(), 1.0)) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
}
void TileDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void TileDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
if (TexturePtr tex = row[kTextureInput].toTexture()) {
QPointF res = tex->virtual_resolution().toPointF();
QPointF pos = row[kPositionInput].toVec2().toPointF();
qreal x = pos.x();
qreal y = pos.y();
if (TexturePtr tex = row[kTextureInput].toTexture()) {
QPointF res = tex->virtual_resolution().toPointF();
QPointF pos = row[kPositionInput].toVec2().toPointF();
qreal x = pos.x();
qreal y = pos.y();
Anchor a = static_cast<Anchor>(row[kAnchorInput].toInt());
if (a == kTopLeft || a == kTopCenter || a == kTopRight) {
// Do nothing
} else if (a == kMiddleLeft || a == kMiddleCenter || a == kMiddleRight) {
y += res.y()/2;
} else if (a == kBottomLeft || a == kBottomCenter || a == kBottomRight) {
y += res.y();
}
if (a == kTopLeft || a == kMiddleLeft || a == kBottomLeft) {
// Do nothing
} else if (a == kTopCenter || a == kMiddleCenter || a == kBottomCenter) {
x += res.x()/2;
} else if (a == kTopRight || a == kMiddleRight || a == kBottomRight) {
x += res.x();
}
Anchor a = static_cast<Anchor>(row[kAnchorInput].toInt());
if (a == kTopLeft || a == kTopCenter || a == kTopRight) {
// Do nothing
} else if (a == kMiddleLeft || a == kMiddleCenter ||
a == kMiddleRight) {
y += res.y() / 2;
} else if (a == kBottomLeft || a == kBottomCenter ||
a == kBottomRight) {
y += res.y();
}
if (a == kTopLeft || a == kMiddleLeft || a == kBottomLeft) {
// Do nothing
} else if (a == kTopCenter || a == kMiddleCenter ||
a == kBottomCenter) {
x += res.x() / 2;
} else if (a == kTopRight || a == kMiddleRight || a == kBottomRight) {
x += res.x();
}
gizmo_->SetPoint(QPointF(x, y));
}
gizmo_->SetPoint(QPointF(x, y));
}
}
void TileDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void TileDistortNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo_->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo_->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
}
+37 -34
View File
@@ -24,53 +24,56 @@
#include "node/gizmo/point.h"
#include "node/node.h"
namespace olive {
class TileDistortNode : public Node
namespace olive
{
Q_OBJECT
class TileDistortNode : public Node {
Q_OBJECT
public:
TileDistortNode();
TileDistortNode();
NODE_DEFAULT_FUNCTIONS(TileDistortNode)
NODE_DEFAULT_FUNCTIONS(TileDistortNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
static const QString kTextureInput;
static const QString kScaleInput;
static const QString kPositionInput;
static const QString kAnchorInput;
static const QString kMirrorXInput;
static const QString kMirrorYInput;
static const QString kTextureInput;
static const QString kScaleInput;
static const QString kPositionInput;
static const QString kAnchorInput;
static const QString kMirrorXInput;
static const QString kMirrorYInput;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
enum Anchor {
kTopLeft,
kTopCenter,
kTopRight,
kMiddleLeft,
kMiddleCenter,
kMiddleRight,
kBottomLeft,
kBottomCenter,
kBottomRight
};
PointGizmo *gizmo_;
enum Anchor {
kTopLeft,
kTopCenter,
kTopRight,
kMiddleLeft,
kMiddleCenter,
kMiddleRight,
kBottomLeft,
kBottomCenter,
kBottomRight
};
PointGizmo *gizmo_;
};
}
@@ -22,428 +22,491 @@
#include <QGuiApplication>
namespace olive {
namespace olive
{
const QString TransformDistortNode::kParentInput = QStringLiteral("parent_in");
const QString TransformDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString TransformDistortNode::kAutoscaleInput = QStringLiteral("autoscale_in");
const QString TransformDistortNode::kInterpolationInput = QStringLiteral("interpolation_in");
const QString TransformDistortNode::kAutoscaleInput =
QStringLiteral("autoscale_in");
const QString TransformDistortNode::kInterpolationInput =
QStringLiteral("interpolation_in");
#define super MatrixGenerator
TransformDistortNode::TransformDistortNode()
{
AddInput(kParentInput, NodeValue::kMatrix);
AddInput(kParentInput, NodeValue::kMatrix);
AddInput(kAutoscaleInput, NodeValue::kCombo, 0);
AddInput(kAutoscaleInput, NodeValue::kCombo, 0);
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
PrependInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
PrependInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
// Initiate gizmos
rotation_gizmo_ = AddDraggableGizmo<ScreenGizmo>();
rotation_gizmo_->AddInput(NodeInput(this, kRotationInput));
rotation_gizmo_->SetDragValueBehavior(ScreenGizmo::kAbsolute);
// Initiate gizmos
rotation_gizmo_ = AddDraggableGizmo<ScreenGizmo>();
rotation_gizmo_->AddInput(NodeInput(this, kRotationInput));
rotation_gizmo_->SetDragValueBehavior(ScreenGizmo::kAbsolute);
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>();
poly_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
poly_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>();
poly_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
poly_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
anchor_gizmo_ = AddDraggableGizmo<PointGizmo>();
anchor_gizmo_->SetShape(PointGizmo::kAnchorPoint);
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 0));
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 1));
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
anchor_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
anchor_gizmo_ = AddDraggableGizmo<PointGizmo>();
anchor_gizmo_->SetShape(PointGizmo::kAnchorPoint);
anchor_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 0));
anchor_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kAnchorInput), 1));
anchor_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0));
anchor_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1));
for (int i=0; i<kGizmoScaleCount; i++) {
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>();
point_gizmo_[i]->AddInput(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0));
point_gizmo_[i]->AddInput(NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1));
point_gizmo_[i]->SetDragValueBehavior(PointGizmo::kAbsolute);
}
for (int i = 0; i < kGizmoScaleCount; i++) {
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>();
point_gizmo_[i]->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 0));
point_gizmo_[i]->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kScaleInput), 1));
point_gizmo_[i]->SetDragValueBehavior(PointGizmo::kAbsolute);
}
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
void TransformDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kParentInput, tr("Parent"));
SetInputName(kAutoscaleInput, tr("Auto-Scale"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kInterpolationInput, tr("Interpolation"));
SetInputName(kParentInput, tr("Parent"));
SetInputName(kAutoscaleInput, tr("Auto-Scale"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kInterpolationInput, tr("Interpolation"));
SetComboBoxStrings(kAutoscaleInput, {tr("None"), tr("Fit"), tr("Fill"), tr("Stretch")});
SetComboBoxStrings(kInterpolationInput, {tr("Nearest Neighbor"), tr("Bilinear"), tr("Mipmapped Bilinear")});
SetComboBoxStrings(kAutoscaleInput,
{ tr("None"), tr("Fit"), tr("Fill"), tr("Stretch") });
SetComboBoxStrings(kInterpolationInput,
{ tr("Nearest Neighbor"), tr("Bilinear"),
tr("Mipmapped Bilinear") });
}
void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TransformDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// Generate matrix
QMatrix4x4 generated_matrix = GenerateMatrix(value, false, false, false, value[kParentInput].toMatrix());
// Generate matrix
QMatrix4x4 generated_matrix = GenerateMatrix(
value, false, false, false, value[kParentInput].toMatrix());
// Pop texture
NodeValue texture_meta = value[kTextureInput];
// Pop texture
NodeValue texture_meta = value[kTextureInput];
TexturePtr job_to_push = nullptr;
TexturePtr job_to_push = nullptr;
// If we have a texture, generate a matrix and make it happen
if (TexturePtr texture = texture_meta.toTexture()) {
// Adjust our matrix by the resolutions involved
QMatrix4x4 real_matrix = GenerateAutoScaledMatrix(generated_matrix, value, globals, texture->params());
// If we have a texture, generate a matrix and make it happen
if (TexturePtr texture = texture_meta.toTexture()) {
// Adjust our matrix by the resolutions involved
QMatrix4x4 real_matrix = GenerateAutoScaledMatrix(
generated_matrix, value, globals, texture->params());
if (!real_matrix.isIdentity()) {
// The matrix will transform things
ShaderJob job;
job.Insert(QStringLiteral("ove_maintex"), texture_meta);
job.Insert(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, real_matrix, this));
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].toInt()));
if (!real_matrix.isIdentity()) {
// The matrix will transform things
ShaderJob job;
job.Insert(QStringLiteral("ove_maintex"), texture_meta);
job.Insert(QStringLiteral("ove_mvpmat"),
NodeValue(NodeValue::kMatrix, real_matrix, this));
job.SetInterpolation(QStringLiteral("ove_maintex"),
static_cast<Texture::Interpolation>(
value[kInterpolationInput].toInt()));
// Use global resolution rather than texture resolution because this may result in a size change
job_to_push = Texture::Job(globals.vparams(), job);
}
}
// Use global resolution rather than texture resolution because this may result in a size change
job_to_push = Texture::Job(globals.vparams(), job);
}
}
table->Push(NodeValue::kMatrix, QVariant::fromValue(generated_matrix), this);
table->Push(NodeValue::kMatrix, QVariant::fromValue(generated_matrix),
this);
if (!job_to_push) {
// Re-push whatever value we received
table->Push(texture_meta);
} else {
table->Push(NodeValue::kTexture, job_to_push, this);
}
if (!job_to_push) {
// Re-push whatever value we received
table->Push(texture_meta);
} else {
table->Push(NodeValue::kTexture, job_to_push, this);
}
}
ShaderCode TransformDistortNode::GetShaderCode(const ShaderRequest &request) const
ShaderCode
TransformDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request);
Q_UNUSED(request);
// Returns default frag and vert shader
return ShaderCode();
// Returns default frag and vert shader
return ShaderCode();
}
void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, double y, const rational &time)
void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x,
double y, const rational &time)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo == anchor_gizmo_) {
if (gizmo == anchor_gizmo_) {
gizmo_inverted_transform_ =
GenerateMatrix(row, true, true, false, row[kParentInput].toMatrix())
.toTransform()
.inverted();
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, false, row[kParentInput].toMatrix()).toTransform().inverted();
} else if (IsAScaleGizmo(gizmo)) {
// Dragging scale handle
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
} else if (IsAScaleGizmo(gizmo)) {
gizmo_scale_uniform_ = row[kUniformScaleInput].toBool();
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() +
gizmo->GetGlobals().nonsquare_resolution() / 2)
.toPointF();
// Dragging scale handle
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
if (gizmo == point_gizmo_[kGizmoScaleTopLeft] ||
gizmo == point_gizmo_[kGizmoScaleTopRight] ||
gizmo == point_gizmo_[kGizmoScaleBottomLeft] ||
gizmo == point_gizmo_[kGizmoScaleBottomRight]) {
gizmo_scale_axes_ = kGizmoScaleBoth;
} else if (gizmo == point_gizmo_[kGizmoScaleCenterLeft] ||
gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
gizmo_scale_axes_ = kGizmoScaleXOnly;
} else {
gizmo_scale_axes_ = kGizmoScaleYOnly;
}
gizmo_scale_uniform_ = row[kUniformScaleInput].toBool();
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().nonsquare_resolution()/2).toPointF();
// Store texture size
VideoParams texture_params = tex->params();
QVector2D texture_sz(texture_params.square_pixel_width(),
texture_params.height());
gizmo_scale_anchor_ = row[kAnchorInput].toVec2() + texture_sz / 2;
if (gizmo == point_gizmo_[kGizmoScaleTopLeft] || gizmo == point_gizmo_[kGizmoScaleTopRight]
|| gizmo == point_gizmo_[kGizmoScaleBottomLeft] || gizmo == point_gizmo_[kGizmoScaleBottomRight]) {
gizmo_scale_axes_ = kGizmoScaleBoth;
} else if (gizmo == point_gizmo_[kGizmoScaleCenterLeft] || gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
gizmo_scale_axes_ = kGizmoScaleXOnly;
} else {
gizmo_scale_axes_ = kGizmoScaleYOnly;
}
if (gizmo == point_gizmo_[kGizmoScaleTopRight] ||
gizmo == point_gizmo_[kGizmoScaleBottomRight] ||
gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
// Right handles, flip X axis
gizmo_scale_anchor_.setX(texture_sz.x() - gizmo_scale_anchor_.x());
}
// Store texture size
VideoParams texture_params = tex->params();
QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height());
gizmo_scale_anchor_ = row[kAnchorInput].toVec2() + texture_sz/2;
if (gizmo == point_gizmo_[kGizmoScaleBottomLeft] ||
gizmo == point_gizmo_[kGizmoScaleBottomRight] ||
gizmo == point_gizmo_[kGizmoScaleBottomCenter]) {
// Bottom handles, flip Y axis
gizmo_scale_anchor_.setY(texture_sz.y() - gizmo_scale_anchor_.y());
}
if (gizmo == point_gizmo_[kGizmoScaleTopRight]
|| gizmo == point_gizmo_[kGizmoScaleBottomRight]
|| gizmo == point_gizmo_[kGizmoScaleCenterRight]) {
// Right handles, flip X axis
gizmo_scale_anchor_.setX(texture_sz.x() - gizmo_scale_anchor_.x());
}
// Store current matrix
gizmo_inverted_transform_ =
GenerateMatrix(row, true, true, true, row[kParentInput].toMatrix())
.toTransform()
.inverted();
if (gizmo == point_gizmo_[kGizmoScaleBottomLeft]
|| gizmo == point_gizmo_[kGizmoScaleBottomRight]
|| gizmo == point_gizmo_[kGizmoScaleBottomCenter]) {
// Bottom handles, flip Y axis
gizmo_scale_anchor_.setY(texture_sz.y() - gizmo_scale_anchor_.y());
}
// Store current matrix
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, true, row[kParentInput].toMatrix()).toTransform().inverted();
} else if (gizmo == rotation_gizmo_) {
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().nonsquare_resolution()/2).toPointF();
gizmo_start_angle_ = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
gizmo_last_angle_ = gizmo_start_angle_;
gizmo_last_alt_angle_ = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
gizmo_rotate_wrap_ = 0;
gizmo_rotate_last_dir_ = kDirectionNone;
}
} else if (gizmo == rotation_gizmo_) {
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() +
gizmo->GetGlobals().nonsquare_resolution() / 2)
.toPointF();
gizmo_start_angle_ =
std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
gizmo_last_angle_ = gizmo_start_angle_;
gizmo_last_alt_angle_ =
std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
gizmo_rotate_wrap_ = 0;
gizmo_rotate_last_dir_ = kDirectionNone;
}
}
void TransformDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void TransformDistortNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo == poly_gizmo_) {
if (gizmo == poly_gizmo_) {
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
} else if (gizmo == anchor_gizmo_) {
NodeInputDragger &x_anchor_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_anchor_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_pos_drag = gizmo->GetDraggers()[2];
NodeInputDragger &y_pos_drag = gizmo->GetDraggers()[3];
} else if (gizmo == anchor_gizmo_) {
QPointF inverted_movement(gizmo_inverted_transform_.map(QPointF(x, y)));
NodeInputDragger &x_anchor_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_anchor_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_pos_drag = gizmo->GetDraggers()[2];
NodeInputDragger &y_pos_drag = gizmo->GetDraggers()[3];
x_anchor_drag.Drag(x_anchor_drag.GetStartValue().toDouble() +
inverted_movement.x());
y_anchor_drag.Drag(y_anchor_drag.GetStartValue().toDouble() +
inverted_movement.y());
x_pos_drag.Drag(x_pos_drag.GetStartValue().toDouble() + x);
y_pos_drag.Drag(y_pos_drag.GetStartValue().toDouble() + y);
QPointF inverted_movement(gizmo_inverted_transform_.map(QPointF(x, y)));
} else if (gizmo == rotation_gizmo_) {
double raw_angle =
std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
double alt_angle =
std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
x_anchor_drag.Drag(x_anchor_drag.GetStartValue().toDouble() + inverted_movement.x());
y_anchor_drag.Drag(y_anchor_drag.GetStartValue().toDouble() + inverted_movement.y());
x_pos_drag.Drag(x_pos_drag.GetStartValue().toDouble() + x);
y_pos_drag.Drag(y_pos_drag.GetStartValue().toDouble() + y);
double current_angle = raw_angle;
} else if (gizmo == rotation_gizmo_) {
// Detect rotation wrap around
RotationDirection this_dir =
GetDirectionFromAngles(gizmo_last_angle_, raw_angle);
RotationDirection alt_dir =
GetDirectionFromAngles(gizmo_last_alt_angle_, alt_angle);
double raw_angle = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
double alt_angle = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
if (gizmo_rotate_last_dir_ != kDirectionNone &&
this_dir != gizmo_rotate_last_dir_) {
if (alt_dir == gizmo_rotate_last_alt_dir_) {
if ((raw_angle - gizmo_last_angle_) < 0) {
gizmo_rotate_wrap_++;
} else {
gizmo_rotate_wrap_--;
}
double current_angle = raw_angle;
this_dir = gizmo_rotate_last_dir_;
alt_dir = gizmo_rotate_last_alt_dir_;
}
}
// Detect rotation wrap around
RotationDirection this_dir = GetDirectionFromAngles(gizmo_last_angle_, raw_angle);
RotationDirection alt_dir = GetDirectionFromAngles(gizmo_last_alt_angle_, alt_angle);
gizmo_rotate_last_dir_ = this_dir;
gizmo_rotate_last_alt_dir_ = alt_dir;
gizmo_last_angle_ = raw_angle;
gizmo_last_alt_angle_ = alt_angle;
if (gizmo_rotate_last_dir_ != kDirectionNone && this_dir != gizmo_rotate_last_dir_) {
if (alt_dir == gizmo_rotate_last_alt_dir_) {
if ((raw_angle - gizmo_last_angle_) < 0) {
gizmo_rotate_wrap_++;
} else {
gizmo_rotate_wrap_--;
}
current_angle += M_PI * 2 * gizmo_rotate_wrap_;
this_dir = gizmo_rotate_last_dir_;
alt_dir = gizmo_rotate_last_alt_dir_;
}
}
// Convert radians to degrees
double rotation_difference =
(current_angle - gizmo_start_angle_) * 57.2958;
gizmo_rotate_last_dir_ = this_dir;
gizmo_rotate_last_alt_dir_ = alt_dir;
gizmo_last_angle_ = raw_angle;
gizmo_last_alt_angle_ = alt_angle;
NodeInputDragger &d = gizmo->GetDraggers()[0];
d.Drag(d.GetStartValue().toDouble() + rotation_difference);
current_angle += M_PI*2*gizmo_rotate_wrap_;
} else if (IsAScaleGizmo(gizmo)) {
QPointF mouse_relative =
gizmo_inverted_transform_.map(QPointF(x, y) - gizmo_anchor_pt_);
// Convert radians to degrees
double rotation_difference = (current_angle - gizmo_start_angle_) * 57.2958;
double x_scaled_movement =
qAbs(mouse_relative.x() / gizmo_scale_anchor_.x());
double y_scaled_movement =
qAbs(mouse_relative.y() / gizmo_scale_anchor_.y());
NodeInputDragger &d = gizmo->GetDraggers()[0];
d.Drag(d.GetStartValue().toDouble() + rotation_difference);
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
} else if (IsAScaleGizmo(gizmo)) {
switch (gizmo_scale_axes_) {
case kGizmoScaleXOnly:
x_drag.Drag(x_scaled_movement);
break;
case kGizmoScaleYOnly:
if (gizmo_scale_uniform_) {
x_drag.Drag(y_scaled_movement);
} else {
y_drag.Drag(y_scaled_movement);
}
break;
case kGizmoScaleBoth:
if (gizmo_scale_uniform_) {
double distance =
std::hypot(mouse_relative.x(), mouse_relative.y());
double texture_diag = std::hypot(gizmo_scale_anchor_.x(),
gizmo_scale_anchor_.y());
QPointF mouse_relative = gizmo_inverted_transform_.map(QPointF(x, y) - gizmo_anchor_pt_);
double x_scaled_movement = qAbs(mouse_relative.x() / gizmo_scale_anchor_.x());
double y_scaled_movement = qAbs(mouse_relative.y() / gizmo_scale_anchor_.y());
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
switch (gizmo_scale_axes_) {
case kGizmoScaleXOnly:
x_drag.Drag(x_scaled_movement);
break;
case kGizmoScaleYOnly:
if (gizmo_scale_uniform_) {
x_drag.Drag(y_scaled_movement);
} else {
y_drag.Drag(y_scaled_movement);
}
break;
case kGizmoScaleBoth:
if (gizmo_scale_uniform_) {
double distance = std::hypot(mouse_relative.x(), mouse_relative.y());
double texture_diag = std::hypot(gizmo_scale_anchor_.x(), gizmo_scale_anchor_.y());
x_drag.Drag(qAbs(distance / texture_diag));
} else {
x_drag.Drag(x_scaled_movement);
y_drag.Drag(y_scaled_movement);
}
break;
}
}
x_drag.Drag(qAbs(distance / texture_diag));
} else {
x_drag.Drag(x_scaled_movement);
y_drag.Drag(y_scaled_movement);
}
break;
}
}
}
QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(const QMatrix4x4 &mat, const QVector2D &sequence_res, const QVector2D &texture_res, const QVector2D &offset, AutoScaleType autoscale_type)
QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(
const QMatrix4x4 &mat, const QVector2D &sequence_res,
const QVector2D &texture_res, const QVector2D &offset,
AutoScaleType autoscale_type)
{
// First, create an identity matrix
QMatrix4x4 adjusted_matrix;
// First, create an identity matrix
QMatrix4x4 adjusted_matrix;
// Scale it to a square based on the sequence's resolution
adjusted_matrix.scale(2.0 / sequence_res.x(), 2.0 / sequence_res.y(), 1.0);
// Scale it to a square based on the sequence's resolution
adjusted_matrix.scale(2.0 / sequence_res.x(), 2.0 / sequence_res.y(), 1.0);
// Apply offset if applicable
adjusted_matrix.translate(offset.x(), offset.y());
// Apply offset if applicable
adjusted_matrix.translate(offset.x(), offset.y());
// Adjust by the matrix we generated earlier
adjusted_matrix *= mat;
// Adjust by the matrix we generated earlier
adjusted_matrix *= mat;
// Scale back out to texture size (adjusted by pixel aspect)
adjusted_matrix.scale(texture_res.x() * 0.5, texture_res.y() * 0.5, 1.0);
// Scale back out to texture size (adjusted by pixel aspect)
adjusted_matrix.scale(texture_res.x() * 0.5, texture_res.y() * 0.5, 1.0);
// If auto-scale is enabled, fit the texture to the sequence (without cropping)
if (autoscale_type != kAutoScaleNone) {
if (autoscale_type == kAutoScaleStretch) {
adjusted_matrix.scale(sequence_res.x() / texture_res.x(),
sequence_res.y() / texture_res.y(),
1.0);
} else {
double footage_real_ar = texture_res.x() / texture_res.y();
double sequence_real_ar = sequence_res.x() / sequence_res.y();
// If auto-scale is enabled, fit the texture to the sequence (without cropping)
if (autoscale_type != kAutoScaleNone) {
if (autoscale_type == kAutoScaleStretch) {
adjusted_matrix.scale(sequence_res.x() / texture_res.x(),
sequence_res.y() / texture_res.y(), 1.0);
} else {
double footage_real_ar = texture_res.x() / texture_res.y();
double sequence_real_ar = sequence_res.x() / sequence_res.y();
double scale_by_x = sequence_res.x() / texture_res.x();
double scale_by_y = sequence_res.y() / texture_res.y();
double autoscale_val;
double scale_by_x = sequence_res.x() / texture_res.x();
double scale_by_y = sequence_res.y() / texture_res.y();
double autoscale_val;
if ((autoscale_type == kAutoScaleFit) == (sequence_real_ar > footage_real_ar)) {
// Scale by height. Either the sequence is wider than the footage or we're using fill and
// cutting off the sides
autoscale_val = scale_by_y;
} else {
// Scale by width. Either the footage is wider than the sequence or we're using fill and
// cutting off the top and bottom
autoscale_val = scale_by_x;
}
if ((autoscale_type == kAutoScaleFit) ==
(sequence_real_ar > footage_real_ar)) {
// Scale by height. Either the sequence is wider than the footage or we're using fill and
// cutting off the sides
autoscale_val = scale_by_y;
} else {
// Scale by width. Either the footage is wider than the sequence or we're using fill and
// cutting off the top and bottom
autoscale_val = scale_by_x;
}
adjusted_matrix.scale(autoscale_val, autoscale_val, 1.0);
}
}
adjusted_matrix.scale(autoscale_val, autoscale_val, 1.0);
}
}
return adjusted_matrix;
return adjusted_matrix;
}
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
// Get the sequence resolution
const QVector2D &sequence_res = globals.nonsquare_resolution();
QVector2D sequence_half_res = sequence_res * 0.5;
QPointF sequence_half_res_pt = sequence_half_res.toPointF();
// Get the sequence resolution
const QVector2D &sequence_res = globals.nonsquare_resolution();
QVector2D sequence_half_res = sequence_res * 0.5;
QPointF sequence_half_res_pt = sequence_half_res.toPointF();
// GizmoTraverser just returns the sizes of the textures and no other data
VideoParams tex_params = tex->params();
QVector2D tex_sz(tex_params.square_pixel_width(), tex_params.height());
QVector2D tex_offset = tex_params.offset();
// GizmoTraverser just returns the sizes of the textures and no other data
VideoParams tex_params = tex->params();
QVector2D tex_sz(tex_params.square_pixel_width(), tex_params.height());
QVector2D tex_offset = tex_params.offset();
// Retrieve autoscale value
AutoScaleType autoscale = static_cast<AutoScaleType>(row[kAutoscaleInput].toInt());
// Retrieve autoscale value
AutoScaleType autoscale =
static_cast<AutoScaleType>(row[kAutoscaleInput].toInt());
// Fold values into a matrix for the rectangle
QMatrix4x4 rectangle_matrix;
rectangle_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
rectangle_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix()),
sequence_res,
tex_sz,
tex_offset,
autoscale);
// Fold values into a matrix for the rectangle
QMatrix4x4 rectangle_matrix;
rectangle_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
rectangle_matrix *= AdjustMatrixByResolutions(
GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix()),
sequence_res, tex_sz, tex_offset, autoscale);
// Create rect and transform it
const QVector<QPointF> points = {QPointF(-1, -1),
QPointF(1, -1),
QPointF(1, 1),
QPointF(-1, 1),
QPointF(-1, -1)};
QTransform rectangle_transform = rectangle_matrix.toTransform();
QPolygonF r = rectangle_transform.map(points);
r.translate(sequence_half_res_pt);
poly_gizmo_->SetPolygon(r);
// Create rect and transform it
const QVector<QPointF> points = { QPointF(-1, -1), QPointF(1, -1),
QPointF(1, 1), QPointF(-1, 1),
QPointF(-1, -1) };
QTransform rectangle_transform = rectangle_matrix.toTransform();
QPolygonF r = rectangle_transform.map(points);
r.translate(sequence_half_res_pt);
poly_gizmo_->SetPolygon(r);
// Draw anchor point
QMatrix4x4 anchor_matrix;
anchor_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
anchor_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, true, false, false, row[kParentInput].toMatrix()),
sequence_res,
tex_sz,
tex_offset,
autoscale);
anchor_gizmo_->SetPoint(anchor_matrix.toTransform().map(QPointF(0, 0)) + sequence_half_res_pt);
// Draw anchor point
QMatrix4x4 anchor_matrix;
anchor_matrix.scale(sequence_half_res.x(), sequence_half_res.y());
anchor_matrix *= AdjustMatrixByResolutions(
GenerateMatrix(row, true, false, false, row[kParentInput].toMatrix()),
sequence_res, tex_sz, tex_offset, autoscale);
anchor_gizmo_->SetPoint(anchor_matrix.toTransform().map(QPointF(0, 0)) +
sequence_half_res_pt);
// Draw scale handles
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(CreateScalePoint(-1, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(CreateScalePoint( 0, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(CreateScalePoint( 1, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(CreateScalePoint(-1, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(CreateScalePoint( 0, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(CreateScalePoint( 1, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(CreateScalePoint(-1, 0, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(CreateScalePoint( 1, 0, sequence_half_res_pt, rectangle_matrix));
// Draw scale handles
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(
CreateScalePoint(-1, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(
CreateScalePoint(0, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(
CreateScalePoint(1, -1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(
CreateScalePoint(-1, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
CreateScalePoint(0, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
CreateScalePoint(1, 1, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
CreateScalePoint(-1, 0, sequence_half_res_pt, rectangle_matrix));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
CreateScalePoint(1, 0, sequence_half_res_pt, rectangle_matrix));
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
SetInputProperty(kPositionInput, QStringLiteral("offset"), sequence_half_res + tex_offset);
SetInputProperty(kAnchorInput, QStringLiteral("offset"), tex_sz * 0.5);
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
SetInputProperty(kPositionInput, QStringLiteral("offset"),
sequence_half_res + tex_offset);
SetInputProperty(kAnchorInput, QStringLiteral("offset"), tex_sz * 0.5);
}
QTransform TransformDistortNode::GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const
QTransform
TransformDistortNode::GizmoTransformation(const NodeValueRow &row,
const NodeGlobals &globals) const
{
if (TexturePtr texture = row[kTextureInput].toTexture()) {
//auto m = GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix());
auto m = GenerateMatrix(row, false, false, false, QMatrix4x4());
return GenerateAutoScaledMatrix(m, row, globals, texture->params()).toTransform();
}
return super::GizmoTransformation(row, globals);
if (TexturePtr texture = row[kTextureInput].toTexture()) {
//auto m = GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix());
auto m = GenerateMatrix(row, false, false, false, QMatrix4x4());
return GenerateAutoScaledMatrix(m, row, globals, texture->params())
.toTransform();
}
return super::GizmoTransformation(row, globals);
}
QPointF TransformDistortNode::CreateScalePoint(double x, double y, const QPointF &half_res, const QMatrix4x4 &mat)
QPointF TransformDistortNode::CreateScalePoint(double x, double y,
const QPointF &half_res,
const QMatrix4x4 &mat)
{
return mat.map(QPointF(x, y)) + half_res;
return mat.map(QPointF(x, y)) + half_res;
}
QMatrix4x4 TransformDistortNode::GenerateAutoScaledMatrix(const QMatrix4x4& generated_matrix, const NodeValueRow& value, const NodeGlobals &globals, const VideoParams& texture_params) const
QMatrix4x4 TransformDistortNode::GenerateAutoScaledMatrix(
const QMatrix4x4 &generated_matrix, const NodeValueRow &value,
const NodeGlobals &globals, const VideoParams &texture_params) const
{
const QVector2D &sequence_res = globals.nonsquare_resolution();
QVector2D texture_res(texture_params.square_pixel_width(), texture_params.height());
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].toInt());
const QVector2D &sequence_res = globals.nonsquare_resolution();
QVector2D texture_res(texture_params.square_pixel_width(),
texture_params.height());
AutoScaleType autoscale =
static_cast<AutoScaleType>(value[kAutoscaleInput].toInt());
return AdjustMatrixByResolutions(generated_matrix,
sequence_res,
texture_res,
texture_params.offset(),
autoscale);
return AdjustMatrixByResolutions(generated_matrix, sequence_res,
texture_res, texture_params.offset(),
autoscale);
}
bool TransformDistortNode::IsAScaleGizmo(NodeGizmo *g) const
{
for (int i=0; i<kGizmoScaleCount; i++) {
if (point_gizmo_[i] == g) {
return true;
}
}
for (int i = 0; i < kGizmoScaleCount; i++) {
if (point_gizmo_[i] == g) {
return true;
}
}
return false;
return false;
}
TransformDistortNode::RotationDirection TransformDistortNode::GetDirectionFromAngles(double last, double current)
TransformDistortNode::RotationDirection
TransformDistortNode::GetDirectionFromAngles(double last, double current)
{
return (current > last) ? kDirectionPositive : kDirectionNegative;
return (current > last) ? kDirectionPositive : kDirectionNegative;
}
}
@@ -26,115 +26,122 @@
#include "node/gizmo/polygon.h"
#include "node/gizmo/screen.h"
namespace olive {
class TransformDistortNode : public MatrixGenerator
namespace olive
{
Q_OBJECT
class TransformDistortNode : public MatrixGenerator {
Q_OBJECT
public:
TransformDistortNode();
TransformDistortNode();
NODE_DEFAULT_FUNCTIONS(TransformDistortNode)
NODE_DEFAULT_FUNCTIONS(TransformDistortNode)
virtual QString Name() const override
{
return tr("Transform");
}
virtual QString Name() const override
{
return tr("Transform");
}
virtual QString ShortName() const override
{
// Override MatrixGenerator's short name "Ortho"
return Name();
}
virtual QString ShortName() const override
{
// Override MatrixGenerator's short name "Ortho"
return Name();
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.transform");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.transform");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryDistort};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryDistort };
}
virtual QString Description() const override
{
return tr("Transform an image in 2D space. Equivalent to multiplying by an orthographic matrix.");
}
virtual QString Description() const override
{
return tr(
"Transform an image in 2D space. Equivalent to multiplying by an orthographic matrix.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
enum AutoScaleType {
kAutoScaleNone,
kAutoScaleFit,
kAutoScaleFill,
kAutoScaleStretch
};
enum AutoScaleType {
kAutoScaleNone,
kAutoScaleFit,
kAutoScaleFill,
kAutoScaleStretch
};
static QMatrix4x4 AdjustMatrixByResolutions(const QMatrix4x4& mat,
const QVector2D& sequence_res,
const QVector2D& texture_res,
const QVector2D& offset,
AutoScaleType autoscale_type = kAutoScaleNone);
static QMatrix4x4 AdjustMatrixByResolutions(
const QMatrix4x4 &mat, const QVector2D &sequence_res,
const QVector2D &texture_res, const QVector2D &offset,
AutoScaleType autoscale_type = kAutoScaleNone);
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual QTransform GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
virtual QTransform
GizmoTransformation(const NodeValueRow &row,
const NodeGlobals &globals) const override;
static const QString kParentInput;
static const QString kTextureInput;
static const QString kAutoscaleInput;
static const QString kInterpolationInput;
static const QString kParentInput;
static const QString kTextureInput;
static const QString kAutoscaleInput;
static const QString kInterpolationInput;
protected slots:
virtual void GizmoDragStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time) override;
virtual void GizmoDragStart(const olive::NodeValueRow &row, double x,
double y, const olive::rational &time) override;
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
static QPointF CreateScalePoint(double x, double y, const QPointF& half_res, const QMatrix4x4& mat);
static QPointF CreateScalePoint(double x, double y, const QPointF &half_res,
const QMatrix4x4 &mat);
QMatrix4x4 GenerateAutoScaledMatrix(const QMatrix4x4 &generated_matrix, const NodeValueRow &db, const NodeGlobals &globals, const VideoParams &texture_params) const;
QMatrix4x4
GenerateAutoScaledMatrix(const QMatrix4x4 &generated_matrix,
const NodeValueRow &db, const NodeGlobals &globals,
const VideoParams &texture_params) const;
bool IsAScaleGizmo(NodeGizmo *g) const;
bool IsAScaleGizmo(NodeGizmo *g) const;
// Gizmo variables
double gizmo_start_angle_;
QTransform gizmo_inverted_transform_;
QPointF gizmo_anchor_pt_;
bool gizmo_scale_uniform_;
double gizmo_last_angle_;
double gizmo_last_alt_angle_;
int gizmo_rotate_wrap_;
// Gizmo variables
double gizmo_start_angle_;
QTransform gizmo_inverted_transform_;
QPointF gizmo_anchor_pt_;
bool gizmo_scale_uniform_;
double gizmo_last_angle_;
double gizmo_last_alt_angle_;
int gizmo_rotate_wrap_;
enum RotationDirection {
kDirectionNone,
kDirectionPositive, // Clockwise
kDirectionNegative // Counter-clockwise
};
enum RotationDirection {
kDirectionNone,
kDirectionPositive, // Clockwise
kDirectionNegative // Counter-clockwise
};
static RotationDirection GetDirectionFromAngles(double last, double current);
RotationDirection gizmo_rotate_last_dir_;
RotationDirection gizmo_rotate_last_alt_dir_;
static RotationDirection GetDirectionFromAngles(double last,
double current);
RotationDirection gizmo_rotate_last_dir_;
RotationDirection gizmo_rotate_last_alt_dir_;
enum GizmoScaleType {
kGizmoScaleXOnly,
kGizmoScaleYOnly,
kGizmoScaleBoth
};
enum GizmoScaleType { kGizmoScaleXOnly, kGizmoScaleYOnly, kGizmoScaleBoth };
GizmoScaleType gizmo_scale_axes_;
QVector2D gizmo_scale_anchor_;
// Gizmo on screen object storage
PointGizmo *point_gizmo_[kGizmoScaleCount];
PointGizmo *anchor_gizmo_;
PolygonGizmo *poly_gizmo_;
ScreenGizmo *rotation_gizmo_;
GizmoScaleType gizmo_scale_axes_;
QVector2D gizmo_scale_anchor_;
// Gizmo on screen object storage
PointGizmo *point_gizmo_[kGizmoScaleCount];
PointGizmo *anchor_gizmo_;
PolygonGizmo *poly_gizmo_;
ScreenGizmo *rotation_gizmo_;
};
}
+38 -33
View File
@@ -20,7 +20,8 @@
#include "wavedistortnode.h"
namespace olive {
namespace olive
{
const QString WaveDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString WaveDistortNode::kFrequencyInput = QStringLiteral("frequency_in");
@@ -32,69 +33,73 @@ const QString WaveDistortNode::kVerticalInput = QStringLiteral("vertical_in");
WaveDistortNode::WaveDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kFrequencyInput, NodeValue::kFloat, 10);
AddInput(kIntensityInput, NodeValue::kFloat, 10);
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
AddInput(kFrequencyInput, NodeValue::kFloat, 10);
AddInput(kIntensityInput, NodeValue::kFloat, 10);
AddInput(kEvolutionInput, NodeValue::kFloat, 0);
AddInput(kVerticalInput, NodeValue::kCombo, false);
AddInput(kVerticalInput, NodeValue::kCombo, false);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
QString WaveDistortNode::Name() const
{
return tr("Wave");
return tr("Wave");
}
QString WaveDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.wave");
return QStringLiteral("org.oliveeditor.Olive.wave");
}
QVector<Node::CategoryID> WaveDistortNode::Category() const
{
return {kCategoryDistort};
return { kCategoryDistort };
}
QString WaveDistortNode::Description() const
{
return tr("Distorts an image along a sine wave.");
return tr("Distorts an image along a sine wave.");
}
void WaveDistortNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kFrequencyInput, tr("Frequency"));
SetInputName(kIntensityInput, tr("Intensity"));
SetInputName(kEvolutionInput, tr("Evolution"));
SetInputName(kVerticalInput, tr("Direction"));
SetComboBoxStrings(kVerticalInput, {tr("Horizontal"), tr("Vertical")});
SetInputName(kTextureInput, tr("Input"));
SetInputName(kFrequencyInput, tr("Frequency"));
SetInputName(kIntensityInput, tr("Intensity"));
SetInputName(kEvolutionInput, tr("Evolution"));
SetInputName(kVerticalInput, tr("Direction"));
SetComboBoxStrings(kVerticalInput, { tr("Horizontal"), tr("Vertical") });
}
ShaderCode WaveDistortNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/wave.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/wave.frag"));
}
void WaveDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void WaveDistortNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr texture = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kIntensityInput].toDouble())) {
table->Push(NodeValue::kTexture, Texture::Job(texture->params(), ShaderJob(value)), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr texture = value[kTextureInput].toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (!qIsNull(value[kIntensityInput].toDouble())) {
table->Push(NodeValue::kTexture,
Texture::Job(texture->params(), ShaderJob(value)),
this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(value[kTextureInput]);
}
}
}
}
+20 -19
View File
@@ -23,32 +23,33 @@
#include "node/node.h"
namespace olive {
class WaveDistortNode : public Node
namespace olive
{
Q_OBJECT
class WaveDistortNode : public Node {
Q_OBJECT
public:
WaveDistortNode();
WaveDistortNode();
NODE_DEFAULT_FUNCTIONS(WaveDistortNode)
NODE_DEFAULT_FUNCTIONS(WaveDistortNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kFrequencyInput;
static const QString kIntensityInput;
static const QString kEvolutionInput;
static const QString kVerticalInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kFrequencyInput;
static const QString kIntensityInput;
static const QString kEvolutionInput;
static const QString kVerticalInput;
};
}
+40 -33
View File
@@ -3,7 +3,8 @@
#include "node/math/math/math.h"
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
#define super Node
@@ -12,55 +13,61 @@ const QString OpacityEffect::kValueInput = QStringLiteral("opacity_in");
OpacityEffect::OpacityEffect()
{
MathNode *math = new MathNode();
MathNode *math = new MathNode();
math->SetOperation(MathNode::kOpMultiply);
math->SetOperation(MathNode::kOpMultiply);
SetNodePositionInContext(math, QPointF(0, 0));
SetNodePositionInContext(math, QPointF(0, 0));
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kValueInput, NodeValue::kFloat, 1.0);
SetInputProperty(kValueInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kValueInput, QStringLiteral("min"), 0.0);
SetInputProperty(kValueInput, QStringLiteral("max"), 1.0);
AddInput(kValueInput, NodeValue::kFloat, 1.0);
SetInputProperty(kValueInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kValueInput, QStringLiteral("min"), 0.0);
SetInputProperty(kValueInput, QStringLiteral("max"), 1.0);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
void OpacityEffect::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kValueInput, tr("Opacity"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kValueInput, tr("Opacity"));
}
ShaderCode OpacityEffect::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("rgbmult")) {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/opacity_rgb.frag"));
} else {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/opacity.frag"));
}
if (request.id == QStringLiteral("rgbmult")) {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/opacity_rgb.frag"));
} else {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/opacity.frag"));
}
}
void OpacityEffect::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void OpacityEffect::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (TexturePtr opacity_tex = value[kValueInput].toTexture()) {
ShaderJob job(value);
job.SetShaderID(QStringLiteral("rgbmult"));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else if (!qFuzzyCompare(value[kValueInput].toDouble(), 1.0)) {
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)), this);
} else {
// 1.0 float is a no-op, so just push the texture
table->Push(value[kTextureInput]);
}
}
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (TexturePtr opacity_tex = value[kValueInput].toTexture()) {
ShaderJob job(value);
job.SetShaderID(QStringLiteral("rgbmult"));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else if (!qFuzzyCompare(value[kValueInput].toDouble(), 1.0)) {
table->Push(NodeValue::kTexture, tex->toJob(ShaderJob(value)),
this);
} else {
// 1.0 float is a no-op, so just push the texture
table->Push(value[kTextureInput]);
}
}
}
}
+29 -27
View File
@@ -3,43 +3,45 @@
#include "node/group/group.h"
namespace olive {
class OpacityEffect : public Node
namespace olive
{
class OpacityEffect : public Node {
public:
OpacityEffect();
OpacityEffect();
NODE_DEFAULT_FUNCTIONS(OpacityEffect)
NODE_DEFAULT_FUNCTIONS(OpacityEffect)
virtual QString Name() const override
{
return tr("Opacity");
}
virtual QString Name() const override
{
return tr("Opacity");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.opacity");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.opacity");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryFilter};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryFilter };
}
virtual QString Description() const override
{
return tr("Alter a video's opacity.\n\nThis is equivalent to multiplying a video by a number between 0.0 and 1.0.");
}
virtual QString Description() const override
{
return tr(
"Alter a video's opacity.\n\nThis is equivalent to multiplying a video by a number between 0.0 and 1.0.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kValueInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kValueInput;
};
}
+193 -190
View File
@@ -71,250 +71,253 @@
#include "time/timeoffset/timeoffsetnode.h"
#include "time/timeremap/timeremap.h"
namespace olive {
namespace olive
{
QList<Node*> NodeFactory::library_;
QList<Node *> NodeFactory::library_;
void NodeFactory::Initialize()
{
Destroy();
Destroy();
// Add internal types
for (int i=0;i<kInternalNodeCount;i++) {
Node* created_node = CreateFromFactoryIndex(static_cast<InternalID>(i));
// Add internal types
for (int i = 0; i < kInternalNodeCount; i++) {
Node *created_node = CreateFromFactoryIndex(static_cast<InternalID>(i));
library_.append(created_node);
}
library_.append(created_node);
}
}
void NodeFactory::Destroy()
{
qDeleteAll(library_);
library_.clear();
qDeleteAll(library_);
library_.clear();
}
Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item, Node::CategoryID restrict_to, uint64_t restrict_flags)
Menu *NodeFactory::CreateMenu(QWidget *parent, bool create_none_item,
Node::CategoryID restrict_to,
uint64_t restrict_flags)
{
Menu* menu = new Menu(parent);
menu->setToolTipsVisible(true);
Menu *menu = new Menu(parent);
menu->setToolTipsVisible(true);
for (int i=0;i<library_.size();i++) {
Node* n = library_.at(i);
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;
}
if (restrict_to != Node::kCategoryUnknown &&
!n->Category().contains(restrict_to)) {
// Skip this node
continue;
}
if (restrict_flags && !(n->GetFlags() & restrict_flags)) {
continue;
}
if (restrict_flags && !(n->GetFlags() & restrict_flags)) {
continue;
}
if (n->GetFlags() & Node::kDontShowInCreateMenu) {
continue;
}
if (n->GetFlags() & Node::kDontShowInCreateMenu) {
continue;
}
// Make sure nodes are up-to-date with the current translation
n->Retranslate();
// Make sure nodes are up-to-date with the current translation
n->Retranslate();
Menu* destination = nullptr;
Menu *destination = nullptr;
QString category_name = Node::GetCategoryName(n->Category().isEmpty()
? Node::kCategoryUnknown
: n->Category().first());
QString category_name = Node::GetCategoryName(
n->Category().isEmpty() ? Node::kCategoryUnknown :
n->Category().first());
// See if a menu with this category name already exists
QList<QAction*> menu_actions = menu->actions();
foreach (QAction* action, menu_actions) {
if (action->menu() && action->menu()->title() == category_name) {
destination = static_cast<Menu*>(action->menu());
break;
}
}
// See if a menu with this category name already exists
QList<QAction *> menu_actions = menu->actions();
foreach (QAction *action, menu_actions) {
if (action->menu() && action->menu()->title() == category_name) {
destination = static_cast<Menu *>(action->menu());
break;
}
}
// Create menu here if it doesn't exist
if (!destination) {
destination = new Menu(category_name, menu);
menu->InsertAlphabetically(destination);
}
// Create menu here if it doesn't exist
if (!destination) {
destination = new Menu(category_name, menu);
menu->InsertAlphabetically(destination);
}
// Add entry to menu
QAction* a = destination->InsertAlphabetically(n->Name());
a->setData(i);
a->setToolTip(n->Description());
}
// Add entry to menu
QAction *a = destination->InsertAlphabetically(n->Name());
a->setData(i);
a->setToolTip(n->Description());
}
if (create_none_item) {
if (create_none_item) {
QAction *none_item = new QAction(
QCoreApplication::translate("NodeFactory", "None"), menu);
QAction* none_item = new QAction(QCoreApplication::translate("NodeFactory", "None"),
menu);
none_item->setData(-1);
none_item->setData(-1);
if (menu->actions().isEmpty()) {
menu->addAction(none_item);
} else {
QAction *separator = menu->insertSeparator(menu->actions().first());
menu->insertAction(separator, none_item);
}
}
if (menu->actions().isEmpty()) {
menu->addAction(none_item);
} else {
QAction* separator = menu->insertSeparator(menu->actions().first());
menu->insertAction(separator, none_item);
}
}
return menu;
return menu;
}
Node* NodeFactory::CreateFromMenuAction(QAction *action)
Node *NodeFactory::CreateFromMenuAction(QAction *action)
{
int index = action->data().toInt();
int index = action->data().toInt();
if (index == -1) {
return nullptr;
}
if (index == -1) {
return nullptr;
}
return library_.at(index)->copy();
return library_.at(index)->copy();
}
QString NodeFactory::GetIDFromMenuAction(QAction *action)
{
int index = action->data().toInt();
int index = action->data().toInt();
if (index == -1) {
return QString();
}
if (index == -1) {
return QString();
}
return library_.at(action->data().toInt())->id();
return library_.at(action->data().toInt())->id();
}
QString NodeFactory::GetNameFromID(const QString &id)
{
if (!id.isEmpty()) {
foreach (Node* n, library_) {
if (n->id() == id) {
return n->Name();
}
}
}
if (!id.isEmpty()) {
foreach (Node *n, library_) {
if (n->id() == id) {
return n->Name();
}
}
}
return QString();
return QString();
}
Node *NodeFactory::CreateFromID(const QString &id)
{
foreach (Node* n, library_) {
if (n->id() == id) {
return n->copy();
}
}
foreach (Node *n, library_) {
if (n->id() == id) {
return n->copy();
}
}
return nullptr;
return nullptr;
}
Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
{
switch (id) {
case kClipBlock:
return new ClipBlock();
case kGapBlock:
return new GapBlock();
case kPolygonGenerator:
return new PolygonGenerator();
case kMatrixGenerator:
return new MatrixGenerator();
case kTransformDistort:
return new TransformDistortNode();
case kTrackOutput:
return new Track();
case kViewerOutput:
return new ViewerOutput();
case kAudioVolume:
return new VolumeNode();
case kAudioPanning:
return new PanNode();
case kMath:
return new MathNode();
case kTrigonometry:
return new TrigonometryNode();
case kTime:
return new TimeInput();
case kBlurFilter:
return new BlurFilterNode();
case kSolidGenerator:
return new SolidGenerator();
case kMerge:
return new MergeNode();
case kStrokeFilter:
return new StrokeFilterNode();
case kTextGeneratorV1:
return new TextGeneratorV1();
case kTextGeneratorV2:
return new TextGeneratorV2();
case kTextGeneratorV3:
return new TextGeneratorV3();
case kCrossDissolveTransition:
return new CrossDissolveTransition();
case kDipToColorTransition:
return new DipToColorTransition();
case kMosaicFilter:
return new MosaicFilterNode();
case kCropDistort:
return new CropDistortNode();
case kProjectFootage:
return new Footage();
case kProjectFolder:
return new Folder();
case kProjectSequence:
return new Sequence();
case kValueNode:
return new ValueNode();
case kTimeRemapNode:
return new TimeRemapNode();
case kSubtitleBlock:
return new SubtitleBlock();
case kShapeGenerator:
return new ShapeNode();
case kColorDifferenceKeyKeying:
return new ColorDifferenceKeyNode();
case kDespillKeying:
return new DespillNode();
case kGroupNode:
return new NodeGroup();
case kOpacityEffect:
return new OpacityEffect();
case kFlipDistort:
return new FlipDistortNode();
case kNoiseGenerator:
return new NoiseGeneratorNode();
case kTimeOffsetNode:
return new TimeOffsetNode();
case kCornerPinDistort:
return new CornerPinDistortNode();
case kDisplayTransform:
return new DisplayTransformNode();
case kOCIOGradingTransformLinear:
return new OCIOGradingTransformLinearNode();
case kChromaKey:
return new ChromaKeyNode();
case kMaskDistort:
return new MaskDistortNode();
case kDropShadowFilter:
return new DropShadowFilter();
case kTimeFormat:
return new TimeFormatNode();
case kWaveDistort:
return new WaveDistortNode();
case kTileDistort:
return new TileDistortNode();
case kSwirlDistort:
return new SwirlDistortNode();
case kRippleDistort:
return new RippleDistortNode();
case kMulticamNode:
return new MultiCamNode();
switch (id) {
case kClipBlock:
return new ClipBlock();
case kGapBlock:
return new GapBlock();
case kPolygonGenerator:
return new PolygonGenerator();
case kMatrixGenerator:
return new MatrixGenerator();
case kTransformDistort:
return new TransformDistortNode();
case kTrackOutput:
return new Track();
case kViewerOutput:
return new ViewerOutput();
case kAudioVolume:
return new VolumeNode();
case kAudioPanning:
return new PanNode();
case kMath:
return new MathNode();
case kTrigonometry:
return new TrigonometryNode();
case kTime:
return new TimeInput();
case kBlurFilter:
return new BlurFilterNode();
case kSolidGenerator:
return new SolidGenerator();
case kMerge:
return new MergeNode();
case kStrokeFilter:
return new StrokeFilterNode();
case kTextGeneratorV1:
return new TextGeneratorV1();
case kTextGeneratorV2:
return new TextGeneratorV2();
case kTextGeneratorV3:
return new TextGeneratorV3();
case kCrossDissolveTransition:
return new CrossDissolveTransition();
case kDipToColorTransition:
return new DipToColorTransition();
case kMosaicFilter:
return new MosaicFilterNode();
case kCropDistort:
return new CropDistortNode();
case kProjectFootage:
return new Footage();
case kProjectFolder:
return new Folder();
case kProjectSequence:
return new Sequence();
case kValueNode:
return new ValueNode();
case kTimeRemapNode:
return new TimeRemapNode();
case kSubtitleBlock:
return new SubtitleBlock();
case kShapeGenerator:
return new ShapeNode();
case kColorDifferenceKeyKeying:
return new ColorDifferenceKeyNode();
case kDespillKeying:
return new DespillNode();
case kGroupNode:
return new NodeGroup();
case kOpacityEffect:
return new OpacityEffect();
case kFlipDistort:
return new FlipDistortNode();
case kNoiseGenerator:
return new NoiseGeneratorNode();
case kTimeOffsetNode:
return new TimeOffsetNode();
case kCornerPinDistort:
return new CornerPinDistortNode();
case kDisplayTransform:
return new DisplayTransformNode();
case kOCIOGradingTransformLinear:
return new OCIOGradingTransformLinearNode();
case kChromaKey:
return new ChromaKeyNode();
case kMaskDistort:
return new MaskDistortNode();
case kDropShadowFilter:
return new DropShadowFilter();
case kTimeFormat:
return new TimeFormatNode();
case kWaveDistort:
return new WaveDistortNode();
case kTileDistort:
return new TileDistortNode();
case kSwirlDistort:
return new SwirlDistortNode();
case kRippleDistort:
return new RippleDistortNode();
case kMulticamNode:
return new MultiCamNode();
case kInternalNodeCount:
break;
}
case kInternalNodeCount:
break;
}
return nullptr;
return nullptr;
}
}
+69 -67
View File
@@ -26,87 +26,89 @@
#include "node.h"
#include "widget/menu/menu.h"
namespace olive {
class NodeFactory
namespace olive
{
class NodeFactory {
public:
enum InternalID {
kViewerOutput,
kClipBlock,
kGapBlock,
kPolygonGenerator,
kMatrixGenerator,
kTransformDistort,
kTrackOutput,
kAudioVolume,
kAudioPanning,
kMath,
kTime,
kTrigonometry,
kBlurFilter,
kSolidGenerator,
kMerge,
kStrokeFilter,
kTextGeneratorV1,
kTextGeneratorV2,
kTextGeneratorV3,
kCrossDissolveTransition,
kDipToColorTransition,
kMosaicFilter,
kCropDistort,
kProjectFootage,
kProjectFolder,
kProjectSequence,
kValueNode,
kTimeRemapNode,
kSubtitleBlock,
kShapeGenerator,
kColorDifferenceKeyKeying,
kDespillKeying,
kGroupNode,
kOpacityEffect,
kFlipDistort,
kNoiseGenerator,
kTimeOffsetNode,
kCornerPinDistort,
kDisplayTransform,
kOCIOGradingTransformLinear,
kChromaKey,
kMaskDistort,
kDropShadowFilter,
kTimeFormat,
kWaveDistort,
kRippleDistort,
kTileDistort,
kSwirlDistort,
kMulticamNode,
enum InternalID {
kViewerOutput,
kClipBlock,
kGapBlock,
kPolygonGenerator,
kMatrixGenerator,
kTransformDistort,
kTrackOutput,
kAudioVolume,
kAudioPanning,
kMath,
kTime,
kTrigonometry,
kBlurFilter,
kSolidGenerator,
kMerge,
kStrokeFilter,
kTextGeneratorV1,
kTextGeneratorV2,
kTextGeneratorV3,
kCrossDissolveTransition,
kDipToColorTransition,
kMosaicFilter,
kCropDistort,
kProjectFootage,
kProjectFolder,
kProjectSequence,
kValueNode,
kTimeRemapNode,
kSubtitleBlock,
kShapeGenerator,
kColorDifferenceKeyKeying,
kDespillKeying,
kGroupNode,
kOpacityEffect,
kFlipDistort,
kNoiseGenerator,
kTimeOffsetNode,
kCornerPinDistort,
kDisplayTransform,
kOCIOGradingTransformLinear,
kChromaKey,
kMaskDistort,
kDropShadowFilter,
kTimeFormat,
kWaveDistort,
kRippleDistort,
kTileDistort,
kSwirlDistort,
kMulticamNode,
// Count value
kInternalNodeCount
};
// Count value
kInternalNodeCount
};
NodeFactory() = default;
NodeFactory() = default;
static void Initialize();
static void Initialize();
static void Destroy();
static void Destroy();
static Menu* CreateMenu(QWidget *parent, bool create_none_item = false, Node::CategoryID restrict_to = Node::kCategoryUnknown, uint64_t restrict_flags = 0);
static Menu *
CreateMenu(QWidget *parent, bool create_none_item = false,
Node::CategoryID restrict_to = Node::kCategoryUnknown,
uint64_t restrict_flags = 0);
static Node* CreateFromMenuAction(QAction* action);
static Node *CreateFromMenuAction(QAction *action);
static QString GetIDFromMenuAction(QAction* action);
static QString GetIDFromMenuAction(QAction *action);
static QString GetNameFromID(const QString& id);
static QString GetNameFromID(const QString &id);
static Node* CreateFromID(const QString& id);
static Node *CreateFromID(const QString &id);
static Node* CreateFromFactoryIndex(const InternalID& id);
static Node *CreateFromFactoryIndex(const InternalID &id);
private:
static QList<Node*> library_;
static QList<Node *> library_;
};
}
+135 -118
View File
@@ -20,199 +20,216 @@
#include "blur.h"
namespace olive {
namespace olive
{
const QString BlurFilterNode::kTextureInput = QStringLiteral("tex_in");
const QString BlurFilterNode::kMethodInput = QStringLiteral("method_in");
const QString BlurFilterNode::kRadiusInput = QStringLiteral("radius_in");
const QString BlurFilterNode::kHorizInput = QStringLiteral("horiz_in");
const QString BlurFilterNode::kVertInput = QStringLiteral("vert_in");
const QString BlurFilterNode::kRepeatEdgePixelsInput = QStringLiteral("repeat_edge_pixels_in");
const QString BlurFilterNode::kRepeatEdgePixelsInput =
QStringLiteral("repeat_edge_pixels_in");
const QString BlurFilterNode::kDirectionalDegreesInput = QStringLiteral("directional_degrees_in");
const QString BlurFilterNode::kDirectionalDegreesInput =
QStringLiteral("directional_degrees_in");
const QString BlurFilterNode::kRadialCenterInput = QStringLiteral("radial_center_in");
const QString BlurFilterNode::kRadialCenterInput =
QStringLiteral("radial_center_in");
#define super Node
BlurFilterNode::BlurFilterNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
Method default_method = kGaussian;
Method default_method = kGaussian;
AddInput(kMethodInput, NodeValue::kCombo, default_method, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kMethodInput, NodeValue::kCombo, default_method,
InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kRadiusInput, NodeValue::kFloat, 10.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
AddInput(kRadiusInput, NodeValue::kFloat, 10.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
{
// Box and gaussian only
AddInput(kHorizInput, NodeValue::kBoolean, true);
AddInput(kVertInput, NodeValue::kBoolean, true);
}
{
// Box and gaussian only
AddInput(kHorizInput, NodeValue::kBoolean, true);
AddInput(kVertInput, NodeValue::kBoolean, true);
}
{
// Directional only
AddInput(kDirectionalDegreesInput, NodeValue::kFloat, 0.0);
}
{
// Directional only
AddInput(kDirectionalDegreesInput, NodeValue::kFloat, 0.0);
}
{
// Radial only
AddInput(kRadialCenterInput, NodeValue::kVec2, QVector2D(0, 0));
}
{
// Radial only
AddInput(kRadialCenterInput, NodeValue::kVec2, QVector2D(0, 0));
}
UpdateInputs(default_method);
UpdateInputs(default_method);
AddInput(kRepeatEdgePixelsInput, NodeValue::kBoolean, true);
AddInput(kRepeatEdgePixelsInput, NodeValue::kBoolean, true);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
radial_center_gizmo_ = AddDraggableGizmo<PointGizmo>();
radial_center_gizmo_->SetShape(PointGizmo::kAnchorPoint);
radial_center_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kRadialCenterInput), 0));
radial_center_gizmo_->AddInput(NodeKeyframeTrackReference(NodeInput(this, kRadialCenterInput), 1));
radial_center_gizmo_ = AddDraggableGizmo<PointGizmo>();
radial_center_gizmo_->SetShape(PointGizmo::kAnchorPoint);
radial_center_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kRadialCenterInput), 0));
radial_center_gizmo_->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kRadialCenterInput), 1));
}
QString BlurFilterNode::Name() const
{
return tr("Blur");
return tr("Blur");
}
QString BlurFilterNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.blur");
return QStringLiteral("org.olivevideoeditor.Olive.blur");
}
QVector<Node::CategoryID> BlurFilterNode::Category() const
{
return {kCategoryFilter};
return { kCategoryFilter };
}
QString BlurFilterNode::Description() const
{
return tr("Blurs an image.");
return tr("Blurs an image.");
}
void BlurFilterNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kMethodInput, tr("Method"));
SetComboBoxStrings(kMethodInput, { tr("Box"), tr("Gaussian"), tr("Directional"), tr("Radial") });
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kHorizInput, tr("Horizontal"));
SetInputName(kVertInput, tr("Vertical"));
SetInputName(kRepeatEdgePixelsInput, tr("Repeat Edge Pixels"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kMethodInput, tr("Method"));
SetComboBoxStrings(kMethodInput, { tr("Box"), tr("Gaussian"),
tr("Directional"), tr("Radial") });
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kHorizInput, tr("Horizontal"));
SetInputName(kVertInput, tr("Vertical"));
SetInputName(kRepeatEdgePixelsInput, tr("Repeat Edge Pixels"));
SetInputName(kDirectionalDegreesInput, tr("Direction"));
SetInputName(kRadialCenterInput, tr("Center"));
SetInputName(kDirectionalDegreesInput, tr("Direction"));
SetInputName(kRadialCenterInput, tr("Center"));
}
ShaderCode BlurFilterNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/blur.frag"));
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/blur.frag"));
}
void BlurFilterNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void BlurFilterNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
Method method = static_cast<Method>(value[kMethodInput].toInt());
// If there's no texture, no need to run an operation
if (TexturePtr tex = value[kTextureInput].toTexture()) {
Method method = static_cast<Method>(value[kMethodInput].toInt());
bool can_push_job = true;
int iterations = 1;
bool can_push_job = true;
int iterations = 1;
// Check if radius is > 0
if (value[kRadiusInput].toDouble() > 0.0) {
// Method-specific considerations
switch (method) {
case kBox:
case kGaussian:
{
bool horiz = value[kHorizInput].toBool();
bool vert = value[kVertInput].toBool();
// Check if radius is > 0
if (value[kRadiusInput].toDouble() > 0.0) {
// Method-specific considerations
switch (method) {
case kBox:
case kGaussian: {
bool horiz = value[kHorizInput].toBool();
bool vert = value[kVertInput].toBool();
if (!horiz && !vert) {
// Disable job if horiz and vert are unchecked
can_push_job = false;
} else if (horiz && vert) {
// Set iteration count to 2 if we're blurring both horizontally and vertically
iterations = 2;
}
break;
}
case kDirectional:
case kRadial:
break;
}
} else {
can_push_job = false;
}
if (!horiz && !vert) {
// Disable job if horiz and vert are unchecked
can_push_job = false;
} else if (horiz && vert) {
// Set iteration count to 2 if we're blurring both horizontally and vertically
iterations = 2;
}
break;
}
case kDirectional:
case kRadial:
break;
}
} else {
can_push_job = false;
}
if (can_push_job) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
job.SetIterations(iterations, kTextureInput);
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not performing the blur job, just push the texture
table->Push(value[kTextureInput]);
}
}
if (can_push_job) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
job.SetIterations(iterations, kTextureInput);
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
// If we're not performing the blur job, just push the texture
table->Push(value[kTextureInput]);
}
}
}
void BlurFilterNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void BlurFilterNode::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
if (TexturePtr tex = row[kTextureInput].toTexture()) {
if (row[kMethodInput].toInt() == kRadial) {
const QVector2D &sequence_res = tex->virtual_resolution();
QVector2D sequence_half_res = sequence_res * 0.5;
if (TexturePtr tex = row[kTextureInput].toTexture()) {
if (row[kMethodInput].toInt() == kRadial) {
const QVector2D &sequence_res = tex->virtual_resolution();
QVector2D sequence_half_res = sequence_res * 0.5;
radial_center_gizmo_->SetVisible(true);
radial_center_gizmo_->SetPoint(sequence_half_res.toPointF() + row[kRadialCenterInput].toVec2().toPointF());
radial_center_gizmo_->SetVisible(true);
radial_center_gizmo_->SetPoint(
sequence_half_res.toPointF() +
row[kRadialCenterInput].toVec2().toPointF());
SetInputProperty(kRadialCenterInput, QStringLiteral("offset"), sequence_half_res);
} else{
radial_center_gizmo_->SetVisible(false);
}
}
SetInputProperty(kRadialCenterInput, QStringLiteral("offset"),
sequence_half_res);
} else {
radial_center_gizmo_->SetVisible(false);
}
}
}
void BlurFilterNode::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void BlurFilterNode::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo == radial_center_gizmo_) {
if (gizmo == radial_center_gizmo_) {
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
}
void BlurFilterNode::InputValueChangedEvent(const QString &input, int element)
{
if (input == kMethodInput) {
UpdateInputs(GetMethod());
}
if (input == kMethodInput) {
UpdateInputs(GetMethod());
}
super::InputValueChangedEvent(input, element);
super::InputValueChangedEvent(input, element);
}
void BlurFilterNode::UpdateInputs(Method method)
{
SetInputFlag(kHorizInput, kInputFlagHidden, !(method == kBox || method == kGaussian));
SetInputFlag(kVertInput, kInputFlagHidden, !(method == kBox || method == kGaussian));
SetInputFlag(kDirectionalDegreesInput, kInputFlagHidden, !(method == kDirectional));
SetInputFlag(kRadialCenterInput, kInputFlagHidden, !(method == kRadial));
SetInputFlag(kHorizInput, kInputFlagHidden,
!(method == kBox || method == kGaussian));
SetInputFlag(kVertInput, kInputFlagHidden,
!(method == kBox || method == kGaussian));
SetInputFlag(kDirectionalDegreesInput, kInputFlagHidden,
!(method == kDirectional));
SetInputFlag(kRadialCenterInput, kInputFlagHidden, !(method == kRadial));
}
}
+36 -37
View File
@@ -24,62 +24,61 @@
#include "node/gizmo/point.h"
#include "node/node.h"
namespace olive {
class BlurFilterNode : public Node
namespace olive
{
Q_OBJECT
class BlurFilterNode : public Node {
Q_OBJECT
public:
BlurFilterNode();
BlurFilterNode();
enum Method {
kBox,
kGaussian,
kDirectional,
kRadial
};
enum Method { kBox, kGaussian, kDirectional, kRadial };
NODE_DEFAULT_FUNCTIONS(BlurFilterNode)
NODE_DEFAULT_FUNCTIONS(BlurFilterNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
Method GetMethod() const
{
return static_cast<Method>(GetStandardValue(kMethodInput).toInt());
}
Method GetMethod() const
{
return static_cast<Method>(GetStandardValue(kMethodInput).toInt());
}
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
static const QString kTextureInput;
static const QString kMethodInput;
static const QString kRadiusInput;
static const QString kHorizInput;
static const QString kVertInput;
static const QString kRepeatEdgePixelsInput;
static const QString kTextureInput;
static const QString kMethodInput;
static const QString kRadiusInput;
static const QString kHorizInput;
static const QString kVertInput;
static const QString kRepeatEdgePixelsInput;
static const QString kDirectionalDegreesInput;
static const QString kDirectionalDegreesInput;
static const QString kRadialCenterInput;
static const QString kRadialCenterInput;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
protected:
virtual void InputValueChangedEvent(const QString& input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
private:
void UpdateInputs(Method method);
PointGizmo *radial_center_gizmo_;
void UpdateInputs(Method method);
PointGizmo *radial_center_gizmo_;
};
}
+43 -34
View File
@@ -22,7 +22,8 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
#define super Node
@@ -36,62 +37,70 @@ const QString DropShadowFilter::kFastInput = QStringLiteral("fast_in");
DropShadowFilter::DropShadowFilter()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(0.0, 0.0, 0.0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(0.0, 0.0, 0.0)));
AddInput(kDistanceInput, NodeValue::kFloat, 10.0);
AddInput(kDistanceInput, NodeValue::kFloat, 10.0);
AddInput(kAngleInput, NodeValue::kFloat, 135.0);
AddInput(kAngleInput, NodeValue::kFloat, 135.0);
AddInput(kSoftnessInput, NodeValue::kFloat, 10.0);
SetInputProperty(kSoftnessInput, QStringLiteral("min"), 0.0);
AddInput(kSoftnessInput, NodeValue::kFloat, 10.0);
SetInputProperty(kSoftnessInput, QStringLiteral("min"), 0.0);
AddInput(kOpacityInput, NodeValue::kFloat, 1.0);
SetInputProperty(kOpacityInput, QStringLiteral("min"), 0.0);
SetInputProperty(kOpacityInput, QStringLiteral("view"), FloatSlider::kPercentage);
AddInput(kOpacityInput, NodeValue::kFloat, 1.0);
SetInputProperty(kOpacityInput, QStringLiteral("min"), 0.0);
SetInputProperty(kOpacityInput, QStringLiteral("view"),
FloatSlider::kPercentage);
AddInput(kFastInput, NodeValue::kBoolean, false);
AddInput(kFastInput, NodeValue::kBoolean, false);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
}
void DropShadowFilter::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kDistanceInput, tr("Distance"));
SetInputName(kAngleInput, tr("Angle"));
SetInputName(kSoftnessInput, tr("Softness"));
SetInputName(kOpacityInput, tr("Opacity"));
SetInputName(kFastInput, tr("Faster (Lower Quality)"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kDistanceInput, tr("Distance"));
SetInputName(kAngleInput, tr("Angle"));
SetInputName(kSoftnessInput, tr("Softness"));
SetInputName(kOpacityInput, tr("Opacity"));
SetInputName(kFastInput, tr("Faster (Lower Quality)"));
}
ShaderCode DropShadowFilter::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/dropshadow.frag"));
Q_UNUSED(request)
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/dropshadow.frag"));
}
void DropShadowFilter::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void DropShadowFilter::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (TexturePtr tex = value[kTextureInput].toTexture()) {
ShaderJob job(value);
if (TexturePtr tex = value[kTextureInput].toTexture()) {
ShaderJob job(value);
QString iterative = QStringLiteral("previous_iteration_in");
QString iterative = QStringLiteral("previous_iteration_in");
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
job.Insert(iterative, value[kTextureInput]);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
job.Insert(iterative, value[kTextureInput]);
if (!qIsNull(value[kSoftnessInput].toDouble())) {
job.SetIterations(3, iterative);
}
if (!qIsNull(value[kSoftnessInput].toDouble())) {
job.SetIterations(3, iterative);
}
table->Push(NodeValue::kTexture, tex->toJob(job), this);
}
table->Push(NodeValue::kTexture, tex->toJob(job), this);
}
}
}
+34 -21
View File
@@ -23,34 +23,47 @@
#include "node/node.h"
namespace olive {
class DropShadowFilter : public Node
namespace olive
{
Q_OBJECT
class DropShadowFilter : public Node {
Q_OBJECT
public:
DropShadowFilter();
DropShadowFilter();
NODE_DEFAULT_FUNCTIONS(DropShadowFilter)
NODE_DEFAULT_FUNCTIONS(DropShadowFilter)
virtual QString Name() const override { return tr("Drop Shadow"); }
virtual QString id() const override { return QStringLiteral("org.olivevideoeditor.Olive.dropshadow"); }
virtual QVector<CategoryID> Category() const override { return {kCategoryFilter}; }
virtual QString Description() const override { return tr("Adds a drop shadow to an image."); }
virtual QString Name() const override
{
return tr("Drop Shadow");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.dropshadow");
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryFilter };
}
virtual QString Description() const override
{
return tr("Adds a drop shadow to an image.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kColorInput;
static const QString kDistanceInput;
static const QString kAngleInput;
static const QString kSoftnessInput;
static const QString kOpacityInput;
static const QString kFastInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kColorInput;
static const QString kDistanceInput;
static const QString kAngleInput;
static const QString kSoftnessInput;
static const QString kOpacityInput;
static const QString kFastInput;
};
}
+30 -27
View File
@@ -20,7 +20,8 @@
#include "mosaicfilternode.h"
namespace olive {
namespace olive
{
const QString MosaicFilterNode::kTextureInput = QStringLiteral("tex_in");
const QString MosaicFilterNode::kHorizInput = QStringLiteral("horiz_in");
@@ -30,50 +31,52 @@ const QString MosaicFilterNode::kVertInput = QStringLiteral("vert_in");
MosaicFilterNode::MosaicFilterNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kHorizInput, NodeValue::kFloat, 32.0);
SetInputProperty(kHorizInput, QStringLiteral("min"), 1.0);
AddInput(kHorizInput, NodeValue::kFloat, 32.0);
SetInputProperty(kHorizInput, QStringLiteral("min"), 1.0);
AddInput(kVertInput, NodeValue::kFloat, 18.0);
SetInputProperty(kVertInput, QStringLiteral("min"), 1.0);
AddInput(kVertInput, NodeValue::kFloat, 18.0);
SetInputProperty(kVertInput, QStringLiteral("min"), 1.0);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
void MosaicFilterNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kHorizInput, tr("Horizontal"));
SetInputName(kVertInput, tr("Vertical"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kHorizInput, tr("Horizontal"));
SetInputName(kVertInput, tr("Vertical"));
}
void MosaicFilterNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void MosaicFilterNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (TexturePtr texture = value[kTextureInput].toTexture()) {
if (texture
&& value[kHorizInput].toInt() != texture->width()
&& value[kVertInput].toInt() != texture->height()) {
ShaderJob job(value);
if (TexturePtr texture = value[kTextureInput].toTexture()) {
if (texture && value[kHorizInput].toInt() != texture->width() &&
value[kVertInput].toInt() != texture->height()) {
ShaderJob job(value);
// Mipmapping makes this look weird, so we just use bilinear for finding the color of each block
job.SetInterpolation(kTextureInput, Texture::kLinear);
// Mipmapping makes this look weird, so we just use bilinear for finding the color of each block
job.SetInterpolation(kTextureInput, Texture::kLinear);
table->Push(NodeValue::kTexture, texture->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
table->Push(NodeValue::kTexture, texture->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
}
ShaderCode MosaicFilterNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/mosaic.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/mosaic.frag"));
}
}
+30 -29
View File
@@ -23,45 +23,46 @@
#include "node/node.h"
namespace olive {
class MosaicFilterNode : public Node
namespace olive
{
Q_OBJECT
class MosaicFilterNode : public Node {
Q_OBJECT
public:
MosaicFilterNode();
MosaicFilterNode();
NODE_DEFAULT_FUNCTIONS(MosaicFilterNode)
NODE_DEFAULT_FUNCTIONS(MosaicFilterNode)
virtual QString Name() const override
{
return tr("Mosaic");
}
virtual QString Name() const override
{
return tr("Mosaic");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.mosaicfilter");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.mosaicfilter");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryFilter};
}
virtual QVector<CategoryID> Category() const override
{
return { kCategoryFilter };
}
virtual QString Description() const override
{
return tr("Apply a pixelated mosaic filter to video.");
}
virtual QString Description() const override
{
return tr("Apply a pixelated mosaic filter to video.");
}
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
static const QString kTextureInput;
static const QString kHorizInput;
static const QString kVertInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kTextureInput;
static const QString kHorizInput;
static const QString kVertInput;
};
}
+43 -35
View File
@@ -22,7 +22,8 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString StrokeFilterNode::kTextureInput = QStringLiteral("tex_in");
const QString StrokeFilterNode::kColorInput = QStringLiteral("color_in");
@@ -34,74 +35,81 @@ const QString StrokeFilterNode::kInnerInput = QStringLiteral("inner_in");
StrokeFilterNode::StrokeFilterNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kTextureInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 1.0f, 1.0f, 1.0f)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0f, 1.0f, 1.0f, 1.0f)));
AddInput(kRadiusInput, NodeValue::kFloat, 10.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
AddInput(kRadiusInput, NodeValue::kFloat, 10.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
AddInput(kOpacityInput, NodeValue::kFloat, 1.0f);
SetInputProperty(kOpacityInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kOpacityInput, QStringLiteral("min"), 0.0f);
SetInputProperty(kOpacityInput, QStringLiteral("max"), 1.0f);
AddInput(kOpacityInput, NodeValue::kFloat, 1.0f);
SetInputProperty(kOpacityInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kOpacityInput, QStringLiteral("min"), 0.0f);
SetInputProperty(kOpacityInput, QStringLiteral("max"), 1.0f);
AddInput(kInnerInput, NodeValue::kBoolean, false);
AddInput(kInnerInput, NodeValue::kBoolean, false);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
SetFlag(kVideoEffect);
SetEffectInput(kTextureInput);
}
QString StrokeFilterNode::Name() const
{
return tr("Stroke");
return tr("Stroke");
}
QString StrokeFilterNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.stroke");
return QStringLiteral("org.olivevideoeditor.Olive.stroke");
}
QVector<Node::CategoryID> StrokeFilterNode::Category() const
{
return {kCategoryFilter};
return { kCategoryFilter };
}
QString StrokeFilterNode::Description() const
{
return tr("Creates a stroke outline around an image.");
return tr("Creates a stroke outline around an image.");
}
void StrokeFilterNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kOpacityInput, tr("Opacity"));
SetInputName(kInnerInput, tr("Inner"));
SetInputName(kTextureInput, tr("Input"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kOpacityInput, tr("Opacity"));
SetInputName(kInnerInput, tr("Inner"));
}
void StrokeFilterNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void StrokeFilterNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (value[kRadiusInput].toDouble() > 0.0
&& value[kOpacityInput].toDouble() > 0.0) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, tex->virtual_resolution(), this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
if (TexturePtr tex = value[kTextureInput].toTexture()) {
if (value[kRadiusInput].toDouble() > 0.0 &&
value[kOpacityInput].toDouble() > 0.0) {
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2, tex->virtual_resolution(),
this));
table->Push(NodeValue::kTexture, tex->toJob(job), this);
} else {
table->Push(value[kTextureInput]);
}
}
}
ShaderCode StrokeFilterNode::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/stroke.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/stroke.frag"));
}
}
+20 -19
View File
@@ -23,32 +23,33 @@
#include "node/node.h"
namespace olive {
class StrokeFilterNode : public Node
namespace olive
{
Q_OBJECT
class StrokeFilterNode : public Node {
Q_OBJECT
public:
StrokeFilterNode();
StrokeFilterNode();
NODE_DEFAULT_FUNCTIONS(StrokeFilterNode)
NODE_DEFAULT_FUNCTIONS(StrokeFilterNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
static const QString kTextureInput;
static const QString kColorInput;
static const QString kRadiusInput;
static const QString kOpacityInput;
static const QString kInnerInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kTextureInput;
static const QString kColorInput;
static const QString kRadiusInput;
static const QString kOpacityInput;
static const QString kInnerInput;
};
}
+75 -69
View File
@@ -25,136 +25,142 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString MatrixGenerator::kPositionInput = QStringLiteral("pos_in");
const QString MatrixGenerator::kRotationInput = QStringLiteral("rot_in");
const QString MatrixGenerator::kScaleInput = QStringLiteral("scale_in");
const QString MatrixGenerator::kUniformScaleInput = QStringLiteral("uniform_scale_in");
const QString MatrixGenerator::kUniformScaleInput =
QStringLiteral("uniform_scale_in");
const QString MatrixGenerator::kAnchorInput = QStringLiteral("anchor_in");
#define super Node
MatrixGenerator::MatrixGenerator()
{
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kRotationInput, NodeValue::kFloat, 0.0);
AddInput(kRotationInput, NodeValue::kFloat, 0.0);
AddInput(kScaleInput, NodeValue::kVec2, QVector2D(1.0f, 1.0f));
SetInputProperty(kScaleInput, QStringLiteral("min"), QVector2D(0, 0));
SetInputProperty(kScaleInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kScaleInput, QStringLiteral("disable1"), true);
AddInput(kScaleInput, NodeValue::kVec2, QVector2D(1.0f, 1.0f));
SetInputProperty(kScaleInput, QStringLiteral("min"), QVector2D(0, 0));
SetInputProperty(kScaleInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kScaleInput, QStringLiteral("disable1"), true);
AddInput(kUniformScaleInput, NodeValue::kBoolean, true, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kUniformScaleInput, NodeValue::kBoolean, true,
InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
AddInput(kAnchorInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
AddInput(kAnchorInput, NodeValue::kVec2, QVector2D(0.0, 0.0));
}
QString MatrixGenerator::Name() const
{
return tr("Orthographic Matrix");
return tr("Orthographic Matrix");
}
QString MatrixGenerator::ShortName() const
{
return tr("Ortho");
return tr("Ortho");
}
QString MatrixGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.ortho");
return QStringLiteral("org.olivevideoeditor.Olive.ortho");
}
QVector<Node::CategoryID> MatrixGenerator::Category() const
{
return {kCategoryGenerator, kCategoryMath};
return { kCategoryGenerator, kCategoryMath };
}
QString MatrixGenerator::Description() const
{
return tr("Generate an orthographic matrix using position, rotation, and scale.");
return tr(
"Generate an orthographic matrix using position, rotation, and scale.");
}
void MatrixGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPositionInput, tr("Position"));
SetInputName(kRotationInput, tr("Rotation"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kUniformScaleInput, tr("Uniform Scale"));
SetInputName(kAnchorInput, tr("Anchor Point"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kRotationInput, tr("Rotation"));
SetInputName(kScaleInput, tr("Scale"));
SetInputName(kUniformScaleInput, tr("Uniform Scale"));
SetInputName(kAnchorInput, tr("Anchor Point"));
}
void MatrixGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void MatrixGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value, false, false, false, QMatrix4x4());
table->Push(NodeValue::kMatrix, mat, this);
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value, false, false, false, QMatrix4x4());
table->Push(NodeValue::kMatrix, mat, this);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value,
bool ignore_anchor,
bool ignore_position,
bool ignore_scale,
const QMatrix4x4 &mat) const
{
QVector2D anchor;
QVector2D position;
QVector2D scale;
QVector2D anchor;
QVector2D position;
QVector2D scale;
if (!ignore_anchor) {
anchor = value[kAnchorInput].toVec2();
}
if (!ignore_anchor) {
anchor = value[kAnchorInput].toVec2();
}
if (!ignore_scale) {
scale = value[kScaleInput].toVec2();
}
if (!ignore_scale) {
scale = value[kScaleInput].toVec2();
}
if (!ignore_position) {
position = value[kPositionInput].toVec2();
}
if (!ignore_position) {
position = value[kPositionInput].toVec2();
}
return GenerateMatrix(position,
value[kRotationInput].toDouble(),
scale,
value[kUniformScaleInput].toBool(),
anchor,
mat);
return GenerateMatrix(position, value[kRotationInput].toDouble(), scale,
value[kUniformScaleInput].toBool(), anchor, mat);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const QVector2D& pos,
const float& rot,
const QVector2D& scale,
bool uniform_scale,
const QVector2D& anchor,
QMatrix4x4 mat)
QMatrix4x4
MatrixGenerator::GenerateMatrix(const QVector2D &pos, const float &rot,
const QVector2D &scale, bool uniform_scale,
const QVector2D &anchor, QMatrix4x4 mat)
{
// Position
mat.translate(pos.x(), pos.y());
// Position
mat.translate(pos.x(), pos.y());
// Rotation
mat.rotate(rot, 0, 0, 1);
// Rotation
mat.rotate(rot, 0, 0, 1);
// Scale (convert to a QVector3D so that the identity matrix is preserved if all values are 1.0f)
QVector3D full_scale;
if (uniform_scale) {
full_scale = QVector3D(scale.x(), scale.x(), 1.0f);
} else {
full_scale = QVector3D(scale, 1.0f);
}
mat.scale(full_scale);
// Scale (convert to a QVector3D so that the identity matrix is preserved if all values are 1.0f)
QVector3D full_scale;
if (uniform_scale) {
full_scale = QVector3D(scale.x(), scale.x(), 1.0f);
} else {
full_scale = QVector3D(scale, 1.0f);
}
mat.scale(full_scale);
// Anchor Point
mat.translate(-anchor.x(), -anchor.y());
// Anchor Point
mat.translate(-anchor.x(), -anchor.y());
return mat;
return mat;
}
void MatrixGenerator::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element)
Q_UNUSED(element)
if (input == kUniformScaleInput) {
SetInputProperty(kScaleInput, QStringLiteral("disable1"), GetStandardValue(kUniformScaleInput).toBool());
}
if (input == kUniformScaleInput) {
SetInputProperty(kScaleInput, QStringLiteral("disable1"),
GetStandardValue(kUniformScaleInput).toBool());
}
}
}
+27 -27
View File
@@ -26,43 +26,43 @@
#include "node/node.h"
#include "node/inputdragger.h"
namespace olive {
class MatrixGenerator : public Node
namespace olive
{
Q_OBJECT
class MatrixGenerator : public Node {
Q_OBJECT
public:
MatrixGenerator();
MatrixGenerator();
NODE_DEFAULT_FUNCTIONS(MatrixGenerator)
NODE_DEFAULT_FUNCTIONS(MatrixGenerator)
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString ShortName() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kPositionInput;
static const QString kRotationInput;
static const QString kScaleInput;
static const QString kUniformScaleInput;
static const QString kAnchorInput;
static const QString kPositionInput;
static const QString kRotationInput;
static const QString kScaleInput;
static const QString kUniformScaleInput;
static const QString kAnchorInput;
protected:
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const;
static QMatrix4x4 GenerateMatrix(const QVector2D &pos,
const float &rot,
const QVector2D &scale,
bool uniform_scale,
const QVector2D &anchor,
QMatrix4x4 mat);
virtual void InputValueChangedEvent(const QString& input, int element) override;
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor,
bool ignore_position, bool ignore_scale,
const QMatrix4x4 &mat) const;
static QMatrix4x4 GenerateMatrix(const QVector2D &pos, const float &rot,
const QVector2D &scale, bool uniform_scale,
const QVector2D &anchor, QMatrix4x4 mat);
virtual void InputValueChangedEvent(const QString &input,
int element) override;
};
}
+34 -24
View File
@@ -22,71 +22,81 @@
#include "widget/slider/floatslider.h"
namespace olive {
namespace olive
{
const QString NoiseGeneratorNode::kBaseIn = QStringLiteral("base_in");
const QString NoiseGeneratorNode::kColorInput = QStringLiteral("color_in");
const QString NoiseGeneratorNode::kStrengthInput = QStringLiteral("strength_in");
const QString NoiseGeneratorNode::kStrengthInput =
QStringLiteral("strength_in");
#define super Node
NoiseGeneratorNode::NoiseGeneratorNode()
{
AddInput(kBaseIn, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kBaseIn, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
AddInput(kStrengthInput, NodeValue::kFloat, 0.2);
SetInputProperty(kStrengthInput, QStringLiteral("view"), FloatSlider::kPercentage);
SetInputProperty(kStrengthInput, QStringLiteral("min"), 0);
AddInput(kStrengthInput, NodeValue::kFloat, 0.2);
SetInputProperty(kStrengthInput, QStringLiteral("view"),
FloatSlider::kPercentage);
SetInputProperty(kStrengthInput, QStringLiteral("min"), 0);
AddInput(kColorInput, NodeValue::kBoolean, false);
AddInput(kColorInput, NodeValue::kBoolean, false);
SetEffectInput(kBaseIn);
SetFlag(kVideoEffect);
SetEffectInput(kBaseIn);
SetFlag(kVideoEffect);
}
QString NoiseGeneratorNode::Name() const
{
return tr("Noise");
return tr("Noise");
}
QString NoiseGeneratorNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.noise");
return QStringLiteral("org.olivevideoeditor.Olive.noise");
}
QVector<Node::CategoryID> NoiseGeneratorNode::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString NoiseGeneratorNode::Description() const
{
return tr("Generates noise patterns");
return tr("Generates noise patterns");
}
void NoiseGeneratorNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBaseIn, tr("Base"));
SetInputName(kStrengthInput, tr("Strength"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kBaseIn, tr("Base"));
SetInputName(kStrengthInput, tr("Strength"));
SetInputName(kColorInput, tr("Color"));
}
ShaderCode NoiseGeneratorNode::GetShaderCode(const ShaderRequest &request) const
{
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/noise.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/noise.frag"));
}
void NoiseGeneratorNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void NoiseGeneratorNode::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
ShaderJob job(value);
ShaderJob job(value);
job.Insert(value);
job.Insert(QStringLiteral("time_in"), NodeValue(NodeValue::kFloat, globals.time().in().toDouble(), this));
job.Insert(value);
job.Insert(QStringLiteral("time_in"),
NodeValue(NodeValue::kFloat, globals.time().in().toDouble(),
this));
TexturePtr base = value[kBaseIn].toTexture();
TexturePtr base = value[kBaseIn].toTexture();
table->Push(NodeValue::kTexture, Texture::Job(base ? base->params() : globals.vparams(), job), this);
table->Push(NodeValue::kTexture,
Texture::Job(base ? base->params() : globals.vparams(), job),
this);
}
}
+20 -18
View File
@@ -23,31 +23,33 @@
#include "node/node.h"
namespace olive {
namespace olive
{
class NoiseGeneratorNode : public Node {
Q_OBJECT
public:
NoiseGeneratorNode();
Q_OBJECT
public:
NoiseGeneratorNode();
NODE_DEFAULT_FUNCTIONS(NoiseGeneratorNode)
NODE_DEFAULT_FUNCTIONS(NoiseGeneratorNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kBaseIn;
static const QString kColorInput;
static const QString kStrengthInput;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static const QString kBaseIn;
static const QString kColorInput;
static const QString kStrengthInput;
};
} // namespace olive
} // namespace olive
#endif // NOISEGENERATORNODE_H
#endif // NOISEGENERATORNODE_H
+180 -153
View File
@@ -23,7 +23,8 @@
#include <QGuiApplication>
#include <QVector2D>
namespace olive {
namespace olive
{
const QString PolygonGenerator::kPointsInput = QStringLiteral("points_in");
const QString PolygonGenerator::kColorInput = QStringLiteral("color_in");
@@ -32,244 +33,270 @@ const QString PolygonGenerator::kColorInput = QStringLiteral("color_in");
PolygonGenerator::PolygonGenerator()
{
AddInput(kPointsInput, NodeValue::kBezier, QVector2D(0, 0), InputFlags(kInputFlagArray));
AddInput(kPointsInput, NodeValue::kBezier, QVector2D(0, 0),
InputFlags(kInputFlagArray));
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0, 1.0, 1.0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0, 1.0, 1.0)));
const int kMiddleX = 135;
const int kMiddleY = 45;
const int kBottomX = 90;
const int kBottomY = 120;
const int kTopY = 135;
const int kMiddleX = 135;
const int kMiddleY = 45;
const int kBottomX = 90;
const int kBottomY = 120;
const int kTopY = 135;
// The Default Pentagon(tm)
InputArrayResize(kPointsInput, 5);
SetSplitStandardValueOnTrack(kPointsInput, 0, 0, 0);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kTopY, 0);
SetSplitStandardValueOnTrack(kPointsInput, 0, kMiddleX, 1);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 1);
SetSplitStandardValueOnTrack(kPointsInput, 0, kBottomX, 2);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 2);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kBottomX, 3);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 3);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kMiddleX, 4);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 4);
// The Default Pentagon(tm)
InputArrayResize(kPointsInput, 5);
SetSplitStandardValueOnTrack(kPointsInput, 0, 0, 0);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kTopY, 0);
SetSplitStandardValueOnTrack(kPointsInput, 0, kMiddleX, 1);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 1);
SetSplitStandardValueOnTrack(kPointsInput, 0, kBottomX, 2);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 2);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kBottomX, 3);
SetSplitStandardValueOnTrack(kPointsInput, 1, kBottomY, 3);
SetSplitStandardValueOnTrack(kPointsInput, 0, -kMiddleX, 4);
SetSplitStandardValueOnTrack(kPointsInput, 1, -kMiddleY, 4);
// Initiate gizmos
poly_gizmo_ = new PathGizmo(this);
// Initiate gizmos
poly_gizmo_ = new PathGizmo(this);
}
QString PolygonGenerator::Name() const
{
return tr("Polygon");
return tr("Polygon");
}
QString PolygonGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.polygon");
return QStringLiteral("org.olivevideoeditor.Olive.polygon");
}
QVector<Node::CategoryID> PolygonGenerator::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString PolygonGenerator::Description() const
{
return tr("Generate a 2D polygon of any amount of points.");
return tr("Generate a 2D polygon of any amount of points.");
}
void PolygonGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPointsInput, tr("Points"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kPointsInput, tr("Points"));
SetInputName(kColorInput, tr("Color"));
}
ShaderJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value, const VideoParams &params) const
ShaderJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value,
const VideoParams &params) const
{
VideoParams p = params;
p.set_format(PixelFormat::U8);
auto job = Texture::Job(p, GenerateJob(value));
VideoParams p = params;
p.set_format(PixelFormat::U8);
auto job = Texture::Job(p, GenerateJob(value));
// Conversion to RGB
ShaderJob rgb;
rgb.SetShaderID(QStringLiteral("rgb"));
rgb.Insert(QStringLiteral("texture_in"), NodeValue(NodeValue::kTexture, job, this));
rgb.Insert(QStringLiteral("color_in"), value[kColorInput]);
// Conversion to RGB
ShaderJob rgb;
rgb.SetShaderID(QStringLiteral("rgb"));
rgb.Insert(QStringLiteral("texture_in"),
NodeValue(NodeValue::kTexture, job, this));
rgb.Insert(QStringLiteral("color_in"), value[kColorInput]);
return rgb;
return rgb;
}
void PolygonGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void PolygonGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
PushMergableJob(value, Texture::Job(globals.vparams(), GetGenerateJob(value, globals.vparams())), table);
PushMergableJob(value,
Texture::Job(globals.vparams(),
GetGenerateJob(value, globals.vparams())),
table);
}
void PolygonGenerator::GenerateFrame(FramePtr frame, const GenerateJob &job) const
void PolygonGenerator::GenerateFrame(FramePtr frame,
const GenerateJob &job) const
{
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img((uchar *) frame->data(), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img((uchar *)frame->data(), frame->width(), frame->height(),
frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
auto points = job.Get(kPointsInput).toArray();
auto points = job.Get(kPointsInput).toArray();
QPainterPath path = GeneratePath(points, InputArraySize(kPointsInput));
QPainterPath path = GeneratePath(points, InputArraySize(kPointsInput));
QPainter p(&img);
double par = frame->video_params().pixel_aspect_ratio().toDouble();
p.scale(1.0 / frame->video_params().divider() / par, 1.0 / frame->video_params().divider());
p.translate(frame->video_params().width()/2 * par, frame->video_params().height()/2);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
QPainter p(&img);
double par = frame->video_params().pixel_aspect_ratio().toDouble();
p.scale(1.0 / frame->video_params().divider() / par,
1.0 / frame->video_params().divider());
p.translate(frame->video_params().width() / 2 * par,
frame->video_params().height() / 2);
p.setBrush(Qt::white);
p.setPen(Qt::NoPen);
p.drawPath(path);
p.drawPath(path);
}
template<typename T>
NodeGizmo *PolygonGenerator::CreateAppropriateGizmo()
template <typename T> NodeGizmo *PolygonGenerator::CreateAppropriateGizmo()
{
return new T(this);
return new T(this);
}
template<>
NodeGizmo *PolygonGenerator::CreateAppropriateGizmo<PointGizmo>()
template <> NodeGizmo *PolygonGenerator::CreateAppropriateGizmo<PointGizmo>()
{
return AddDraggableGizmo<PointGizmo>();
return AddDraggableGizmo<PointGizmo>();
}
template<typename T>
void PolygonGenerator::ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz)
template <typename T>
void PolygonGenerator::ValidateGizmoVectorSize(QVector<T *> &vec, int new_sz)
{
int old_sz = vec.size();
int old_sz = vec.size();
if (old_sz != new_sz) {
if (old_sz > new_sz) {
for (int i=new_sz; i<old_sz; i++) {
delete vec.at(i);
}
}
if (old_sz != new_sz) {
if (old_sz > new_sz) {
for (int i = new_sz; i < old_sz; i++) {
delete vec.at(i);
}
}
vec.resize(new_sz);
vec.resize(new_sz);
if (old_sz < new_sz) {
for (int i=old_sz; i<new_sz; i++) {
vec[i] = static_cast<T*>(CreateAppropriateGizmo<T>());
}
}
}
if (old_sz < new_sz) {
for (int i = old_sz; i < new_sz; i++) {
vec[i] = static_cast<T *>(CreateAppropriateGizmo<T>());
}
}
}
}
void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
QVector2D res;
if (TexturePtr tex = row[kBaseInput].toTexture()) {
res = tex->virtual_resolution();
} else {
res = globals.square_resolution();
}
QVector2D res;
if (TexturePtr tex = row[kBaseInput].toTexture()) {
res = tex->virtual_resolution();
} else {
res = globals.square_resolution();
}
Imath::V2d half_res(res.x()/2, res.y()/2);
Imath::V2d half_res(res.x() / 2, res.y() / 2);
auto points = row[kPointsInput].toArray();
auto points = row[kPointsInput].toArray();
int current_pos_sz = gizmo_position_handles_.size();
int current_pos_sz = gizmo_position_handles_.size();
ValidateGizmoVectorSize(gizmo_position_handles_, points.size());
ValidateGizmoVectorSize(gizmo_bezier_handles_, points.size() * 2);
ValidateGizmoVectorSize(gizmo_bezier_lines_, points.size() * 2);
ValidateGizmoVectorSize(gizmo_position_handles_, points.size());
ValidateGizmoVectorSize(gizmo_bezier_handles_, points.size() * 2);
ValidateGizmoVectorSize(gizmo_bezier_lines_, points.size() * 2);
for (int i=current_pos_sz; i<gizmo_position_handles_.size(); i++) {
gizmo_position_handles_.at(i)->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 0));
gizmo_position_handles_.at(i)->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 1));
for (int i = current_pos_sz; i < gizmo_position_handles_.size(); i++) {
gizmo_position_handles_.at(i)->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 0));
gizmo_position_handles_.at(i)->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 1));
PointGizmo *bez_gizmo1 = gizmo_bezier_handles_.at(i*2+0);
bez_gizmo1->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 2));
bez_gizmo1->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 3));
bez_gizmo1->SetShape(PointGizmo::kCircle);
bez_gizmo1->SetSmaller(true);
PointGizmo *bez_gizmo1 = gizmo_bezier_handles_.at(i * 2 + 0);
bez_gizmo1->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 2));
bez_gizmo1->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 3));
bez_gizmo1->SetShape(PointGizmo::kCircle);
bez_gizmo1->SetSmaller(true);
PointGizmo *bez_gizmo2 = gizmo_bezier_handles_.at(i*2+1);
bez_gizmo2->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 4));
bez_gizmo2->AddInput(NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 5));
bez_gizmo2->SetShape(PointGizmo::kCircle);
bez_gizmo2->SetSmaller(true);
}
PointGizmo *bez_gizmo2 = gizmo_bezier_handles_.at(i * 2 + 1);
bez_gizmo2->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 4));
bez_gizmo2->AddInput(
NodeKeyframeTrackReference(NodeInput(this, kPointsInput, i), 5));
bez_gizmo2->SetShape(PointGizmo::kCircle);
bez_gizmo2->SetSmaller(true);
}
int pts_sz = InputArraySize(kPointsInput);
if (!points.empty()) {
for (int i=0; i<pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
int pts_sz = InputArraySize(kPointsInput);
if (!points.empty()) {
for (int i = 0; i < pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
Imath::V2d main = pt.to_vec() + half_res;
Imath::V2d cp1 = main + pt.control_point_1_to_vec();
Imath::V2d cp2 = main + pt.control_point_2_to_vec();
Imath::V2d main = pt.to_vec() + half_res;
Imath::V2d cp1 = main + pt.control_point_1_to_vec();
Imath::V2d cp2 = main + pt.control_point_2_to_vec();
gizmo_position_handles_[i]->SetPoint(QPointF(main.x, main.y));
gizmo_position_handles_[i]->SetPoint(QPointF(main.x, main.y));
gizmo_bezier_handles_[i*2]->SetPoint(QPointF(cp1.x, cp1.y));
gizmo_bezier_lines_[i*2]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp1.x, cp1.y)));
gizmo_bezier_handles_[i*2+1]->SetPoint(QPointF(cp2.x, cp2.y));
gizmo_bezier_lines_[i*2+1]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp2.x, cp2.y)));
}
}
gizmo_bezier_handles_[i * 2]->SetPoint(QPointF(cp1.x, cp1.y));
gizmo_bezier_lines_[i * 2]->SetLine(
QLineF(QPointF(main.x, main.y), QPointF(cp1.x, cp1.y)));
gizmo_bezier_handles_[i * 2 + 1]->SetPoint(QPointF(cp2.x, cp2.y));
gizmo_bezier_lines_[i * 2 + 1]->SetLine(
QLineF(QPointF(main.x, main.y), QPointF(cp2.x, cp2.y)));
}
}
poly_gizmo_->SetPath(GeneratePath(points, pts_sz).translated(QPointF(half_res.x, half_res.y)));
poly_gizmo_->SetPath(GeneratePath(points, pts_sz)
.translated(QPointF(half_res.x, half_res.y)));
}
ShaderCode PolygonGenerator::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("rgb")) {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/rgb.frag"));
} else {
return super::GetShaderCode(request);
}
if (request.id == QStringLiteral("rgb")) {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/rgb.frag"));
} else {
return super::GetShaderCode(request);
}
}
void PolygonGenerator::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void PolygonGenerator::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
if (gizmo == poly_gizmo_) {
// FIXME: Drag all points
} else {
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
if (gizmo == poly_gizmo_) {
// FIXME: Drag all points
} else {
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
}
}
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after)
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before,
const Bezier &after)
{
Imath::V2d a = before.to_vec() + before.control_point_2_to_vec();
Imath::V2d b = after.to_vec() + after.control_point_1_to_vec();
Imath::V2d c = after.to_vec();
Imath::V2d a = before.to_vec() + before.control_point_2_to_vec();
Imath::V2d b = after.to_vec() + after.control_point_1_to_vec();
Imath::V2d c = after.to_vec();
path->cubicTo(QPointF(a.x, a.y), QPointF(b.x, b.y), QPointF(c.x, c.y));
path->cubicTo(QPointF(a.x, a.y), QPointF(b.x, b.y), QPointF(c.x, c.y));
}
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points, int size)
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points,
int size)
{
QPainterPath path;
QPainterPath path;
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
Imath::V2d v = first_pt.to_vec();
path.moveTo(QPointF(v.x, v.y));
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
Imath::V2d v = first_pt.to_vec();
path.moveTo(QPointF(v.x, v.y));
for (int i=1; i<size; i++) {
AddPointToPath(&path, points.at(i-1).toBezier(), points.at(i).toBezier());
}
for (int i = 1; i < size; i++) {
AddPointToPath(&path, points.at(i - 1).toBezier(),
points.at(i).toBezier());
}
AddPointToPath(&path, points.at(size-1).toBezier(), first_pt);
}
AddPointToPath(&path, points.at(size - 1).toBezier(), first_pt);
}
return path;
return path;
}
}
+35 -30
View File
@@ -30,56 +30,61 @@
#include "node/node.h"
#include "node/inputdragger.h"
namespace olive {
class PolygonGenerator : public GeneratorWithMerge
namespace olive
{
Q_OBJECT
class PolygonGenerator : public GeneratorWithMerge {
Q_OBJECT
public:
PolygonGenerator();
PolygonGenerator();
NODE_DEFAULT_FUNCTIONS(PolygonGenerator)
NODE_DEFAULT_FUNCTIONS(PolygonGenerator)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kPointsInput;
static const QString kColorInput;
static const QString kPointsInput;
static const QString kColorInput;
protected:
ShaderJob GetGenerateJob(const NodeValueRow &value, const VideoParams &params) const;
ShaderJob GetGenerateJob(const NodeValueRow &value,
const VideoParams &params) const;
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
static void AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after);
static void AddPointToPath(QPainterPath *path, const Bezier &before,
const Bezier &after);
static QPainterPath GeneratePath(const NodeValueArray &points, int size);
static QPainterPath GeneratePath(const NodeValueArray &points, int size);
template<typename T>
void ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz);
template <typename T>
void ValidateGizmoVectorSize(QVector<T *> &vec, int new_sz);
template<typename T>
NodeGizmo *CreateAppropriateGizmo();
PathGizmo *poly_gizmo_;
QVector<PointGizmo*> gizmo_position_handles_;
QVector<PointGizmo*> gizmo_bezier_handles_;
QVector<LineGizmo*> gizmo_bezier_lines_;
template <typename T> NodeGizmo *CreateAppropriateGizmo();
PathGizmo *poly_gizmo_;
QVector<PointGizmo *> gizmo_position_handles_;
QVector<PointGizmo *> gizmo_bezier_handles_;
QVector<LineGizmo *> gizmo_bezier_lines_;
};
}
+28 -22
View File
@@ -22,7 +22,8 @@
#include "node/math/merge/merge.h"
namespace olive {
namespace olive
{
#define super Node
@@ -30,42 +31,47 @@ const QString GeneratorWithMerge::kBaseInput = QStringLiteral("base_in");
GeneratorWithMerge::GeneratorWithMerge()
{
AddInput(kBaseInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
SetEffectInput(kBaseInput);
SetFlag(kVideoEffect);
AddInput(kBaseInput, NodeValue::kTexture,
InputFlags(kInputFlagNotKeyframable));
SetEffectInput(kBaseInput);
SetFlag(kVideoEffect);
}
void GeneratorWithMerge::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kBaseInput, tr("Base"));
SetInputName(kBaseInput, tr("Base"));
}
ShaderCode GeneratorWithMerge::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
}
if (request.id == QStringLiteral("mrg")) {
return ShaderCode(
FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
}
return ShaderCode();
return ShaderCode();
}
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const
void GeneratorWithMerge::PushMergableJob(const NodeValueRow &value,
TexturePtr job,
NodeValueTable *table) const
{
if (TexturePtr base = value[kBaseInput].toTexture()) {
// Push as merge node
ShaderJob merge;
if (TexturePtr base = value[kBaseInput].toTexture()) {
// Push as merge node
ShaderJob merge;
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
merge.Insert(MergeNode::kBlendIn, NodeValue(NodeValue::kTexture, job, this));
merge.SetShaderID(QStringLiteral("mrg"));
merge.Insert(MergeNode::kBaseIn, value[kBaseInput]);
merge.Insert(MergeNode::kBlendIn,
NodeValue(NodeValue::kTexture, job, this));
table->Push(NodeValue::kTexture, base->toJob(merge), this);
} else {
// Just push generate job
table->Push(NodeValue::kTexture, job, this);
}
table->Push(NodeValue::kTexture, base->toJob(merge), this);
} else {
// Just push generate job
table->Push(NodeValue::kTexture, job, this);
}
}
}
+11 -10
View File
@@ -23,23 +23,24 @@
#include "node/node.h"
namespace olive {
class GeneratorWithMerge : public Node
namespace olive
{
Q_OBJECT
class GeneratorWithMerge : public Node {
Q_OBJECT
public:
GeneratorWithMerge();
GeneratorWithMerge();
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kBaseInput;
static const QString kBaseInput;
protected:
void PushMergableJob(const NodeValueRow &value, TexturePtr job, NodeValueTable *table) const;
void PushMergableJob(const NodeValueRow &value, TexturePtr job,
NodeValueTable *table) const;
};
}
+40 -28
View File
@@ -20,7 +20,8 @@
#include "shapenode.h"
namespace olive {
namespace olive
{
#define super ShapeNodeBase
@@ -29,70 +30,81 @@ QString ShapeNode::kRadiusInput = QStringLiteral("radius_in");
ShapeNode::ShapeNode()
{
PrependInput(kTypeInput, NodeValue::kCombo);
PrependInput(kTypeInput, NodeValue::kCombo);
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
AddInput(kRadiusInput, NodeValue::kFloat, 20.0);
SetInputProperty(kRadiusInput, QStringLiteral("min"), 0.0);
}
QString ShapeNode::Name() const
{
return tr("Shape");
return tr("Shape");
}
QString ShapeNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.shape");
return QStringLiteral("org.olivevideoeditor.Olive.shape");
}
QVector<Node::CategoryID> ShapeNode::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString ShapeNode::Description() const
{
return tr("Generate a 2D primitive shape.");
return tr("Generate a 2D primitive shape.");
}
void ShapeNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTypeInput, tr("Type"));
SetInputName(kRadiusInput, tr("Radius"));
SetInputName(kTypeInput, tr("Type"));
SetInputName(kRadiusInput, tr("Radius"));
// Coordinate with Type enum
SetComboBoxStrings(kTypeInput, {tr("Rectangle"), tr("Ellipse"), tr("Rounded Rectangle")});
// Coordinate with Type enum
SetComboBoxStrings(kTypeInput, { tr("Rectangle"), tr("Ellipse"),
tr("Rounded Rectangle") });
}
ShaderCode ShapeNode::GetShaderCode(const ShaderRequest &request) const
{
if (request.id == QStringLiteral("shape")) {
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/shape.frag")));
} else {
return super::GetShaderCode(request);
}
if (request.id == QStringLiteral("shape")) {
return ShaderCode(FileFunctions::ReadFileAsString(
QStringLiteral(":/shaders/shape.frag")));
} else {
return super::GetShaderCode(request);
}
}
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
TexturePtr base = value[kBaseInput].toTexture();
TexturePtr base = value[kBaseInput].toTexture();
ShaderJob job(value);
ShaderJob job(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, base ? base->virtual_resolution() : globals.square_resolution(), this));
job.SetShaderID(QStringLiteral("shape"));
job.Insert(QStringLiteral("resolution_in"),
NodeValue(NodeValue::kVec2,
base ? base->virtual_resolution() :
globals.square_resolution(),
this));
job.SetShaderID(QStringLiteral("shape"));
PushMergableJob(value, Texture::Job(base ? base->params() : globals.vparams(), job), table);
PushMergableJob(
value, Texture::Job(base ? base->params() : globals.vparams(), job),
table);
}
void ShapeNode::InputValueChangedEvent(const QString &input, int element)
{
if (input == kTypeInput) {
SetInputFlag(kRadiusInput, kInputFlagHidden, (GetStandardValue(kTypeInput).toInt() != kRoundedRectangle));
}
super::InputValueChangedEvent(input, element);
if (input == kTypeInput) {
SetInputFlag(kRadiusInput, kInputFlagHidden,
(GetStandardValue(kTypeInput).toInt() !=
kRoundedRectangle));
}
super::InputValueChangedEvent(input, element);
}
}
+20 -22
View File
@@ -23,38 +23,36 @@
#include "shapenodebase.h"
namespace olive {
class ShapeNode : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class ShapeNode : public ShapeNodeBase {
Q_OBJECT
public:
ShapeNode();
ShapeNode();
enum Type {
kRectangle,
kEllipse,
kRoundedRectangle
};
enum Type { kRectangle, kEllipse, kRoundedRectangle };
NODE_DEFAULT_FUNCTIONS(ShapeNode)
NODE_DEFAULT_FUNCTIONS(ShapeNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
static QString kTypeInput;
static QString kRadiusInput;
static QString kTypeInput;
static QString kRadiusInput;
protected:
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
};
}
+238 -200
View File
@@ -27,7 +27,8 @@
#include "core.h"
#include "node/nodeundo.h"
namespace olive {
namespace olive
{
#define super GeneratorWithMerge
@@ -37,287 +38,324 @@ const QString ShapeNodeBase::kColorInput = QStringLiteral("color_in");
ShapeNodeBase::ShapeNodeBase(bool create_color_input)
{
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
AddInput(kPositionInput, NodeValue::kVec2, QVector2D(0, 0));
AddInput(kSizeInput, NodeValue::kVec2, QVector2D(100, 100));
SetInputProperty(kSizeInput, QStringLiteral("min"), QVector2D(0, 0));
if (create_color_input) {
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
}
if (create_color_input) {
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0, 0.0, 0.0, 1.0)));
}
// Initiate gizmos
QVector<NodeKeyframeTrackReference> pos_n_sz = {
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
};
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
for (int i=0; i<kGizmoScaleCount; i++) {
point_gizmo_[i] = AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
}
// Initiate gizmos
QVector<NodeKeyframeTrackReference> pos_n_sz = {
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kSizeInput), 1)
};
poly_gizmo_ = AddDraggableGizmo<PolygonGizmo>({
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 0),
NodeKeyframeTrackReference(NodeInput(this, kPositionInput), 1),
});
for (int i = 0; i < kGizmoScaleCount; i++) {
point_gizmo_[i] =
AddDraggableGizmo<PointGizmo>(pos_n_sz, PointGizmo::kAbsolute);
}
}
void ShapeNodeBase::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kPositionInput, tr("Position"));
SetInputName(kSizeInput, tr("Size"));
SetInputName(kPositionInput, tr("Position"));
SetInputName(kSizeInput, tr("Size"));
if (HasInputWithID(kColorInput)) {
SetInputName(kColorInput, tr("Color"));
}
if (HasInputWithID(kColorInput)) {
SetInputName(kColorInput, tr("Color"));
}
}
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
QVector2D center_pt = globals.square_resolution() * 0.5;
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
QVector2D center_pt = globals.square_resolution() * 0.5;
SetInputProperty(kPositionInput, QStringLiteral("offset"), center_pt);
QVector2D pos = row[kPositionInput].toVec2();
QVector2D sz = row[kSizeInput].toVec2();
QVector2D half_sz = sz * 0.5;
QVector2D pos = row[kPositionInput].toVec2();
QVector2D sz = row[kSizeInput].toVec2();
QVector2D half_sz = sz * 0.5;
double left_pt = pos.x() + center_pt.x() - half_sz.x();
double top_pt = pos.y() + center_pt.y() - half_sz.y();
double right_pt = left_pt + sz.x();
double bottom_pt = top_pt + sz.y();
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
double left_pt = pos.x() + center_pt.x() - half_sz.x();
double top_pt = pos.y() + center_pt.y() - half_sz.y();
double right_pt = left_pt + sz.x();
double bottom_pt = top_pt + sz.y();
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(QPointF(right_pt, center_y_pt));
point_gizmo_[kGizmoScaleTopLeft]->SetPoint(QPointF(left_pt, top_pt));
point_gizmo_[kGizmoScaleTopCenter]->SetPoint(QPointF(center_x_pt, top_pt));
point_gizmo_[kGizmoScaleTopRight]->SetPoint(QPointF(right_pt, top_pt));
point_gizmo_[kGizmoScaleBottomLeft]->SetPoint(QPointF(left_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomCenter]->SetPoint(
QPointF(center_x_pt, bottom_pt));
point_gizmo_[kGizmoScaleBottomRight]->SetPoint(
QPointF(right_pt, bottom_pt));
point_gizmo_[kGizmoScaleCenterLeft]->SetPoint(
QPointF(left_pt, center_y_pt));
point_gizmo_[kGizmoScaleCenterRight]->SetPoint(
QPointF(right_pt, center_y_pt));
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
poly_gizmo_->SetPolygon(
QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
}
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command)
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res,
MultiUndoCommand *command)
{
// Normalize around center of sequence
rect.translate(-sequence_res.width()*0.5, -sequence_res.height()*0.5);
rect.translate(rect.width()*0.5, rect.height()*0.5);
// Normalize around center of sequence
rect.translate(-sequence_res.width() * 0.5, -sequence_res.height() * 0.5);
rect.translate(rect.width() * 0.5, rect.height() * 0.5);
NodeInput pos(this, ShapeNodeBase::kPositionInput);
NodeInput sz(this, ShapeNodeBase::kSizeInput);
NodeInput pos(this, ShapeNodeBase::kPositionInput);
NodeInput sz(this, ShapeNodeBase::kSizeInput);
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 1), rect.y()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(
NodeKeyframeTrackReference(pos, 1), rect.y()));
}
void ShapeNodeBase::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void ShapeNodeBase::GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
DraggableGizmo *gizmo = static_cast<DraggableGizmo *>(sender());
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
NodeInputDragger &x_drag = gizmo->GetDraggers()[0];
NodeInputDragger &y_drag = gizmo->GetDraggers()[1];
if (gizmo == poly_gizmo_) {
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
} else {
bool from_center = modifiers & Qt::AltModifier;
bool keep_ratio = modifiers & Qt::ShiftModifier;
if (gizmo == poly_gizmo_) {
x_drag.Drag(x_drag.GetStartValue().toDouble() + x);
y_drag.Drag(y_drag.GetStartValue().toDouble() + y);
} else {
bool from_center = modifiers & Qt::AltModifier;
bool keep_ratio = modifiers & Qt::ShiftModifier;
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
NodeInputDragger &w_drag = gizmo->GetDraggers()[2];
NodeInputDragger &h_drag = gizmo->GetDraggers()[3];
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(), h_drag.GetStartValue().toDouble());
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(), y_drag.GetStartValue().toDouble());
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution()/2;
QVector2D adjusted_pt(x, y);
QVector2D new_size;
QVector2D new_pos;
QVector2D anchor;
static const int kXYCount = 2;
bool negative[kXYCount] = {false};
QVector2D gizmo_sz_start(w_drag.GetStartValue().toDouble(),
h_drag.GetStartValue().toDouble());
QVector2D gizmo_pos_start(x_drag.GetStartValue().toDouble(),
y_drag.GetStartValue().toDouble());
QVector2D gizmo_half_res = gizmo->GetGlobals().square_resolution() / 2;
QVector2D adjusted_pt(x, y);
QVector2D new_size;
QVector2D new_pos;
QVector2D anchor;
static const int kXYCount = 2;
bool negative[kXYCount] = { false };
double original_ratio;
if (keep_ratio) {
original_ratio = w_drag.GetStartValue().toDouble() / h_drag.GetStartValue().toDouble();
}
double original_ratio;
if (keep_ratio) {
original_ratio = w_drag.GetStartValue().toDouble() /
h_drag.GetStartValue().toDouble();
}
// Calculate new size
if (from_center) {
// Calculate new size by using distance from center and doubling it
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
// Calculate new size
if (from_center) {
// Calculate new size by using distance from center and doubling it
new_size = (adjusted_pt - gizmo_half_res - gizmo_pos_start) * 2;
if (IsGizmoTop(gizmo)) {
new_size.setY(-new_size.y());
}
if (IsGizmoTop(gizmo)) {
new_size.setY(-new_size.y());
}
if (IsGizmoLeft(gizmo)) {
new_size.setX(-new_size.x());
}
} else {
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
// from the gizmo being dragged
adjusted_pt -= gizmo_half_res;
if (IsGizmoLeft(gizmo)) {
new_size.setX(-new_size.x());
}
} else {
// Calculate new size by using distance from "anchor" - i.e. the opposite point of the shape
// from the gizmo being dragged
adjusted_pt -= gizmo_half_res;
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo, &adjusted_pt) + gizmo_half_res;
anchor = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo,
&adjusted_pt) +
gizmo_half_res;
adjusted_pt += gizmo_half_res;
adjusted_pt += gizmo_half_res;
// Calculate size and position
new_size = adjusted_pt - anchor;
// Calculate size and position
new_size = adjusted_pt - anchor;
// Abs size so neither coord is negative
for (int i=0; i<kXYCount; i++) {
if (new_size[i] < 0) {
negative[i] = true;
new_size[i] = -new_size[i];
}
}
}
// Abs size so neither coord is negative
for (int i = 0; i < kXYCount; i++) {
if (new_size[i] < 0) {
negative[i] = true;
new_size[i] = -new_size[i];
}
}
}
// Restrict sizes by constraints
if (IsGizmoVerticalCenter(gizmo)) {
if (keep_ratio) {
// Calculate width from new height
new_size.setX(new_size.y() * original_ratio);
} else {
// Constrain to original width
new_size.setX(gizmo_sz_start.x());
}
}
// Restrict sizes by constraints
if (IsGizmoVerticalCenter(gizmo)) {
if (keep_ratio) {
// Calculate width from new height
new_size.setX(new_size.y() * original_ratio);
} else {
// Constrain to original width
new_size.setX(gizmo_sz_start.x());
}
}
if (IsGizmoHorizontalCenter(gizmo)) {
if (keep_ratio) {
// Calculate height from new width
new_size.setY(new_size.x() / original_ratio);
} else {
// Constrain to original height
new_size.setY(gizmo_sz_start.y());
}
}
if (IsGizmoHorizontalCenter(gizmo)) {
if (keep_ratio) {
// Calculate height from new width
new_size.setY(new_size.x() / original_ratio);
} else {
// Constrain to original height
new_size.setY(gizmo_sz_start.y());
}
}
if (IsGizmoCorner(gizmo)) {
if (keep_ratio) {
float hypot = std::hypot(new_size.x(), new_size.y());
if (IsGizmoCorner(gizmo)) {
if (keep_ratio) {
float hypot = std::hypot(new_size.x(), new_size.y());
float original_angle = std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
float original_angle =
std::atan2(gizmo_sz_start.x(), gizmo_sz_start.y());
// Calculate new size based on original angle and hypotenuse
new_size.setX(std::sin(original_angle) * hypot);
new_size.setY(std::cos(original_angle) * hypot);
}
}
// Calculate new size based on original angle and hypotenuse
new_size.setX(std::sin(original_angle) * hypot);
new_size.setY(std::cos(original_angle) * hypot);
}
}
// Calculate position
if (from_center) {
new_pos = gizmo_pos_start;
} else {
QVector2D using_size = new_size;
// Calculate position
if (from_center) {
new_pos = gizmo_pos_start;
} else {
QVector2D using_size = new_size;
// Un-abs size
for (int i=0; i<kXYCount; i++) {
if (negative[i]) {
using_size[i] = -using_size[i];
}
}
// Un-abs size
for (int i = 0; i < kXYCount; i++) {
if (negative[i]) {
using_size[i] = -using_size[i];
}
}
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
if (IsGizmoHorizontalCenter(gizmo)) {
using_size.setY(0);
}
// I'm pretty sure there's an algorithmic way of doing this, but I'm tired and this works
if (IsGizmoHorizontalCenter(gizmo)) {
using_size.setY(0);
}
if (IsGizmoVerticalCenter(gizmo)) {
using_size.setX(0);
}
if (IsGizmoVerticalCenter(gizmo)) {
using_size.setX(0);
}
new_pos = GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) + using_size / 2;
}
new_pos =
GenerateGizmoAnchor(gizmo_pos_start, gizmo_sz_start, gizmo) +
using_size / 2;
}
x_drag.Drag(new_pos.x());
y_drag.Drag(new_pos.y());
w_drag.Drag(new_size.x());
h_drag.Drag(new_size.y());
}
x_drag.Drag(new_pos.x());
y_drag.Drag(new_pos.y());
w_drag.Drag(new_size.x());
h_drag.Drag(new_size.y());
}
}
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt) const
QVector2D ShapeNodeBase::GenerateGizmoAnchor(const QVector2D &pos,
const QVector2D &size,
NodeGizmo *gizmo,
QVector2D *pt) const
{
QVector2D anchor = pos;
QVector2D half_sz = size/2;
QVector2D anchor = pos;
QVector2D half_sz = size / 2;
if (IsGizmoLeft(gizmo)) {
anchor.setX(anchor.x() + half_sz.x());
if (pt && pt->x() > anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoLeft(gizmo)) {
anchor.setX(anchor.x() + half_sz.x());
if (pt && pt->x() > anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoRight(gizmo)) {
anchor.setX(anchor.x() - half_sz.x());
if (pt && pt->x() < anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoRight(gizmo)) {
anchor.setX(anchor.x() - half_sz.x());
if (pt && pt->x() < anchor.x()) {
pt->setX(anchor.x());
}
}
if (IsGizmoTop(gizmo)) {
anchor.setY(anchor.y() + half_sz.y());
if (pt && pt->y() > anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoTop(gizmo)) {
anchor.setY(anchor.y() + half_sz.y());
if (pt && pt->y() > anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoBottom(gizmo)) {
anchor.setY(anchor.y() - half_sz.y());
if (pt && pt->y() < anchor.y()) {
pt->setY(anchor.y());
}
}
if (IsGizmoBottom(gizmo)) {
anchor.setY(anchor.y() - half_sz.y());
if (pt && pt->y() < anchor.y()) {
pt->setY(anchor.y());
}
}
return anchor;
return anchor;
}
bool ShapeNodeBase::IsGizmoTop(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight];
return g == point_gizmo_[kGizmoScaleTopCenter] ||
g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleTopRight];
}
bool ShapeNodeBase::IsGizmoBottom(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleBottomCenter] || g == point_gizmo_[kGizmoScaleBottomLeft] || g == point_gizmo_[kGizmoScaleBottomRight];
return g == point_gizmo_[kGizmoScaleBottomCenter] ||
g == point_gizmo_[kGizmoScaleBottomLeft] ||
g == point_gizmo_[kGizmoScaleBottomRight];
}
bool ShapeNodeBase::IsGizmoLeft(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleBottomLeft];
return g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleCenterLeft] ||
g == point_gizmo_[kGizmoScaleBottomLeft];
}
bool ShapeNodeBase::IsGizmoRight(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopRight] || g == point_gizmo_[kGizmoScaleCenterRight] || g == point_gizmo_[kGizmoScaleBottomRight];
return g == point_gizmo_[kGizmoScaleTopRight] ||
g == point_gizmo_[kGizmoScaleCenterRight] ||
g == point_gizmo_[kGizmoScaleBottomRight];
}
bool ShapeNodeBase::IsGizmoHorizontalCenter(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleCenterLeft] || g == point_gizmo_[kGizmoScaleCenterRight];
return g == point_gizmo_[kGizmoScaleCenterLeft] ||
g == point_gizmo_[kGizmoScaleCenterRight];
}
bool ShapeNodeBase::IsGizmoVerticalCenter(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopCenter] || g == point_gizmo_[kGizmoScaleBottomCenter];
return g == point_gizmo_[kGizmoScaleTopCenter] ||
g == point_gizmo_[kGizmoScaleBottomCenter];
}
bool ShapeNodeBase::IsGizmoCorner(NodeGizmo *g) const
{
return g == point_gizmo_[kGizmoScaleTopLeft] || g == point_gizmo_[kGizmoScaleTopRight]
|| g == point_gizmo_[kGizmoScaleBottomRight] || g == point_gizmo_[kGizmoScaleBottomLeft];
return g == point_gizmo_[kGizmoScaleTopLeft] ||
g == point_gizmo_[kGizmoScaleTopRight] ||
g == point_gizmo_[kGizmoScaleBottomRight] ||
g == point_gizmo_[kGizmoScaleBottomLeft];
}
}
+33 -29
View File
@@ -27,49 +27,53 @@
#include "node/inputdragger.h"
#include "node/node.h"
namespace olive {
class ShapeNodeBase : public GeneratorWithMerge
namespace olive
{
Q_OBJECT
class ShapeNodeBase : public GeneratorWithMerge {
Q_OBJECT
public:
ShapeNodeBase(bool create_color_input = true);
ShapeNodeBase(bool create_color_input = true);
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
void SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command);
void SetRect(QRectF rect, const VideoParams &sequence_res,
MultiUndoCommand *command);
static const QString kPositionInput;
static const QString kSizeInput;
static const QString kColorInput;
static const QString kPositionInput;
static const QString kSizeInput;
static const QString kColorInput;
protected:
PolygonGizmo *poly_gizmo() const
{
return poly_gizmo_;
}
PolygonGizmo *poly_gizmo() const
{
return poly_gizmo_;
}
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
virtual void GizmoDragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers) override;
private:
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size, NodeGizmo *gizmo, QVector2D *pt = nullptr) const;
QVector2D GenerateGizmoAnchor(const QVector2D &pos, const QVector2D &size,
NodeGizmo *gizmo,
QVector2D *pt = nullptr) const;
bool IsGizmoTop(NodeGizmo *g) const;
bool IsGizmoBottom(NodeGizmo *g) const;
bool IsGizmoLeft(NodeGizmo *g) const;
bool IsGizmoRight(NodeGizmo *g) const;
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
bool IsGizmoCorner(NodeGizmo *g) const;
// Gizmo variables
static const int kGizmoWholeRect = kGizmoScaleCount;
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
bool IsGizmoTop(NodeGizmo *g) const;
bool IsGizmoBottom(NodeGizmo *g) const;
bool IsGizmoLeft(NodeGizmo *g) const;
bool IsGizmoRight(NodeGizmo *g) const;
bool IsGizmoHorizontalCenter(NodeGizmo *g) const;
bool IsGizmoVerticalCenter(NodeGizmo *g) const;
bool IsGizmoCorner(NodeGizmo *g) const;
// Gizmo variables
static const int kGizmoWholeRect = kGizmoScaleCount;
PointGizmo *point_gizmo_[kGizmoScaleCount];
PolygonGizmo *poly_gizmo_;
};
}
+18 -13
View File
@@ -20,7 +20,8 @@
#include "solid.h"
namespace olive {
namespace olive
{
const QString SolidGenerator::kColorInput = QStringLiteral("color_in");
@@ -28,47 +29,51 @@ const QString SolidGenerator::kColorInput = QStringLiteral("color_in");
SolidGenerator::SolidGenerator()
{
// Default to a color that isn't black
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 0.0f, 0.0f, 1.0f)));
// Default to a color that isn't black
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0f, 0.0f, 0.0f, 1.0f)));
}
QString SolidGenerator::Name() const
{
return tr("Solid");
return tr("Solid");
}
QString SolidGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.solidgenerator");
return QStringLiteral("org.olivevideoeditor.Olive.solidgenerator");
}
QVector<Node::CategoryID> SolidGenerator::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString SolidGenerator::Description() const
{
return tr("Generate a solid color.");
return tr("Generate a solid color.");
}
void SolidGenerator::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kColorInput, tr("Color"));
SetInputName(kColorInput, tr("Color"));
}
void SolidGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void SolidGenerator::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
table->Push(NodeValue::kTexture, Texture::Job(globals.vparams(), ShaderJob(value)), this);
table->Push(NodeValue::kTexture,
Texture::Job(globals.vparams(), ShaderJob(value)), this);
}
ShaderCode SolidGenerator::GetShaderCode(const ShaderRequest &request) const
{
Q_UNUSED(request)
Q_UNUSED(request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag"));
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/solid.frag"));
}
}
+16 -15
View File
@@ -23,28 +23,29 @@
#include "node/node.h"
namespace olive {
class SolidGenerator : public Node
namespace olive
{
Q_OBJECT
class SolidGenerator : public Node {
Q_OBJECT
public:
SolidGenerator();
SolidGenerator();
NODE_DEFAULT_FUNCTIONS(SolidGenerator)
NODE_DEFAULT_FUNCTIONS(SolidGenerator)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
static const QString kColorInput;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual ShaderCode
GetShaderCode(const ShaderRequest &request) const override;
static const QString kColorInput;
};
}
+96 -85
View File
@@ -23,12 +23,13 @@
#include <QAbstractTextDocumentLayout>
#include <QTextDocument>
namespace olive {
namespace olive
{
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV1::kTextInput = QStringLiteral("text_in");
@@ -42,132 +43,142 @@ const QString TextGeneratorV1::kFontSizeInput = QStringLiteral("font_size_in");
TextGeneratorV1::TextGeneratorV1()
{
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
AddInput(kColorInput, NodeValue::kColor,
QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
AddInput(kVAlignInput, NodeValue::kCombo, 1);
AddInput(kVAlignInput, NodeValue::kCombo, 1);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
SetFlag(kDontShowInCreateMenu);
SetFlag(kDontShowInCreateMenu);
}
QString TextGeneratorV1::Name() const
{
return tr("Text (Legacy)");
return tr("Text (Legacy)");
}
QString TextGeneratorV1::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
}
QVector<Node::CategoryID> TextGeneratorV1::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV1::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV1::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kColorInput, tr("Color"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
}
void TextGeneratorV1::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV1::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (!value[kTextInput].toString().isEmpty()) {
table->Push(NodeValue::kTexture, Texture::Job(globals.vparams(), GenerateJob(value)), this);
}
if (!value[kTextInput].toString().isEmpty()) {
table->Push(NodeValue::kTexture,
Texture::Job(globals.vparams(), GenerateJob(value)), this);
}
}
void TextGeneratorV1::GenerateFrame(FramePtr frame, const GenerateJob& job) const
void TextGeneratorV1::GenerateFrame(FramePtr frame,
const GenerateJob &job) const
{
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(0);
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(0);
QTextDocument text_doc;
QTextDocument text_doc;
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Center by default
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
// Center by default
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
// Align to 80% width because that's considered the "title safe" area
int tenth_of_width = frame->video_params().width() / 10;
text_doc.setTextWidth(tenth_of_width * 8);
// Align to 80% width because that's considered the "title safe" area
int tenth_of_width = frame->video_params().width() / 10;
text_doc.setTextWidth(tenth_of_width * 8);
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(),
1.0 / frame->video_params().divider());
// Push 10% inwards to compensate for title safe area
p.translate(tenth_of_width, 0);
// Push 10% inwards to compensate for title safe area
p.translate(tenth_of_width, 0);
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
TextVerticalAlign valign =
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
switch (valign) {
case kVerticalAlignTop:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() / 10);
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() - doc_height - frame->video_params().height() / 10);
break;
}
switch (valign) {
case kVerticalAlignTop:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() / 10);
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() - doc_height -
frame->video_params().height() / 10);
break;
}
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
// Transplant alpha channel to frame
Color rgb = job.Get(kColorInput).toColor();
for (int x=0; x<frame->width(); x++) {
for (int y=0; y<frame->height(); y++) {
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
float alpha = float(src_alpha) / 255.0f;
// Transplant alpha channel to frame
Color rgb = job.Get(kColorInput).toColor();
for (int x = 0; x < frame->width(); x++) {
for (int y = 0; y < frame->height(); y++) {
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
float alpha = float(src_alpha) / 255.0f;
frame->set_pixel(x, y, Color(rgb.red() * alpha, rgb.green() * alpha, rgb.blue() * alpha, alpha));
}
}
frame->set_pixel(x, y,
Color(rgb.red() * alpha, rgb.green() * alpha,
rgb.blue() * alpha, alpha));
}
}
}
}
+21 -20
View File
@@ -23,34 +23,35 @@
#include "node/node.h"
namespace olive {
class TextGeneratorV1 : public Node
namespace olive
{
Q_OBJECT
class TextGeneratorV1 : public Node {
Q_OBJECT
public:
TextGeneratorV1();
TextGeneratorV1();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kColorInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kColorInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
};
}
+107 -100
View File
@@ -25,14 +25,15 @@
#include <QDateTime>
#include <QTextDocument>
namespace olive {
namespace olive
{
#define super ShapeNodeBase
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV2::kTextInput = QStringLiteral("text_in");
@@ -43,156 +44,162 @@ const QString TextGeneratorV2::kFontSizeInput = QStringLiteral("font_size_in");
TextGeneratorV2::TextGeneratorV2()
{
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kHtmlInput, NodeValue::kBoolean, false);
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontInput, NodeValue::kFont);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetFlag(kDontShowInCreateMenu);
SetFlag(kDontShowInCreateMenu);
}
QString TextGeneratorV2::Name() const
{
return tr("Text (Legacy)");
return tr("Text (Legacy)");
}
QString TextGeneratorV2::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.text2");
return QStringLiteral("org.olivevideoeditor.Olive.text2");
}
QVector<Node::CategoryID> TextGeneratorV2::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV2::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV2::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
SetInputName(kTextInput, tr("Text"));
SetInputName(kHtmlInput, tr("Enable HTML"));
SetInputName(kFontInput, tr("Font"));
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
}
void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV2::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
if (!value[kTextInput].toString().isEmpty()) {
GenerateJob job(value);
auto text_params = globals.vparams();
text_params.set_format(PixelFormat::F32);
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
}
if (!value[kTextInput].toString().isEmpty()) {
GenerateJob job(value);
auto text_params = globals.vparams();
text_params.set_format(PixelFormat::F32);
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
}
}
void TextGeneratorV2::GenerateFrame(FramePtr frame, const GenerateJob& job) const
void TextGeneratorV2::GenerateFrame(FramePtr frame,
const GenerateJob &job) const
{
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(Qt::transparent);
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
// with correct float RGB.
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
img.fill(Qt::transparent);
// 72 DPI in DPM (72 / 2.54 * 100)
const int dpm = 2835;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
// 72 DPI in DPM (72 / 2.54 * 100)
const int dpm = 2835;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
// Set default font
QFont default_font;
default_font.setFamily(job.Get(kFontInput).toString());
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
text_doc.setDefaultFont(default_font);
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QString html = job.Get(kTextInput).toString();
if (job.Get(kHtmlInput).toBool()) {
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
}
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(),
1.0 / frame->video_params().divider());
QVector2D pos = job.Get(kPositionInput).toVec2();
p.translate(pos.x() - size.x() / 2, pos.y() - size.y() / 2);
p.translate(frame->video_params().width() / 2,
frame->video_params().height() / 2);
p.setClipRect(0, 0, size.x(), size.y());
QVector2D pos = job.Get(kPositionInput).toVec2();
p.translate(pos.x() - size.x()/2, pos.y() - size.y()/2);
p.translate(frame->video_params().width()/2, frame->video_params().height()/2);
p.setClipRect(0, 0, size.x(), size.y());
TextVerticalAlign valign =
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
int doc_height = text_doc.size().height();
switch (valign) {
case kVerticalAlignTop:
// Do nothing
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, size.y() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
p.translate(0, size.y() - doc_height);
break;
}
switch (valign) {
case kVerticalAlignTop:
// Do nothing
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, size.y() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
p.translate(0, size.y() - doc_height);
break;
}
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
text_doc.documentLayout()->draw(&p, ctx);
// Transplant alpha channel to frame
Color rgba = job.Get(kColorInput).toColor();
// Transplant alpha channel to frame
Color rgba = job.Get(kColorInput).toColor();
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
__m128 sse_color = _mm_loadu_ps(rgba.data());
__m128 sse_color = _mm_loadu_ps(rgba.data());
#endif
float *frame_dst = reinterpret_cast<float*>(frame->data());
for (int y=0; y<frame->height(); y++) {
uchar *src_y = img.bits() + img.bytesPerLine() * y;
float *dst_y = frame_dst + y*frame->linesize_pixels()*VideoParams::kRGBAChannelCount;
float *frame_dst = reinterpret_cast<float *>(frame->data());
for (int y = 0; y < frame->height(); y++) {
uchar *src_y = img.bits() + img.bytesPerLine() * y;
float *dst_y = frame_dst + y * frame->linesize_pixels() *
VideoParams::kRGBAChannelCount;
for (int x=0; x<frame->width(); x++) {
float alpha = float(src_y[x]) / 255.0f;
float *dst = dst_y + x*VideoParams::kRGBAChannelCount;
for (int x = 0; x < frame->width(); x++) {
float alpha = float(src_y[x]) / 255.0f;
float *dst = dst_y + x * VideoParams::kRGBAChannelCount;
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
__m128 sse_alpha = _mm_load1_ps(&alpha);
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
__m128 sse_alpha = _mm_load1_ps(&alpha);
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
_mm_store_ps(dst, sse_res);
_mm_store_ps(dst, sse_res);
#else
for (int i=0; i<VideoParams::kRGBAChannelCount; i++) {
dst[i] = rgba.data()[i] * alpha;
}
for (int i = 0; i < VideoParams::kRGBAChannelCount; i++) {
dst[i] = rgba.data()[i] * alpha;
}
#endif
}
}
}
}
}
}
+20 -19
View File
@@ -23,33 +23,34 @@
#include "node/generator/shape/shapenodebase.h"
namespace olive {
class TextGeneratorV2 : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class TextGeneratorV2 : public ShapeNodeBase {
Q_OBJECT
public:
TextGeneratorV2();
TextGeneratorV2();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
static const QString kTextInput;
static const QString kHtmlInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
};
}
+182 -154
View File
@@ -29,253 +29,281 @@
#include "node/project.h"
#include "node/nodeundo.h"
namespace olive {
namespace olive
{
#define super ShapeNodeBase
enum TextVerticalAlign {
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
kVerticalAlignTop,
kVerticalAlignCenter,
kVerticalAlignBottom,
};
const QString TextGeneratorV3::kTextInput = QStringLiteral("text_in");
const QString TextGeneratorV3::kVerticalAlignmentInput = QStringLiteral("valign_in");
const QString TextGeneratorV3::kVerticalAlignmentInput =
QStringLiteral("valign_in");
const QString TextGeneratorV3::kUseArgsInput = QStringLiteral("use_args_in");
const QString TextGeneratorV3::kArgsInput = QStringLiteral("args_in");
TextGeneratorV3::TextGeneratorV3() :
ShapeNodeBase(false),
dont_emit_valign_(false)
TextGeneratorV3::TextGeneratorV3()
: ShapeNodeBase(false)
, dont_emit_valign_(false)
{
AddInput(kTextInput, NodeValue::kText, QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>").arg(tr("Sample Text")));
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
AddInput(kTextInput, NodeValue::kText,
QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>")
.arg(tr("Sample Text")));
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
SetStandardValue(kSizeInput, QVector2D(400, 300));
SetStandardValue(kSizeInput, QVector2D(400, 300));
AddInput(kVerticalAlignmentInput, NodeValue::kCombo, InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kVerticalAlignmentInput, NodeValue::kCombo,
InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kUseArgsInput, NodeValue::kBoolean, true, InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kUseArgsInput, NodeValue::kBoolean, true,
InputFlags(kInputFlagHidden | kInputFlagStatic));
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
text_gizmo_ = new TextGizmo(this);
text_gizmo_->SetInput(NodeInput(this, kTextInput));
connect(text_gizmo_, &TextGizmo::Activated, this, &TextGeneratorV3::GizmoActivated);
connect(text_gizmo_, &TextGizmo::Deactivated, this, &TextGeneratorV3::GizmoDeactivated);
text_gizmo_ = new TextGizmo(this);
text_gizmo_->SetInput(NodeInput(this, kTextInput));
connect(text_gizmo_, &TextGizmo::Activated, this,
&TextGeneratorV3::GizmoActivated);
connect(text_gizmo_, &TextGizmo::Deactivated, this,
&TextGeneratorV3::GizmoDeactivated);
}
QString TextGeneratorV3::Name() const
{
return tr("Text");
return tr("Text");
}
QString TextGeneratorV3::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.text3");
return QStringLiteral("org.olivevideoeditor.Olive.text3");
}
QVector<Node::CategoryID> TextGeneratorV3::Category() const
{
return {kCategoryGenerator};
return { kCategoryGenerator };
}
QString TextGeneratorV3::Description() const
{
return tr("Generate rich text.");
return tr("Generate rich text.");
}
void TextGeneratorV3::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kTextInput, tr("Text"));
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
SetComboBoxStrings(kVerticalAlignmentInput, {tr("Top"), tr("Middle"), tr("Bottom")});
SetInputName(kArgsInput, tr("Arguments"));
SetInputName(kTextInput, tr("Text"));
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
SetComboBoxStrings(kVerticalAlignmentInput,
{ tr("Top"), tr("Middle"), tr("Bottom") });
SetInputName(kArgsInput, tr("Arguments"));
}
void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TextGeneratorV3::Value(const NodeValueRow &value,
const NodeGlobals &globals,
NodeValueTable *table) const
{
QString text = value[kTextInput].toString();
QString text = value[kTextInput].toString();
if (value[kUseArgsInput].toBool()) {
auto args = value[kArgsInput].toArray();
if (!args.empty()) {
QStringList list;
list.reserve(args.size());
for (size_t i=0; i<args.size(); i++) {
list.append(args[i].toString());
}
if (value[kUseArgsInput].toBool()) {
auto args = value[kArgsInput].toArray();
if (!args.empty()) {
QStringList list;
list.reserve(args.size());
for (size_t i = 0; i < args.size(); i++) {
list.append(args[i].toString());
}
text = FormatString(text, list);
}
}
text = FormatString(text, list);
}
}
if (!text.isEmpty()) {
TexturePtr base = value[kTextInput].toTexture();
if (!text.isEmpty()) {
TexturePtr base = value[kTextInput].toTexture();
VideoParams text_params = base ? base->params() : globals.vparams();
text_params.set_format(PixelFormat::U8);
text_params.set_colorspace(project()->color_manager()->GetDefaultInputColorSpace());
VideoParams text_params = base ? base->params() : globals.vparams();
text_params.set_format(PixelFormat::U8);
text_params.set_colorspace(
project()->color_manager()->GetDefaultInputColorSpace());
GenerateJob job(value);
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
GenerateJob job(value);
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
PushMergableJob(value, Texture::Job(text_params, job), table);
} else if (value[kBaseInput].toTexture()) {
table->Push(value[kBaseInput]);
}
PushMergableJob(value, Texture::Job(text_params, job), table);
} else if (value[kBaseInput].toTexture()) {
table->Push(value[kBaseInput]);
}
}
void TextGeneratorV3::GenerateFrame(FramePtr frame, const GenerateJob& job) const
void TextGeneratorV3::GenerateFrame(FramePtr frame,
const GenerateJob &job) const
{
QImage img(reinterpret_cast<uchar*>(frame->data()), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
QImage img(reinterpret_cast<uchar *>(frame->data()), frame->width(),
frame->height(), frame->linesize_bytes(),
QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
// 96 DPI in DPM (96 / 2.54 * 100)
const int dpm = 3780;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
// 96 DPI in DPM (96 / 2.54 * 100)
const int dpm = 3780;
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
QTextDocument text_doc;
text_doc.documentLayout()->setPaintDevice(&img);
QString html = job.Get(kTextInput).toString();
Html::HtmlToDoc(&text_doc, html);
QString html = job.Get(kTextInput).toString();
Html::HtmlToDoc(&text_doc, html);
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
QVector2D size = job.Get(kSizeInput).toVec2();
text_doc.setTextWidth(size.x());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
// Draw rich text onto image
QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(),
1.0 / frame->video_params().divider());
QVector2D pos = job.Get(kPositionInput).toVec2();
p.translate(pos.x() - size.x()/2, pos.y() - size.y()/2);
p.translate(frame->video_params().width()/2, frame->video_params().height()/2);
p.setClipRect(0, 0, size.x(), size.y());
QVector2D pos = job.Get(kPositionInput).toVec2();
p.translate(pos.x() - size.x() / 2, pos.y() - size.y() / 2);
p.translate(frame->video_params().width() / 2,
frame->video_params().height() / 2);
p.setClipRect(0, 0, size.x(), size.y());
switch (static_cast<VerticalAlignment>(job.Get(kVerticalAlignmentInput).toInt())) {
case kVAlignTop:
// Do nothing
break;
case kVAlignMiddle:
p.translate(0, size.y()/2-text_doc.size().height()/2);
break;
case kVAlignBottom:
p.translate(0, size.y()-text_doc.size().height());
break;
}
switch (static_cast<VerticalAlignment>(
job.Get(kVerticalAlignmentInput).toInt())) {
case kVAlignTop:
// Do nothing
break;
case kVAlignMiddle:
p.translate(0, size.y() / 2 - text_doc.size().height() / 2);
break;
case kVAlignBottom:
p.translate(0, size.y() - text_doc.size().height());
break;
}
// Ensure default text color is white
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
// Ensure default text color is white
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, Qt::white);
text_doc.documentLayout()->draw(&p, ctx);
text_doc.documentLayout()->draw(&p, ctx);
}
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals)
{
super::UpdateGizmoPositions(row, globals);
super::UpdateGizmoPositions(row, globals);
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
text_gizmo_->SetRect(rect);
text_gizmo_->SetHtml(row[kTextInput].toString());
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
text_gizmo_->SetRect(rect);
text_gizmo_->SetHtml(row[kTextInput].toString());
}
Qt::Alignment TextGeneratorV3::GetQtAlignmentFromOurs(VerticalAlignment v)
{
switch (v) {
case kVAlignTop:
return Qt::AlignTop;
case kVAlignMiddle:
return Qt::AlignVCenter;
case kVAlignBottom:
return Qt::AlignBottom;
}
return Qt::Alignment();
switch (v) {
case kVAlignTop:
return Qt::AlignTop;
case kVAlignMiddle:
return Qt::AlignVCenter;
case kVAlignBottom:
return Qt::AlignBottom;
}
return Qt::Alignment();
}
TextGeneratorV3::VerticalAlignment TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
TextGeneratorV3::VerticalAlignment
TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
{
switch (v) {
case Qt::AlignTop:
return kVAlignTop;
case Qt::AlignVCenter:
return kVAlignMiddle;
case Qt::AlignBottom:
return kVAlignBottom;
}
switch (v) {
case Qt::AlignTop:
return kVAlignTop;
case Qt::AlignVCenter:
return kVAlignMiddle;
case Qt::AlignBottom:
return kVAlignBottom;
}
return kVAlignTop;
return kVAlignTop;
}
QString TextGeneratorV3::FormatString(const QString &input, const QStringList &args)
QString TextGeneratorV3::FormatString(const QString &input,
const QStringList &args)
{
QString output;
output.reserve(input.size());
QString output;
output.reserve(input.size());
for (int i=0; i<input.size(); i++) {
const QChar &this_char = input.at(i);
for (int i = 0; i < input.size(); i++) {
const QChar &this_char = input.at(i);
if (i < input.size()-1 && this_char == '%') {
const QChar &next_char = input.at(i+1);
if (next_char == '%') {
// Double percent, append a single percent
output.append('%');
i++;
} else if (next_char.isDigit()) {
// Find length of number
QString num;
i++;
while (i < input.size() && input.at(i).isDigit()) {
num.append(input.at(i));
i++;
}
i--;
int index = num.toInt()-1;
if (index >= 0 && index < args.size()) {
output.append(args.at(index));
}
} else {
output.append(this_char);
}
} else {
output.append(this_char);
}
}
if (i < input.size() - 1 && this_char == '%') {
const QChar &next_char = input.at(i + 1);
if (next_char == '%') {
// Double percent, append a single percent
output.append('%');
i++;
} else if (next_char.isDigit()) {
// Find length of number
QString num;
i++;
while (i < input.size() && input.at(i).isDigit()) {
num.append(input.at(i));
i++;
}
i--;
int index = num.toInt() - 1;
if (index >= 0 && index < args.size()) {
output.append(args.at(index));
}
} else {
output.append(this_char);
}
} else {
output.append(this_char);
}
}
return output;
return output;
}
void TextGeneratorV3::InputValueChangedEvent(const QString &input, int element)
{
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
text_gizmo_->SetVerticalAlignment(GetQtAlignmentFromOurs(GetVerticalAlignment()));
}
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
text_gizmo_->SetVerticalAlignment(
GetQtAlignmentFromOurs(GetVerticalAlignment()));
}
super::InputValueChangedEvent(input, element);
super::InputValueChangedEvent(input, element);
}
void TextGeneratorV3::GizmoActivated()
{
SetStandardValue(kUseArgsInput, false);
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
SetStandardValue(kUseArgsInput, false);
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
&TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
}
void TextGeneratorV3::GizmoDeactivated()
{
SetStandardValue(kUseArgsInput, true);
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
SetStandardValue(kUseArgsInput, true);
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
&TextGeneratorV3::SetVerticalAlignmentUndoable);
dont_emit_valign_ = true;
}
void TextGeneratorV3::SetVerticalAlignmentUndoable(Qt::Alignment a)
{
Core::instance()->undo_stack()->push(new NodeParamSetStandardValueCommand(NodeInput(this, kVerticalAlignmentInput), GetOurAlignmentFromQts(a)), tr("Set Text Vertical Alignment"));
Core::instance()->undo_stack()->push(
new NodeParamSetStandardValueCommand(NodeInput(this,
kVerticalAlignmentInput),
GetOurAlignmentFromQts(a)),
tr("Set Text Vertical Alignment"));
}
}
+37 -38
View File
@@ -24,64 +24,63 @@
#include "node/generator/shape/shapenodebase.h"
#include "node/gizmo/text.h"
namespace olive {
class TextGeneratorV3 : public ShapeNodeBase
namespace olive
{
Q_OBJECT
class TextGeneratorV3 : public ShapeNodeBase {
Q_OBJECT
public:
TextGeneratorV3();
TextGeneratorV3();
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
virtual void GenerateFrame(FramePtr frame,
const GenerateJob &job) const override;
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual void UpdateGizmoPositions(const NodeValueRow &row,
const NodeGlobals &globals) override;
enum VerticalAlignment
{
kVAlignTop,
kVAlignMiddle,
kVAlignBottom
};
enum VerticalAlignment { kVAlignTop, kVAlignMiddle, kVAlignBottom };
VerticalAlignment GetVerticalAlignment() const
{
return static_cast<VerticalAlignment>(GetStandardValue(kVerticalAlignmentInput).toInt());
}
VerticalAlignment GetVerticalAlignment() const
{
return static_cast<VerticalAlignment>(
GetStandardValue(kVerticalAlignmentInput).toInt());
}
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
static const QString kTextInput;
static const QString kVerticalAlignmentInput;
static const QString kUseArgsInput;
static const QString kArgsInput;
static const QString kTextInput;
static const QString kVerticalAlignmentInput;
static const QString kUseArgsInput;
static const QString kArgsInput;
static QString FormatString(const QString &input, const QStringList &args);
static QString FormatString(const QString &input, const QStringList &args);
protected:
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual void InputValueChangedEvent(const QString &input,
int element) override;
private:
TextGizmo *text_gizmo_;
TextGizmo *text_gizmo_;
bool dont_emit_valign_;
bool dont_emit_valign_;
private slots:
void GizmoActivated();
void GizmoDeactivated();
void SetVerticalAlignmentUndoable(Qt::Alignment a);
void GizmoActivated();
void GizmoDeactivated();
void SetVerticalAlignmentUndoable(Qt::Alignment a);
};
}
+16 -13
View File
@@ -20,33 +20,36 @@
#include "draggable.h"
namespace olive {
namespace olive
{
DraggableGizmo::DraggableGizmo(QObject *parent)
: NodeGizmo{parent},
drag_value_behavior_(kAbsolute)
: NodeGizmo{ parent }
, drag_value_behavior_(kAbsolute)
{
}
void DraggableGizmo::DragStart(const NodeValueRow &row, double abs_x, double abs_y, const rational &time)
void DraggableGizmo::DragStart(const NodeValueRow &row, double abs_x,
double abs_y, const rational &time)
{
for (int i=0; i<draggers_.size(); i++) {
draggers_[i].Start(inputs_[i], time);
}
for (int i = 0; i < draggers_.size(); i++) {
draggers_[i].Start(inputs_[i], time);
}
emit HandleStart(row, abs_x, abs_y, time);
emit HandleStart(row, abs_x, abs_y, time);
}
void DraggableGizmo::DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
void DraggableGizmo::DragMove(double x, double y,
const Qt::KeyboardModifiers &modifiers)
{
emit HandleMovement(x, y, modifiers);
emit HandleMovement(x, y, modifiers);
}
void DraggableGizmo::DragEnd(MultiUndoCommand *command)
{
for (int i=0; i<draggers_.size(); i++) {
draggers_[i].End(command);
}
for (int i = 0; i < draggers_.size(); i++) {
draggers_[i].End(command);
}
}
}
+42 -34
View File
@@ -25,58 +25,66 @@
#include "node/inputdragger.h"
#include "undo/undocommand.h"
namespace olive {
class DraggableGizmo : public NodeGizmo
namespace olive
{
Q_OBJECT
class DraggableGizmo : public NodeGizmo {
Q_OBJECT
public:
/// Changes what the X/Y coordinates emitted from HandleMovement specify
enum DragValueBehavior {
/// X/Y will be the exact mouse coordinates (in sequence pixels)
kAbsolute,
/// Changes what the X/Y coordinates emitted from HandleMovement specify
enum DragValueBehavior {
/// X/Y will be the exact mouse coordinates (in sequence pixels)
kAbsolute,
/// X/Y will be the movement since the last time HandleMovement was called
kDeltaFromPrevious,
/// X/Y will be the movement since the last time HandleMovement was called
kDeltaFromPrevious,
/// X/Y will be the movement from the start of the drag
kDeltaFromStart
};
/// X/Y will be the movement from the start of the drag
kDeltaFromStart
};
explicit DraggableGizmo(QObject *parent = nullptr);
explicit DraggableGizmo(QObject *parent = nullptr);
void DragStart(const NodeValueRow &row, double abs_x, double abs_y, const olive::core::rational &time);
void DragStart(const NodeValueRow &row, double abs_x, double abs_y,
const olive::core::rational &time);
void DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers);
void DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers);
void DragEnd(olive::MultiUndoCommand *command);
void DragEnd(olive::MultiUndoCommand *command);
void AddInput(const NodeKeyframeTrackReference &input)
{
inputs_.append(input);
draggers_.append(NodeInputDragger());
}
void AddInput(const NodeKeyframeTrackReference &input)
{
inputs_.append(input);
draggers_.append(NodeInputDragger());
}
QVector<NodeInputDragger> &GetDraggers()
{
return draggers_;
}
QVector<NodeInputDragger> &GetDraggers()
{
return draggers_;
}
DragValueBehavior GetDragValueBehavior() const { return drag_value_behavior_; }
void SetDragValueBehavior(DragValueBehavior d) { drag_value_behavior_ = d; }
DragValueBehavior GetDragValueBehavior() const
{
return drag_value_behavior_;
}
void SetDragValueBehavior(DragValueBehavior d)
{
drag_value_behavior_ = d;
}
signals:
void HandleStart(const olive::NodeValueRow &row, double x, double y, const olive::core::rational &time);
void HandleStart(const olive::NodeValueRow &row, double x, double y,
const olive::core::rational &time);
void HandleMovement(double x, double y, const Qt::KeyboardModifiers &modifiers);
void HandleMovement(double x, double y,
const Qt::KeyboardModifiers &modifiers);
private:
QVector<NodeKeyframeTrackReference> inputs_;
QVector<NodeKeyframeTrackReference> inputs_;
QVector<NodeInputDragger> draggers_;
DragValueBehavior drag_value_behavior_;
QVector<NodeInputDragger> draggers_;
DragValueBehavior drag_value_behavior_;
};
}
+7 -6
View File
@@ -20,17 +20,18 @@
#include "gizmo.h"
namespace olive {
NodeGizmo::NodeGizmo(QObject *parent) :
visible_(true)
namespace olive
{
setParent(parent);
NodeGizmo::NodeGizmo(QObject *parent)
: visible_(true)
{
setParent(parent);
}
NodeGizmo::~NodeGizmo()
{
setParent(nullptr);
setParent(nullptr);
}
}
+27 -14
View File
@@ -26,30 +26,43 @@
#include "node/globals.h"
namespace olive {
class NodeGizmo : public QObject
namespace olive
{
Q_OBJECT
class NodeGizmo : public QObject {
Q_OBJECT
public:
explicit NodeGizmo(QObject *parent = nullptr);
virtual ~NodeGizmo() override;
explicit NodeGizmo(QObject *parent = nullptr);
virtual ~NodeGizmo() override;
virtual void Draw(QPainter *p) const {}
virtual void Draw(QPainter *p) const
{
}
const NodeGlobals &GetGlobals() const { return globals_; }
void SetGlobals(const NodeGlobals &globals) { globals_ = globals; }
const NodeGlobals &GetGlobals() const
{
return globals_;
}
void SetGlobals(const NodeGlobals &globals)
{
globals_ = globals;
}
bool IsVisible() const { return visible_; }
void SetVisible(bool e) { visible_ = e; }
bool IsVisible() const
{
return visible_;
}
void SetVisible(bool e)
{
visible_ = e;
}
signals:
private:
NodeGlobals globals_;
bool visible_;
NodeGlobals globals_;
bool visible_;
};
}
+14 -13
View File
@@ -20,26 +20,27 @@
#include "line.h"
namespace olive {
namespace olive
{
LineGizmo::LineGizmo(QObject *parent) :
NodeGizmo(parent)
LineGizmo::LineGizmo(QObject *parent)
: NodeGizmo(parent)
{
}
void LineGizmo::Draw(QPainter *p) const
{
// Draw transposed black
QLineF transposed = p->transform().map(line_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawLine(transposed);
// Draw transposed black
QLineF transposed = p->transform().map(line_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawLine(transposed);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawLine(line_);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawLine(line_);
}
}
+15 -10
View File
@@ -25,22 +25,27 @@
#include "gizmo.h"
namespace olive {
class LineGizmo : public NodeGizmo
namespace olive
{
Q_OBJECT
class LineGizmo : public NodeGizmo {
Q_OBJECT
public:
LineGizmo(QObject *parent = nullptr);
LineGizmo(QObject *parent = nullptr);
const QLineF &GetLine() const { return line_; }
void SetLine(const QLineF &line) { line_ = line; }
const QLineF &GetLine() const
{
return line_;
}
void SetLine(const QLineF &line)
{
line_ = line;
}
virtual void Draw(QPainter *p) const override;
virtual void Draw(QPainter *p) const override;
private:
QLineF line_;
QLineF line_;
};
}
+14 -14
View File
@@ -20,27 +20,27 @@
#include "path.h"
namespace olive {
PathGizmo::PathGizmo(QObject *parent) :
DraggableGizmo{parent}
namespace olive
{
PathGizmo::PathGizmo(QObject *parent)
: DraggableGizmo{ parent }
{
}
void PathGizmo::Draw(QPainter *p) const
{
// Draw transposed black
QPainterPath transposed = p->transform().map(path_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawPath(transposed);
// Draw transposed black
QPainterPath transposed = p->transform().map(path_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawPath(transposed);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawPath(path_);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawPath(path_);
}
}
+15 -10
View File
@@ -25,22 +25,27 @@
#include "draggable.h"
namespace olive {
class PathGizmo : public DraggableGizmo
namespace olive
{
Q_OBJECT
class PathGizmo : public DraggableGizmo {
Q_OBJECT
public:
explicit PathGizmo(QObject *parent = nullptr);
explicit PathGizmo(QObject *parent = nullptr);
const QPainterPath &GetPath() const { return path_; }
void SetPath(const QPainterPath &path) { path_ = path; }
const QPainterPath &GetPath() const
{
return path_;
}
void SetPath(const QPainterPath &path)
{
path_ = path;
}
virtual void Draw(QPainter *p) const override;
virtual void Draw(QPainter *p) const override;
private:
QPainterPath path_;
QPainterPath path_;
};
}
+50 -50
View File
@@ -22,87 +22,87 @@
#include <QApplication>
namespace olive {
namespace olive
{
PointGizmo::PointGizmo(const Shape &shape, bool smaller, QObject *parent) :
DraggableGizmo{parent},
shape_(shape),
smaller_(smaller)
PointGizmo::PointGizmo(const Shape &shape, bool smaller, QObject *parent)
: DraggableGizmo{ parent }
, shape_(shape)
, smaller_(smaller)
{
}
PointGizmo::PointGizmo(const Shape &shape, QObject *parent) :
PointGizmo(shape, false, parent)
PointGizmo::PointGizmo(const Shape &shape, QObject *parent)
: PointGizmo(shape, false, parent)
{
}
PointGizmo::PointGizmo(QObject *parent) :
PointGizmo(kSquare, parent)
PointGizmo::PointGizmo(QObject *parent)
: PointGizmo(kSquare, parent)
{
}
void PointGizmo::Draw(QPainter *p) const
{
QRectF rect = GetDrawingRect(p->transform(), GetStandardRadius());
QRectF rect = GetDrawingRect(p->transform(), GetStandardRadius());
if (shape_ != kAnchorPoint) {
p->setPen(QPen(Qt::black, 0));
p->setBrush(Qt::white);
}
if (shape_ != kAnchorPoint) {
p->setPen(QPen(Qt::black, 0));
p->setBrush(Qt::white);
}
switch (shape_) {
case kSquare:
p->drawRect(rect);
break;
case kCircle:
p->drawEllipse(rect);
break;
case kAnchorPoint:
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
switch (shape_) {
case kSquare:
p->drawRect(rect);
break;
case kCircle:
p->drawEllipse(rect);
break;
case kAnchorPoint:
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawEllipse(rect);
p->drawLines({QPointF(rect.left(), rect.center().y()),
QPointF(rect.right(), rect.center().y()),
QPointF(rect.center().x(), rect.top()),
QPointF(rect.center().x(), rect.bottom())});
break;
}
p->drawEllipse(rect);
p->drawLines({ QPointF(rect.left(), rect.center().y()),
QPointF(rect.right(), rect.center().y()),
QPointF(rect.center().x(), rect.top()),
QPointF(rect.center().x(), rect.bottom()) });
break;
}
}
QRectF PointGizmo::GetClickingRect(const QTransform &t) const
{
return GetDrawingRect(t, GetStandardRadius());
return GetDrawingRect(t, GetStandardRadius());
}
double PointGizmo::GetStandardRadius()
{
return QFontMetrics(qApp->font()).height() * 0.25;
return QFontMetrics(qApp->font()).height() * 0.25;
}
QRectF PointGizmo::GetDrawingRect(const QTransform &transform, double radius) const
QRectF PointGizmo::GetDrawingRect(const QTransform &transform,
double radius) const
{
QRectF r(0,0, radius, radius);
QRectF r(0, 0, radius, radius);
r = transform.inverted().mapRect(r);
r = transform.inverted().mapRect(r);
double width = r.width();
double height = r.height();
double width = r.width();
double height = r.height();
if (shape_ == kAnchorPoint) {
width *= 2;
height *= 2;
}
if (shape_ == kAnchorPoint) {
width *= 2;
height *= 2;
}
if (smaller_) {
width *= 0.5;
height *= 0.5;
}
if (smaller_) {
width *= 0.5;
height *= 0.5;
}
return QRectF(point_.x() - width,
point_.y() - height,
2*width,
2*height);
return QRectF(point_.x() - width, point_.y() - height, 2 * width,
2 * height);
}
}
+40 -26
View File
@@ -25,46 +25,60 @@
#include "draggable.h"
namespace olive {
class PointGizmo : public DraggableGizmo
namespace olive
{
Q_OBJECT
class PointGizmo : public DraggableGizmo {
Q_OBJECT
public:
enum Shape {
kSquare,
kCircle,
kAnchorPoint
};
enum Shape { kSquare, kCircle, kAnchorPoint };
explicit PointGizmo(const Shape &shape, bool smaller, QObject *parent = nullptr);
explicit PointGizmo(const Shape &shape, QObject *parent = nullptr);
explicit PointGizmo(QObject *parent = nullptr);
explicit PointGizmo(const Shape &shape, bool smaller,
QObject *parent = nullptr);
explicit PointGizmo(const Shape &shape, QObject *parent = nullptr);
explicit PointGizmo(QObject *parent = nullptr);
const Shape &GetShape() const { return shape_; }
void SetShape(const Shape &s) { shape_ = s; }
const Shape &GetShape() const
{
return shape_;
}
void SetShape(const Shape &s)
{
shape_ = s;
}
const QPointF &GetPoint() const { return point_; }
void SetPoint(const QPointF &pt) { point_ = pt; }
const QPointF &GetPoint() const
{
return point_;
}
void SetPoint(const QPointF &pt)
{
point_ = pt;
}
bool GetSmaller() const { return smaller_; }
void SetSmaller(bool e) { smaller_ = e; }
bool GetSmaller() const
{
return smaller_;
}
void SetSmaller(bool e)
{
smaller_ = e;
}
virtual void Draw(QPainter *p) const override;
virtual void Draw(QPainter *p) const override;
QRectF GetClickingRect(const QTransform &t) const;
QRectF GetClickingRect(const QTransform &t) const;
private:
static double GetStandardRadius();
static double GetStandardRadius();
QRectF GetDrawingRect(const QTransform &transform, double radius) const;
QRectF GetDrawingRect(const QTransform &transform, double radius) const;
Shape shape_;
Shape shape_;
QPointF point_;
bool smaller_;
QPointF point_;
bool smaller_;
};
}
+13 -12
View File
@@ -20,26 +20,27 @@
#include "polygon.h"
namespace olive {
namespace olive
{
PolygonGizmo::PolygonGizmo(QObject *parent)
: DraggableGizmo{parent}
: DraggableGizmo{ parent }
{
}
void PolygonGizmo::Draw(QPainter *p) const
{
// Draw transposed black
QPolygonF transposed = p->transform().map(polygon_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawPolyline(transposed);
// Draw transposed black
QPolygonF transposed = p->transform().map(polygon_);
transposed.translate(1, 1);
transposed = p->transform().inverted().map(transposed);
p->setPen(QPen(Qt::black, 0));
p->drawPolyline(transposed);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawPolyline(polygon_);
// Draw normal white polygon
p->setPen(QPen(Qt::white, 0));
p->setBrush(Qt::NoBrush);
p->drawPolyline(polygon_);
}
}
+15 -10
View File
@@ -25,22 +25,27 @@
#include "draggable.h"
namespace olive {
class PolygonGizmo : public DraggableGizmo
namespace olive
{
Q_OBJECT
class PolygonGizmo : public DraggableGizmo {
Q_OBJECT
public:
explicit PolygonGizmo(QObject *parent = nullptr);
explicit PolygonGizmo(QObject *parent = nullptr);
const QPolygonF &GetPolygon() const { return polygon_; }
void SetPolygon(const QPolygonF &polygon) { polygon_ = polygon; }
const QPolygonF &GetPolygon() const
{
return polygon_;
}
void SetPolygon(const QPolygonF &polygon)
{
polygon_ = polygon;
}
virtual void Draw(QPainter *p) const override;
virtual void Draw(QPainter *p) const override;
private:
QPolygonF polygon_;
QPolygonF polygon_;
};
}
+4 -4
View File
@@ -20,12 +20,12 @@
#include "screen.h"
namespace olive {
ScreenGizmo::ScreenGizmo(QObject *parent)
: DraggableGizmo{parent}
namespace olive
{
ScreenGizmo::ScreenGizmo(QObject *parent)
: DraggableGizmo{ parent }
{
}
}
+5 -6
View File
@@ -23,14 +23,13 @@
#include "draggable.h"
namespace olive {
class ScreenGizmo : public DraggableGizmo
namespace olive
{
Q_OBJECT
public:
explicit ScreenGizmo(QObject *parent = nullptr);
class ScreenGizmo : public DraggableGizmo {
Q_OBJECT
public:
explicit ScreenGizmo(QObject *parent = nullptr);
};
}
+15 -14
View File
@@ -23,34 +23,35 @@
#include "core.h"
#include "undo/undocommand.h"
namespace olive {
TextGizmo::TextGizmo(QObject *parent)
: NodeGizmo{parent},
valign_(Qt::AlignTop)
namespace olive
{
TextGizmo::TextGizmo(QObject *parent)
: NodeGizmo{ parent }
, valign_(Qt::AlignTop)
{
}
void TextGizmo::SetRect(const QRectF &r)
{
rect_ = r;
emit RectChanged(rect_);
rect_ = r;
emit RectChanged(rect_);
}
void TextGizmo::UpdateInputHtml(const QString &s, const rational &time)
{
if (input_.IsValid()) {
MultiUndoCommand *command = new MultiUndoCommand();
Node::SetValueAtTime(input_.input(), time, s, input_.track(), command, true);
Core::instance()->undo_stack()->push(command, tr("Edit Text"));
}
if (input_.IsValid()) {
MultiUndoCommand *command = new MultiUndoCommand();
Node::SetValueAtTime(input_.input(), time, s, input_.track(), command,
true);
Core::instance()->undo_stack()->push(command, tr("Edit Text"));
}
}
void TextGizmo::SetVerticalAlignment(Qt::Alignment va)
{
valign_ = va;
emit VerticalAlignmentChanged(valign_);
valign_ = va;
emit VerticalAlignmentChanged(valign_);
}
}
+36 -22
View File
@@ -24,42 +24,56 @@
#include "gizmo.h"
#include "node/param.h"
namespace olive {
class TextGizmo : public NodeGizmo
namespace olive
{
Q_OBJECT
class TextGizmo : public NodeGizmo {
Q_OBJECT
public:
explicit TextGizmo(QObject *parent = nullptr);
explicit TextGizmo(QObject *parent = nullptr);
const QRectF &GetRect() const { return rect_; }
void SetRect(const QRectF &r);
const QRectF &GetRect() const
{
return rect_;
}
void SetRect(const QRectF &r);
const QString &GetHtml() const { return text_; }
void SetHtml(const QString &t) { text_ = t; }
const QString &GetHtml() const
{
return text_;
}
void SetHtml(const QString &t)
{
text_ = t;
}
void SetInput(const NodeKeyframeTrackReference &input) { input_ = input; }
void SetInput(const NodeKeyframeTrackReference &input)
{
input_ = input;
}
void UpdateInputHtml(const QString &s, const rational &time);
void UpdateInputHtml(const QString &s, const rational &time);
Qt::Alignment GetVerticalAlignment() const { return valign_; }
void SetVerticalAlignment(Qt::Alignment va);
Qt::Alignment GetVerticalAlignment() const
{
return valign_;
}
void SetVerticalAlignment(Qt::Alignment va);
signals:
void Activated();
void Deactivated();
void VerticalAlignmentChanged(Qt::Alignment va);
void RectChanged(const QRectF &r);
void Activated();
void Deactivated();
void VerticalAlignmentChanged(Qt::Alignment va);
void RectChanged(const QRectF &r);
private:
QRectF rect_;
QRectF rect_;
QString text_;
QString text_;
NodeKeyframeTrackReference input_;
Qt::Alignment valign_;
NodeKeyframeTrackReference input_;
Qt::Alignment valign_;
};
}
+2 -1
View File
@@ -20,6 +20,7 @@
#include "globals.h"
namespace olive {
namespace olive
{
}
+49 -26
View File
@@ -26,39 +26,62 @@
#include "render/loopmode.h"
#include "render/videoparams.h"
namespace olive {
class NodeGlobals
namespace olive
{
class NodeGlobals {
public:
NodeGlobals(){}
NodeGlobals()
{
}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam, const TimeRange &time, LoopMode loop_mode) :
video_params_(vparam),
audio_params_(aparam),
time_(time),
loop_mode_(loop_mode)
{
}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam,
const TimeRange &time, LoopMode loop_mode)
: video_params_(vparam)
, audio_params_(aparam)
, time_(time)
, loop_mode_(loop_mode)
{
}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam, const rational &time, LoopMode loop_mode) :
NodeGlobals(vparam, aparam, TimeRange(time, time + vparam.frame_rate_as_time_base()), loop_mode)
{
}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam,
const rational &time, LoopMode loop_mode)
: NodeGlobals(vparam, aparam,
TimeRange(time, time + vparam.frame_rate_as_time_base()),
loop_mode)
{
}
QVector2D square_resolution() const { return video_params_.square_resolution(); }
QVector2D nonsquare_resolution() const { return video_params_.resolution(); }
const AudioParams &aparams() const { return audio_params_; }
const VideoParams &vparams() const { return video_params_; }
const TimeRange &time() const { return time_; }
LoopMode loop_mode() const { return loop_mode_; }
QVector2D square_resolution() const
{
return video_params_.square_resolution();
}
QVector2D nonsquare_resolution() const
{
return video_params_.resolution();
}
const AudioParams &aparams() const
{
return audio_params_;
}
const VideoParams &vparams() const
{
return video_params_;
}
const TimeRange &time() const
{
return time_;
}
LoopMode loop_mode() const
{
return loop_mode_;
}
private:
VideoParams video_params_;
AudioParams audio_params_;
TimeRange time_;
LoopMode loop_mode_;
VideoParams video_params_;
AudioParams audio_params_;
TimeRange time_;
LoopMode loop_mode_;
};
}
+245 -204
View File
@@ -22,329 +22,370 @@
#include "node/serializeddata.h"
namespace olive {
namespace olive
{
#define super Node
NodeGroup::NodeGroup() :
output_passthrough_(nullptr)
NodeGroup::NodeGroup()
: output_passthrough_(nullptr)
{
SetFlag(kDontShowInCreateMenu);
SetFlag(kDontShowInCreateMenu);
}
QString NodeGroup::Name() const
{
return tr("Group");
return tr("Group");
}
QString NodeGroup::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.group");
return QStringLiteral("org.olivevideoeditor.Olive.group");
}
QVector<Node::CategoryID> NodeGroup::Category() const
{
return {kCategoryUnknown};
return { kCategoryUnknown };
}
QString NodeGroup::Description() const
{
return tr("A group of nodes that is represented as a single node.");
return tr("A group of nodes that is represented as a single node.");
}
void NodeGroup::Retranslate()
{
super::Retranslate();
super::Retranslate();
for (auto it=GetContextPositions().cbegin(); it!=GetContextPositions().cend(); it++) {
it.key()->Retranslate();
}
for (auto it = GetContextPositions().cbegin();
it != GetContextPositions().cend(); it++) {
it.key()->Retranslate();
}
}
bool NodeGroup::LoadCustom(QXmlStreamReader *reader, SerializedData *data)
{
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("inputpassthroughs")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("inputpassthrough")) {
SerializedData::GroupLink link;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("inputpassthroughs")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("inputpassthrough")) {
SerializedData::GroupLink link;
link.group = this;
link.group = this;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("node")) {
link.input_node = reader->readElementText().toULongLong();
} else if (reader->name() == QStringLiteral("input")) {
link.input_id = reader->readElementText();
} else if (reader->name() == QStringLiteral("element")) {
link.input_element = reader->readElementText().toInt();
} else if (reader->name() == QStringLiteral("id")) {
link.passthrough_id = reader->readElementText();
} else if (reader->name() == QStringLiteral("name")) {
link.custom_name = reader->readElementText();
} else if (reader->name() == QStringLiteral("flags")) {
link.custom_flags = InputFlags(reader->readElementText().toULongLong());
} else if (reader->name() == QStringLiteral("type")) {
link.data_type = NodeValue::GetDataTypeFromName(reader->readElementText());
} else if (reader->name() == QStringLiteral("default")) {
link.default_val = NodeValue::StringToValue(link.data_type, reader->readElementText(), false);
} else if (reader->name() == QStringLiteral("properties")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("property")) {
QString key;
QString value;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("node")) {
link.input_node =
reader->readElementText().toULongLong();
} else if (reader->name() == QStringLiteral("input")) {
link.input_id = reader->readElementText();
} else if (reader->name() ==
QStringLiteral("element")) {
link.input_element =
reader->readElementText().toInt();
} else if (reader->name() == QStringLiteral("id")) {
link.passthrough_id = reader->readElementText();
} else if (reader->name() == QStringLiteral("name")) {
link.custom_name = reader->readElementText();
} else if (reader->name() == QStringLiteral("flags")) {
link.custom_flags = InputFlags(
reader->readElementText().toULongLong());
} else if (reader->name() == QStringLiteral("type")) {
link.data_type = NodeValue::GetDataTypeFromName(
reader->readElementText());
} else if (reader->name() ==
QStringLiteral("default")) {
link.default_val = NodeValue::StringToValue(
link.data_type, reader->readElementText(),
false);
} else if (reader->name() ==
QStringLiteral("properties")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() ==
QStringLiteral("property")) {
QString key;
QString value;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("key")) {
key = reader->readElementText();
} else if (reader->name() == QStringLiteral("value")) {
value = reader->readElementText();
} else {
reader->skipCurrentElement();
}
}
while (XMLReadNextStartElement(reader)) {
if (reader->name() ==
QStringLiteral("key")) {
key = reader->readElementText();
} else if (reader->name() ==
QStringLiteral("value")) {
value = reader->readElementText();
} else {
reader->skipCurrentElement();
}
}
if (!key.isEmpty()) {
link.custom_properties.insert(key, value);
}
} else {
reader->skipCurrentElement();
}
}
} else {
reader->skipCurrentElement();
}
}
if (!key.isEmpty()) {
link.custom_properties.insert(key,
value);
}
} else {
reader->skipCurrentElement();
}
}
} else {
reader->skipCurrentElement();
}
}
data->group_input_links.append(link);
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("outputpassthrough")) {
data->group_output_links.insert(this, reader->readElementText().toULongLong());
} else {
reader->skipCurrentElement();
}
}
data->group_input_links.append(link);
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("outputpassthrough")) {
data->group_output_links.insert(
this, reader->readElementText().toULongLong());
} else {
reader->skipCurrentElement();
}
}
return true;
return true;
}
void NodeGroup::SaveCustom(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("inputpassthroughs"));
writer->writeStartElement(QStringLiteral("inputpassthroughs"));
foreach (const NodeGroup::InputPassthrough &ip, this->GetInputPassthroughs()) {
writer->writeStartElement(QStringLiteral("inputpassthrough"));
foreach (const NodeGroup::InputPassthrough &ip,
this->GetInputPassthroughs()) {
writer->writeStartElement(QStringLiteral("inputpassthrough"));
// Reference to inner input
writer->writeTextElement(QStringLiteral("node"), QString::number(reinterpret_cast<quintptr>(ip.second.node())));
writer->writeTextElement(QStringLiteral("input"), ip.second.input());
writer->writeTextElement(QStringLiteral("element"), QString::number(ip.second.element()));
// Reference to inner input
writer->writeTextElement(
QStringLiteral("node"),
QString::number(reinterpret_cast<quintptr>(ip.second.node())));
writer->writeTextElement(QStringLiteral("input"), ip.second.input());
writer->writeTextElement(QStringLiteral("element"),
QString::number(ip.second.element()));
// ID of passthrough
writer->writeTextElement(QStringLiteral("id"), ip.first);
// ID of passthrough
writer->writeTextElement(QStringLiteral("id"), ip.first);
// Passthrough-specific details
const QString &input = ip.first;
writer->writeTextElement(QStringLiteral("name"), this->Node::GetInputName(input));
// Passthrough-specific details
const QString &input = ip.first;
writer->writeTextElement(QStringLiteral("name"),
this->Node::GetInputName(input));
writer->writeTextElement(QStringLiteral("flags"), QString::number((GetInputFlags(input) & ~ip.second.GetFlags()).value()));
writer->writeTextElement(
QStringLiteral("flags"),
QString::number(
(GetInputFlags(input) & ~ip.second.GetFlags()).value()));
NodeValue::Type data_type = GetInputDataType(input);
writer->writeTextElement(QStringLiteral("type"), NodeValue::GetDataTypeName(data_type));
NodeValue::Type data_type = GetInputDataType(input);
writer->writeTextElement(QStringLiteral("type"),
NodeValue::GetDataTypeName(data_type));
writer->writeTextElement(QStringLiteral("default"), NodeValue::ValueToString(data_type, GetDefaultValue(input), false));
writer->writeTextElement(
QStringLiteral("default"),
NodeValue::ValueToString(data_type, GetDefaultValue(input), false));
writer->writeStartElement(QStringLiteral("properties"));
auto p = GetInputProperties(input);
for (auto it=p.cbegin(); it!=p.cend(); it++) {
writer->writeStartElement(QStringLiteral("property"));
writer->writeTextElement(QStringLiteral("key"), it.key());
writer->writeTextElement(QStringLiteral("value"), it.value().toString());
writer->writeEndElement(); // property
}
writer->writeEndElement(); // properties
writer->writeStartElement(QStringLiteral("properties"));
auto p = GetInputProperties(input);
for (auto it = p.cbegin(); it != p.cend(); it++) {
writer->writeStartElement(QStringLiteral("property"));
writer->writeTextElement(QStringLiteral("key"), it.key());
writer->writeTextElement(QStringLiteral("value"),
it.value().toString());
writer->writeEndElement(); // property
}
writer->writeEndElement(); // properties
writer->writeEndElement(); // input
}
writer->writeEndElement(); // input
}
writer->writeEndElement(); // inputpassthroughs
writer->writeEndElement(); // inputpassthroughs
writer->writeTextElement(QStringLiteral("outputpassthrough"), QString::number(reinterpret_cast<quintptr>(this->GetOutputPassthrough())));
writer->writeTextElement(QStringLiteral("outputpassthrough"),
QString::number(reinterpret_cast<quintptr>(
this->GetOutputPassthrough())));
}
void NodeGroup::PostLoadEvent(SerializedData *data)
{
super::PostLoadEvent(data);
super::PostLoadEvent(data);
foreach (const SerializedData::GroupLink &l, data->group_input_links) {
if (Node *input_node = data->node_ptrs.value(l.input_node)) {
NodeInput resolved(input_node, l.input_id, l.input_element);
foreach (const SerializedData::GroupLink &l, data->group_input_links) {
if (Node *input_node = data->node_ptrs.value(l.input_node)) {
NodeInput resolved(input_node, l.input_id, l.input_element);
l.group->AddInputPassthrough(resolved, l.passthrough_id);
l.group->AddInputPassthrough(resolved, l.passthrough_id);
l.group->SetInputFlag(l.passthrough_id, InputFlag(l.custom_flags.value()));
l.group->SetInputFlag(l.passthrough_id,
InputFlag(l.custom_flags.value()));
if (!l.custom_name.isEmpty()) {
l.group->SetInputName(l.passthrough_id, l.custom_name);
}
if (!l.custom_name.isEmpty()) {
l.group->SetInputName(l.passthrough_id, l.custom_name);
}
l.group->SetInputDataType(l.passthrough_id, l.data_type);
l.group->SetInputDataType(l.passthrough_id, l.data_type);
l.group->SetDefaultValue(l.passthrough_id, l.default_val);
l.group->SetDefaultValue(l.passthrough_id, l.default_val);
for (auto it=l.custom_properties.cbegin(); it!=l.custom_properties.cend(); it++) {
l.group->SetInputProperty(l.passthrough_id, it.key(), it.value());
}
}
}
for (auto it = l.custom_properties.cbegin();
it != l.custom_properties.cend(); it++) {
l.group->SetInputProperty(l.passthrough_id, it.key(),
it.value());
}
}
}
for (auto it=data->group_output_links.cbegin(); it!=data->group_output_links.cend(); it++) {
if (Node *output_node = data->node_ptrs.value(it.value())) {
it.key()->SetOutputPassthrough(output_node);
}
}
for (auto it = data->group_output_links.cbegin();
it != data->group_output_links.cend(); it++) {
if (Node *output_node = data->node_ptrs.value(it.value())) {
it.key()->SetOutputPassthrough(output_node);
}
}
}
QString NodeGroup::AddInputPassthrough(const NodeInput &input, const QString &force_id)
QString NodeGroup::AddInputPassthrough(const NodeInput &input,
const QString &force_id)
{
Q_ASSERT(ContextContainsNode(input.node()));
Q_ASSERT(ContextContainsNode(input.node()));
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it->second == input) {
// Already passing this input through
return it->first;
}
}
for (auto it = input_passthroughs_.cbegin();
it != input_passthroughs_.cend(); it++) {
if (it->second == input) {
// Already passing this input through
return it->first;
}
}
// Add input
QString id;
if (force_id.isEmpty()) {
id = input.input();
int i = 2;
while (HasInputWithID(id)) {
id = QStringLiteral("%1_%2").arg(input.name(), QString::number(i));
i++;
}
} else {
id = force_id;
// Add input
QString id;
if (force_id.isEmpty()) {
id = input.input();
int i = 2;
while (HasInputWithID(id)) {
id = QStringLiteral("%1_%2").arg(input.name(), QString::number(i));
i++;
}
} else {
id = force_id;
bool already_exists = false;
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it->first == id) {
already_exists = true;
break;
}
}
bool already_exists = false;
for (auto it = input_passthroughs_.cbegin();
it != input_passthroughs_.cend(); it++) {
if (it->first == id) {
already_exists = true;
break;
}
}
Q_ASSERT(!already_exists);
}
Q_ASSERT(!already_exists);
}
AddInput(id, input.GetDataType(), input.GetDefaultValue(), input.GetFlags());
AddInput(id, input.GetDataType(), input.GetDefaultValue(),
input.GetFlags());
input_passthroughs_.append({id, input});
input_passthroughs_.append({ id, input });
emit InputPassthroughAdded(this, input);
emit InputPassthroughAdded(this, input);
return id;
return id;
}
void NodeGroup::RemoveInputPassthrough(const NodeInput &input)
{
for (auto it=input_passthroughs_.begin(); it!=input_passthroughs_.end(); it++) {
if (it->second == input) {
RemoveInput(it->first);
emit InputPassthroughRemoved(this, it->second);
input_passthroughs_.erase(it);
break;
}
}
for (auto it = input_passthroughs_.begin(); it != input_passthroughs_.end();
it++) {
if (it->second == input) {
RemoveInput(it->first);
emit InputPassthroughRemoved(this, it->second);
input_passthroughs_.erase(it);
break;
}
}
}
void NodeGroup::SetOutputPassthrough(Node *node)
{
Q_ASSERT(!node || ContextContainsNode(node));
Q_ASSERT(!node || ContextContainsNode(node));
output_passthrough_ = node;
output_passthrough_ = node;
emit OutputPassthroughChanged(this, output_passthrough_);
emit OutputPassthroughChanged(this, output_passthrough_);
}
bool NodeGroup::ContainsInputPassthrough(const NodeInput &input) const
{
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it->second == input) {
return true;
}
}
for (auto it = input_passthroughs_.cbegin();
it != input_passthroughs_.cend(); it++) {
if (it->second == input) {
return true;
}
}
return false;
return false;
}
QString NodeGroup::GetInputName(const QString &id) const
{
// If an override name was set, use that
QString override = super::GetInputName(id);
if (!override.isEmpty()) {
return override;
}
// If an override name was set, use that
QString override = super::GetInputName(id);
if (!override.isEmpty()) {
return override;
}
// Call GetInputName of passed through node, which may be another group
NodeInput pass = GetInputFromID(id);
return pass.node()->GetInputName(pass.input());
// Call GetInputName of passed through node, which may be another group
NodeInput pass = GetInputFromID(id);
return pass.node()->GetInputName(pass.input());
}
NodeInput NodeGroup::ResolveInput(NodeInput input)
{
while (GetInner(&input)) {}
while (GetInner(&input)) {
}
return input;
return input;
}
bool NodeGroup::GetInner(NodeInput *input)
{
if (NodeGroup *g = dynamic_cast<NodeGroup*>(input->node())) {
const NodeInput &passthrough = g->GetInputFromID(input->input());
if (!passthrough.IsValid()) {
return false;
}
if (NodeGroup *g = dynamic_cast<NodeGroup *>(input->node())) {
const NodeInput &passthrough = g->GetInputFromID(input->input());
if (!passthrough.IsValid()) {
return false;
}
input->set_node(passthrough.node());
input->set_input(passthrough.input());
return true;
} else {
return false;
}
input->set_node(passthrough.node());
input->set_input(passthrough.input());
return true;
} else {
return false;
}
}
void NodeGroupAddInputPassthrough::redo()
{
if (!group_->ContainsInputPassthrough(input_)) {
group_->AddInputPassthrough(input_, force_id_);
actually_added_ = true;
} else {
actually_added_ = false;
}
if (!group_->ContainsInputPassthrough(input_)) {
group_->AddInputPassthrough(input_, force_id_);
actually_added_ = true;
} else {
actually_added_ = false;
}
}
void NodeGroupAddInputPassthrough::undo()
{
if (actually_added_) {
group_->RemoveInputPassthrough(input_);
}
if (actually_added_) {
group_->RemoveInputPassthrough(input_);
}
}
void NodeGroupSetOutputPassthrough::redo()
{
old_output_ = group_->GetOutputPassthrough();
group_->SetOutputPassthrough(new_output_);
old_output_ = group_->GetOutputPassthrough();
group_->SetOutputPassthrough(new_output_);
}
void NodeGroupSetOutputPassthrough::undo()
{
group_->SetOutputPassthrough(old_output_);
group_->SetOutputPassthrough(old_output_);
}
}
+93 -89
View File
@@ -23,140 +23,144 @@
#include "node/node.h"
namespace olive {
class NodeGroup : public Node
namespace olive
{
Q_OBJECT
class NodeGroup : public Node {
Q_OBJECT
public:
NodeGroup();
NodeGroup();
NODE_DEFAULT_FUNCTIONS(NodeGroup)
NODE_DEFAULT_FUNCTIONS(NodeGroup)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
virtual bool LoadCustom(QXmlStreamReader *reader, SerializedData *data) override;
virtual void SaveCustom(QXmlStreamWriter *writer) const override;
virtual void PostLoadEvent(SerializedData *data) override;
virtual bool LoadCustom(QXmlStreamReader *reader,
SerializedData *data) override;
virtual void SaveCustom(QXmlStreamWriter *writer) const override;
virtual void PostLoadEvent(SerializedData *data) override;
QString AddInputPassthrough(const NodeInput &input, const QString &force_id = QString());
QString AddInputPassthrough(const NodeInput &input,
const QString &force_id = QString());
void RemoveInputPassthrough(const NodeInput &input);
void RemoveInputPassthrough(const NodeInput &input);
Node *GetOutputPassthrough() const
{
return output_passthrough_;
}
Node *GetOutputPassthrough() const
{
return output_passthrough_;
}
void SetOutputPassthrough(Node *node);
void SetOutputPassthrough(Node *node);
using InputPassthrough = QPair<QString, NodeInput>;
using InputPassthroughs = QVector<InputPassthrough>;
const InputPassthroughs &GetInputPassthroughs() const
{
return input_passthroughs_;
}
using InputPassthrough = QPair<QString, NodeInput>;
using InputPassthroughs = QVector<InputPassthrough>;
const InputPassthroughs &GetInputPassthroughs() const
{
return input_passthroughs_;
}
bool ContainsInputPassthrough(const NodeInput &input) const;
bool ContainsInputPassthrough(const NodeInput &input) const;
virtual QString GetInputName(const QString& id) const override;
virtual QString GetInputName(const QString &id) const override;
static NodeInput ResolveInput(NodeInput input);
static bool GetInner(NodeInput *input);
static NodeInput ResolveInput(NodeInput input);
static bool GetInner(NodeInput *input);
QString GetIDOfPassthrough(const NodeInput &input) const
{
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it->second == input) {
return it->first;
}
}
return QString();
}
QString GetIDOfPassthrough(const NodeInput &input) const
{
for (auto it = input_passthroughs_.cbegin();
it != input_passthroughs_.cend(); it++) {
if (it->second == input) {
return it->first;
}
}
return QString();
}
NodeInput GetInputFromID(const QString &id) const
{
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it->first == id) {
return it->second;
}
}
return NodeInput();
}
NodeInput GetInputFromID(const QString &id) const
{
for (auto it = input_passthroughs_.cbegin();
it != input_passthroughs_.cend(); it++) {
if (it->first == id) {
return it->second;
}
}
return NodeInput();
}
signals:
void InputPassthroughAdded(olive::NodeGroup *group, const olive::NodeInput &input);
void InputPassthroughAdded(olive::NodeGroup *group,
const olive::NodeInput &input);
void InputPassthroughRemoved(olive::NodeGroup *group, const olive::NodeInput &input);
void InputPassthroughRemoved(olive::NodeGroup *group,
const olive::NodeInput &input);
void OutputPassthroughChanged(olive::NodeGroup *group, olive::Node *output);
void OutputPassthroughChanged(olive::NodeGroup *group, olive::Node *output);
private:
InputPassthroughs input_passthroughs_;
Node *output_passthrough_;
InputPassthroughs input_passthroughs_;
Node *output_passthrough_;
};
class NodeGroupAddInputPassthrough : public UndoCommand
{
class NodeGroupAddInputPassthrough : public UndoCommand {
public:
NodeGroupAddInputPassthrough(NodeGroup *group, const NodeInput &input, const QString &force_id = QString()) :
group_(group),
input_(input),
actually_added_(false)
{}
NodeGroupAddInputPassthrough(NodeGroup *group, const NodeInput &input,
const QString &force_id = QString())
: group_(group)
, input_(input)
, actually_added_(false)
{
}
virtual Project * GetRelevantProject() const override
{
return group_->project();
}
virtual Project *GetRelevantProject() const override
{
return group_->project();
}
protected:
virtual void redo() override;
virtual void redo() override;
virtual void undo() override;
virtual void undo() override;
private:
NodeGroup *group_;
NodeGroup *group_;
NodeInput input_;
NodeInput input_;
QString force_id_;
bool actually_added_;
QString force_id_;
bool actually_added_;
};
class NodeGroupSetOutputPassthrough : public UndoCommand
{
class NodeGroupSetOutputPassthrough : public UndoCommand {
public:
NodeGroupSetOutputPassthrough(NodeGroup *group, Node *output) :
group_(group),
new_output_(output)
{}
NodeGroupSetOutputPassthrough(NodeGroup *group, Node *output)
: group_(group)
, new_output_(output)
{
}
virtual Project * GetRelevantProject() const override
{
return group_->project();
}
virtual Project *GetRelevantProject() const override
{
return group_->project();
}
protected:
virtual void redo() override;
virtual void redo() override;
virtual void undo() override;
virtual void undo() override;
private:
NodeGroup *group_;
Node *new_output_;
Node *old_output_;
NodeGroup *group_;
Node *new_output_;
Node *old_output_;
};
}
+109 -93
View File
@@ -2,172 +2,188 @@
#include "node/project/sequence/sequence.h"
namespace olive {
namespace olive
{
#define super Node
const QString MultiCamNode::kCurrentInput = QStringLiteral("current_in");
const QString MultiCamNode::kSourcesInput = QStringLiteral("sources_in");
const QString MultiCamNode::kSequenceInput = QStringLiteral("sequence_in");
const QString MultiCamNode::kSequenceTypeInput = QStringLiteral("sequence_type_in");
const QString MultiCamNode::kSequenceTypeInput =
QStringLiteral("sequence_type_in");
MultiCamNode::MultiCamNode()
{
AddInput(kCurrentInput, NodeValue::kCombo, InputFlags(kInputFlagStatic));
AddInput(kCurrentInput, NodeValue::kCombo, InputFlags(kInputFlagStatic));
AddInput(kSourcesInput, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable | kInputFlagArray));
SetInputProperty(kSourcesInput, QStringLiteral("arraystart"), 1);
AddInput(kSourcesInput, NodeValue::kNone,
InputFlags(kInputFlagNotKeyframable | kInputFlagArray));
SetInputProperty(kSourcesInput, QStringLiteral("arraystart"), 1);
AddInput(kSequenceInput, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
AddInput(kSequenceTypeInput, NodeValue::kCombo, InputFlags(kInputFlagStatic | kInputFlagHidden));
AddInput(kSequenceInput, NodeValue::kNone,
InputFlags(kInputFlagNotKeyframable));
AddInput(kSequenceTypeInput, NodeValue::kCombo,
InputFlags(kInputFlagStatic | kInputFlagHidden));
sequence_ = nullptr;
sequence_ = nullptr;
}
QString MultiCamNode::Name() const
{
return tr("Multi-Cam");
return tr("Multi-Cam");
}
QString MultiCamNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.multicam");
return QStringLiteral("org.olivevideoeditor.Olive.multicam");
}
QVector<Node::CategoryID> MultiCamNode::Category() const
{
return {kCategoryTimeline};
return { kCategoryTimeline };
}
QString MultiCamNode::Description() const
{
return tr("Allows easy switching between multiple sources.");
return tr("Allows easy switching between multiple sources.");
}
Node::ActiveElements MultiCamNode::GetActiveElementsAtTime(const QString &input, const TimeRange &r) const
Node::ActiveElements
MultiCamNode::GetActiveElementsAtTime(const QString &input,
const TimeRange &r) const
{
if (input == kSourcesInput) {
int src = GetCurrentSource();
if (src >= 0 && src < GetSourceCount()) {
Node::ActiveElements a;
a.add(src);
return a;
} else {
return ActiveElements::kNoElements;
}
} else {
return super::GetActiveElementsAtTime(input, r);
}
if (input == kSourcesInput) {
int src = GetCurrentSource();
if (src >= 0 && src < GetSourceCount()) {
Node::ActiveElements a;
a.add(src);
return a;
} else {
return ActiveElements::kNoElements;
}
} else {
return super::GetActiveElementsAtTime(input, r);
}
}
void MultiCamNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void MultiCamNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
NodeValueArray arr = value[kSourcesInput].toArray();
if (!arr.empty()) {
table->Push(arr.begin()->second);
}
NodeValueArray arr = value[kSourcesInput].toArray();
if (!arr.empty()) {
table->Push(arr.begin()->second);
}
}
void MultiCamNode::IndexToRowCols(int index, int total_rows, int total_cols, int *row, int *col)
void MultiCamNode::IndexToRowCols(int index, int total_rows, int total_cols,
int *row, int *col)
{
Q_UNUSED(total_rows)
Q_UNUSED(total_rows)
*col = index%total_cols;
*row = index/total_cols;
*col = index % total_cols;
*row = index / total_cols;
}
Node *MultiCamNode::GetConnectedRenderOutput(const QString &input, int element) const
Node *MultiCamNode::GetConnectedRenderOutput(const QString &input,
int element) const
{
if (sequence_ && input == kSourcesInput && element >= 0 && element < GetSourceCount()) {
return GetTrackList()->GetTrackAt(element);
} else {
return Node::GetConnectedRenderOutput(input, element);
}
if (sequence_ && input == kSourcesInput && element >= 0 &&
element < GetSourceCount()) {
return GetTrackList()->GetTrackAt(element);
} else {
return Node::GetConnectedRenderOutput(input, element);
}
}
bool MultiCamNode::IsInputConnectedForRender(const QString &input, int element) const
bool MultiCamNode::IsInputConnectedForRender(const QString &input,
int element) const
{
if (sequence_ && input == kSourcesInput && element >= 0 && element < GetSourceCount()) {
return true;
} else {
return Node::IsInputConnectedForRender(input, element);
}
if (sequence_ && input == kSourcesInput && element >= 0 &&
element < GetSourceCount()) {
return true;
} else {
return Node::IsInputConnectedForRender(input, element);
}
}
QVector<QString> MultiCamNode::IgnoreInputsForRendering() const
{
return {kSequenceInput};
return { kSequenceInput };
}
void MultiCamNode::InputConnectedEvent(const QString &input, int element, Node *output)
void MultiCamNode::InputConnectedEvent(const QString &input, int element,
Node *output)
{
if (input == kSequenceInput) {
if (Sequence *s = dynamic_cast<Sequence*>(output)) {
SetInputFlag(kSequenceTypeInput, kInputFlagHidden, false);
sequence_ = s;
}
}
if (input == kSequenceInput) {
if (Sequence *s = dynamic_cast<Sequence *>(output)) {
SetInputFlag(kSequenceTypeInput, kInputFlagHidden, false);
sequence_ = s;
}
}
}
void MultiCamNode::InputDisconnectedEvent(const QString &input, int element, Node *output)
void MultiCamNode::InputDisconnectedEvent(const QString &input, int element,
Node *output)
{
if (input == kSequenceInput) {
SetInputFlag(kSequenceTypeInput, kInputFlagHidden, true);
sequence_ = nullptr;
}
if (input == kSequenceInput) {
SetInputFlag(kSequenceTypeInput, kInputFlagHidden, true);
sequence_ = nullptr;
}
}
TrackList *MultiCamNode::GetTrackList() const
{
return sequence_->track_list(static_cast<Track::Type>(GetStandardValue(kSequenceTypeInput).toInt()));
return sequence_->track_list(
static_cast<Track::Type>(GetStandardValue(kSequenceTypeInput).toInt()));
}
void MultiCamNode::Retranslate()
{
super::Retranslate();
super::Retranslate();
SetInputName(kCurrentInput, tr("Current"));
SetInputName(kSourcesInput, tr("Sources"));
SetInputName(kSequenceInput, tr("Sequence"));
SetInputName(kSequenceTypeInput, tr("Sequence Type"));
SetComboBoxStrings(kSequenceTypeInput, {tr("Video"), tr("Audio")});
SetInputName(kCurrentInput, tr("Current"));
SetInputName(kSourcesInput, tr("Sources"));
SetInputName(kSequenceInput, tr("Sequence"));
SetInputName(kSequenceTypeInput, tr("Sequence Type"));
SetComboBoxStrings(kSequenceTypeInput, { tr("Video"), tr("Audio") });
QStringList names;
int name_count = GetSourceCount();
names.reserve(name_count);
for (int i=0; i<name_count; i++) {
QString src_name;
if (Node *n = GetConnectedRenderOutput(kSourcesInput, i)) {
src_name = n->Name();
}
names.append(tr("%1: %2").arg(QString::number(i+1), src_name));
}
SetComboBoxStrings(kCurrentInput, names);
QStringList names;
int name_count = GetSourceCount();
names.reserve(name_count);
for (int i = 0; i < name_count; i++) {
QString src_name;
if (Node *n = GetConnectedRenderOutput(kSourcesInput, i)) {
src_name = n->Name();
}
names.append(tr("%1: %2").arg(QString::number(i + 1), src_name));
}
SetComboBoxStrings(kCurrentInput, names);
}
int MultiCamNode::GetSourceCount() const
{
if (sequence_) {
return GetTrackList()->GetTrackCount();
} else {
return InputArraySize(kSourcesInput);
}
if (sequence_) {
return GetTrackList()->GetTrackCount();
} else {
return InputArraySize(kSourcesInput);
}
}
void MultiCamNode::GetRowsAndColumns(int sources, int *rows_in, int *cols_in)
{
int &rows = *rows_in;
int &cols = *cols_in;
int &rows = *rows_in;
int &cols = *cols_in;
rows = 1;
cols = 1;
while (rows*cols < sources) {
if (rows < cols) {
rows++;
} else {
cols++;
}
}
rows = 1;
cols = 1;
while (rows * cols < sources) {
if (rows < cols) {
rows++;
} else {
cols++;
}
}
}
}
+51 -44
View File
@@ -4,73 +4,80 @@
#include "node/node.h"
#include "node/output/track/tracklist.h"
namespace olive {
namespace olive
{
class Sequence;
class MultiCamNode : public Node
{
Q_OBJECT
class MultiCamNode : public Node {
Q_OBJECT
public:
MultiCamNode();
MultiCamNode();
NODE_DEFAULT_FUNCTIONS(MultiCamNode)
NODE_DEFAULT_FUNCTIONS(MultiCamNode)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual ActiveElements GetActiveElementsAtTime(const QString &input, const TimeRange &r) const override;
virtual ActiveElements
GetActiveElementsAtTime(const QString &input,
const TimeRange &r) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
virtual void Retranslate() override;
virtual void Retranslate() override;
static const QString kCurrentInput;
static const QString kSourcesInput;
static const QString kSequenceInput;
static const QString kSequenceTypeInput;
static const QString kCurrentInput;
static const QString kSourcesInput;
static const QString kSequenceInput;
static const QString kSequenceTypeInput;
int GetCurrentSource() const
{
return GetStandardValue(kCurrentInput).toInt();
}
int GetCurrentSource() const
{
return GetStandardValue(kCurrentInput).toInt();
}
int GetSourceCount() const;
int GetSourceCount() const;
static void GetRowsAndColumns(int sources, int *rows, int *cols);
void GetRowsAndColumns(int *rows, int *cols) const
{
return GetRowsAndColumns(GetSourceCount(), rows, cols);
}
static void GetRowsAndColumns(int sources, int *rows, int *cols);
void GetRowsAndColumns(int *rows, int *cols) const
{
return GetRowsAndColumns(GetSourceCount(), rows, cols);
}
void SetSequenceType(Track::Type t)
{
SetStandardValue(kSequenceTypeInput, t);
}
void SetSequenceType(Track::Type t)
{
SetStandardValue(kSequenceTypeInput, t);
}
static void IndexToRowCols(int index, int total_rows, int total_cols, int *row, int *col);
static void IndexToRowCols(int index, int total_rows, int total_cols,
int *row, int *col);
static int RowsColsToIndex(int row, int col, int total_rows, int total_cols)
{
return col + row * total_cols;
}
static int RowsColsToIndex(int row, int col, int total_rows, int total_cols)
{
return col + row * total_cols;
}
virtual Node *GetConnectedRenderOutput(const QString& input, int element = -1) const override;
virtual bool IsInputConnectedForRender(const QString& input, int element = -1) const override;
virtual Node *GetConnectedRenderOutput(const QString &input,
int element = -1) const override;
virtual bool IsInputConnectedForRender(const QString &input,
int element = -1) const override;
virtual QVector<QString> IgnoreInputsForRendering() const override;
virtual QVector<QString> IgnoreInputsForRendering() const override;
protected:
virtual void InputConnectedEvent(const QString &input, int element, Node *output) override;
virtual void InputDisconnectedEvent(const QString &input, int element, Node *output) override;
virtual void InputConnectedEvent(const QString &input, int element,
Node *output) override;
virtual void InputDisconnectedEvent(const QString &input, int element,
Node *output) override;
private:
TrackList *GetTrackList() const;
Sequence *sequence_;
TrackList *GetTrackList() const;
Sequence *sequence_;
};
}
+10 -11
View File
@@ -20,7 +20,8 @@
#include "timeinput.h"
namespace olive {
namespace olive
{
#define super Node
@@ -30,31 +31,29 @@ TimeInput::TimeInput()
QString TimeInput::Name() const
{
return tr("Time");
return tr("Time");
}
QString TimeInput::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.time");
return QStringLiteral("org.olivevideoeditor.Olive.time");
}
QVector<Node::CategoryID> TimeInput::Category() const
{
return {kCategoryTime};
return { kCategoryTime };
}
QString TimeInput::Description() const
{
return tr("Generates the time (in seconds) at this frame.");
return tr("Generates the time (in seconds) at this frame.");
}
void TimeInput::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
void TimeInput::Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const
{
table->Push(NodeValue::kFloat,
globals.time().in().toDouble(),
this,
false,
QStringLiteral("time"));
table->Push(NodeValue::kFloat, globals.time().in().toDouble(), this, false,
QStringLiteral("time"));
}
}
+12 -12
View File
@@ -23,23 +23,23 @@
#include "node/node.h"
namespace olive {
class TimeInput : public Node
namespace olive
{
Q_OBJECT
class TimeInput : public Node {
Q_OBJECT
public:
TimeInput();
TimeInput();
NODE_DEFAULT_FUNCTIONS(TimeInput)
NODE_DEFAULT_FUNCTIONS(TimeInput)
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
NodeValueTable *table) const override;
};
}

Some files were not shown because too many files have changed in this diff Show More