#include "playbackconfig.h"
#include "playabletracks.h"
#include "plugin.h"
+#include "pluginset.h"
#include "preferences.h"
#include "recordconfig.h"
#include "recordlabel.h"
// The string is not terminated in this call.
int EDL::save_xml(FileXML *file, const char *output_path)
{
- copy(1, file, output_path, 0);
+ copy(COPY_EDL, file, output_path, 0);
return 0;
}
}
}
-int EDL::copy_assets(double start,
- double end,
- FileXML *file,
- int all,
- const char *output_path)
+int EDL::copy_assets(int copy_flags, double start, double end,
+ FileXML *file, const char *output_path)
{
ArrayList<Asset*> asset_list;
Track* current;
file->append_newline();
// Copy everything for a save
- if( all ) {
+ if( (copy_flags & COPY_ALL_ASSETS) ) {
for( Asset *asset=assets->first; asset; asset=asset->next ) {
asset_list.append(asset);
}
}
- else {
+ if( (copy_flags & COPY_USED_ASSETS) ) {
// Copy just the ones being used.
for( current = tracks->first; current; current = NEXT ) {
if( !current->record ) continue;
}
-int EDL::copy(double start, double end, int all,
+int EDL::copy(int copy_flags, double start, double end,
FileXML *file, const char *output_path, int rewind_it)
{
file->tag.set_title("EDL");
file->tag.set_property("VERSION", CINELERRA_VERSION);
// Save path for restoration of the project title from a backup.
if( this->path[0] ) file->tag.set_property("PATH", path);
- return copy(start, end, all,
- "/EDL", file, output_path, rewind_it);
+ return copy_xml(copy_flags, start, end, file, "/EDL", output_path, rewind_it);
}
-int EDL::copy(int all, FileXML *file, const char *output_path, int rewind_it)
+int EDL::copy(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
{
- return copy(0, tracks->total_length(), all, file, output_path, rewind_it);
+ return copy(copy_flags, 0., tracks->total_length(),
+ file, output_path, rewind_it);
}
-int EDL::copy_clip(double start, double end, int all,
+int EDL::copy_clip(int copy_flags, double start, double end,
FileXML *file, const char *output_path, int rewind_it)
{
file->tag.set_title("CLIP_EDL");
- return copy(start, end, all,
- "/CLIP_EDL", file, output_path, rewind_it);
+ return copy_xml(copy_flags, start, end, file, "/CLIP_EDL", output_path, rewind_it);
}
-int EDL::copy_clip(int all, FileXML *file, const char *output_path, int rewind_it)
+int EDL::copy_clip(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
{
- return copy_clip(0, tracks->total_length(), all, file, output_path, rewind_it);
+ return copy_clip(copy_flags, 0., tracks->total_length(),
+ file, output_path, rewind_it);
}
-int EDL::copy_nested_edl(double start, double end, int all,
+int EDL::copy_nested(int copy_flags, double start, double end,
FileXML *file, const char *output_path, int rewind_it)
{
file->tag.set_title("NESTED_EDL");
if( this->path[0] ) file->tag.set_property("PATH", path);
- return copy(start, end, all,
- "/NESTED_EDL", file, output_path, rewind_it);
+ return copy_xml(copy_flags, start, end, file, "/NESTED_EDL", output_path, rewind_it);
}
-int EDL::copy_nested_edl(int all, FileXML *file, const char *output_path, int rewind_it)
+int EDL::copy_nested(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
{
- return copy_nested_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
+ return copy_nested(copy_flags, 0., tracks->total_length(),
+ file, output_path, rewind_it);
}
-int EDL::copy_vwindow_edl(double start, double end, int all,
+int EDL::copy_vwindow(int copy_flags, double start, double end,
FileXML *file, const char *output_path, int rewind_it)
{
file->tag.set_title("VWINDOW_EDL");
- return copy(start, end, all,
- "/VWINDOW_EDL", file, output_path, rewind_it);
+ return copy_xml(copy_flags, start, end, file, "/VWINDOW_EDL", output_path, rewind_it);
}
-int EDL::copy_vwindow_edl(int all, FileXML *file, const char *output_path, int rewind_it)
+int EDL::copy_vwindow(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
{
- return copy_vwindow_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
+ return copy_vwindow(copy_flags, 0., tracks->total_length(),
+ file, output_path, rewind_it);
}
-
-int EDL::copy(double start, double end, int all,
- const char *closer, FileXML *file,
- const char *output_path, int rewind_it)
+int EDL::copy_xml(int copy_flags, double start, double end,
+ FileXML *file, const char *closer, const char *output_path,
+ int rewind_it)
{
file->append_tag();
file->append_newline();
// Set clipboard samples only if copying to clipboard
- if( !all ) {
+ if( (copy_flags & COPY_LENGTH) ) {
file->tag.set_title("CLIPBOARD");
file->tag.set_property("LENGTH", end - start);
file->append_tag();
//printf("EDL::copy 1\n");
// Sessions
- local_session->save_xml(file, start);
-
-//printf("EDL::copy 1\n");
+ if( (copy_flags & COPY_LOCAL_SESSION) )
+ local_session->save_xml(file, start);
// Top level stuff.
-// if(!parent_edl)
- {
// Need to copy all this from child EDL if pasting is desired.
-// Session
+
+ if( (copy_flags & COPY_SESSION) )
session->save_xml(file);
+
+ if( (copy_flags & COPY_VIDEO_CONFIG) )
session->save_video_config(file);
+
+ if( (copy_flags & COPY_AUDIO_CONFIG) )
session->save_audio_config(file);
+
+ if( (copy_flags & COPY_FOLDERS) )
folders.save_xml(file);
- if( !parent_edl )
- copy_assets(start, end, file, all, output_path);
+ if( (copy_flags & (COPY_ALL_ASSETS | COPY_USED_ASSETS)) )
+ copy_assets(copy_flags, start, end, file, output_path);
+ if( (copy_flags & COPY_NESTED_EDL) ) {
for( int i=0; i<nested_edls.size(); ++i )
- nested_edls[i]->copy_nested_edl(0, tracks->total_length(), 1,
+ nested_edls[i]->copy_nested(copy_flags,
file, output_path, 0);
-
+ }
// Clips
-// Don't want this if using clipboard
- if( all ) {
- for( int i=0; i<total_vwindow_edls(); ++i )
- get_vwindow_edl(i)->copy_vwindow_edl(1, file, output_path, 0);
+ if( (copy_flags & COPY_CLIPS) ) {
+ for( int i=0; i<clips.size(); ++i )
+ clips[i]->copy_clip(copy_flags, file, output_path, 0);
+ }
- for( int i=0; i<clips.size(); ++i )
- clips[i]->copy_clip(1, file, output_path, 0);
+ if( (copy_flags & COPY_VWINDOWS) ) {
+ for( int i=0; i<total_vwindow_edls(); ++i )
+ get_vwindow_edl(i)->copy_vwindow(copy_flags,
+ file, output_path, 0);
+ }
- mixers.save(file);
- }
+ if( (copy_flags & COPY_MIXERS) )
+ mixers.save(file);
- file->append_newline();
- file->append_newline();
- }
+ file->append_newline();
+ file->append_newline();
- labels->copy(start, end, file);
- tracks->copy(start, end, all, file, output_path);
+ if( (copy_flags & COPY_LABELS) )
+ labels->copy(start, end, file);
+
+ tracks->copy(copy_flags, start, end, file, output_path);
// terminate file
file->tag.set_title(closer);
return 0;
}
-void EDL::modify_edithandles(double oldposition,
- double newposition,
- int currentend,
- int handle_mode,
- int edit_labels,
- int edit_plugins,
- int edit_autos)
+static int dead_edit_cmp(Edit**ap, Edit**bp)
{
- tracks->modify_edithandles(oldposition,
- newposition,
- currentend,
- handle_mode,
- edit_labels,
- edit_plugins,
- edit_autos);
- labels->modify_handles(oldposition,
- newposition,
- currentend,
- handle_mode,
- edit_labels);
-}
-
-void EDL::modify_pluginhandles(double oldposition,
- double newposition,
- int currentend,
- int handle_mode,
- int edit_labels,
- int edit_autos,
- Edits *trim_edits)
-{
- tracks->modify_pluginhandles(oldposition,
- newposition,
- currentend,
- handle_mode,
- edit_labels,
- edit_autos,
- trim_edits);
+ Edit *a = *ap, *b = *bp;
+ if( a->track != b->track ) return 0;
+ return a->startproject > b->startproject ? -1 : 1;
+}
+
+void EDL::delete_edits(ArrayList<Edit*> *edits, int collapse)
+{
+ edits->sort(dead_edit_cmp);
+ for( int i=0; i<edits->size(); ++i ) {
+ Edit *edit = edits->get(i);
+ Track *track = edit->track;
+ int64_t start = edit->startproject;
+ int64_t length = edit->length;
+ int64_t end = start + length;
+ if( session->autos_follow_edits ) {
+ track->automation->clear(start, end, 0, collapse);
+ }
+ if( session->plugins_follow_edits ) {
+ for( int k=0; k<track->plugin_set.size(); ++k ) {
+ PluginSet *plugin_set = track->plugin_set[k];
+ plugin_set->clear(start, end, 1);
+ if( !collapse )
+ plugin_set->paste_silence(start, end, 1);
+ plugin_set->optimize();
+ }
+ }
+ Edit *dead_edit = edit;
+ if( collapse ) {
+ while( (edit=edit->next) )
+ edit->startproject -= length;
+ }
+ delete dead_edit;
+ }
optimize();
}
-void EDL::paste_silence(double start,
- double end,
- int edit_labels,
- int edit_plugins,
- int edit_autos)
+class Range {
+public:
+ static int cmp(Range *ap, Range *bp);
+ double start, end;
+ bool operator ==(Range &that) { return this->start == that.start; }
+ bool operator >(Range &that) { return this->start > that.start; }
+};
+int Range::cmp(Range *ap, Range *bp) {
+ return ap->start < bp->start ? -1 : ap->start == bp->start ? 0 : 1;
+}
+
+static void get_edit_regions(ArrayList<Edit*> *edits, ArrayList<Range> ®ions)
+{
+// move edit inclusive labels by regions
+ for( int i=0; i<edits->size(); ++i ) {
+ Edit *edit = edits->get(i);
+ double pos = edit->track->from_units(edit->startproject);
+ double end = edit->track->from_units(edit->startproject + edit->length);
+ int n = regions.size(), k = n;
+ while( --k >= 0 ) {
+ Range &range = regions[k];
+ if( pos >= range.end ) continue;
+ if( range.start >= end ) continue;
+ int expand = 0;
+ if( range.start > pos ) { range.start = pos; expand = 1; }
+ if( range.end < end ) { range.end = end; expand = 1; }
+ if( !expand ) break;
+ k = n;
+ }
+ if( k < 0 ) {
+ Range &range = regions.append();
+ range.start = pos; range.end = end;
+ }
+ }
+ regions.sort(Range::cmp);
+}
+
+void EDL::delete_edit_labels(ArrayList<Edit*> *edits, int collapse)
+{
+ ArrayList<Range> regions;
+ get_edit_regions(edits, regions);
+ int n = regions.size(), k = n;
+ while( --k >= 0 ) {
+ Range &range = regions[k];
+ labels->clear(range.start, range.end, collapse);
+ }
+}
+
+void EDL::move_edit_labels(ArrayList<Edit*> *edits, double dist)
+{
+ ArrayList<Range> regions;
+ get_edit_regions(edits, regions);
+ int n = regions.size(), k = n;
+ Labels moved(this, 0);
+ while( --k >= 0 ) {
+ Range &range = regions[k];
+ Label *label = labels->label_of(range.start);
+ for( Label *next=0; label && label->position <= range.end; label=next ) {
+ next = label->next;
+ labels->remove_pointer(label);
+ label->position += dist;
+ moved.append(label);
+ }
+ Label *current = labels->first;
+ while( (label=moved.first) ) {
+ moved.remove_pointer(label);
+ while( current && current->position < label->position )
+ current = current->next;
+ if( current && current->position == label->position ) {
+ delete label; continue;
+ }
+ labels->insert_before(current, label);
+ }
+ }
+}
+
+void EDL::modify_edithandles(double oldposition, double newposition,
+ int currentend, int handle_mode, int edit_labels,
+ int edit_plugins, int edit_autos, int group_id)
+{
+ tracks->modify_edithandles(oldposition, newposition,
+ currentend, handle_mode, edit_labels,
+ edit_plugins, edit_autos, group_id);
+}
+
+void EDL::modify_pluginhandles(double oldposition, double newposition,
+ int currentend, int handle_mode, int edit_labels,
+ int edit_autos, Edits *trim_edits)
+{
+ tracks->modify_pluginhandles(oldposition, newposition,
+ currentend, handle_mode, edit_labels,
+ edit_autos, trim_edits);
+ optimize();
+}
+
+void EDL::paste_silence(double start, double end,
+ int edit_labels, int edit_plugins, int edit_autos)
{
if( edit_labels )
labels->paste_silence(start, end);
- tracks->paste_silence(start,
- end,
- edit_plugins,
- edit_autos);
+ tracks->paste_silence(start, end, edit_plugins, edit_autos);
}
}
}
-// aligned frame time
+// aligned frame time, account for sample truncation
double EDL::frame_align(double position, int round)
{
- double frame_pos = position * session->frame_rate;
- frame_pos = (int64_t)(frame_pos + (round ? 0.5 : 1e-6));
- position = frame_pos / session->frame_rate;
- return position;
+ if( !round && session->sample_rate > 0 ) {
+ int64_t sample_pos = position * session->sample_rate;
+ position = (sample_pos+2.) / session->sample_rate;
+ }
+ int64_t frame_pos = (position * session->frame_rate + (round ? 0.5 : 1e-6));
+ return frame_pos / session->frame_rate;
}
// Convert position to frames if alignment is enabled.
tracks->first->edits->first->asset : 0;
}
+Track *EDL::add_new_track(int data_type)
+{
+ Track *new_track = 0;
+ switch( data_type ) {
+ case TRACK_VIDEO:
+ ++session->video_tracks;
+ new_track = tracks->add_video_track(0, 0);
+ break;
+ case TRACK_AUDIO:
+ ++session->audio_tracks;
+ new_track = tracks->add_audio_track(0, 0);
+ break;
+ case TRACK_SUBTITLE:
+ new_track = tracks->add_subttl_track(0, 0);
+ break;
+ }
+ return new_track;
+}
+
double EDL::get_cursor_position(int cursor_x, int pane_no)
{
return (double)cursor_x * local_session->zoom_sample / session->sample_rate +
(double)local_session->view_start[pane_no] *
local_session->zoom_sample / session->sample_rate;
}
+int64_t EDL::get_position_cursorx(double position, int pane_no)
+{
+ return (int64_t)(position * session->sample_rate / local_session->zoom_sample)
+ - local_session->view_start[pane_no];
+}
int EDL::in_use(Indexable *indexable)
{
return 0;
}
+int EDL::regroup(int next_id)
+{
+ ArrayList<int> new_groups;
+ for( Track *track=tracks->first; track; track=track->next ) {
+ for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
+ if( !edit->group_id ) continue;
+ int k = new_groups.size();
+ while( --k >= 0 && new_groups[k] != edit->group_id );
+ if( k >= 0 ) continue;
+ new_groups.append(edit->group_id);
+ }
+ }
+ for( Track *track=tracks->first; track; track=track->next ) {
+ for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
+ if( !edit->group_id ) continue;
+ int k = new_groups.size();
+ while( --k >= 0 && new_groups[k] != edit->group_id );
+ if( k < 0 ) continue;
+ edit->group_id = k + next_id;
+ }
+ }
+ return new_groups.size();
+}
+