enforced field semantics and completed shared transitions

This commit is contained in:
itsmattkc
2018-11-24 20:12:51 +11:00
parent c5dca79d1d
commit 00b31d514e
31 changed files with 635 additions and 531 deletions
+74 -54
View File
@@ -934,7 +934,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
// step 3 - move clips
Clip* c = sequence->clips.at(g.clip);
if (g.transition == NULL) {
ca->append(new MoveClipAction(c, c->timeline_in + (g.in - g.old_in), c->timeline_out + (g.out - g.old_out), c->clip_in + (g.clip_in - g.old_clip_in), c->track + (g.track - g.old_track)));
move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out + (g.out - g.old_out), c->clip_in + (g.clip_in - g.old_clip_in), c->track + (g.track - g.old_track));
// adjust transitions if we need to
long new_clip_length = (g.out - g.in);
@@ -971,13 +971,13 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
if (g.transition->secondary_clip != NULL) {
if (g.in != g.old_in && !g.trimming) {
long movement = g.in - g.old_in;
ca->append(new MoveClipAction(g.transition->parent_clip, g.transition->parent_clip->timeline_in + movement, g.transition->parent_clip->timeline_out, g.transition->parent_clip->clip_in + movement, g.transition->parent_clip->track));
ca->append(new MoveClipAction(g.transition->secondary_clip, g.transition->secondary_clip->timeline_in, g.transition->secondary_clip->timeline_out + movement, g.transition->secondary_clip->clip_in, g.transition->secondary_clip->track));
move_clip(ca, g.transition->parent_clip, g.transition->parent_clip->timeline_in + movement, g.transition->parent_clip->timeline_out, g.transition->parent_clip->clip_in + movement, g.transition->parent_clip->track, false);
move_clip(ca, g.transition->secondary_clip, g.transition->secondary_clip->timeline_in, g.transition->secondary_clip->timeline_out + movement, g.transition->secondary_clip->clip_in, g.transition->secondary_clip->track, false);
}
} else if (is_opening_transition) {
if (g.in != g.old_in) {
// if transition is going to make the clip bigger, make the clip bigger
ca->append(new MoveClipAction(c, c->timeline_in + (g.in - g.old_in), c->timeline_out, c->clip_in + (g.clip_in - g.old_clip_in), c->track));
move_clip(ca, c, c->timeline_in + (g.in - g.old_in), c->timeline_out, c->clip_in + (g.clip_in - g.old_clip_in), c->track);
clip_length -= (g.in - g.old_in);
}
@@ -985,7 +985,7 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
} else {
if (g.out != g.old_out) {
// if transition is going to make the clip bigger, make the clip bigger
ca->append(new MoveClipAction(c, c->timeline_in, c->timeline_out + (g.out - g.old_out), c->clip_in, c->track));
move_clip(ca, c, c->timeline_in, c->timeline_out + (g.out - g.old_out), c->clip_in, c->track);
clip_length += (g.out - g.old_out);
}
@@ -1053,14 +1053,14 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) {
panel_timeline->delete_areas_and_relink(ca, areas);
if (move_post) ca->append(new MoveClipAction(post, qMin(transition_start, post->timeline_in), post->timeline_out, post->clip_in - (post->timeline_in - transition_start), post->track));
if (move_pre) ca->append(new MoveClipAction(pre, pre->timeline_in, qMax(transition_end, pre->timeline_out), pre->clip_in, pre->track));
if (move_post) move_clip(ca, post, qMin(transition_start, post->timeline_in), post->timeline_out, post->clip_in - (post->timeline_in - transition_start), post->track);
if (move_pre) move_clip(ca, pre, pre->timeline_in, qMax(transition_end, pre->timeline_out), pre->clip_in, pre->track);
}
if (panel_timeline->transition_tool_post_clip > -1) {
ca->append(new AddTransitionCommand(pre, post, panel_timeline->transition_tool_meta, TA_OPENING_TRANSITION, transition_end - pre->timeline_in));
ca->append(new AddTransitionCommand(pre, post, NULL, panel_timeline->transition_tool_meta, TA_OPENING_TRANSITION, transition_end - pre->timeline_in));
} else {
ca->append(new AddTransitionCommand(pre, NULL, panel_timeline->transition_tool_meta, panel_timeline->transition_tool_type, transition_end - transition_start));
ca->append(new AddTransitionCommand(pre, NULL, NULL, panel_timeline->transition_tool_meta, panel_timeline->transition_tool_type, transition_end - transition_start));
}
push_undo = true;
@@ -1124,9 +1124,14 @@ void TimelineWidget::init_ghosts() {
Clip* c = sequence->clips.at(g.clip);
g.track = g.old_track = c->track;
g.clip_in = g.old_clip_in = panel_timeline->tool == TIMELINE_TOOL_SLIP ? c->get_clip_in_with_transition() : c->clip_in;
g.clip_in = g.old_clip_in = c->clip_in;
if (g.transition == NULL) {
if (panel_timeline->tool == TIMELINE_TOOL_SLIP) {
g.clip_in = g.old_clip_in = c->get_clip_in_with_transition();
g.in = g.old_in = c->get_timeline_in_with_transition();
g.out = g.old_out = c->get_timeline_out_with_transition();
g.ghost_length = g.old_out - g.old_in;
} else if (g.transition == NULL) {
// this ghost is for a clip
g.in = g.old_in = c->timeline_in;
g.out = g.old_out = c->timeline_out;
@@ -1153,6 +1158,42 @@ void TimelineWidget::init_ghosts() {
}
}
void validate_transitions(Clip* otc, Clip* ctc, long length, long& frame_diff) {
long validator;
if (otc != NULL) {
validator = otc->timeline_in + frame_diff;
if (validator < 0) frame_diff -= validator; // prevent from going below 0 on the timeline
if (panel_timeline->transition_tool_post_clip > -1) {
validator = otc->clip_in + length - frame_diff;
if (validator < 0) frame_diff += validator; // prevent from going below 0 for the media
validator = otc->clip_in + length + frame_diff - otc->getMaximumLength();
if (validator > 0) frame_diff -= validator; // prevent transition from exceeding media length
} else {
validator = otc->clip_in + length + frame_diff;
if (validator < 0) frame_diff -= validator; // prevent from going below 0 for the media
if (validator > otc->getMaximumLength()) frame_diff -= (validator - otc->getMaximumLength()); // prevent transition from exceeding media length
}
}
if (ctc != NULL) {
// prevent transition from exceeding media length
validator = ctc->clip_in + length + ctc->getLength() + frame_diff;
if (validator > ctc->getMaximumLength()) frame_diff -= (validator - ctc->getMaximumLength());
// prevent from going below 0 for the media
if (panel_timeline->transition_tool_post_clip > -1) {
validator = ctc->clip_in + length - ctc->getLength() + frame_diff;
if (validator > 0) frame_diff -= validator;
}
// prevent from going below 0 on the timeline
validator = ctc->timeline_out + length + frame_diff;
if (validator < 0) frame_diff -= validator;
}
}
void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
int mouse_track = getTrackFromScreenPoint(mouse_pos.y());
long frame_diff = (lock_frame) ? 0 : panel_timeline->getTimelineFrameFromScreenPoint(mouse_pos.x()) - panel_timeline->drag_frame_start;
@@ -1246,14 +1287,12 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
frame_diff = -frame_diff;
}
validator = g.transition->parent_clip->get_clip_in_with_transition() - frame_diff;
if (validator < 0) frame_diff += validator;
// TESTING CODE
Clip* otc = g.transition->parent_clip;
Clip* ctc = g.transition->secondary_clip;
validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff - g.transition->secondary_clip->getMaximumLength();
if (validator > 0) frame_diff -= validator;
validator = g.transition->length + frame_diff - 1;
if (validator < 0) frame_diff -= validator;
validate_transitions(otc, ctc, g.transition->length, frame_diff);
// TESTING CODE END
if (g.trim_in) {
frame_diff = -frame_diff;
@@ -1294,9 +1333,16 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
if (g.transition != NULL) {
if (g.transition->secondary_clip != NULL) {
// prevent dual transitions from going below 0 on the primary or above media length on the secondary
validator = g.transition->parent_clip->get_clip_in_with_transition() + frame_diff;
if (validator < 0) frame_diff -= validator;
validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() - g.transition->get_length() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff;
if (validator < 0) frame_diff -= validator;
validator = g.transition->parent_clip->clip_in + frame_diff - g.transition->parent_clip->getMaximumLength() + g.transition->length;
if (validator > 0) frame_diff -= validator;
validator = g.transition->secondary_clip->get_timeline_out_with_transition() - g.transition->secondary_clip->get_timeline_in_with_transition() + g.transition->secondary_clip->get_clip_in_with_transition() + frame_diff - g.transition->secondary_clip->getMaximumLength();
if (validator > 0) frame_diff -= validator;
} else {
@@ -1344,38 +1390,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
ctc = temp;
}
if (otc != NULL) {
validator = otc->timeline_in + frame_diff;
if (validator < 0) frame_diff -= validator; // prevent from going below 0 on the timeline
if (panel_timeline->transition_tool_post_clip > -1) {
validator = otc->clip_in - frame_diff;
if (validator < 0) frame_diff += validator; // prevent from going below 0 for the media
validator = otc->clip_in + frame_diff - otc->getMaximumLength();
if (validator > 0) frame_diff -= validator; // prevent transition from exceeding media length
} else {
validator = otc->clip_in + frame_diff;
if (validator < 0) frame_diff -= validator; // prevent from going below 0 for the media
if (validator > otc->getMaximumLength()) frame_diff -= (validator - otc->getMaximumLength()); // prevent transition from exceeding media length
}
}
if (ctc != NULL) {
validator = ctc->clip_in + ctc->getLength() + frame_diff; // prevent transition from exceeding media length
if (validator > ctc->getMaximumLength()) {
frame_diff -= (validator - ctc->getMaximumLength());
}
if (validator < 0) { // prevent from going below 0 for the media
frame_diff -= validator;
}
validator = ctc->timeline_out + frame_diff; // prevent from going below 0 on the timeline
if (validator < 0) {
frame_diff -= validator;
}
}
validate_transitions(otc, ctc, 0, frame_diff);
if (flipped) {
frame_diff = -frame_diff;
@@ -1614,7 +1629,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
bool add = panel_timeline->is_clip_selected(c, true);
// if a whole clip is not selected, maybe just a transition is
if (!add && panel_timeline->tool == TIMELINE_TOOL_POINTER && (c->get_opening_transition() != NULL || c->get_closing_transition() != NULL)) {
if (panel_timeline->tool == TIMELINE_TOOL_POINTER && (c->get_opening_transition() != NULL || c->get_closing_transition() != NULL)) {
// check if any selections contain the whole clip or transition
for (int j=0;j<sequence->selections.size();j++) {
const Selection& s = sequence->selections.at(j);
@@ -2129,6 +2144,8 @@ void draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, QRect& text_r
p.fillRect(transition_rect, transition_color);
QRect transition_text_rect(transition_rect.x() + CLIP_TEXT_PADDING, transition_rect.y() + CLIP_TEXT_PADDING, transition_rect.width() - CLIP_TEXT_PADDING, transition_rect.height() - CLIP_TEXT_PADDING);
if (transition_text_rect.width() > MAX_TEXT_WIDTH) {
bool draw_text = true;
p.setPen(QColor(0, 0, 0, 96));
if (t->secondary_clip == NULL) {
if (transition_type == TA_OPENING_TRANSITION) {
@@ -2136,18 +2153,21 @@ void draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, QRect& text_r
} else {
p.drawLine(transition_rect.topLeft(), transition_rect.bottomRight());
}
} else{
} else {
if (transition_type == TA_OPENING_TRANSITION) {
p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.topRight());
p.drawLine(QPoint(transition_rect.left(), transition_rect.center().y()), transition_rect.bottomRight());
draw_text = false;
} else {
p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.topLeft());
p.drawLine(QPoint(transition_rect.right(), transition_rect.center().y()), transition_rect.bottomLeft());
}
}
p.setPen(Qt::white);
p.drawText(transition_text_rect, 0, t->name, &transition_text_rect);
if (draw_text) {
p.setPen(Qt::white);
p.drawText(transition_text_rect, 0, t->meta->name, &transition_text_rect);
}
}
p.setPen(Qt::black);
p.drawRect(transition_rect);
+39 -34
View File
@@ -441,9 +441,11 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
coords.vertexTopLeftX = coords.vertexBottomLeftX = -video_width/2;
coords.vertexTopLeftY = coords.vertexTopRightY = -video_height/2;
coords.vertexTopRightX = coords.vertexBottomRightX = video_width/2;
coords.vertexBottomLeftY = coords.vertexBottomRightY = video_height/2;
coords.textureTopLeftY = coords.textureTopRightY = coords.textureTopLeftX = coords.textureBottomLeftX = 0;
coords.vertexBottomLeftY = coords.vertexBottomRightY = video_height/2;
coords.vertexBottomLeftZ = coords.vertexBottomRightZ = coords.vertexTopLeftZ = coords.vertexTopRightZ = 1;
coords.textureTopLeftY = coords.textureTopRightY = coords.textureTopLeftX = coords.textureBottomLeftX = 0.0;
coords.textureBottomLeftY = coords.textureBottomRightY = coords.textureTopRightX = coords.textureBottomRightX = 1.0;
coords.textureTopLeftQ = coords.textureTopRightQ = coords.textureTopLeftQ = coords.textureBottomLeftQ = 1;
if (c->autoscale && (video_width != s->width && video_height != s->height)) {
float width_multiplier = (float) s->width / (float) video_width;
@@ -496,43 +498,45 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio)
glBegin(GL_QUADS);
if (coords.grid_size <= 1) {
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
glVertex2f(coords.vertexTopLeftX, coords.vertexTopLeftY); // top left
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
glVertex2f(coords.vertexTopRightX, coords.vertexTopRightY); // top right
glTexCoord2f(coords.textureBottomRightX, coords.textureBottomRightY); // bottom right
glVertex2f(coords.vertexBottomRightX, coords.vertexBottomRightY); // bottom right
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
glVertex2f(coords.vertexBottomLeftX, coords.vertexBottomLeftY); // bottom left
float z = 0.5f;
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
glVertex3f(coords.vertexTopLeftX, coords.vertexTopLeftY, z); // top left
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
glVertex3f(coords.vertexTopRightX, coords.vertexTopRightY, z); // top right
glTexCoord2f(coords.textureBottomRightX, coords.textureBottomRightY); // bottom right
glVertex3f(coords.vertexBottomRightX, coords.vertexBottomRightY, z); // bottom right
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
glVertex3f(coords.vertexBottomLeftX, coords.vertexBottomLeftY, z); // bottom left
} else {
double rows = coords.grid_size;
double cols = coords.grid_size;
float rows = coords.grid_size;
float cols = coords.grid_size;
for (double i=0;i<rows;i++) {
double row_prog = i/rows;
double next_row_prog = (i+1)/rows;
for (double j=0;j<cols;j++) {
double col_prog = j/cols;
double next_col_prog = (j+1)/cols;
for (float i=0;i<rows;i++) {
float row_prog = i/rows;
float next_row_prog = (i+1)/rows;
for (float j=0;j<cols;j++) {
float col_prog = j/cols;
float next_col_prog = (j+1)/cols;
double vertexTLX = double_lerp(coords.vertexTopLeftX, coords.vertexBottomLeftX, row_prog);
double vertexTRX = double_lerp(coords.vertexTopRightX, coords.vertexBottomRightX, row_prog);
double vertexBLX = double_lerp(coords.vertexTopLeftX, coords.vertexBottomLeftX, next_row_prog);
double vertexBRX = double_lerp(coords.vertexTopRightX, coords.vertexBottomRightX, next_row_prog);
float vertexTLX = float_lerp(coords.vertexTopLeftX, coords.vertexBottomLeftX, row_prog);
float vertexTRX = float_lerp(coords.vertexTopRightX, coords.vertexBottomRightX, row_prog);
float vertexBLX = float_lerp(coords.vertexTopLeftX, coords.vertexBottomLeftX, next_row_prog);
float vertexBRX = float_lerp(coords.vertexTopRightX, coords.vertexBottomRightX, next_row_prog);
double vertexTLY = double_lerp(coords.vertexTopLeftY, coords.vertexTopRightY, col_prog);
double vertexTRY = double_lerp(coords.vertexTopLeftY, coords.vertexTopRightY, next_col_prog);
double vertexBLY = double_lerp(coords.vertexBottomLeftY, coords.vertexBottomRightY, col_prog);
double vertexBRY = double_lerp(coords.vertexBottomLeftY, coords.vertexBottomRightY, next_col_prog);
float vertexTLY = float_lerp(coords.vertexTopLeftY, coords.vertexTopRightY, col_prog);
float vertexTRY = float_lerp(coords.vertexTopLeftY, coords.vertexTopRightY, next_col_prog);
float vertexBLY = float_lerp(coords.vertexBottomLeftY, coords.vertexBottomRightY, col_prog);
float vertexBRY = float_lerp(coords.vertexBottomLeftY, coords.vertexBottomRightY, next_col_prog);
glTexCoord2f(double_lerp(coords.textureTopLeftX, coords.textureTopRightX, col_prog), double_lerp(coords.textureTopLeftY, coords.textureBottomLeftY, row_prog)); // top left
glVertex2f(double_lerp(vertexTLX, vertexTRX, col_prog), double_lerp(vertexTLY, vertexBLY, row_prog)); // top left
glTexCoord2f(double_lerp(coords.textureTopLeftX, coords.textureTopRightX, next_col_prog), double_lerp(coords.textureTopRightY, coords.textureBottomRightY, row_prog)); // top right
glVertex2f(double_lerp(vertexTLX, vertexTRX, next_col_prog), double_lerp(vertexTRY, vertexBRY, row_prog)); // top right
glTexCoord2f(double_lerp(coords.textureBottomLeftX, coords.textureBottomRightX, next_col_prog), double_lerp(coords.textureTopRightY, coords.textureBottomRightY, next_row_prog)); // bottom right
glVertex2f(double_lerp(vertexBLX, vertexBRX, next_col_prog), double_lerp(vertexTRY, vertexBRY, next_row_prog)); // bottom right
glTexCoord2f(double_lerp(coords.textureBottomLeftX, coords.textureBottomRightX, col_prog), double_lerp(coords.textureTopLeftY, coords.textureBottomLeftY, next_row_prog)); // bottom left
glVertex2f(double_lerp(vertexBLX, vertexBRX, col_prog), double_lerp(vertexTLY, vertexBLY, next_row_prog)); // bottom left
glTexCoord2f(float_lerp(coords.textureTopLeftX, coords.textureTopRightX, col_prog), float_lerp(coords.textureTopLeftY, coords.textureBottomLeftY, row_prog)); // top left
glVertex2f(float_lerp(vertexTLX, vertexTRX, col_prog), float_lerp(vertexTLY, vertexBLY, row_prog)); // top left
glTexCoord2f(float_lerp(coords.textureTopLeftX, coords.textureTopRightX, next_col_prog), float_lerp(coords.textureTopRightY, coords.textureBottomRightY, row_prog)); // top right
glVertex2f(float_lerp(vertexTLX, vertexTRX, next_col_prog), float_lerp(vertexTRY, vertexBRY, row_prog)); // top right
glTexCoord2f(float_lerp(coords.textureBottomLeftX, coords.textureBottomRightX, next_col_prog), float_lerp(coords.textureTopRightY, coords.textureBottomRightY, next_row_prog)); // bottom right
glVertex2f(float_lerp(vertexBLX, vertexBRX, next_col_prog), float_lerp(vertexTRY, vertexBRY, next_row_prog)); // bottom right
glTexCoord2f(float_lerp(coords.textureBottomLeftX, coords.textureBottomRightX, col_prog), float_lerp(coords.textureTopLeftY, coords.textureBottomLeftY, next_row_prog)); // bottom left
glVertex2f(float_lerp(vertexBLX, vertexBRX, col_prog), float_lerp(vertexTLY, vertexBLY, next_row_prog)); // bottom left
}
}
}
@@ -617,6 +621,7 @@ void ViewerWidget::paintGL() {
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_DEPTH);
texture_failed = false;