r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mainindexes.C
blob3a6c873ba77d2b5455994f6d9214facb91e4f985
1 #include "assets.h"
2 #include "defaults.h"
3 #include "edl.h"
4 #include "filesystem.h"
5 #include "indexfile.h"
6 #include "loadfile.h"
7 #include "guicast.h"
8 #include "mainindexes.h"
9 #include "mainprogress.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
13 #include <string.h>
15 #include <libintl.h>
16 #define _(String) gettext(String)
17 #define gettext_noop(String) String
18 #define N_(String) gettext_noop (String)
20 MainIndexes::MainIndexes(MWindow *mwindow)
21  : Thread()
23         this->mwindow = mwindow;
24         set_synchronous(1);
25         interrupt_flag = 0;
26         done = 0;
27         indexfile = new IndexFile(mwindow);
30 MainIndexes::~MainIndexes()
32         delete indexfile;
35 void MainIndexes::add_next_asset(Asset *asset)
37         next_lock.lock();
39 // Test current asset
40         IndexFile indexfile(mwindow);
42 //printf("MainIndexes::add_next_asset 1 %s\n", asset->path);
43         if(!indexfile.open_index(asset))
44         {
45 //printf("MainIndexes::add_next_asset 2\n");
46                 asset->index_status = INDEX_READY;
47                 indexfile.close_index();
48         }
49         else
50 // Put copy of asset in stack, not the real thing.
51         {
52 //printf("MainIndexes::add_next_asset 3\n");
53                 Asset *new_asset = new Asset;
54                 *new_asset = *asset;
55 // If the asset existed and was overwritten, the status will be READY.
56                 new_asset->index_status = INDEX_NOTTESTED;
57                 next_assets.append(new_asset);
58         }
60         next_lock.unlock();
63 void MainIndexes::delete_current_assets()
65         current_assets.remove_all_objects();
68 void MainIndexes::start_loop()
70         input_lock.lock();
71         interrupt_flag = 0;
72         start();
75 void MainIndexes::stop_loop()
77         interrupt_flag = 1;
78         input_lock.unlock();
79         Thread::join();
83 void MainIndexes::start_build()
85 //printf("MainIndexes::start_build 1\n");
86         interrupt_flag = 0;
87 // Locked up when indexes were already being built and an asset was 
88 // pasted.
89 //      interrupt_lock.lock();
90         input_lock.unlock();
93 void MainIndexes::interrupt_build()
95 //printf("MainIndexes::interrupt_build 1\n");
96         interrupt_flag = 1;
97         indexfile->interrupt_index();
98 //printf("MainIndexes::interrupt_build 2\n");
99         interrupt_lock.lock();
100 //printf("MainIndexes::interrupt_build 3\n");
101         interrupt_lock.unlock();
102 //printf("MainIndexes::interrupt_build 4\n");
105 void MainIndexes::load_next_assets()
107         delete_current_assets();
109 // Transfer from new list
110         next_lock.lock();
111         for(int i = 0; i < next_assets.total; i++)
112                 current_assets.append(next_assets.values[i]);
114 // Clear pointers from new list only
115         next_assets.remove_all();
116         next_lock.unlock();
120 void MainIndexes::run()
122         while(!done)
123         {
124 // Wait for new assets to be released
125                 input_lock.lock();
126                 if(done) return;
128 //printf("MainIndexes::run 1 %d\n", next_assets.total);
129                 load_next_assets();
130                 interrupt_flag = 0;
131 //printf("MainIndexes::run 2 %d\n", current_assets.total);
138 // test index of each asset
139                 MainProgressBar *progress = 0;
140                 for(int i = 0; i < current_assets.total && !interrupt_flag; i++)
141                 {
142                         Asset *current_asset = current_assets.values[i];
143 //printf("MainIndexes::run 3 %s %d %d\n", current_asset->path, current_asset->index_status, current_asset->audio_data);
145                         if(current_asset->index_status == INDEX_NOTTESTED && 
146                                 current_asset->audio_data)
147                         {
148 //printf("MainIndexes::run 4\n");
151 // Doesn't exist.
152 // Try to create index now.
153                                 if(indexfile->open_index(current_asset))
154                                 {
155 //printf("MainIndexes::run 5 %p %s %p %p\n", current_asset, current_asset->path, mwindow, mwindow->mainprogress);
156                                         if(!progress)
157                                         {
158                                                 if(mwindow->gui) mwindow->gui->lock_window();
159                                                 progress = mwindow->mainprogress->start_progress(_("Building Indexes..."), 1);
160                                                 if(mwindow->gui) mwindow->gui->unlock_window();
161                                         }
163 //printf("MainIndexes::run 5 %p %s\n", current_asset, current_asset->path);
165                                         indexfile->create_index(current_asset, progress);
166 //printf("MainIndexes::run 6 %p %s\n", current_asset, current_asset->path);
167                                         if(progress->is_cancelled()) interrupt_flag = 1;
168 //printf("MainIndexes::run 7 %p %s\n", current_asset, current_asset->path);
169                                 }
170                                 else
171 // Exists.  Update real thing.
172                                 {
173 //printf("MainIndexes::run 8\n");
174                                         if(current_asset->index_status == INDEX_NOTTESTED)
175                                         {
176                                                 current_asset->index_status = INDEX_READY;
177                                                 if(mwindow->gui) mwindow->gui->lock_window();
178                                                 mwindow->edl->set_index_file(current_asset);
179                                                 if(mwindow->gui) mwindow->gui->unlock_window();
180                                         }
181                                         indexfile->close_index();
182                                 }
185 //printf("MainIndexes::run 8\n");
186                         }
187 //printf("MainIndexes::run 9\n");
188                 }
189 //printf("MainIndexes::run 10\n");
191                 if(progress)     // progress box is only created when an index is built
192                 {
193                         if(mwindow->gui) mwindow->gui->lock_window();
194                         progress->stop_progress();
195                         delete progress;
196                         if(mwindow->gui) mwindow->gui->unlock_window();
197                         progress = 0;
198                 }
204 //printf("MainIndexes::run 11\n");
206                 interrupt_lock.unlock();
207         }