addressed #86 and #89

This commit is contained in:
itsmattkc
2018-06-30 03:02:19 +01:00
parent 384bb4eb5d
commit ae86a36902
11 changed files with 148 additions and 127 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.6.2, 2018-06-25T09:24:14. -->
<!-- Written by QtCreator 4.6.2, 2018-06-30T01:51:31. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
+13 -14
View File
@@ -198,23 +198,21 @@ bool Timeline::focused() {
}
void Timeline::undo() {
qDebug() << "[INFO] Undo/redo was so buggy, it's not been disabled. Sorry for any inconvenience";
// if (sequence != NULL) {
// current_clips.clear();
// panel_effect_controls->set_clip(NULL);
// sequence->undo();
// redraw_all_clips(false);
// }
// qDebug() << "[INFO] Undo/redo was so buggy, it's been disabled. Sorry for any inconvenience";
if (sequence != NULL) {
panel_effect_controls->clear_effects();
sequence->undo();
redraw_all_clips(false);
}
}
void Timeline::redo() {
qDebug() << "[INFO] Undo/redo was so buggy, it's not been disabled. Sorry for any inconvenience";
// if (sequence != NULL) {
// current_clips.clear();
// panel_effect_controls->set_clip(NULL);
// sequence->redo();
// redraw_all_clips(false);
// }
// qDebug() << "[INFO] Undo/redo was so buggy, it's been disabled. Sorry for any inconvenience";
if (sequence != NULL) {
panel_effect_controls->clear_effects();
sequence->redo();
redraw_all_clips(false);
}
}
QString frame_to_timecode(long f) {
@@ -256,6 +254,7 @@ void Timeline::redraw_all_clips(bool changed) {
project_changed = true;
if (!playing) reset_all_audio();
panel_viewer->viewer_widget->update();
sequence->undo_add_current();
}
ui->video_area->redraw_clips();
+1
View File
@@ -121,6 +121,7 @@ public:
// selecting functions
bool selecting;
int selection_offset;
QVector<Selection> selections;
bool is_clip_selected(Clip* clip);
void delete_selection(bool ripple);
+1 -14
View File
@@ -326,7 +326,6 @@ void cache_clip_worker(Clip* clip, long playhead, bool write_A, bool write_B, bo
}
void close_clip_worker(Clip* clip) {
cc_lock.lock();
// closes ffmpeg file handle and frees any memory used for caching
if (clip->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
sws_freeContext(clip->sws_ctx);
@@ -345,19 +344,7 @@ void close_clip_worker(Clip* clip) {
delete [] clip->cache_A.frames;
if (!clip->media_stream->infinite_length) delete [] clip->cache_B.frames;
av_frame_free(&clip->frame);
// remove clip from current_clips
bool found = false;
for (int i=0;i<current_clips.count();i++) {
if (current_clips[i] == clip) {
current_clips.removeAt(i);
found = true;
i = current_clips.count();
}
}
cc_lock.unlock();
if (!found) qDebug() << "[WARNING] Could not remove clip from current clips";
av_frame_free(&clip->frame);
clip->reset();
-39
View File
@@ -22,47 +22,8 @@ extern "C" {
#include <QDebug>
#include <QOpenGLPixelTransferOptions>
QList<Clip*> current_clips;
bool texture_failed = false;
QMutex cc_lock;
void handle_media(Sequence* sequence, long playhead, bool multithreaded) {
for (int i=0;i<sequence->clip_count();i++) {
Clip* c = sequence->get_clip(i);
// if clip starts within one second and/or hasn't finished yet
if (c != NULL) {
if (is_clip_active(c, playhead)) {
// if thread is already working, we don't want to touch this,
// but we also don't want to hang the UI thread
if (!c->open) {
if (c->open_lock.tryLock()) {
open_clip(c, multithreaded);
// add to current_clips, (insertion) sorted by track so composite them in order
cc_lock.lock();
bool found = false;
for (int j=0;j<current_clips.size();j++) {
if (current_clips[j]->track < c->track) {
current_clips.insert(current_clips.begin()+j, c);
found = true;
break;
}
}
if (!found) {
current_clips.push_back(c);
}
cc_lock.unlock();
}
}
} else if (c->open) {
close_clip(c);
}
}
}
}
void open_clip(Clip* clip, bool multithreaded) {
clip->multithreaded = multithreaded;
if (multithreaded) {
-3
View File
@@ -9,9 +9,6 @@ struct ClipCache;
struct Sequence;
struct AVFrame;
extern QList<Clip*> current_clips;
extern QMutex cc_lock;
extern bool texture_failed;
void open_clip(Clip* clip, bool multithreaded);
+46 -37
View File
@@ -6,6 +6,7 @@
Sequence::Sequence() {
undo_pointer = -1;
undo_add_current();
}
Sequence::~Sequence() {
@@ -95,52 +96,60 @@ Clip* Sequence::split_clip(Clip* pre, long frame) {
}
void Sequence::undo_add_current() {
// if (undo_stack.size() == UNDO_LIMIT) {
// delete undo_stack.at(0);
// undo_stack.removeFirst();
// } else {
// undo_pointer++;
// while (undo_stack.size() > undo_pointer+1) {
// delete undo_stack.last();
// undo_stack.removeLast();
// }
// }
if (undo_stack.size() == UNDO_LIMIT) {
delete undo_stack.at(0);
undo_stack.removeFirst();
} else {
undo_pointer++;
while (undo_stack.size() > undo_pointer+1) {
delete undo_stack.last();
undo_stack.removeLast();
}
}
// // copy clips
// QVector<Clip*>* copied_clips = new QVector<Clip*>();
// for (int i=0;i<clip_count();i++) {
// copied_clips->append(get_clip(i)->copy());
// }
// undo_stack.append(copied_clips);
// copy clips
QVector<Clip*>* copied_clips = new QVector<Clip*>();
for (int i=0;i<clip_count();i++) {
Clip* original = get_clip(i);
Clip* copy = original->copy();
copy->linked = original->linked;
copied_clips->append(copy);
}
undo_stack.append(copied_clips);
}
void Sequence::set_undo(int i) {
// for (int i=0;i<clip_count();i++) {
// delete clips.at(i);
// }
// clips.clear();
void Sequence::set_undo() {
qDebug() << "[INFO] Setting undo pointer to" << undo_pointer;
// QVector<Clip*>* copy_from_list = undo_stack.at(undo_pointer);
// for (int i=0;i<copy_from_list->size();i++) {
// add_clip(copy_from_list->at(i)->copy());
// }
for (int i=0;i<clip_count();i++) {
delete clips.at(i);
}
clips.clear();
QVector<Clip*>* copy_from_list = undo_stack.at(undo_pointer);
for (int i=0;i<copy_from_list->size();i++) {
Clip* original = copy_from_list->at(i);
Clip* copy = original->copy();
copy->linked = original->linked;
add_clip(copy);
}
}
void Sequence::undo() {
// if (undo_pointer > 0) {
// undo_pointer--;
// set_undo(undo_pointer);
// } else {
// qDebug() << "[INFO] No more undos";
// }
if (undo_pointer > 0) {
undo_pointer--;
set_undo();
} else {
qDebug() << "[INFO] No more undos";
}
}
void Sequence::redo() {
// if (undo_pointer == undo_stack.size() - 1) {
// qDebug() << "[INFO] No more redos";
// } else {
// undo_pointer++;
// set_undo(undo_pointer);
// }
if (undo_pointer == undo_stack.size() - 1) {
qDebug() << "[INFO] No more redos";
} else {
undo_pointer++;
set_undo();
}
}
// static variable for the currently active sequence
+1 -1
View File
@@ -31,7 +31,7 @@ public:
private:
QVector<Clip*> clips;
void set_undo(int i);
void set_undo();
QVector<QVector<Clip*>*> undo_stack;
int undo_pointer;
int undo_stack_start;
+47 -8
View File
@@ -231,6 +231,11 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) {
break;
case TIMELINE_TOOL_EDIT:
if (panel_timeline->edit_tool_also_seeks) panel_timeline->seek(panel_timeline->drag_frame_start);
if ((event->modifiers() & Qt::ShiftModifier)) {
panel_timeline->selection_offset = panel_timeline->selections.size();
} else {
panel_timeline->selection_offset = 0;
}
panel_timeline->selecting = true;
break;
case TIMELINE_TOOL_RAZOR:
@@ -249,6 +254,8 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) {
void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
bool repaint = false;
if (panel_timeline->moving_proc) {
if (event->modifiers() & Qt::AltModifier) { // if holding alt, duplicate rather than move
// duplicate clips
@@ -340,6 +347,37 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
}
panel_timeline->redraw_all_clips(true);
} else if (panel_timeline->selecting) {
// remove duplicate selections
for (int i=0;i<panel_timeline->selections.size();i++) {
Selection& s = panel_timeline->selections[i];
for (int j=0;j<panel_timeline->selections.size();j++) {
if (i != j) {
Selection& ss = panel_timeline->selections[j];
if (s.track == ss.track) {
bool remove = false;
if (s.in < ss.in && s.out > ss.out) {
// do nothing
} else if (s.in >= ss.in && s.out <= ss.out) {
remove = true;
} else if (s.in <= ss.out && s.out > ss.out) {
ss.out = s.out;
remove = true;
} else if (s.out >= ss.in && s.in < ss.in) {
ss.in = s.in;
remove = true;
}
if (remove) {
panel_timeline->selections.removeAt(i);
i--;
repaint = true;
break;
}
}
}
}
}
}
// destroy all ghosts
@@ -353,10 +391,12 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
pre_clips.clear();
post_clips.clear();
// panel_timeline->repaint_timeline();
if (repaint) panel_timeline->repaint_timeline();
// SEND CLIPS TO EFFECT CONTROLS
// find out how many clips are selected
// limits to one video clip and one audio clip and only if they're linked
// one of these days it might be nice to have multiple clips in the effects panel
bool got_vclip = false;
bool got_aclip = false;
Clip* vclip = NULL;
@@ -632,7 +672,6 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) {
// prevent slip moving clip beyond media length
validator += g.ghost_length;
qDebug() << "validator:" << validator;
if (validator > g.media_length) frame_diff += validator - g.media_length;
}
}
@@ -654,18 +693,18 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
panel_timeline->snap_to_clip(&panel_timeline->cursor_frame, !panel_timeline->edit_tool_also_seeks || !panel_timeline->selecting);
}
if (panel_timeline->selecting) {
int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start);
int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start) + panel_timeline->selection_offset;
if (panel_timeline->selections.size() != selection_count) {
panel_timeline->selections.resize(selection_count);
}
int minimum_selection_track = qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start);
for (int i=0;i<selection_count;i++) {
Selection* s = &panel_timeline->selections[i];
s->track = minimum_selection_track + i;
for (int i=panel_timeline->selection_offset;i<selection_count;i++) {
Selection& s = panel_timeline->selections[i];
s.track = minimum_selection_track + i - panel_timeline->selection_offset;
long in = panel_timeline->drag_frame_start;
long out = panel_timeline->cursor_frame;
s->in = qMin(in, out);
s->out = qMax(in, out);
s.in = qMin(in, out);
s.out = qMax(in, out);
}
if (panel_timeline->edit_tool_also_seeks) {
panel_timeline->seek(qMin(panel_timeline->drag_frame_start, panel_timeline->cursor_frame));
+36 -10
View File
@@ -61,30 +61,58 @@ void ViewerWidget::paintGL()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
long playhead = panel_timeline->playhead;
current_clips.clear();
for (int i=0;i<sequence->clip_count();i++) {
Clip* c = sequence->get_clip(i);
// if clip starts within one second and/or hasn't finished yet
if (c != NULL) {
if (is_clip_active(c, panel_timeline->playhead)) {
// if thread is already working, we don't want to touch this,
// but we also don't want to hang the UI thread
if (!c->open) {
if (c->open_lock.tryLock()) {
open_clip(c, multithreaded);
}
}
bool added = false;
for (int j=0;j<current_clips.size();j++) {
if (current_clips.at(j)->track > c->track) {
current_clips.insert(j, c);
added = true;
break;
}
}
if (!added) {
current_clips.append(c);
}
} else if (c->open) {
close_clip(c);
}
}
}
handle_media(sequence, playhead, multithreaded);
texture_failed = false;
bool render_audio = (panel_timeline->playing || force_audio);
cc_lock.lock();
for (int i=0;i<current_clips.size();i++) {
Clip* c = current_clips.at(i);
if (!c->finished_opening) {
qDebug() << "[WARNING] Tried to display clip" << i << "but it's closed";
texture_failed = true;
} else if (is_clip_active(c, playhead)) {
} else if (is_clip_active(c, panel_timeline->playhead)) {
if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
// start preparing cache
get_clip_frame(c, playhead);
get_clip_frame(c, panel_timeline->playhead);
if (c->texture == NULL) {
qDebug() << "[WARNING] Texture hasn't been created yet";
texture_failed = true;
} else if (playhead >= c->timeline_in) {
} else if (panel_timeline->playhead >= c->timeline_in) {
glLoadIdentity();
int half_width = c->sequence->width/2;
int half_height = c->sequence->height/2;
@@ -119,7 +147,7 @@ void ViewerWidget::paintGL()
c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
c->lock.tryLock()) {
// clip is not caching, start caching audio
cache_clip(c, playhead, false, false, c->reset_audio);
cache_clip(c, panel_timeline->playhead, false, false, c->reset_audio);
c->lock.unlock();
}
}
@@ -143,8 +171,6 @@ void ViewerWidget::paintGL()
p.drawText({0, 0, 200, 200}, "text!");
p.end();*/
cc_lock.unlock();
if (texture_failed) {
if (multithreaded) {
retry_timer.start();
+2
View File
@@ -6,6 +6,7 @@
#include <QMatrix4x4>
#include <QOpenGLTexture>
#include <QTimer>
struct Clip;
class Viewer;
@@ -25,6 +26,7 @@ protected:
void paintGL();
private:
QTimer retry_timer;
QVector<Clip*> current_clips;
private slots:
void retry();
};