X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fmwindowedit.C;h=5e4b797be1f96ead14415d179af9467b3f04116b;hp=64c54eb15c08e3997bda64e391e604a8ad371df9;hb=26d01a213db5d4f6ee57224cc9a9ea37bd74318c;hpb=a64e7d16c44bba0d137936227fc55871bb26c903 diff --git a/cinelerra-5.1/cinelerra/mwindowedit.C b/cinelerra-5.1/cinelerra/mwindowedit.C index 64c54eb1..5e4b797b 100644 --- a/cinelerra-5.1/cinelerra/mwindowedit.C +++ b/cinelerra-5.1/cinelerra/mwindowedit.C @@ -27,6 +27,7 @@ #include "clip.h" #include "clipedit.h" #include "commercials.h" +#include "convert.h" #include "cplayback.h" #include "ctimebar.h" #include "cwindow.h" @@ -84,86 +85,70 @@ void MWindow::add_audio_track_entry(int above, Track *dst) { undo_before(); - add_audio_track(above, dst); + Track *track = add_audio_track(above, dst); + track->master = 1; save_backup(); undo_after(_("add track"), LOAD_ALL); restart_brender(); gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0); gui->activate_timeline(); - -// gui->get_scrollbars(0); -// gui->canvas->draw(); -// gui->patchbay->update(); -// gui->cursor->draw(1); -// gui->canvas->flash(); -// gui->canvas->activate(); cwindow->refresh_frame(CHANGE_EDL); } -void MWindow::add_video_track_entry(Track *dst) +void MWindow::add_video_track_entry(int above, Track *dst) { undo_before(); - add_video_track(1, dst); + Track *track = add_video_track(above, dst); + track->master = 1; undo_after(_("add track"), LOAD_ALL); restart_brender(); gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0); gui->activate_timeline(); -// gui->get_scrollbars(0); -// gui->canvas->draw(); -// gui->patchbay->update(); -// gui->cursor->draw(1); -// gui->canvas->flash(); -// gui->canvas->activate(); cwindow->refresh_frame(CHANGE_EDL); save_backup(); } -void MWindow::add_subttl_track_entry(Track *dst) +void MWindow::add_subttl_track_entry(int above, Track *dst) { undo_before(); - add_subttl_track(1, dst); + Track *track = add_subttl_track(above, dst); + track->master = 1; undo_after(_("add track"), LOAD_ALL); restart_brender(); gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0); gui->activate_timeline(); -// gui->get_scrollbars(0); -// gui->canvas->draw(); -// gui->patchbay->update(); -// gui->cursor->draw(1); -// gui->canvas->flash(); -// gui->canvas->activate(); cwindow->refresh_frame(CHANGE_EDL); save_backup(); } -int MWindow::add_audio_track(int above, Track *dst) +Track *MWindow::add_audio_track(int above, Track *dst) { - edl->tracks->add_audio_track(above, dst); + Track *track = edl->tracks->add_audio_track(above, dst); edl->tracks->update_y_pixels(theme); save_backup(); - return 0; + return track; } -int MWindow::add_video_track(int above, Track *dst) +Track *MWindow::add_video_track(int above, Track *dst) { - edl->tracks->add_video_track(above, dst); + Track *track = edl->tracks->add_video_track(above, dst); edl->tracks->update_y_pixels(theme); save_backup(); - return 0; + return track; } -int MWindow::add_subttl_track(int above, Track *dst) +Track *MWindow::add_subttl_track(int above, Track *dst) { - edl->tracks->add_subttl_track(above, dst); + Track *track = edl->tracks->add_subttl_track(above, dst); edl->tracks->update_y_pixels(theme); save_backup(); - return 0; + return track; } void MWindow::asset_to_all() @@ -197,13 +182,13 @@ void MWindow::asset_to_all() for( Track *current=edl->tracks->first; current; current=NEXT ) { if( current->data_type == TRACK_VIDEO /* && - current->record */ ) { + current->is_armed() */ ) { current->track_w = w; current->track_h = h; } } - +#ifdef GLx4 if( ((edl->session->output_w % 4) || (edl->session->output_h % 4)) && edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) { @@ -211,7 +196,7 @@ void MWindow::asset_to_all() _("This project's dimensions are not multiples of 4 so\n" "it can't be rendered by OpenGL.")); } - +#endif // Get aspect ratio if( defaults->get("AUTOASPECT", 0) ) { create_aspect_ratio( @@ -250,7 +235,7 @@ void MWindow::asset_to_size() h = indexable->get_h(); edl->session->output_w = w; edl->session->output_h = h; - +#ifdef GLx4 if( ((edl->session->output_w % 4) || (edl->session->output_h % 4)) && edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) { @@ -258,7 +243,7 @@ void MWindow::asset_to_size() _("This project's dimensions are not multiples of 4 so\n" "it can't be rendered by OpenGL.")); } - +#endif // Get aspect ratio if( defaults->get("AUTOASPECT", 0) ) { create_aspect_ratio(edl->session->aspect_w, @@ -403,10 +388,43 @@ void MWindow::clear_labels() int MWindow::clear_labels(double start, double end) { + if( start == end ) { + start = 0; + end = edl->tracks->total_length(); + } edl->labels->clear(start, end, 0); return 0; } +void MWindow::clear_hard_edges() +{ + undo_before(); + clear_hard_edges(edl->local_session->get_selectionstart(), + edl->local_session->get_selectionend()); + edl->optimize(); + save_backup(); + undo_after(_("clear hard edges"), LOAD_EDITS); + restart_brender(); + gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0); + cwindow->refresh_frame(CHANGE_EDL); +} + +int MWindow::clear_hard_edges(double start, double end) +{ + if( start == end ) { + start = 0; + end = edl->tracks->total_length(); + } + edl->clear_hard_edges(start, end); + return 0; +} + +void MWindow::clear_select() +{ + edl->tracks->clear_selected_edits(); + gui->draw_overlays(1); +} + void MWindow::concatenate_tracks() { undo_before(); @@ -421,6 +439,17 @@ void MWindow::concatenate_tracks() } +int MWindow::copy_flags(int copy_flags) +{ + if( !edl->session->labels_follow_edits ) + copy_flags &= ~COPY_LABELS; + if( !edl->session->autos_follow_edits ) + copy_flags &= ~COPY_AUTOS; + if( !edl->session->plugins_follow_edits ) + copy_flags &= ~COPY_PLUGINS; + return copy_flags; +} + void MWindow::copy() { copy(edl->local_session->get_selectionstart(), @@ -432,7 +461,7 @@ int MWindow::copy(double start, double end) if( start == end ) return 1; FileXML file; - edl->copy(start, end, 0, &file, "", 1); + edl->copy(copy_flags(), start, end, &file, "", 1); const char *file_string = file.string(); long file_length = strlen(file_string); gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION); @@ -467,12 +496,10 @@ int MWindow::copy_default_keyframe() return 0; } - // Uses cropping coordinates in edl session to crop and translate video. // We modify the projector since camera automation depends on the track size. -void MWindow::crop_video() +void MWindow::crop_video(int mode) { - undo_before(); // Clamp EDL crop region if( edl->session->crop_x1 > edl->session->crop_x2 ) { @@ -485,22 +512,54 @@ void MWindow::crop_video() edl->session->crop_y2 ^= edl->session->crop_y1; edl->session->crop_y1 ^= edl->session->crop_y2; } - - float old_projector_x = (float)edl->session->output_w / 2; - float old_projector_y = (float)edl->session->output_h / 2; - float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2; - float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2; - float projector_offset_x = -(new_projector_x - old_projector_x); - float projector_offset_y = -(new_projector_y - old_projector_y); - - edl->tracks->translate_projector(projector_offset_x, projector_offset_y); - - edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1; - edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1; - edl->session->crop_x1 = 0; - edl->session->crop_y1 = 0; - edl->session->crop_x2 = edl->session->output_w; - edl->session->crop_y2 = edl->session->output_h; + switch( mode ) { + case CROP_REFORMAT: { + float ctr_x = edl->session->output_w / 2.; + float ctr_y = edl->session->output_h / 2.; + float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.; + float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.; + float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y); + edl->tracks->translate_projector(dx, dy, 1); + + edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1; + edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1; + edl->session->crop_x1 = edl->session->crop_y1 = 0; + edl->session->crop_x2 = edl->session->output_w; + edl->session->crop_y2 = edl->session->output_h; + break; } + case CROP_RESIZE: { + float old_w = edl->session->output_w; + float old_h = edl->session->output_h; + float new_w = edl->session->crop_x2 - edl->session->crop_x1; + float new_h = edl->session->crop_y2 - edl->session->crop_y1; + if( !new_w ) new_w = 1; + if( !new_h ) new_h = 1; + float xzoom = old_w / new_w, yzoom = old_h / new_h; + float new_z = bmin(xzoom, yzoom); + float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.; + float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.; + edl->tracks->crop_resize(new_x, new_y, new_z); + + edl->session->crop_x1 = 0; + edl->session->crop_y1 = 0; + edl->session->crop_x2 = edl->session->output_w; + edl->session->crop_y2 = edl->session->output_h; + break; } + case CROP_SHRINK: { + float old_w = edl->session->output_w; + float old_h = edl->session->output_h; + float new_w = edl->session->crop_x2 - edl->session->crop_x1; + float new_h = edl->session->crop_y2 - edl->session->crop_y1; + if( !new_w ) new_w = 1; + if( !new_h ) new_h = 1; + float xzoom = old_w / new_w, yzoom = old_h / new_h; + float new_z = bmin(xzoom, yzoom); + + float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.; + float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.; + edl->tracks->crop_shrink(new_x, new_y, new_z); + break; } + } // Recalculate aspect ratio if( defaults->get("AUTOASPECT", 0) ) { @@ -635,12 +694,6 @@ int MWindow::cut_default_keyframe() } -void MWindow::delete_track() -{ - if( edl->tracks->last ) - delete_track(edl->tracks->last); -} - void MWindow::delete_tracks() { undo_before(); @@ -711,19 +764,40 @@ void MWindow::insert(double position, FileXML *file, //printf("MWindow::insert 6 %p\n", vwindow->get_edl()); } -void MWindow::insert_effects_canvas(double start, - double length) +void MWindow::insert_effects_canvas(Track *dest_track, double start, double length) { - Track *dest_track = session->track_highlighted; - if( !dest_track ) return; - undo_before(); - for( int i=0; idrag_pluginservers->total; ++i ) { - PluginServer *plugin = session->drag_pluginservers->values[i]; - insert_effect(plugin->title, 0, dest_track, - i == 0 ? session->pluginset_highlighted : 0, - start, length, PLUGIN_STANDALONE); + ArrayList shared_locations; + PluginSet *pluginset = session->pluginset_highlighted; + int gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0; + int data_type = dest_track->data_type; + int first_track = 1; + + for( Track *track=dest_track; track; track=track->next ) { + if( gang && track->master && !first_track ) break; + if( track->data_type != data_type ) continue; + if( !track->is_armed() ) continue; + int module = edl->tracks->number_of(track); + for( int i=0; idrag_pluginservers->total; ++i ) { + PluginServer *plugin = session->drag_pluginservers->values[i]; + int shared = gang; // && plugin->multichannel ? 1 : 0; + int plugin_type = !first_track && shared ? + PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE; + SharedLocation *shared_location = !first_track ? + &shared_locations[i] : &shared_locations.append(); + insert_effect(plugin->title, shared_location, track, + pluginset, start, length, plugin_type); + if( first_track && shared ) { + shared_location->module = module; + shared_location->plugin = pluginset ? + track->plugin_set.number_of(pluginset) : + track->plugin_set.total-1 ; + } + } + if( !gang ) break; + first_track = 0; + pluginset = 0; } save_backup(); @@ -737,8 +811,6 @@ void MWindow::insert_effects_cwindow(Track *dest_track) { if( !dest_track ) return; - undo_before(); - double start = 0; double length = dest_track->get_length(); @@ -749,55 +821,45 @@ void MWindow::insert_effects_cwindow(Track *dest_track) edl->local_session->get_selectionstart(); } - for( int i=0; idrag_pluginservers->total; ++i ) { - PluginServer *plugin = session->drag_pluginservers->values[i]; - insert_effect(plugin->title, 0, dest_track, 0, - start, length, PLUGIN_STANDALONE); - } - - save_backup(); - undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES); - restart_brender(); - sync_parameters(CHANGE_EDL); + insert_effects_canvas(dest_track, start, length); gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0); } -void MWindow::insert_effect(char *title, - SharedLocation *shared_location, - int data_type, - int plugin_type, - int single_standalone) +void MWindow::insert_effect(char *title, SharedLocation *shared_location, + int data_type, int plugin_type, int single_standalone) { Track *current = edl->tracks->first; SharedLocation shared_location_local; shared_location_local.copy_from(shared_location); int first_track = 1; + double start_pos = edl->local_session->get_selectionstart(1); + double end_pos = edl->local_session->get_selectionend(1); for( ; current; current=NEXT ) { - if( current->data_type == data_type && - current->record ) { - insert_effect(title, &shared_location_local, - current, 0, 0, 0, plugin_type); - - if( first_track ) { - if( plugin_type == PLUGIN_STANDALONE && single_standalone ) { - plugin_type = PLUGIN_SHAREDPLUGIN; - shared_location_local.module = edl->tracks->number_of(current); - shared_location_local.plugin = current->plugin_set.total - 1; - } - first_track = 0; + if( current->data_type != data_type ) continue; + if( !current->is_armed() ) continue; + double start = start_pos, end = end_pos; + if( plugin_type == PLUGIN_STANDALONE && start >= end ) { + start = 0; + end = current->get_length(); + } + double length = end - start; + insert_effect(title, &shared_location_local, + current, 0, start, length, plugin_type); + if( first_track ) { + if( plugin_type == PLUGIN_STANDALONE && single_standalone ) { + plugin_type = PLUGIN_SHAREDPLUGIN; + shared_location_local.module = edl->tracks->number_of(current); + shared_location_local.plugin = current->plugin_set.total - 1; + start_pos = start; end_pos = end; } + first_track = 0; } } } - void MWindow::insert_effect(char *title, - SharedLocation *shared_location, - Track *track, - PluginSet *plugin_set, - double start, - double length, - int plugin_type) + SharedLocation *shared_location, Track *track, PluginSet *plugin_set, + double start, double length, int plugin_type) { KeyFrame *default_keyframe = 0; PluginServer *server = 0; @@ -810,9 +872,8 @@ void MWindow::insert_effect(char *title, server->save_data(default_keyframe); } // Insert plugin object - track->insert_effect(title, shared_location, - default_keyframe, plugin_set, - start, length, plugin_type); + track->insert_effect(title, shared_location, default_keyframe, + plugin_set, start, length, plugin_type); track->optimize(); if( plugin_type == PLUGIN_STANDALONE ) { @@ -903,191 +964,6 @@ void MWindow::match_output_size(Track *track) } -EDL *MWindow::selected_edits_to_clip(int packed, - double *start_position, Track **start_track, - int edit_labels, int edit_autos, int edit_plugins) -{ - 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; - 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( 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); - const char *text = _("new_edl edit"); - new_edl->set_path(text); - strcpy(new_edl->local_session->clip_title, text); - strcpy(new_edl->local_session->clip_notes, text); - new_edl->session->video_tracks = 0; - new_edl->session->audio_tracks = 0; - for( Track *track=edl->tracks->first; track; track=track->next ) { - if( !track->record ) continue; - if( first_track ) { - if( first_track != track ) continue; - first_track = 0; - } - 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; - 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); - 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->positionnext; - 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; iautos[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; iplugin_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); - } - } - } - } - } - 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); - const char *file_string = file.string(); - long file_length = strlen(file_string); - gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION); - gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION); - new_edl->remove_user(); -} - void MWindow::delete_edit(Edit *edit, const char *msg, int collapse) { ArrayList edits; @@ -1154,131 +1030,20 @@ void MWindow::move_edits(ArrayList *edits, 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) +void MWindow::selected_edits_to_clipboard(int packed) { - 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; iautomation->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; iplugin_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; iautomation->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; iplugin_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(); + EDL *new_edl = 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; + FileXML file; + new_edl->copy(COPY_EDL, &file, "", 1); + const char *file_string = file.string(); + long file_length = strlen(file_string); + gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION); + gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION); + new_edl->remove_user(); } void MWindow::paste_clipboard(Track *first_track, double position, int overwrite, @@ -1295,7 +1060,7 @@ void MWindow::paste_clipboard(Track *first_track, double position, int overwrite clip->create_objects(); if( !clip->load_xml(&file, LOAD_ALL) ) { undo_before(); - paste_edits(clip, first_track, position, overwrite, + edl->paste_edits(clip, first_track, position, overwrite, edit_edits, edit_labels, edit_autos, edit_plugins); save_backup(); undo_after(_("paste clip"), LOAD_ALL); @@ -1320,7 +1085,7 @@ void MWindow::move_group(EDL *group, Track *first_track, double position, int ov 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->paste_edits(group, first_track, position, overwrite, 1, edl->session->labels_follow_edits, edl->session->autos_follow_edits, edl->session->plugins_follow_edits); @@ -1490,16 +1255,22 @@ void MWindow::overwrite(EDL *source, int all) overwrite_len = dst_len; } - source->copy(src_start, src_start + overwrite_len, 0, &file, "", 1); + source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1); // HACK around paste_edl get_start/endselection on its own // so we need to clear only when not using both io points // FIXME: need to write simple overwrite_edl to be used for overwrite function if( edl->local_session->get_inpoint() < 0 || - edl->local_session->get_outpoint() < 0 ) - edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0); + edl->local_session->get_outpoint() < 0 ) + edl->clear(dst_start, dst_start + overwrite_len, + edl->session->labels_follow_edits, + edl->session->plugins_follow_edits, + edl->session->autos_follow_edits); - paste(dst_start, dst_start + overwrite_len, &file, 0, 0, 0, 0, 0); + paste(dst_start, dst_start + overwrite_len, &file, + edl->session->labels_follow_edits, + edl->session->plugins_follow_edits, + edl->session->autos_follow_edits, 0, 0); edl->local_session->set_selectionstart(dst_start + overwrite_len); edl->local_session->set_selectionend(dst_start + overwrite_len); @@ -1610,13 +1381,14 @@ void MWindow::load_assets(ArrayList *new_assets, load_mode = LOADMODE_ASSETSONLY; const int debug = 0; if( debug ) printf("MWindow::load_assets %d\n", __LINE__); - if( position < 0 ) position = edl->local_session->get_selectionstart(); + if( position < 0 ) + position = edl->local_session->get_selectionstart(); ArrayList new_edls; for( int i=0; itotal; ++i ) { Indexable *indexable = new_assets->get(i); if( indexable->is_asset ) { - remove_asset_from_caches((Asset*)indexable); + remove_from_caches(indexable); } EDL *new_edl = new EDL; new_edl->create_objects(); @@ -1761,6 +1533,7 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, need_new_tracks = 1; for( int i=0; itotal; ++i ) { EDL *new_edl = new_edls->values[i]; + int first_track = 1; for( Track *current=new_edl->tracks->first; current; current=NEXT ) { switch( current->data_type ) { case TRACK_VIDEO: @@ -1776,6 +1549,13 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, default: continue; } + if( first_track ) { + edl->tracks->last->master = 1; + first_track = 0; + } +// re-label only if not already labeled + if( new_edl->local_session->asset2edl ) + strcpy(current->title, edl->tracks->last->title); destination_tracks.append(edl->tracks->last); } @@ -1787,26 +1567,14 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, else // Recycle existing tracks of master EDL if( load_mode == LOADMODE_CONCATENATE || - load_mode == LOADMODE_PASTE || - load_mode == LOADMODE_NESTED ) { -//PRINT_TRACE - -// The point of this is to shift forward labels after the selection so they can -// then be shifted back to their original locations without recursively -// shifting back every paste. - if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) && - edl->session->labels_follow_edits ) - edl->labels->clear(edl->local_session->get_selectionstart(), - edl->local_session->get_selectionend(), 1); - + load_mode == LOADMODE_PASTE ) { Track *current = first_track ? first_track : edl->tracks->first; for( ; current; current=NEXT ) { - if( current->record ) { + if( current->is_armed() ) { destination_tracks.append(current); } } //PRINT_TRACE - } //PRINT_TRACE int destination_track = 0; @@ -1836,17 +1604,22 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, // Add assets and prepare index files for( Asset *new_asset=new_edl->assets->first; new_asset; new_asset=new_asset->next ) { - mainindexes->add_next_asset(0, new_asset); + mainindexes->add_indexable(new_asset); } // Capture index file status from mainindex test edl->update_assets(new_edl); //PRINT_TRACE // Get starting point of insertion. Need this to paste labels. switch( load_mode ) { + case LOADMODE_NOTHING: + continue; case LOADMODE_REPLACE: - case LOADMODE_NEW_TRACKS: current_position = 0; break; + case LOADMODE_NEW_TRACKS: + if( !overwrite ) + current_position = 0; + break; case LOADMODE_CONCATENATE: case LOADMODE_REPLACE_CONCATENATE: @@ -1858,7 +1631,6 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, break; case LOADMODE_PASTE: - case LOADMODE_NESTED: destination_track = 0; if( i == 0 ) { for( int j=0; j *new_edls, int load_mode, edl->add_clip(new_edl); break; } -//PRINT_TRACE // Insert edl 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 ) + if( edit_labels ) { + if( load_mode == LOADMODE_PASTE ) edl->labels->insert_labels(new_edl->labels, destination_tracks.total ? paste_position[0] : 0.0, - edl_length, edit_labels); + edl_length, 1); else edl->labels->insert_labels(new_edl->labels, current_position, - edl_length, edit_labels); + edl_length, 1); } -//PRINT_TRACE double total_length = new_edl->tracks->total_length(); for( Track *new_track=new_edl->tracks->first; new_track; new_track=new_track->next ) { @@ -1905,14 +1674,14 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, if( destination_track < destination_tracks.total && destination_tracks.values[destination_track]->data_type == new_track->data_type ) { Track *track = destination_tracks.values[destination_track]; - // Replace default keyframes if first EDL and new tracks were created. // This means data copied from one track and pasted to another won't retain // the camera position unless it's a keyframe. If it did, previous data in the // track might get unknowingly corrupted. Ideally we would detect when differing // default keyframes existed and create discrete keyframes for both. int replace_default = (i == 0) && need_new_tracks; - +// master tracks are the first track in each new edl when new tracks are created + int master = track->master; //printf("MWindow::paste_edls 1 %d\n", replace_default); // Insert new track at current position switch( load_mode ) { @@ -1922,7 +1691,6 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, break; case LOADMODE_PASTE: - case LOADMODE_NESTED: current_position = paste_position[destination_track]; paste_position[destination_track] += new_track->get_length(); break; @@ -1939,6 +1707,7 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, //PRINT_TRACE track->insert_track(new_track, current_position, replace_default, edit_plugins, edit_autos, edl_length); + if( master ) track->master = 1; //PRINT_TRACE } @@ -1949,8 +1718,7 @@ int MWindow::paste_edls(ArrayList *new_edls, int load_mode, } } - if( load_mode == LOADMODE_PASTE || - load_mode == LOADMODE_NESTED ) + if( load_mode == LOADMODE_PASTE ) current_position += edl_length; } @@ -2287,8 +2055,8 @@ void MWindow::redo_entry(BC_WindowBase *calling_window_gui) gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1); gui->update_proxy_toggle(); gui->unlock_window(); - cwindow->update(1, 1, 1, 1, 1); cwindow->gui->unlock_window(); + cwindow->update(1, 1, 1, 1, 1); for( int i=0; i < vwindows.size(); ++i ) { if( vwindows.get(i)->is_running() ) { @@ -2374,7 +2142,7 @@ void MWindow::splice(EDL *source, int all) src->outpoint_valid() ? src->get_outpoint() : src->inpoint_valid() ? source->tracks->total_length() : src->get_selectionend(); - source->copy(source_start, source_end, 1, &file, "", 1); + source->copy(COPY_EDL, source_start, source_end, &file, "", 1); //file.dump(); double start = edl->local_session->get_selectionstart(); //double end = edl->local_session->get_selectionend(); @@ -2413,7 +2181,7 @@ void MWindow::save_clip(EDL *new_edl, const char *txt) Track *track = new_edl->tracks->first; const char *path = edl->path; for( ; (!path || !*path) && track; track=track->next ) { - if( !track->record ) continue; + if( !track->is_armed() ) continue; Edit *edit = track->edits->first; if( !edit ) continue; Indexable *indexable = edit->get_source(); @@ -2424,28 +2192,24 @@ void MWindow::save_clip(EDL *new_edl, const char *txt) time_t now; time(&now); struct tm dtm; localtime_r(&now, &dtm); char *cp = new_edl->local_session->clip_notes; - int n, sz = sizeof(new_edl->local_session->clip_notes)-1; - if( txt && *txt ) { - n = snprintf(cp, sz, "%s", txt); - cp += n; sz -= n; - } - n = snprintf(cp, sz, + char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1; + if( txt && *txt ) + cp += snprintf(cp, ep-cp, "%s", txt); + cp += snprintf(cp, ep-cp, "%02d/%02d/%02d %02d:%02d:%02d, +%s\n", dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday, dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration); - cp += n; sz -= n; if( path && *path ) { FileSystem fs; char title[BCTEXTLEN]; fs.extract_name(title, path); - n = snprintf(cp, sz, "%s", title); - cp += n; sz -= n; + cp += snprintf(cp, ep-cp, "%s", title); } - cp[n] = 0; sprintf(new_edl->local_session->clip_icon, - "clip_%02d%02d%02d-%02d%02d%02d.png", + "clip_%02d%02d%02d-%02d%02d%02d-%d.png", dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday, - dtm.tm_hour, dtm.tm_min, dtm.tm_sec); + dtm.tm_hour, dtm.tm_min, dtm.tm_sec, + new_edl->id); new_edl->folder_no = AW_CLIP_FOLDER; edl->update_assets(new_edl); int cur_x, cur_y; @@ -2478,7 +2242,7 @@ void MWindow::to_clip(EDL *edl, const char *txt, int all) } // Don't copy all since we don't want the clips twice. - edl->copy(start, end, 0, &file, "", 1); + edl->copy(copy_flags(), start, end, &file, "", 1); EDL *new_edl = new EDL(edl); new_edl->create_objects(); @@ -2562,8 +2326,8 @@ void MWindow::undo_entry(BC_WindowBase *calling_window_gui) gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1); gui->update_proxy_toggle(); gui->unlock_window(); - cwindow->update(1, 1, 1, 1, 1); cwindow->gui->unlock_window(); + cwindow->update(1, 1, 1, 1, 1); for( int i=0; iis_running() ) { @@ -2644,7 +2408,7 @@ void MWindow::remap_audio(int pattern) int current_track = 0; for( Track *current=edl->tracks->first; current; current=NEXT ) { if( current->data_type == TRACK_AUDIO && - current->record ) { + current->is_armed() ) { Autos *pan_autos = current->automation->autos[AUTOMATION_PAN]; PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1); @@ -2692,10 +2456,48 @@ void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale) edl->rescale_proxy(orig_scale, new_scale); } -void MWindow::add_proxy(int use_scaler, - ArrayList *orig_assets, ArrayList *proxy_assets) +void MWindow::add_proxy(ArrayList *orig_assets, ArrayList *proxy_assets) +{ + edl->add_proxy(orig_assets, proxy_assets); +} + +void MWindow::start_convert(Asset *format_asset, const char *suffix, + float beep, int to_proxy, int remove_originals) { - edl->add_proxy(use_scaler, orig_assets, proxy_assets); + if( !convert_render ) + convert_render = new ConvertRender(this); + convert_render->set_format(format_asset, suffix, to_proxy); + int found = convert_render->find_convertable_assets(edl); + if( convert_render->needed_idxbls.size() > 0 ) + convert_render->start_convert(beep, remove_originals); + else if( found > 0 ) + finish_convert(remove_originals); + else if( found < 0 ) + eprintf(_("convert assets format error")); + else + eprintf(_("No convertable assets found")); +} + +void MWindow::finish_convert(int remove_originals) +{ + gui->lock_window("MWindow::finish_convert"); + undo_before(); + edl->replace_assets( + convert_render->orig_idxbls, + convert_render->orig_copies); + if( remove_originals ) { + remove_assets_from_project(0, 0, 0, + &convert_render->orig_idxbls, 0); + } + save_backup(); + undo_after(_("convert"), LOAD_ALL); + + update_plugin_guis(); + gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0); + cwindow->update(1, 0, 0, 0, 1); + awindow->gui->async_update_assets(); + cwindow->refresh_frame(CHANGE_EDL); + gui->unlock_window(); } void MWindow::cut_commercials() @@ -2772,3 +2574,89 @@ int MWindow::speed_after(int done) return result; } +void MWindow::collect_effects() +{ + FileXML file; + const char *file_string = ""; + EDL *group = 0; + int ret = edl->collect_effects(group); + switch( ret ) { + case COLLECT_EFFECTS_RECORD: + eprintf(_("Selected edit track not armed.")); + break; + case COLLECT_EFFECTS_MULTIPLE: + eprintf(_("More than one edit selected on a track.")); + break; + case COLLECT_EFFECTS_MISSING: + eprintf(_("No effects under selected edit.")); + break; + case COLLECT_EFFECTS_EMPTY: + eprintf(_("No edits selected.")); + break; + case COLLECT_EFFECTS_MASTER: + eprintf(_("Shared effect added without master.")); + break; + case 0: + group->save_xml(&file, ""); + file_string = file.string(); + group->remove_user(); + } + long file_length = strlen(file_string); + gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION); + gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION); +} + +void MWindow::paste_effects() +{ + char *string = 0; + int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION); + if( len ) { + string = new char[len]; + gui->from_clipboard(string, len, BC_PRIMARY_SELECTION); + } + if( !string || !string[0] ) { + eprintf(_("Error clipboard buffer empty.")); + return; + } + FileXML file; + file.read_from_string(string); + EDL *group = new EDL(); + group->create_objects(); + if( !group->load_xml(&file, LOAD_ALL) ) { + undo_before(); + int ret = edl->insert_effects(group); + switch( ret ) { + case INSERT_EFFECTS_RECORD: + eprintf(_("Selected edit track not armed.")); + break; + case INSERT_EFFECTS_TYPE: + eprintf(_("Track type mismatched.")); + break; + case INSERT_EFFECTS_MULTIPLE: + eprintf(_("More than one edit selected on a track.")); + break; + case INSERT_EFFECTS_MISSING: + eprintf(_("Too few target edits to add group effects.")); + break; + case INSERT_EFFECTS_EXTRA: + eprintf(_("Too many target edits to add group effects.")); + break; + case INSERT_EFFECTS_MASTER: + eprintf(_("Shared effect added without master.")); + break; + case 0: + break; + } + save_backup(); + undo_after(_("paste effects"), LOAD_ALL); + restart_brender(); + cwindow->refresh_frame(CHANGE_EDL); + update_plugin_guis(); + gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0); + } + else + eprintf(_("Error loading clip from clipboard buffer.")); + delete [] string; + group->remove_user(); +} +