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
+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();
};