Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / clipedls.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #include "bcsignals.h"
22 #include "clipedls.h"
23 #include "edl.h"
24 #include "filexml.h"
25 #include "indexstate.h"
26
27
28 ClipEDLs::ClipEDLs()
29 {
30 }
31
32 ClipEDLs::~ClipEDLs()
33 {
34         clear();
35 }
36
37 void ClipEDLs::clear()
38 {
39         for( int i=0; i<size(); ++i ) get(i)->remove_user();
40         remove_all();
41 }
42
43 void ClipEDLs::add_clip(EDL *edl)
44 {
45         edl->folder_no = AW_CLIP_FOLDER;
46         append(edl);
47         edl->add_user();
48 }
49
50 void ClipEDLs::remove_clip(EDL *clip)
51 {
52         int n = size();
53         remove(clip);
54         n -= size();
55         while( --n >= 0 ) clip->remove_user();
56 }
57
58
59 EDL* ClipEDLs::get_nested(EDL *src)
60 {
61         if( !src ) return 0;
62         for( int i=0; i<size(); ++i ) {
63                 EDL *dst = get(i);
64                 if( src == dst || src->id == dst->id ) return dst;
65         }
66         for( int i=0; i<size(); ++i ) {
67                 EDL *dst = get(i);
68                 if( !strcmp(dst->path, src->path) ) return dst;
69         }
70
71         EDL *dst = new EDL;
72         dst->create_objects();
73         dst->copy_all(src);
74         append(dst);
75         return dst;
76 }
77
78 EDL* ClipEDLs::load(char *path)
79 {
80         for( int i=0; i<size(); ++i ) {
81                 EDL *dst = get(i);
82                 if( !strcmp(dst->path, path) ) return dst;
83         }
84
85         EDL *dst = new EDL;
86         dst->create_objects();
87
88         FileXML xml_file;
89         xml_file.read_from_file(path);
90         dst->load_xml(&xml_file, LOAD_ALL);
91
92 // Override path EDL was saved to with the path it was loaded from.
93         dst->set_path(path);
94         append(dst);
95         return dst;
96 }
97
98 void ClipEDLs::copy_nested(ClipEDLs &nested)
99 {
100         clear();
101         for( int i=0; i<nested.size(); ++i ) {
102                 EDL *new_edl = new EDL;
103                 new_edl->create_objects();
104                 new_edl->copy_all(nested[i]);
105                 append(new_edl);
106         }
107 }
108
109 void ClipEDLs::update_index(EDL *clip_edl)
110 {
111         for( int i=0; i<size(); ++i ) {
112                 EDL *current = get(i);
113                 if( !strcmp(current->path, clip_edl->path) ) {
114                         current->update_index(clip_edl);
115                 }
116         }
117 }
118