Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / assets.C
blob4599f116400622d75a33793ad68ff745823be3d5
1 #include "asset.h"
2 #include "assets.h"
3 #include "awindowgui.inc"
4 #include "batch.h"
5 #include "cache.h"
6 #include "bchash.h"
7 #include "edl.h"
8 #include "file.h"
9 #include "filexml.h"
10 #include "filesystem.h"
11 #include "indexfile.h"
12 #include "quicktime.h"
13 #include "mainsession.h"
14 #include "threadindexer.h"
15 #include <string.h>
17 #include <iterator>
19 Assets::Assets(EDL *edl)
21         this->edl = edl;
24 Assets::~Assets()
26         delete_all();
29 int Assets::load(ArrayList<PluginServer*> *plugindb, 
30         FileXML *file, 
31         uint32_t load_flags)
33         int result = 0;
35 //printf("Assets::load 1\n");
36         while(!result)
37         {
38                 result = file->read_tag();
39                 if(!result)
40                 {
41                         if(file->tag.title_is("/ASSETS"))
42                         {
43                                 result = 1;
44                         }
45                         else
46                         if(file->tag.title_is("ASSET"))
47                         {
48 //printf("Assets::load 2\n");
49                                 char *path = file->tag.get_property("SRC");
50 //printf("Assets::load 3\n");
51                                 Asset_GC new_asset(new Asset(path ? path : SILENCE));
52 //printf("Assets::load 4\n");
53                                 new_asset->read(file);
54 //printf("Assets::load 5\n");
55                                 update(new_asset);
56 //printf("Assets::load 6\n");
57                         }
58                 }
59         }
60 //printf("Assets::load 7\n");
61         return 0;
64 int Assets::save(ArrayList<PluginServer*> *plugindb, FileXML *file, char *path)
66         file->tag.set_title("ASSETS");
67         file->append_tag();
68         file->append_newline();
70         for (Assets_list::iterator current = assets.begin(); current != assets.end(); ++current)
71         {
72                 (*current)->write(file, 0 , path);
73         };
75         file->tag.set_title("/ASSETS");
76         file->append_tag();
77         file->append_newline(); 
78         file->append_newline(); 
79         return 0;
82 void Assets::copy_from(const Assets &assets)
84         delete_all();
86         for(Assets_list::const_iterator current = assets.begin();
87             current != assets.end(); ++current)
88         {
89                 Asset_GC new_asset(new Asset);
90                 this->assets.push_back(new_asset);
91                 new_asset->copy_from(**current, 1);
92         }
95 Assets& Assets::operator=(const Assets &assets)
97 printf("Assets::operator= 1\n");
98         copy_from(assets);
99         return *this;
103 void Assets::update_index(Asset &asset)
105         for (Assets_list::iterator current = assets.begin(); current != assets.end(); ++current)
106         {
107                 if((*current)->test_path(asset.path))
108                 {
109                         (*current)->update_index(asset);
110                 }
111         }
114 Asset_GC Assets::update(Asset_GC asset)
116         if(! asset.get()) return Asset_GC();
118         for (Assets_list::iterator current = assets.begin(); current != assets.end(); ++current)
119         {
120 // Asset already exists.
121                 if((*current)->test_path(asset->path)) 
122                 {
123                         return *current;
124                 }
125         }
127 // Asset doesn't exist.
128         Asset_GC asset_copy(new Asset(*asset));
129         assets.push_back(asset_copy);
130         return asset_copy;
133 int Assets::delete_all()
135         assets.clear();
136         return 0;
139 Asset_GC Assets::update(const char *path)
141         for (Assets_list::iterator current = assets.begin(); current != assets.end(); ++current)
142         {
143                 if((*current)->test_path(path))
144                 {
145                         return *current;
146                 }
147         }
149         Asset_GC new_asset(new Asset(path));
150         assets.push_back(new_asset);
151         return new_asset;
154 Asset_GC Assets::get_asset(const char *filename)
156         for (Assets_list::iterator current = assets.begin(); current != assets.end(); ++current)
157         {
158                 if((*current)->test_path(filename))
159                 {
160                         return *current;
161                 }
162         }
164         return Asset_GC();
167 void Assets::remove_asset(Asset_GC asset)
169         assets.remove(asset);
173 int Assets::number_of(Asset_GC asset)
175         int i;
176         Assets_list::const_iterator current;
178         for(i = 0, current = assets.begin();
179             current != assets.end() && *current != asset;
180             i++, ++current)
181                 ;
183         return i;
186 Asset_GC Assets::asset_number(int number)
188         Assets_list::iterator current = assets.begin();
189         std::advance(current, number);
190         return *current;
193 int Assets::update_old_filename(char *old_filename, char *new_filename)
195         for(Assets_list::iterator current = assets.begin();
196             current != assets.end();
197             ++current)
198         {
199                 if(!strcmp((*current)->path, old_filename))
200                 {
201                         (*current)->update_path(new_filename);
202                 }
203         }
204         return 0;
208 int Assets::dump()
210         for(Assets_list::iterator current = assets.begin();
211             current != assets.end();
212             ++current)
213         {
214                 (*current)->dump();
215         }
216         return 0;
221 //      Local Variables:
222 //      mode: C++
223 //      c-file-style: "linux"
224 //      End: