65dd58e2c23fc3b36d038189d3bfff46dd5ada7b
[goodguy/history.git] / cinelerra-5.1 / cinelerra / clipedls.C
1 #include "bcsignals.h"
2 #include "clipedls.h"
3 #include "edl.h"
4 #include "filexml.h"
5 #include "indexstate.h"
6
7
8 ClipEDLs::ClipEDLs()
9 {
10 }
11
12 ClipEDLs::~ClipEDLs()
13 {
14         clear();
15 }
16
17 void ClipEDLs::clear()
18 {
19         for( int i=0; i<size(); ++i ) get(i)->remove_user();
20         remove_all();
21 }
22
23 void ClipEDLs::add_clip(EDL *edl)
24 {
25         append(edl);
26         edl->add_user();
27 }
28
29 void ClipEDLs::remove_clip(EDL *clip)
30 {
31         int n = size();
32         remove(clip);
33         n -= size();
34         while( --n >= 0 ) clip->remove_user();
35 }
36
37
38 EDL* ClipEDLs::get_copy(EDL *src)
39 {
40         if( !src ) return 0;
41         for( int i=0; i<size(); ++i ) {
42                 EDL *dst = get(i);
43                 if( !strcmp(dst->path, src->path) ) return dst;
44         }
45
46         EDL *dst = new EDL;
47         dst->create_objects();
48         dst->copy_all(src);
49         append(dst);
50         return dst;
51 }
52
53 EDL* ClipEDLs::load(char *path)
54 {
55         for( int i=0; i<size(); ++i ) {
56                 EDL *dst = get(i);
57                 if( !strcmp(dst->path, path) ) return dst;
58         }
59
60         EDL *dst = new EDL;
61         dst->create_objects();
62
63         FileXML xml_file;
64         xml_file.read_from_file(path);
65         dst->load_xml(&xml_file, LOAD_ALL);
66
67 // Override path EDL was saved to with the path it was loaded from.
68         dst->set_path(path);
69         append(dst);
70         return dst;
71 }
72
73 void ClipEDLs::copy_nested(ClipEDLs &nested)
74 {
75         clear();
76         for( int i=0; i<nested.size(); ++i ) {
77                 EDL *new_edl = new EDL;
78                 new_edl->create_objects();
79                 new_edl->copy_all(nested[i]);
80                 append(new_edl);
81         }
82 }
83
84 void ClipEDLs::update_index(EDL *clip_edl)
85 {
86         for( int i=0; i<size(); ++i ) {
87                 EDL *current = get(i);
88                 if( !strcmp(current->path, clip_edl->path) ) {
89                         current->update_index(clip_edl);
90                 }
91         }
92 }
93