revised keyframe system for graph editor

This commit is contained in:
itsmattkc
2019-01-05 16:30:51 +11:00
parent 90181ea9c5
commit 5123ec0669
8 changed files with 96 additions and 133 deletions
+16 -36
View File
@@ -53,8 +53,8 @@ Viewer::Viewer(QWidget *parent) :
headers->viewer = this;
headers->snapping = false;
headers->show_text(false);
glViewerPane->viewer = this;
viewer_widget = glViewerPane->child;
viewer_container->viewer = this;
viewer_widget = viewer_container->child;
viewer_widget->viewer = this;
set_media(NULL);
@@ -69,9 +69,9 @@ Viewer::Viewer(QWidget *parent) :
connect(&playback_updater, SIGNAL(timeout()), this, SLOT(timer_update()));
connect(&recording_flasher, SIGNAL(timeout()), this, SLOT(recording_flasher_update()));
connect(horizontalScrollBar, SIGNAL(valueChanged(int)), headers, SLOT(set_scroll(int)));
connect(horizontalScrollBar, SIGNAL(valueChanged(int)), viewer_widget, SLOT(set_waveform_scroll(int)));
connect(horizontalScrollBar, SIGNAL(resize_move(double)), this, SLOT(resize_move(double)));
connect(horizontal_bar, SIGNAL(valueChanged(int)), headers, SLOT(set_scroll(int)));
connect(horizontal_bar, SIGNAL(valueChanged(int)), viewer_widget, SLOT(set_waveform_scroll(int)));
connect(horizontal_bar, SIGNAL(resize_move(double)), this, SLOT(resize_move(double)));
update_playhead_timecode(0);
update_end_timecode();
@@ -441,13 +441,13 @@ void Viewer::set_zoom_value(double d) {
}
if (seq != NULL) {
set_sb_max();
if (!horizontalScrollBar->is_resizing())
center_scroll_to_playhead(horizontalScrollBar, headers->get_zoom(), seq->playhead);
if (!horizontal_bar->is_resizing())
center_scroll_to_playhead(horizontal_bar, headers->get_zoom(), seq->playhead);
}
}
void Viewer::set_sb_max() {
headers->set_scrollbar_max(horizontalScrollBar, seq->getEndFrame(), headers->width());
headers->set_scrollbar_max(horizontal_bar, seq->getEndFrame(), headers->width());
}
void Viewer::setup_ui() {
@@ -457,17 +457,17 @@ void Viewer::setup_ui() {
layout->setSpacing(0);
layout->setMargin(0);
glViewerPane = new ViewerContainer(contents);
glViewerPane->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(glViewerPane);
viewer_container = new ViewerContainer(contents);
viewer_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(viewer_container);
headers = new TimelineHeader(contents);
layout->addWidget(headers);
horizontalScrollBar = new ResizableScrollBar(contents);
horizontalScrollBar->setSingleStep(20);
horizontalScrollBar->setOrientation(Qt::Horizontal);
layout->addWidget(horizontalScrollBar);
horizontal_bar = new ResizableScrollBar(contents);
horizontal_bar->setSingleStep(20);
horizontal_bar->setOrientation(Qt::Horizontal);
layout->addWidget(horizontal_bar);
QWidget* lower_controls = new QWidget(contents);
@@ -628,26 +628,6 @@ void Viewer::set_media(Media* m) {
set_sequence(false, seq);
}
void Viewer::on_btnSkipToStart_clicked() {
go_to_start();
}
void Viewer::on_btnSkipToEnd_clicked() {
go_to_end();
}
void Viewer::on_btnRewind_clicked() {
previous_frame();
}
void Viewer::on_btnFastForward_clicked() {
next_frame();
}
void Viewer::on_btnPlay_clicked() {
toggle_play();
}
void Viewer::update_playhead() {
seek(currentTimecode->value());
}
@@ -725,7 +705,7 @@ void Viewer::set_sequence(bool main, Sequence *s) {
update_playhead_timecode(seq->playhead);
update_end_timecode();
glViewerPane->adjust();
viewer_container->adjust();
setWindowTitle(panel_name + seq->name);
} else {
+2 -8
View File
@@ -77,12 +77,6 @@ public slots:
void go_to_end();
private slots:
void on_btnSkipToStart_clicked();
void on_btnRewind_clicked();
void on_btnPlay_clicked();
void on_btnFastForward_clicked();
void on_btnSkipToEnd_clicked();
void update_playhead();
void timer_update();
void recording_flasher_update();
@@ -102,8 +96,8 @@ private:
void setup_ui();
TimelineHeader* headers;
ResizableScrollBar* horizontalScrollBar;
ViewerContainer* glViewerPane;
ResizableScrollBar* horizontal_bar;
ViewerContainer* viewer_container;
LabelSlider* currentTimecode;
QLabel* endTimecode;
+70 -2
View File
@@ -56,6 +56,7 @@ void EffectRow::setKeyframing(bool b) {
void EffectRow::set_keyframe_enabled(bool enabled) {
if (enabled) {
ComboAction* ca = new ComboAction();
ca->append(new SetKeyframing(this, true));
set_keyframe_now(ca);
undo_stack.push(ca);
} else {
@@ -156,7 +157,74 @@ EffectRow::~EffectRow() {
}
void EffectRow::set_keyframe_now(ComboAction* ca) {
int index = -1;
long time = sequence->playhead-parent_effect->parent_clip->timeline_in+parent_effect->parent_clip->clip_in;
if (!just_made_unsafe_keyframe) {
EffectKeyframe key;
key.time = time;
unsafe_keys.resize(fieldCount());
unsafe_old_data.resize(fieldCount());
key_is_new.resize(fieldCount());
for (int i=0;i<fieldCount();i++) {
EffectField* f = field(i);
int exist_key = -1;
int closest_key = 0;
for (int j=0;j<f->keyframes.size();j++) {
if (f->keyframes.at(j).time == time) {
exist_key = j;
} else if (f->keyframes.at(j).time < time
&& f->keyframes.at(closest_key).time < f->keyframes.at(j).time) {
closest_key = j;
}
}
if (exist_key == -1) {
key.type = (f->keyframes.size() == 0) ? KEYFRAME_TYPE_LINEAR : f->keyframes.at(closest_key).type;
key.data = f->get_current_data();//f->keyframes.at(closest_key).data;
unsafe_keys[i] = f->keyframes.size();
f->keyframes.append(key);
key_is_new[i] = true;
} else {
unsafe_keys[i] = exist_key;
key_is_new[i] = false;
}
unsafe_old_data[i] = f->get_current_data();
}
just_made_unsafe_keyframe = true;
}
for (int i=0;i<fieldCount();i++) {
field(i)->keyframes[unsafe_keys.at(i)].data = field(i)->get_current_data();
}
if (ca != NULL) {
for (int i=0;i<fieldCount();i++) {
if (key_is_new.at(i)) ca->append(new KeyframeFieldSet(field(i), unsafe_keys.at(i)));
ca->append(new SetQVariant(&field(i)->keyframes[unsafe_keys.at(i)].data, unsafe_old_data.at(i), field(i)->get_current_data()));
}
unsafe_keys.clear();
unsafe_old_data.clear();
just_made_unsafe_keyframe = false;
}
panel_effect_controls->update_keyframes();
/*if (ca != NULL) {
just_made_unsafe_keyframe = false;
} else {
if (!just_made_unsafe_keyframe) {
just_made_unsafe_keyframe = true;
}
}*/
/*int index = -1;
long time = sequence->playhead-parent_effect->parent_clip->timeline_in+parent_effect->parent_clip->clip_in;
for (int j=0;j<fieldCount();j++) {
EffectField* f = field(j);
@@ -179,7 +247,7 @@ void EffectRow::set_keyframe_now(ComboAction* ca) {
delete ks;
}
panel_effect_controls->update_keyframes();
panel_effect_controls->update_keyframes();*/
}
void EffectRow::delete_keyframe_at_time(ComboAction* ca, long time) {
+4
View File
@@ -48,6 +48,10 @@ private:
KeyframeNavigator* keyframe_nav;
bool just_made_unsafe_keyframe;
QVector<int> unsafe_keys;
QVector<QVariant> unsafe_old_data;
QVector<bool> key_is_new;
};
#endif // EFFECTROW_H
-60
View File
@@ -752,66 +752,6 @@ void KeyframeDelete::redo() {
mainWindow->setWindowModified(true);
}
KeyframeSet::KeyframeSet(EffectRow* r, int i, long t, bool justMadeKeyframe) :
old_project_changed(mainWindow->isWindowModified()),
row(r),
index(i),
time(t),
just_made_keyframe(justMadeKeyframe),
done(true)
{
enable_keyframes = !row->isKeyframing();
if (index != -1) old_values.resize(row->fieldCount());
new_values.resize(row->fieldCount());
for (int i=0;i<row->fieldCount();i++) {
EffectField* field = row->field(i);
if (index != -1) {
if (field->type == EFFECT_FIELD_DOUBLE) {
old_values[i] = static_cast<LabelSlider*>(field->ui_element)->getPreviousValue();
} else {
old_values[i] = field->keyframes.at(index).data;
}
}
new_values[i] = field->get_current_data();
}
}
void KeyframeSet::undo() {
if (enable_keyframes) row->setKeyframing(false);
bool append = (index == -1 || just_made_keyframe);
for (int i=0;i<row->fieldCount();i++) {
if (append) {
row->field(i)->keyframes.removeLast();
} else {
row->field(i)->keyframes[index].data = old_values.at(i);
}
}
mainWindow->setWindowModified(old_project_changed);
done = false;
}
void KeyframeSet::redo() {
bool append = (index == -1 || (just_made_keyframe && !done));
for (int i=0;i<row->fieldCount();i++) {
EffectField* f = row->field(i);
if (append) {
EffectKeyframe k;
k.data = new_values.at(i);
k.time = time;
k.type = (f->keyframes.size() > 0) ? f->keyframes.last().type : EFFECT_KEYFRAME_LINEAR;
f->keyframes.append(k);
} else {
f->keyframes[index].data = new_values.at(i);
}
}
row->setKeyframing(true);
mainWindow->setWindowModified(true);
done = true;
}
EffectFieldUndo::EffectFieldUndo(EffectField* f) :
field(f),
done(true),
-18
View File
@@ -342,24 +342,6 @@ private:
bool old_project_changed;
};
class KeyframeSet : public QUndoCommand {
public:
KeyframeSet(EffectRow* r, int i, long t, bool justMadeKeyframe);
void undo();
void redo();
QVector<QVariant> old_values;
QVector<QVariant> new_values;
private:
bool old_project_changed;
EffectRow* row;
int index;
long time;
bool enable_keyframes;
bool just_made_keyframe;
bool done;
};
// a more modern version of the above, could probably replace it
// assumes the keyframe already exists
class KeyframeFieldSet : public QUndoCommand {
-3
View File
@@ -133,9 +133,6 @@ void GraphView::set_view_to_rect(int x1, double y1, int x2, double y2) {
set_scroll_x(qRound((double(x1) - ((x_diff_padded-x_diff)/2))*zoom));
set_scroll_y(qRound((double(y1) - ((y_diff_padded-y_diff)/2))*zoom));
//set_scroll_y(height() - y1);
}
void GraphView::draw_line_text(QPainter &p, bool vert, int line_no, int line_pos, int next_line_pos) {
+4 -6
View File
@@ -116,19 +116,17 @@ void KeyframeView::paintEvent(QPaintEvent*) {
long keyframe_frame = adjust_row_keyframe(row, f->keyframes.at(k).time);
// see if any other keyframes have this time
bool solo = true;
int appearances = 0;
for (int m=0;m<row->fieldCount();m++) {
EffectField* compf = row->field(m);
for (int n=0;n<compf->keyframes.size();n++) {
if (f->keyframes.at(k).time == compf->keyframes.at(n).time
&& !(m == l && k == n)) {
solo = false;
break;
if (f->keyframes.at(k).time == compf->keyframes.at(n).time) {
appearances++;
}
}
}
if (solo) {
if (appearances != row->fieldCount()) {
QColor cc = get_curve_color(l, row->fieldCount());
draw_keyframe(p, f->keyframes.at(k).type, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected, cc.red(), cc.green(), cc.blue());
} else {