#include "gwindow.h"
#include "gwindowgui.h"
#include "keyframe.h"
+#include "keyframes.h"
#include "language.h"
#include "labels.h"
#include "levelwindow.h"
int MWindow::modify_edithandles()
{
undo->update_undo_before();
+ int handle_mode = edl->session->edit_handle_mode[session->drag_button];
edl->modify_edithandles(session->drag_start,
- session->drag_position,
- session->drag_handle,
- edl->session->edit_handle_mode[session->drag_button],
+ session->drag_position, session->drag_handle, handle_mode,
edl->session->labels_follow_edits,
edl->session->plugins_follow_edits,
- edl->session->autos_follow_edits);
-
+ edl->session->autos_follow_edits,
+ session->drag_edit->group_id);
finish_modify_handles();
//printf("MWindow::modify_handles 1\n");
return 0;
void MWindow::finish_modify_handles()
{
int edit_mode = edl->session->edit_handle_mode[session->drag_button];
-
- if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
- (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
-//printf("MWindow::finish_modify_handles %d\n", __LINE__);
- edl->local_session->set_selectionstart(session->drag_position);
- edl->local_session->set_selectionend(session->drag_position);
- }
- else
- if( edit_mode != MOVE_NO_EDITS ) {
-//printf("MWindow::finish_modify_handles %d\n", __LINE__);
- edl->local_session->set_selectionstart(session->drag_start);
- edl->local_session->set_selectionend(session->drag_start);
- }
-
-// clamp the selection to 0
- if( edl->local_session->get_selectionstart(1) < 0 ) {
- edl->local_session->set_selectionstart(0);
- edl->local_session->set_selectionend(0);
+ double position = -1;
+ switch( edit_mode ) {
+ case MOVE_RIPPLE:
+ case MOVE_ROLL:
+ case MOVE_SLIDE:
+ position = session->drag_position;
+ break;
+ case MOVE_SLIP:
+ case MOVE_EDGE:
+ position = session->drag_start;
+ break;
+ }
+ if( position >= 0 ) {
+ edl->local_session->set_selectionstart(position);
+ edl->local_session->set_selectionend(position);
}
undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
}
-void MWindow::selected_to_clipboard(int packed)
+EDL *MWindow::selected_edits_to_clip(int packed,
+ double *start_position, Track **start_track,
+ int edit_labels, int edit_autos, int edit_plugins)
{
- int64_t start = INT64_MAX, end = -INT64_MAX, pos = 0;
+ double start = DBL_MAX, end = DBL_MIN;
Track *first_track=0, *last_track = 0;
for( Track *track=edl->tracks->first; track; track=track->next ) {
if( !track->record ) continue;
int empty = 1;
for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
if( !edit->is_selected || edit->silence() ) continue;
- if( start > (pos=edit->startproject) ) start = pos;
- if( end < (pos+=edit->length) ) end = pos;
+ double edit_pos = track->from_units(edit->startproject);
+ if( start > edit_pos ) start = edit_pos;
+ if( end < (edit_pos+=edit->length) ) end = edit_pos;
empty = 0;
}
if( empty ) continue;
if( !first_track ) first_track = track;
last_track = track;
}
- if( !first_track ) return;
+ if( start_position ) *start_position = start;
+ if( start_track ) *start_track = first_track;
+ if( !first_track ) return 0;
EDL *new_edl = new EDL();
new_edl->create_objects();
new_edl->copy_session(edl);
Track *new_track = 0;
if( !packed )
new_track = new_edl->add_new_track(track->data_type);
+ int64_t start_pos = track->to_units(start, 0);
+ int64_t end_pos = track->to_units(end, 0);
int64_t startproject = 0;
- for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
- if( edit->startproject < start ) continue;
- if( edit->startproject >= end ) break;
+ Edit *edit = track->edits->first;
+ for( ; edit; edit=edit->next ) {
if( !edit->is_selected || edit->silence() ) continue;
+ if( edit->startproject < start_pos ) continue;
+ if( edit->startproject >= end_pos ) break;
+ int64_t edit_start_pos = edit->startproject;
+ int64_t edit_end_pos = edit->startproject + edit->length;
if( !new_track )
new_track = new_edl->add_new_track(track->data_type);
- if( new_track ) {
- if( !packed ) {
- int64_t edit_position = edit->startproject - start;
- if( edit_position > startproject ) {
- Edit *silence = new Edit(new_edl, new_track);
- silence->startproject = startproject;
- silence->length = edit_position - startproject;
- new_track->edits->append(silence);
- startproject = edit_position;
+ int64_t edit_pos = edit_start_pos - start_pos;
+ if( !packed && edit_pos > startproject ) {
+ Edit *silence = new Edit(new_edl, new_track);
+ silence->startproject = startproject;
+ silence->length = edit_pos - startproject;
+ new_track->edits->append(silence);
+ startproject = edit_pos;
+ }
+ int64_t clip_start_pos = startproject;
+ Edit *clip_edit = new Edit(new_edl, new_track);
+ clip_edit->copy_from(edit);
+ clip_edit->startproject = startproject;
+ startproject += clip_edit->length;
+ new_track->edits->append(clip_edit);
+ if( edit_labels ) {
+ double edit_start = track->from_units(edit_start_pos);
+ double edit_end = track->from_units(edit_end_pos);
+ double clip_start = new_track->from_units(clip_start_pos);
+ Label *label = edl->labels->first;
+ for( ; label; label=label->next ) {
+ if( label->position < edit_start ) continue;
+ if( label->position >= edit_end ) break;
+ double clip_position = label->position - edit_start + clip_start;
+ Label *clip_label = new_edl->labels->first;
+ while( clip_label && clip_label->position<clip_position )
+ clip_label = clip_label->next;
+ if( clip_label && clip_label->position == clip_position ) continue;
+ Label *new_label = new Label(new_edl,
+ new_edl->labels, clip_position, label->textstr);
+ new_edl->labels->insert_before(clip_label, new_label);
+ }
+ }
+ if( edit_autos ) {
+ Automation *automation = track->automation;
+ Automation *new_automation = new_track->automation;
+ for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
+ Autos *autos = automation->autos[i];
+ if( !autos ) continue;
+ Autos *new_autos = new_automation->autos[i];
+ new_autos->default_auto->copy_from(autos->default_auto);
+ Auto *aut0 = autos->first;
+ for( ; aut0; aut0=aut0->next ) {
+ if( aut0->position < edit_start_pos ) continue;
+ if( aut0->position >= edit_end_pos ) break;
+ Auto *new_auto = new_autos->new_auto();
+ new_auto->copy_from(aut0);
+ int64_t clip_position = aut0->position - edit_start_pos + clip_start_pos;
+ new_auto->position = clip_position;
+ new_autos->append(new_auto);
+ }
+ }
+ }
+ if( edit_plugins ) {
+ while( new_track->plugin_set.size() < track->plugin_set.size() )
+ new_track->plugin_set.append(0);
+ for( int i=0; i<track->plugin_set.total; ++i ) {
+ PluginSet *plugin_set = track->plugin_set[i];
+ if( !plugin_set ) continue;
+ PluginSet *new_plugin_set = new_track->plugin_set[i];
+ if( !new_plugin_set ) {
+ new_plugin_set = new PluginSet(new_edl, new_track);
+ new_track->plugin_set[i] = new_plugin_set;
+ }
+ Plugin *plugin = (Plugin*)plugin_set->first;
+ int64_t startplugin = new_plugin_set->length();
+ for( ; plugin ; plugin=(Plugin*)plugin->next ) {
+ if( plugin->silence() ) continue;
+ int64_t plugin_start_pos = plugin->startproject;
+ int64_t plugin_end_pos = plugin_start_pos + plugin->length;
+ if( plugin_end_pos < start_pos ) continue;
+ if( plugin_start_pos > end_pos ) break;
+ if( plugin_start_pos < edit_start_pos )
+ plugin_start_pos = edit_start_pos;
+ if( plugin_end_pos > edit_end_pos )
+ plugin_end_pos = edit_end_pos;
+ if( plugin_start_pos >= plugin_end_pos ) continue;
+ int64_t plugin_pos = plugin_start_pos - start_pos;
+ if( !packed && plugin_pos > startplugin ) {
+ Plugin *silence = new Plugin(new_edl, new_track, "");
+ silence->startproject = startplugin;
+ silence->length = plugin_pos - startplugin;
+ new_plugin_set->append(silence);
+ startplugin = plugin_pos;
+ }
+ Plugin *new_plugin = new Plugin(new_edl, new_track, plugin->title);
+ new_plugin->copy_base(plugin);
+ new_plugin->startproject = startplugin;
+ new_plugin->length = plugin_end_pos - plugin_start_pos;
+ startplugin += new_plugin->length;
+ new_plugin_set->append(new_plugin);
+ KeyFrames *keyframes = plugin->keyframes;
+ KeyFrames *new_keyframes = new_plugin->keyframes;
+ new_keyframes->default_auto->copy_from(keyframes->default_auto);
+ new_keyframes->default_auto->position = new_plugin->startproject;
+ KeyFrame *keyframe = (KeyFrame*)keyframes->first;
+ for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
+ if( keyframe->position < edit_start_pos ) continue;
+ if( keyframe->position >= edit_end_pos ) break;
+ KeyFrame *clip_keyframe = new KeyFrame(new_edl, new_keyframes);
+ clip_keyframe->copy_from(keyframe);
+ int64_t key_position = keyframe->position - start_pos;
+ if( packed )
+ key_position += new_plugin->startproject - plugin_pos;
+ clip_keyframe->position = key_position;
+ new_keyframes->append(clip_keyframe);
+ }
}
}
- Edit *clip_edit = new Edit(new_edl, new_track);
- clip_edit->copy_from(edit);
- clip_edit->startproject = startproject;
- startproject += clip_edit->length;
- new_track->edits->append(clip_edit);
}
}
if( last_track == track ) break;
}
+ return new_edl;
+}
+
+void MWindow::selected_edits_to_clipboard(int packed)
+{
+ EDL *new_edl = selected_edits_to_clip(packed, 0, 0,
+ edl->session->labels_follow_edits,
+ edl->session->autos_follow_edits,
+ edl->session->plugins_follow_edits);
+ if( !new_edl ) return;
double length = new_edl->tracks->total_length();
FileXML file;
new_edl->copy(0, length, 1, &file, "", 1);
{
if( !edits->size() ) return;
undo->update_undo_before();
- for( Track *track=edl->tracks->first; track; track=track->next ) {
- for( Edit *next=track->edits->first; next; ) {
- Edit *edit = next; next = edit->next;
- if( !edit->is_selected ) continue;
- int64_t len = edit->length;
- delete edit;
- if( !collapse ) continue;
- for( edit=next; edit; edit=edit->next )
- edit->startproject -= len;
- }
- }
+ if( edl->session->labels_follow_edits )
+ edl->delete_edit_labels(edits, collapse);
+ edl->delete_edits(edits, collapse);
edl->optimize();
save_backup();
undo->update_undo_after(msg, LOAD_EDITS);
// packed - omit unselected from selection, unpacked - replace unselected with silence
void MWindow::cut_selected_edits(int collapse, int packed)
{
- selected_to_clipboard(packed);
+ selected_edits_to_clipboard(packed);
ArrayList<Edit*> edits;
edl->tracks->get_selected_edits(&edits);
delete_edits(&edits, _("cut edit"), collapse);
void MWindow::move_edits(ArrayList<Edit*> *edits,
- Track *track,
- double position,
- int behaviour)
+ Track *track, double position, int mode)
{
undo->update_undo_before();
-
- edl->tracks->move_edits(edits,
- track,
- position,
+// lockout timebar labels update
+// labels can be deleted with tooltip repeater running
+ cwindow->gui->lock_window("Tracks::move_edits");
+ edl->tracks->move_edits(edits, track, position,
edl->session->labels_follow_edits,
edl->session->plugins_follow_edits,
- edl->session->autos_follow_edits,
- behaviour);
+ edl->session->autos_follow_edits, mode);
+ cwindow->gui->timebar->update(1);
+ cwindow->gui->unlock_window();
save_backup();
undo->update_undo_after(_("move edit"), LOAD_ALL);
gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
}
+void MWindow::paste_edits(EDL *clip, Track *first_track, double position, int overwrite,
+ int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
+{
+ if( !first_track )
+ first_track = edl->tracks->first;
+ Track *src = clip->tracks->first;
+ for( Track *track=first_track; track && src; track=track->next ) {
+ if( !track->record ) continue;
+ int64_t pos = track->to_units(position, 0);
+ if( edit_edits ) {
+ for( Edit *edit=src->edits->first; edit; edit=edit->next ) {
+ if( edit->silence() ) continue;
+ int64_t start = pos + edit->startproject;
+ int64_t len = edit->length, end = start + len;
+ if( overwrite )
+ track->edits->clear(start, end);
+ Edit *dst = track->edits->insert_new_edit(start);
+ dst->copy_from(edit);
+ dst->startproject = start;
+ dst->is_selected = 1;
+ while( (dst=dst->next) != 0 )
+ dst->startproject += edit->length;
+ if( overwrite ) continue;
+ if( edit_labels && track == first_track ) {
+ double dst_pos = track->from_units(start);
+ double dst_len = track->from_units(len);
+ for( Label *label=edl->labels->first; label; label=label->next ) {
+ if( label->position >= dst_pos )
+ label->position += dst_len;
+ }
+ }
+ if( edit_autos ) {
+ for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
+ Autos *autos = track->automation->autos[i];
+ if( !autos ) continue;
+ for( Auto *aut0=autos->first; aut0; aut0=aut0->next ) {
+ if( aut0->position >= start )
+ aut0->position += edit->length;
+ }
+ }
+ }
+ if( edit_plugins ) {
+ for( int i=0; i<track->plugin_set.size(); ++i ) {
+ PluginSet *plugin_set = track->plugin_set[i];
+ Plugin *plugin = (Plugin *)plugin_set->first;
+ for( ; plugin; plugin=(Plugin *)plugin->next ) {
+ if( plugin->startproject >= start )
+ plugin->startproject += edit->length;
+ else if( plugin->startproject+plugin->length > end )
+ plugin->length += edit->length;
+ Auto *default_keyframe = plugin->keyframes->default_auto;
+ if( default_keyframe->position >= start )
+ default_keyframe->position += edit->length;
+ KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
+ for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
+ if( keyframe->position >= start )
+ keyframe->position += edit->length;
+ }
+ }
+ plugin_set->optimize();
+ }
+ }
+ }
+ }
+ if( edit_autos ) {
+ for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
+ Autos *src_autos = src->automation->autos[i];
+ if( !src_autos ) continue;
+ Autos *autos = track->automation->autos[i];
+ for( Auto *aut0=src_autos->first; aut0; aut0=aut0->next ) {
+ int64_t auto_pos = pos + aut0->position;
+ autos->insert_auto(auto_pos, aut0);
+ }
+ }
+ }
+ if( edit_plugins ) {
+ for( int i=0; i<src->plugin_set.size(); ++i ) {
+ PluginSet *plugin_set = src->plugin_set[i];
+ if( !plugin_set ) continue;
+ while( i >= track->plugin_set.size() )
+ track->plugin_set.append(0);
+ PluginSet *dst_plugin_set = track->plugin_set[i];
+ if( !dst_plugin_set ) {
+ dst_plugin_set = new PluginSet(edl, track);
+ track->plugin_set[i] = dst_plugin_set;
+ }
+ Plugin *plugin = (Plugin *)plugin_set->first;
+ if( plugin ) track->expand_view = 1;
+ for( ; plugin; plugin=(Plugin *)plugin->next ) {
+ int64_t start = pos + plugin->startproject;
+ int64_t end = start + plugin->length;
+ if( overwrite || edit_edits )
+ dst_plugin_set->clear(start, end, 1);
+ Plugin *new_plugin = dst_plugin_set->insert_plugin(plugin->title,
+ start, end-start, plugin->plugin_type, &plugin->shared_location,
+ (KeyFrame*)plugin->keyframes->default_auto, 0);
+ KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
+ for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
+ int64_t keyframe_pos = pos + keyframe->position;
+ new_plugin->keyframes->insert_auto(keyframe_pos, keyframe);
+ }
+ while( (new_plugin=(Plugin *)new_plugin->next) ) {
+ KeyFrame *keyframe = (KeyFrame*)new_plugin->keyframes->first;
+ for( ; keyframe; keyframe=(KeyFrame*)keyframe->next )
+ keyframe->position += plugin->length;
+ }
+ }
+ }
+ }
+ src = src->next;
+ }
+ if( edit_labels ) {
+ Label *edl_label = edl->labels->first;
+ for( Label *label=clip->labels->first; label; label=label->next ) {
+ double label_pos = position + label->position;
+ int exists = 0;
+ while( edl_label &&
+ !(exists=edl->equivalent(edl_label->position, label_pos)) &&
+ edl_label->position < position ) edl_label = edl_label->next;
+ if( exists ) continue;
+ edl->labels->insert_before(edl_label,
+ new Label(edl, edl->labels, label_pos, label->textstr));
+ }
+ }
+ edl->optimize();
+}
+
+void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
+ int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
+{
+ int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
+ if( !len ) return;
+ char *string = new char[len];
+ gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
+ FileXML file;
+ file.read_from_string(string);
+ delete [] string;
+ EDL *clip = new EDL();
+ clip->create_objects();
+ if( !clip->load_xml(&file, LOAD_ALL) ) {
+ undo->update_undo_before();
+ paste_edits(clip, first_track, position, overwrite,
+ edit_edits, edit_labels, edit_autos, edit_plugins);
+ save_backup();
+ undo->update_undo_after(_("paste clip"), LOAD_ALL);
+ restart_brender();
+ cwindow->refresh_frame(CHANGE_EDL);
+
+ update_plugin_guis();
+ gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
+ }
+ clip->remove_user();
+}
+
+void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
+{
+ undo->update_undo_before();
+// lockout timebar labels update
+// labels can be deleted with tooltip repeater running
+ cwindow->gui->lock_window("Tracks::move_group");
+
+ ArrayList<Edit *>edits;
+ edl->tracks->get_selected_edits(&edits);
+ if( edl->session->labels_follow_edits )
+ edl->delete_edit_labels(&edits, 0);
+ edl->delete_edits(&edits, 0);
+ paste_edits(group, first_track, position, overwrite, 1,
+ edl->session->labels_follow_edits,
+ edl->session->autos_follow_edits,
+ edl->session->plugins_follow_edits);
+ cwindow->gui->timebar->update(1);
+ cwindow->gui->unlock_window();
+// big debate over whether to do this, must either clear selected, or no tweaking
+// edl->tracks->clear_selected_edits();
+
+ save_backup();
+ undo->update_undo_after(_("move group"), LOAD_ALL);
+ restart_brender();
+ cwindow->refresh_frame(CHANGE_EDL);
+
+ update_plugin_guis();
+ gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
+}
+
void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
{
undo->update_undo_before();
if( load_mode != LOADMODE_RESOURCESONLY &&
load_mode != LOADMODE_ASSETSONLY ) {
// Insert labels
+ if( edl->session->labels_follow_edits ) {
//printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
- if( load_mode == LOADMODE_PASTE ||
- load_mode == LOADMODE_NESTED )
- edl->labels->insert_labels(new_edl->labels,
- destination_tracks.total ? paste_position[0] : 0.0,
- edl_length,
- edit_labels);
- else
- edl->labels->insert_labels(new_edl->labels,
- current_position,
- edl_length,
- edit_labels);
+ if( load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED )
+ edl->labels->insert_labels(new_edl->labels,
+ destination_tracks.total ? paste_position[0] : 0.0,
+ edl_length, edit_labels);
+ else
+ edl->labels->insert_labels(new_edl->labels, current_position,
+ edl_length, edit_labels);
+ }
//PRINT_TRACE
double total_length = new_edl->tracks->total_length();
for( Track *new_track=new_edl->tracks->first;
current_position + length,
1, // edit edits
edit_labels, edit_plugins, edit_autos,
- 1, // convert units
0); // trim edits
}
//PRINT_TRACE