6 #include "filesystem.h"
12 #include "mainindexes.h"
13 #include "mainprogress.h"
16 #include "mwindowgui.h"
17 #include "preferences.h"
22 MainIndexes::MainIndexes(MWindow *mwindow)
26 this->mwindow = mwindow;
27 input_lock = new Condition(0, "MainIndexes::input_lock");
28 next_lock = new Mutex("MainIndexes::next_lock");
29 interrupt_lock = new Condition(1, "MainIndexes::interrupt_lock");
32 indexfile = new IndexFile(mwindow);
35 MainIndexes::~MainIndexes()
37 mwindow->mainprogress->cancelled = 1;
42 delete interrupt_lock;
45 void MainIndexes::add_next_asset(File *file, Asset_GC asset)
47 next_lock->lock("MainIndexes::add_next_asset");
50 IndexFile indexfile(mwindow);
54 if(!indexfile.open_index(asset))
56 asset->index_status = INDEX_READY;
57 indexfile.close_index();
63 File *this_file = file;
68 this_file->open_file(mwindow->preferences,
76 char index_filename[BCTEXTLEN];
77 char source_filename[BCTEXTLEN];
78 IndexFile::get_index_filename(source_filename,
79 mwindow->preferences->index_directory,
82 if(!this_file->get_index(index_filename))
84 if(!indexfile.open_index(asset))
86 indexfile.close_index();
87 asset->index_status = INDEX_READY;
91 if(!file) delete this_file;
95 // Put copy of asset in stack, not the real thing.
98 //printf("MainIndexes::add_next_asset 3\n");
99 Asset_GC new_asset = Asset_GC(new Asset);
101 // If the asset existed and was overwritten, the status will be READY.
102 new_asset->index_status = INDEX_NOTTESTED;
103 next_assets.push_back(new_asset);
109 void MainIndexes::delete_current_assets()
111 current_assets.clear();
114 void MainIndexes::start_loop()
120 void MainIndexes::stop_loop()
124 input_lock->unlock();
125 interrupt_lock->unlock();
130 void MainIndexes::start_build()
132 //printf("MainIndexes::start_build 1\n");
134 // Locked up when indexes were already being built and an asset was
136 // interrupt_lock.lock();
137 input_lock->unlock();
140 void MainIndexes::interrupt_build()
142 //printf("MainIndexes::interrupt_build 1\n");
144 indexfile->interrupt_index();
145 //printf("MainIndexes::interrupt_build 2\n");
146 interrupt_lock->lock("MainIndexes::interrupt_build");
147 //printf("MainIndexes::interrupt_build 3\n");
148 interrupt_lock->unlock();
149 //printf("MainIndexes::interrupt_build 4\n");
152 void MainIndexes::load_next_assets()
154 delete_current_assets();
156 // Transfer from new list
157 next_lock->lock("MainIndexes::load_next_assets");
158 for(int i = 0; i < next_assets.size(); i++)
159 current_assets.push_back(next_assets[i]);
161 // Clear pointers from new list only
167 void MainIndexes::run()
171 // Wait for new assets to be released
172 input_lock->lock("MainIndexes::run 1");
174 interrupt_lock->lock("MainIndexes::run 2");
183 // test index of each asset
184 MainProgressBar *progress = 0;
185 for(int i = 0; i < current_assets.size() && !interrupt_flag; i++)
187 Asset_GC current_asset = current_assets[i];
188 //printf("MainIndexes::run 3 %s %d %d\n", current_asset->path, current_asset->index_status, current_asset->audio_data);
190 if(current_asset->index_status == INDEX_NOTTESTED &&
191 current_asset->audio_data)
198 // Doesn't exist if this returns 1.
199 if(indexfile->open_index(current_asset))
201 // Try to create index now.
204 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 1");
205 progress = mwindow->mainprogress->start_progress(_("Building Indexes..."), 1);
206 if(mwindow->gui) mwindow->gui->unlock_window();
209 //printf("MainIndexes::run 5 %p %s\n", current_asset, current_asset->path);
211 indexfile->create_index(current_asset, progress);
212 //printf("MainIndexes::run 6 %p %s\n", current_asset, current_asset->path);
213 if(progress->is_cancelled()) interrupt_flag = 1;
214 //printf("MainIndexes::run 7 %p %s\n", current_asset, current_asset->path);
217 // Exists. Update real thing.
219 //printf("MainIndexes::run 8\n");
220 if(current_asset->index_status == INDEX_NOTTESTED)
222 current_asset->index_status = INDEX_READY;
223 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 2");
224 mwindow->edl->set_index_file(current_asset);
225 if(mwindow->gui) mwindow->gui->unlock_window();
227 indexfile->close_index();
231 //printf("MainIndexes::run 8\n");
233 //printf("MainIndexes::run 9\n");
236 if(progress) // progress box is only created when an index is built
238 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 3");
239 progress->stop_progress();
241 if(mwindow->gui) mwindow->gui->unlock_window();
250 interrupt_lock->unlock();
257 // c-file-style: "linux"