#475 and some clip pointer changes
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
#include "clippropertiesdialog.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include "panels/panels.h"
|
||||
#include "project/undo.h"
|
||||
|
||||
ClipPropertiesDialog::ClipPropertiesDialog(QWidget *parent, QVector<Clip *> clips) :
|
||||
QDialog(parent)
|
||||
{
|
||||
setWindowTitle((clips.size() == 1) ?
|
||||
tr("\"%1\" Properties").arg(clips.at(0)->name()) :
|
||||
tr("Multiple Clip Properties"));
|
||||
|
||||
clips_ = clips;
|
||||
|
||||
QGridLayout* layout = new QGridLayout(this);
|
||||
|
||||
int row = 0;
|
||||
|
||||
// Clip Name field
|
||||
layout->addWidget(new QLabel(tr("Name:")), row, 0);
|
||||
|
||||
clip_name_field_ = new QLineEdit();
|
||||
|
||||
layout->addWidget(clip_name_field_, row, 1);
|
||||
|
||||
row++;
|
||||
|
||||
// Clip Duration field
|
||||
layout->addWidget(new QLabel(tr("Duration:")), row, 0);
|
||||
|
||||
duration_field_ = new LabelSlider();
|
||||
duration_field_->set_display_type(LABELSLIDER_FRAMENUMBER);
|
||||
duration_field_->set_minimum_value(1);
|
||||
layout->addWidget(duration_field_, row, 1);
|
||||
|
||||
row++;
|
||||
|
||||
// Dialog buttons (OK and Cancel)
|
||||
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttons->setCenterButtons(true);
|
||||
layout->addWidget(buttons, row, 0, 1, 2);
|
||||
|
||||
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
// analyze list of clips for default values
|
||||
|
||||
bool all_clips_have_same_name = true;
|
||||
bool all_clips_have_same_duration = true;
|
||||
|
||||
for (int i=1;i<clips.size();i++) {
|
||||
if (clips.at(i-1)->name() != clips.at(i)->name()) {
|
||||
all_clips_have_same_name = false;
|
||||
}
|
||||
if (clips.at(i-1)->length() != clips.at(i)->length()) {
|
||||
all_clips_have_same_duration = false;
|
||||
}
|
||||
}
|
||||
|
||||
Clip* first_clip = clips_.first();
|
||||
|
||||
if (all_clips_have_same_name) {
|
||||
// if there's only one clip selected, set all defaults to that clip's properties
|
||||
clip_name_field_->setText(first_clip->name());
|
||||
} else {
|
||||
// if there are multiple clips, use different properties
|
||||
clip_name_field_->setPlaceholderText(tr("(multiple)"));
|
||||
}
|
||||
|
||||
// it's assumed all the clips come from the same sequence
|
||||
duration_field_->set_frame_rate(first_clip->sequence->frame_rate);
|
||||
|
||||
if (all_clips_have_same_duration) {
|
||||
duration_field_->set_default_value(first_clip->length());
|
||||
duration_field_->set_value(first_clip->length(), false);
|
||||
duration_field_->set_maximum_value(first_clip->media_length());
|
||||
} else {
|
||||
duration_field_->set_default_value(qSNaN());
|
||||
duration_field_->set_value(qSNaN(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void ClipPropertiesDialog::accept()
|
||||
{
|
||||
const QString& clip_name = clip_name_field_->text();
|
||||
double clip_duration = duration_field_->value();
|
||||
|
||||
ComboAction* ca = new ComboAction();
|
||||
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* clip = clips_.at(i);
|
||||
|
||||
if (!clip_name.isEmpty()) {
|
||||
ca->append(new RenameClipCommand(clip, clip_name));
|
||||
}
|
||||
|
||||
if (!qIsNaN(clip_duration)) {
|
||||
clip->move(ca,
|
||||
clip->timeline_in(),
|
||||
clip->timeline_in() + qRound(clip_duration),
|
||||
clip->clip_in(),
|
||||
clip->track());
|
||||
}
|
||||
}
|
||||
|
||||
if (ca->hasActions()) {
|
||||
olive::UndoStack.push(ca);
|
||||
update_ui(false);
|
||||
} else {
|
||||
delete ca;
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CLIPPROPERTIESDIALOG_H
|
||||
#define CLIPPROPERTIESDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "project/clip.h"
|
||||
#include "ui/labelslider.h"
|
||||
|
||||
class ClipPropertiesDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ClipPropertiesDialog(QWidget* parent, QVector<Clip*> clips);
|
||||
protected:
|
||||
virtual void accept() override;
|
||||
private:
|
||||
QVector<Clip*> clips_;
|
||||
|
||||
QLineEdit* clip_name_field_;
|
||||
LabelSlider* duration_field_;
|
||||
};
|
||||
|
||||
#endif // CLIPPROPERTIESDIALOG_H
|
||||
+29
-29
@@ -35,9 +35,11 @@
|
||||
#include "project/effect.h"
|
||||
#include "project/media.h"
|
||||
|
||||
SpeedDialog::SpeedDialog(QWidget *parent) : QDialog(parent) {
|
||||
SpeedDialog::SpeedDialog(QWidget *parent, QVector<Clip*> clips) : QDialog(parent) {
|
||||
setWindowTitle(tr("Speed/Duration"));
|
||||
|
||||
clips_ = clips;
|
||||
|
||||
QVBoxLayout* main_layout = new QVBoxLayout(this);
|
||||
|
||||
QGridLayout* grid = new QGridLayout();
|
||||
@@ -93,8 +95,8 @@ void SpeedDialog::run() {
|
||||
default_length = -1;
|
||||
current_length = -1;
|
||||
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
double clip_percent;
|
||||
|
||||
@@ -185,8 +187,8 @@ void SpeedDialog::percent_update() {
|
||||
double fr_val = qSNaN();
|
||||
long len_val = -1;
|
||||
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
// get frame rate
|
||||
if (frame_rate->isEnabled() && c->track() < 0) {
|
||||
@@ -220,8 +222,8 @@ void SpeedDialog::duration_update() {
|
||||
bool got_fr = false;
|
||||
double fr_val = qSNaN();
|
||||
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
// get percent
|
||||
long clip_default_length = qRound(c->length() * c->speed().value);
|
||||
@@ -263,8 +265,8 @@ void SpeedDialog::frame_rate_update() {
|
||||
long len_val = -1;
|
||||
|
||||
// analyze video clips
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
// check if all selected clips are currently the same speed
|
||||
if (i == 0) {
|
||||
@@ -295,8 +297,8 @@ void SpeedDialog::frame_rate_update() {
|
||||
}
|
||||
|
||||
// analyze audio clips
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
if (c->track() >= 0) {
|
||||
long new_clip_len = (qIsNaN(old_pc_val) || qIsNaN(pc_val)) ? c->length() : ((c->length() * c->speed().value) / pc_val);
|
||||
@@ -311,7 +313,7 @@ void SpeedDialog::frame_rate_update() {
|
||||
duration->set_value((len_val == -1) ? qSNaN() : len_val, false);
|
||||
}
|
||||
|
||||
void set_speed(ComboAction* ca, ClipPtr c, double speed, bool ripple, long& ep, long& lr) {
|
||||
void set_speed(ComboAction* ca, Clip* c, double speed, bool ripple, long& ep, long& lr) {
|
||||
panel_timeline->deselect_area(c->timeline_in(), c->timeline_out(), c->track());
|
||||
|
||||
long proposed_out = c->timeline_out();
|
||||
@@ -330,7 +332,7 @@ void set_speed(ComboAction* ca, ClipPtr c, double speed, bool ripple, long& ep,
|
||||
}
|
||||
ep = qMin(ep, c->timeline_out());
|
||||
lr = qMax(lr, proposed_out - c->timeline_out());
|
||||
move_clip(ca, c, c->timeline_in(), proposed_out, qRound(c->clip_in() * multiplier), c->track());
|
||||
c->move(ca, c->timeline_in(), proposed_out, qRound(c->clip_in() * multiplier), c->track());
|
||||
|
||||
c->refactor_frame_rate(ca, multiplier, false);
|
||||
|
||||
@@ -358,8 +360,8 @@ void SpeedDialog::accept() {
|
||||
long earliest_point = LONG_MAX;
|
||||
long longest_ripple = LONG_MIN;
|
||||
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
|
||||
// make sure the clip is closed while we're making changes
|
||||
if (c->IsOpen()) {
|
||||
@@ -376,7 +378,7 @@ void SpeedDialog::accept() {
|
||||
// set reverse setting if the user made a selection
|
||||
if (reverse->checkState() != Qt::PartiallyChecked && c->reversed() != reverse->isChecked()) {
|
||||
long new_clip_in = (c->media_length() - (c->length() + c->clip_in()));
|
||||
move_clip(ca, c, c->timeline_in(), c->timeline_out(), new_clip_in, c->track());
|
||||
c->move(ca, c->timeline_in(), c->timeline_out(), new_clip_in, c->track());
|
||||
c->set_clip_in(new_clip_in);
|
||||
reversed_action->AddSetting(c, reverse->isChecked());
|
||||
}
|
||||
@@ -386,8 +388,8 @@ void SpeedDialog::accept() {
|
||||
if (!qIsNaN(percent->value())) {
|
||||
|
||||
// if we have a percentage value, use that on all the clips
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
set_speed(ca, c, percent->value(), ripple->isChecked(), earliest_point, longest_ripple);
|
||||
}
|
||||
|
||||
@@ -395,15 +397,13 @@ void SpeedDialog::accept() {
|
||||
|
||||
// if the user changed the speed by changing the frame rate,
|
||||
bool can_change_all = true;
|
||||
double cached_speed;
|
||||
double cached_speed = clips_.first()->speed().value;
|
||||
double cached_fr = qSNaN();
|
||||
|
||||
// see if we can use the frame rate to change all the speeds
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
if (i == 0) {
|
||||
cached_speed = c->speed().value;
|
||||
} else if (!qFuzzyCompare(cached_speed, c->speed().value)) {
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
if (i > 0 && !qFuzzyCompare(cached_speed, c->speed().value)) {
|
||||
can_change_all = false;
|
||||
}
|
||||
if (c->track() < 0) {
|
||||
@@ -417,8 +417,8 @@ void SpeedDialog::accept() {
|
||||
}
|
||||
|
||||
// make changes
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
if (c->track() < 0) {
|
||||
set_speed(ca, c, frame_rate->value() / c->media_frame_rate(), ripple->isChecked(), earliest_point, longest_ripple);
|
||||
} else if (can_change_all) {
|
||||
@@ -427,14 +427,14 @@ void SpeedDialog::accept() {
|
||||
}
|
||||
} else if (!qIsNaN(duration->value())) {
|
||||
// simply set duration
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
ClipPtr c = clips.at(i);
|
||||
for (int i=0;i<clips_.size();i++) {
|
||||
Clip* c = clips_.at(i);
|
||||
set_speed(ca, c, (c->length() * c->speed().value) / duration->value(), ripple->isChecked(), earliest_point, longest_ripple);
|
||||
}
|
||||
}
|
||||
|
||||
if (ripple->isChecked()) {
|
||||
ripple_clips(ca, clips.at(0)->sequence, earliest_point, longest_ripple);
|
||||
ripple_clips(ca, clips_.at(0)->sequence, earliest_point, longest_ripple);
|
||||
}
|
||||
|
||||
sel_command->new_data = olive::ActiveSequence->selections;
|
||||
|
||||
+20
-19
@@ -29,31 +29,32 @@
|
||||
|
||||
class SpeedDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpeedDialog(QWidget* parent = 0);
|
||||
QVector<ClipPtr> clips;
|
||||
SpeedDialog(QWidget* parent, QVector<Clip*> clips);
|
||||
|
||||
void run();
|
||||
void run();
|
||||
private slots:
|
||||
void percent_update();
|
||||
void duration_update();
|
||||
void frame_rate_update();
|
||||
void accept();
|
||||
void percent_update();
|
||||
void duration_update();
|
||||
void frame_rate_update();
|
||||
void accept();
|
||||
private:
|
||||
LabelSlider* percent;
|
||||
LabelSlider* duration;
|
||||
LabelSlider* frame_rate;
|
||||
QVector<Clip*> clips_;
|
||||
|
||||
QCheckBox* reverse;
|
||||
QCheckBox* maintain_pitch;
|
||||
QCheckBox* ripple;
|
||||
LabelSlider* percent;
|
||||
LabelSlider* duration;
|
||||
LabelSlider* frame_rate;
|
||||
|
||||
double default_frame_rate;
|
||||
double current_frame_rate;
|
||||
double current_percent;
|
||||
long default_length;
|
||||
long current_length;
|
||||
QCheckBox* reverse;
|
||||
QCheckBox* maintain_pitch;
|
||||
QCheckBox* ripple;
|
||||
|
||||
double default_frame_rate;
|
||||
double current_frame_rate;
|
||||
double current_percent;
|
||||
long default_length;
|
||||
long current_length;
|
||||
};
|
||||
|
||||
#endif // SPEEDDIALOG_H
|
||||
|
||||
Reference in New Issue
Block a user